sparsam 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/ext/ruby_hooks.c +1 -0
- data/ext/serializer.cpp +11 -0
- data/ext/serializer.h +2 -1
- data/lib/sparsam/deserializer.rb +5 -1
- data/spec/sparsam_spec.rb +8 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c47d8f62e5244736a0f3e8e0e02f1f0104d3fb41982da0ca598940d2bfb6bc52
|
4
|
+
data.tar.gz: fe43b9eb4b3167adec9d435269a14ab90b08f4518f9c242875555a144fe3a689
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a62b9bc043e205badb26495651e918b6ff14c6ab3574b2fbf5cbdc00ca61cd1f1bbd7f44ea18ebd40673bde1fffbff57e981cd3db532ffba43451b7e8d71e3b5
|
7
|
+
data.tar.gz: 6d6454f006da2089124019b176d5e916b2a1ff77ff67731601e18cf64275f224afc234b9bd27a5d10ff687992163743bcf804b153cc00526d51155786eb77171
|
data/ext/ruby_hooks.c
CHANGED
@@ -77,6 +77,7 @@ void Init_sparsam_native() {
|
|
77
77
|
rb_define_method(SparsamSerializer, "initialize", initialize, 2);
|
78
78
|
rb_define_method(SparsamSerializer, "serialize", serializer_writeStruct, 2);
|
79
79
|
rb_define_method(SparsamSerializer, "deserialize", serializer_readStruct, 1);
|
80
|
+
rb_define_method(SparsamSerializer, "deserializeUnion", serializer_readUnion, 1);
|
80
81
|
rb_define_const(Sparsam, "CompactProtocol", INT2FIX(compact));
|
81
82
|
rb_define_const(Sparsam, "BinaryProtocol", INT2FIX(binary));
|
82
83
|
rb_define_const(Sparsam, "UNION", INT2FIX(t_union));
|
data/ext/serializer.cpp
CHANGED
@@ -658,6 +658,17 @@ VALUE serializer_readStruct(VALUE self, VALUE klass) {
|
|
658
658
|
catch_thrift_and_reraise();
|
659
659
|
}
|
660
660
|
|
661
|
+
VALUE serializer_readUnion(VALUE self, VALUE klass) {
|
662
|
+
watch_for_texcept() get_ts();
|
663
|
+
string cname;
|
664
|
+
VALUE ret;
|
665
|
+
ts->tprot->readStructBegin(cname);
|
666
|
+
ret = ts->readUnion(klass);
|
667
|
+
ts->tprot->readStructEnd();
|
668
|
+
return ret;
|
669
|
+
catch_thrift_and_reraise();
|
670
|
+
}
|
671
|
+
|
661
672
|
#define R_FIX_TO_TTYPE(x) (static_cast<TType>(FIX2INT(x)))
|
662
673
|
|
663
674
|
FieldInfoMap *FindOrCreateFieldInfoMap(VALUE klass) {
|
data/ext/serializer.h
CHANGED
@@ -24,6 +24,7 @@ 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);
|
27
|
+
VALUE serializer_readUnion(VALUE self, VALUE klass);
|
27
28
|
VALUE serializer_writeStruct(VALUE self, VALUE klass, VALUE data);
|
28
29
|
|
29
30
|
VALUE cache_fields(VALUE self, VALUE klass);
|
@@ -78,10 +79,10 @@ public:
|
|
78
79
|
boost::shared_ptr< ::apache::thrift::transport::TMemoryBuffer > tmb;
|
79
80
|
|
80
81
|
VALUE readStruct(VALUE klass);
|
82
|
+
VALUE readUnion(VALUE klass);
|
81
83
|
void writeStruct(VALUE klass, VALUE data);
|
82
84
|
|
83
85
|
private:
|
84
|
-
VALUE readUnion(VALUE klass);
|
85
86
|
VALUE readAny(TType ttype, FieldInfo *field_info);
|
86
87
|
void writeAny(TType ttype, FieldInfo *field_info, VALUE data, VALUE outer_struct, VALUE field_sym);
|
87
88
|
void skip_n_type(uint32_t n, TType ttype);
|
data/lib/sparsam/deserializer.rb
CHANGED
@@ -2,7 +2,11 @@ module Sparsam
|
|
2
2
|
module Deserializer
|
3
3
|
def self.deserialize(klass, serialized_string, prot = Sparsam::CompactProtocol)
|
4
4
|
s = Sparsam::Serializer.new(prot, serialized_string)
|
5
|
-
|
5
|
+
if klass <= Sparsam::Union
|
6
|
+
s.deserializeUnion(klass)
|
7
|
+
else
|
8
|
+
s.deserialize(klass)
|
9
|
+
end
|
6
10
|
end
|
7
11
|
end
|
8
12
|
end
|
data/spec/sparsam_spec.rb
CHANGED
@@ -79,6 +79,14 @@ describe 'Sparsam' do
|
|
79
79
|
ids.size.should == 0
|
80
80
|
end
|
81
81
|
|
82
|
+
it "can deserialize unions" do
|
83
|
+
data = UN.new({ :id_i32 => 1000 })
|
84
|
+
result = data.serialize
|
85
|
+
data2 = Sparsam::Deserializer.deserialize(UN, result)
|
86
|
+
Sparsam.validate(UN, data2, Sparsam::RECURSIVE).should == true
|
87
|
+
data2.id_i32.should == 1000
|
88
|
+
end
|
89
|
+
|
82
90
|
it "can handle passing in initialization data" do
|
83
91
|
init = { "id_i32" => 10, "id_s" => "woohoo blackbird" }
|
84
92
|
data = SS.new(init)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sparsam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Airbnb Thrift Developers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
version: '0'
|
166
166
|
requirements: []
|
167
167
|
rubyforge_project: thrift
|
168
|
-
rubygems_version: 2.6
|
168
|
+
rubygems_version: 2.7.6
|
169
169
|
signing_key:
|
170
170
|
specification_version: 4
|
171
171
|
summary: Ruby bindings for Apache Thrift
|