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.
- 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/spec/sparsam_spec.rb
CHANGED
@@ -227,6 +227,44 @@ describe 'Sparsam' do
|
|
227
227
|
e.field_name.should == "id_i32"
|
228
228
|
end
|
229
229
|
|
230
|
+
it "includes additional information on serializing mismatched types" do
|
231
|
+
data = MiniRequired.new
|
232
|
+
data.id_i32 = "not an i32"
|
233
|
+
|
234
|
+
e = nil
|
235
|
+
begin
|
236
|
+
data.serialize
|
237
|
+
rescue Sparsam::TypeMismatch => exception
|
238
|
+
e = exception
|
239
|
+
end
|
240
|
+
e.message.should include("T_I32", "String")
|
241
|
+
|
242
|
+
data = EveryType.new
|
243
|
+
data.a_struct = EveryType.new
|
244
|
+
|
245
|
+
e = nil
|
246
|
+
begin
|
247
|
+
data.serialize
|
248
|
+
rescue Sparsam::TypeMismatch => exception
|
249
|
+
e = exception
|
250
|
+
end
|
251
|
+
e.message.should include("US", "EveryType")
|
252
|
+
end
|
253
|
+
|
254
|
+
it "includes additional information on deserializing mismatched types" do
|
255
|
+
data = NotSS.new
|
256
|
+
data.id_s = "not an i32"
|
257
|
+
|
258
|
+
serialized = data.serialize
|
259
|
+
|
260
|
+
begin
|
261
|
+
Sparsam::Deserializer.deserialize(SS, serialized)
|
262
|
+
rescue Sparsam::TypeMismatch => exception
|
263
|
+
e = exception
|
264
|
+
end
|
265
|
+
e.message.should include("T_I32", "T_STRING")
|
266
|
+
end
|
267
|
+
|
230
268
|
it "will throw errors when given junk data" do
|
231
269
|
expect {
|
232
270
|
Sparsam::Deserializer.deserialize(SS, "wolololololol")
|
@@ -451,6 +489,23 @@ describe 'Sparsam' do
|
|
451
489
|
end
|
452
490
|
end
|
453
491
|
|
492
|
+
it 'handles recursive structs' do
|
493
|
+
recursive_struct = RecursiveStruct.new
|
494
|
+
recursive_struct.id = 1
|
495
|
+
recursive_struct.self_struct = RecursiveStruct.new
|
496
|
+
recursive_struct.self_struct.id = 2
|
497
|
+
recursive_struct.self_list = [RecursiveStruct.new]
|
498
|
+
recursive_struct.self_list[0].id = 3
|
499
|
+
|
500
|
+
data = recursive_struct.serialize
|
501
|
+
|
502
|
+
new_recursive = Sparsam::Deserializer.deserialize(RecursiveStruct, data)
|
503
|
+
|
504
|
+
new_recursive.id.should == 1
|
505
|
+
new_recursive.self_struct.id.should == 2
|
506
|
+
new_recursive.self_list[0].id.should == 3
|
507
|
+
end
|
508
|
+
|
454
509
|
it 'handles structs with modified eigenclasses' do
|
455
510
|
nested_struct = US.new
|
456
511
|
|
@@ -491,4 +546,76 @@ describe 'Sparsam' do
|
|
491
546
|
end
|
492
547
|
end
|
493
548
|
end
|
549
|
+
|
550
|
+
describe 'generated enum types' do
|
551
|
+
let(:enum_module) { Magic }
|
552
|
+
|
553
|
+
it 'includes thrift constants as top level module constants' do
|
554
|
+
enum_module.const_defined?(:Black).should == true
|
555
|
+
enum_module.const_defined?(:White).should == true
|
556
|
+
enum_module.const_defined?(:Red).should == true
|
557
|
+
enum_module.const_defined?(:Blue).should == true
|
558
|
+
enum_module.const_defined?(:Green).should == true
|
559
|
+
|
560
|
+
enum_module.const_get(:Black).should == 0
|
561
|
+
enum_module.const_get(:White).should == 1
|
562
|
+
enum_module.const_get(:Red).should == 2
|
563
|
+
enum_module.const_get(:Blue).should == 3
|
564
|
+
enum_module.const_get(:Green).should == 4
|
565
|
+
end
|
566
|
+
|
567
|
+
it 'contains a VALUE_MAP constant that maps from int value to string' do
|
568
|
+
enum_module.const_defined?(:VALUE_MAP).should == true
|
569
|
+
|
570
|
+
value_map = enum_module.const_get(:VALUE_MAP)
|
571
|
+
|
572
|
+
value_map.should eql({
|
573
|
+
0 => 'Black',
|
574
|
+
1 => 'White',
|
575
|
+
2 => 'Red',
|
576
|
+
3 => 'Blue',
|
577
|
+
4 => 'Green',
|
578
|
+
})
|
579
|
+
|
580
|
+
value_map[enum_module.const_get(:Black)].should == 'Black'
|
581
|
+
value_map[enum_module.const_get(:White)].should == 'White'
|
582
|
+
value_map[enum_module.const_get(:Red)].should == 'Red'
|
583
|
+
value_map[enum_module.const_get(:Blue)].should == 'Blue'
|
584
|
+
value_map[enum_module.const_get(:Green)].should == 'Green'
|
585
|
+
end
|
586
|
+
|
587
|
+
it 'contains an INVERTED_VALUE_MAP constant that maps from name to int value' do
|
588
|
+
enum_module.const_defined?(:INVERTED_VALUE_MAP).should == true
|
589
|
+
|
590
|
+
inverted_value_map = enum_module.const_get(:INVERTED_VALUE_MAP)
|
591
|
+
|
592
|
+
inverted_value_map.should eql({
|
593
|
+
'Black' => 0,
|
594
|
+
'White' => 1,
|
595
|
+
'Red' => 2,
|
596
|
+
'Blue' => 3,
|
597
|
+
'Green' => 4,
|
598
|
+
})
|
599
|
+
|
600
|
+
inverted_value_map['Black'].should == enum_module.const_get(:Black)
|
601
|
+
inverted_value_map['White'].should == enum_module.const_get(:White)
|
602
|
+
inverted_value_map['Red'].should == enum_module.const_get(:Red)
|
603
|
+
inverted_value_map['Blue'].should == enum_module.const_get(:Blue)
|
604
|
+
inverted_value_map['Green'].should == enum_module.const_get(:Green)
|
605
|
+
end
|
606
|
+
|
607
|
+
it 'contains a VALID_VALUES constant that is a set of all enum values' do
|
608
|
+
enum_module.const_defined?(:VALID_VALUES).should == true
|
609
|
+
|
610
|
+
valid_values = enum_module.const_get(:VALID_VALUES)
|
611
|
+
|
612
|
+
valid_values.should be_a(Set)
|
613
|
+
valid_values.should include(enum_module.const_get(:Black))
|
614
|
+
valid_values.should include(enum_module.const_get(:White))
|
615
|
+
valid_values.should include(enum_module.const_get(:Red))
|
616
|
+
valid_values.should include(enum_module.const_get(:Blue))
|
617
|
+
valid_values.should include(enum_module.const_get(:Green))
|
618
|
+
valid_values.length.should == 5
|
619
|
+
end
|
620
|
+
end
|
494
621
|
end
|
data/spec/user.thrift
CHANGED
@@ -82,6 +82,12 @@ struct EveryType {
|
|
82
82
|
15: optional UN a_union
|
83
83
|
}
|
84
84
|
|
85
|
+
struct RecursiveStruct {
|
86
|
+
1: optional i64 id
|
87
|
+
2: optional RecursiveStruct self_struct
|
88
|
+
3: optional list<RecursiveStruct> self_list
|
89
|
+
}
|
90
|
+
|
85
91
|
exception SimpleException {
|
86
92
|
1: optional string message
|
87
93
|
}
|
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.9
|
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:
|
11
|
+
date: 2022-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -164,8 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
164
|
- !ruby/object:Gem::Version
|
165
165
|
version: '0'
|
166
166
|
requirements: []
|
167
|
-
|
168
|
-
rubygems_version: 2.7.6
|
167
|
+
rubygems_version: 3.0.3.1
|
169
168
|
signing_key:
|
170
169
|
specification_version: 4
|
171
170
|
summary: Ruby bindings for Apache Thrift
|