sparsam 0.2.5 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/extconf.rb +59 -1
- data/ext/ruby_hooks.c +16 -12
- data/ext/serializer.cpp +283 -264
- data/ext/serializer.h +41 -20
- data/lib/sparsam/struct.rb +2 -0
- data/spec/gen-ruby/user_types.rb +553 -49
- data/spec/sparsam_spec.rb +127 -0
- data/spec/user.thrift +6 -0
- metadata +3 -4
data/ext/serializer.h
CHANGED
@@ -18,9 +18,9 @@ enum TOType {
|
|
18
18
|
|
19
19
|
enum ValidateStrictness { normal = 0, strict = 1, recursive = 2 };
|
20
20
|
|
21
|
-
void serializer_free(void
|
22
|
-
void
|
23
|
-
void serializer_init(void
|
21
|
+
void serializer_free(void* data);
|
22
|
+
void* serializer_create();
|
23
|
+
void serializer_init(void* serializer, int protocol, void* str_arg1,
|
24
24
|
uint32_t len);
|
25
25
|
|
26
26
|
VALUE serializer_readStruct(VALUE self, VALUE klass);
|
@@ -36,18 +36,36 @@ void initialize_constants();
|
|
36
36
|
void initialize_runtime_constants();
|
37
37
|
|
38
38
|
#ifdef __cplusplus
|
39
|
-
}
|
39
|
+
} // end extern "C"
|
40
40
|
|
41
|
+
#include <thrift/protocol/TProtocol.h>
|
42
|
+
#include <thrift/transport/TBufferTransports.h>
|
41
43
|
#include <boost/shared_ptr.hpp>
|
42
44
|
#include <map>
|
43
45
|
#include <string>
|
44
|
-
#include <thrift/protocol/TProtocol.h>
|
45
|
-
#include <thrift/transport/TBufferTransports.h>
|
46
46
|
#include <unordered_set>
|
47
47
|
#include "third-party/sparsepp/sparsepp/spp.h"
|
48
48
|
|
49
49
|
using ::apache::thrift::protocol::TType;
|
50
50
|
|
51
|
+
// transposed from:
|
52
|
+
// https://github.com/apache/thrift/blob/0.10.0/lib/cpp/src/thrift/protocol/TProtocol.h#L176
|
53
|
+
// with: https://gist.github.com/andyfangdz/d4d52daa9f8a75223e76e92657036bb0
|
54
|
+
// fun fact: it's not sorted there
|
55
|
+
const std::string TTypeNames[] = {
|
56
|
+
"T_STOP", "T_VOID", "T_BOOL", "T_BYTE or T_I08",
|
57
|
+
"T_DOUBLE", "T_UNKNOWN", "T_I16", "T_UNKNOWN",
|
58
|
+
"T_I32", "T_U64", "T_I64", "T_STRING or T_UTF7",
|
59
|
+
"T_STRUCT", "T_MAP", "T_SET", "T_LIST",
|
60
|
+
"T_UTF8", "T_UTF16"};
|
61
|
+
|
62
|
+
const size_t TTypeMaxID = sizeof(TTypeNames) / sizeof(TTypeNames[0]);
|
63
|
+
|
64
|
+
const std::string TTypeUnknown = "T_UNKNOWN";
|
65
|
+
|
66
|
+
#define TTypeName(typeId) \
|
67
|
+
(typeId < TTypeMaxID ? TTypeNames[typeId] : TTypeUnknown)
|
68
|
+
|
51
69
|
typedef uint16_t FieldIdIndex;
|
52
70
|
typedef uint16_t KlassIndex;
|
53
71
|
|
@@ -60,38 +78,41 @@ typedef struct FieldBegin {
|
|
60
78
|
|
61
79
|
typedef struct FieldInfo {
|
62
80
|
TType ftype;
|
63
|
-
VALUE klass;
|
64
|
-
ID ivarName;
|
65
|
-
VALUE symName;
|
81
|
+
VALUE klass; // set if TTYPE is struct or union
|
82
|
+
ID ivarName; // set if field is on struct
|
83
|
+
VALUE symName; // set if field is on struct/union
|
66
84
|
bool isOptional;
|
67
85
|
bool isBinaryString;
|
68
|
-
FieldInfo
|
69
|
-
FieldInfo
|
86
|
+
FieldInfo* elementType; // element of list or set, or map
|
87
|
+
FieldInfo* keyType; // type of key in maps
|
70
88
|
} FieldInfo;
|
71
89
|
|
72
|
-
typedef std::map<FieldID, FieldInfo
|
73
|
-
typedef spp::sparse_hash_map<VALUE, FieldInfoMap
|
90
|
+
typedef std::map<FieldID, FieldInfo*> FieldInfoMap;
|
91
|
+
typedef spp::sparse_hash_map<VALUE, FieldInfoMap*> KlassFieldsCache;
|
74
92
|
|
75
93
|
class ThriftSerializer {
|
76
|
-
public:
|
94
|
+
public:
|
77
95
|
ThriftSerializer(){};
|
96
|
+
// clang-format off
|
78
97
|
boost::shared_ptr< ::apache::thrift::protocol::TProtocol > tprot;
|
79
98
|
boost::shared_ptr< ::apache::thrift::transport::TMemoryBuffer > tmb;
|
99
|
+
// clang-format on
|
80
100
|
|
81
101
|
VALUE readStruct(VALUE klass);
|
82
102
|
VALUE readUnion(VALUE klass);
|
83
103
|
void writeStruct(VALUE klass, VALUE data);
|
84
104
|
|
85
|
-
private:
|
86
|
-
VALUE readAny(TType ttype, FieldInfo
|
87
|
-
void writeAny(TType ttype, FieldInfo
|
105
|
+
private:
|
106
|
+
VALUE readAny(TType ttype, FieldInfo* field_info);
|
107
|
+
void writeAny(TType ttype, FieldInfo* field_info, VALUE data,
|
108
|
+
VALUE outer_struct, VALUE field_sym);
|
88
109
|
void skip_n_type(uint32_t n, TType ttype);
|
89
110
|
void skip_n_pair(uint32_t n, TType type_a, TType type_b);
|
90
111
|
};
|
91
112
|
|
92
|
-
FieldInfoMap
|
93
|
-
FieldInfo
|
94
|
-
FieldInfoMap
|
113
|
+
FieldInfoMap* FindOrCreateFieldInfoMap(VALUE klass);
|
114
|
+
FieldInfo* CreateFieldInfo(VALUE field_map_entry);
|
115
|
+
FieldInfoMap* CreateFieldInfoMap(VALUE klass);
|
95
116
|
|
96
117
|
#endif
|
97
118
|
#endif
|