sparsam 0.2.5 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 *data);
22
- void *serializer_create();
23
- void serializer_init(void *serializer, int protocol, void *str_arg1,
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
- } // end extern "C"
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; // set if TTYPE is struct or union
64
- ID ivarName; // set if field is on struct
65
- VALUE symName; // set if field is on struct/union
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 *elementType; // element of list or set, or map
69
- FieldInfo *keyType; // type of key in maps
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 *> FieldInfoMap;
73
- typedef spp::sparse_hash_map<VALUE, FieldInfoMap *> KlassFieldsCache;
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 *field_info);
87
- void writeAny(TType ttype, FieldInfo *field_info, VALUE data, VALUE outer_struct, VALUE field_sym);
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 *FindOrCreateFieldInfoMap(VALUE klass);
93
- FieldInfo *CreateFieldInfo(VALUE field_map_entry);
94
- FieldInfoMap *CreateFieldInfoMap(VALUE klass);
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
@@ -16,6 +16,8 @@ module Sparsam
16
16
  reader = name_to_accessors(info[:name]).reader
17
17
  return false unless send(reader) == other.send(reader)
18
18
  end
19
+
20
+ true
19
21
  end
20
22
  alias_method :eql?, :==
21
23
  end