sparsam 0.2.4 → 0.2.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 463e62afdb83d72613bae91f8bdfa8ee62863674
4
- data.tar.gz: 8f53fa9ee9251f405deca43fc23940976e0c610e
2
+ SHA256:
3
+ metadata.gz: c47d8f62e5244736a0f3e8e0e02f1f0104d3fb41982da0ca598940d2bfb6bc52
4
+ data.tar.gz: fe43b9eb4b3167adec9d435269a14ab90b08f4518f9c242875555a144fe3a689
5
5
  SHA512:
6
- metadata.gz: 2fc153a2a4eccfd8c1b9c6ececaa5d5414a4c770544d07e32a3f07e034dde7ee7f5b52966abd50622eb40fea22dd43fb246058e34c47d4cf258ff4b1acf80b7a
7
- data.tar.gz: ace526ffb1c1d231458273b9b0a5fb967edcf6b360af9a4e32ff9517359da890793e05afd263a778dedea5fd61a04253ac695c04fdf7e57a684cac4b0ef3f3a7
6
+ metadata.gz: a62b9bc043e205badb26495651e918b6ff14c6ab3574b2fbf5cbdc00ca61cd1f1bbd7f44ea18ebd40673bde1fffbff57e981cd3db532ffba43451b7e8d71e3b5
7
+ data.tar.gz: 6d6454f006da2089124019b176d5e916b2a1ff77ff67731601e18cf64275f224afc234b9bd27a5d10ff687992163743bcf804b153cc00526d51155786eb77171
@@ -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));
@@ -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) {
@@ -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);
@@ -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
- s.deserialize(klass)
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
@@ -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
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-02-23 00:00:00.000000000 Z
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.11
168
+ rubygems_version: 2.7.6
169
169
  signing_key:
170
170
  specification_version: 4
171
171
  summary: Ruby bindings for Apache Thrift