sparsam 0.2.7 → 0.2.10
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 +5 -5
- data/ext/extconf.rb +59 -1
- data/ext/serializer.cpp +5 -11
- data/lib/sparsam/struct.rb +2 -0
- data/spec/gen-ruby/user_types.rb +1 -0
- data/spec/sparsam_spec.rb +72 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c759ead3b6f09dd4e6b1e1754dc0443ea782e37fd717617d4069e5952605bc85
|
4
|
+
data.tar.gz: 3734e8cfa8796efdcfe78a702a536672bf88e5e442fdedb1e59b60602b34daaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9eec207eba73e7fdb9a53edf2de172f34d640cfc15d484804204b929ecdc4caf223eb76a01be496487734ca1af54760fc1e7ad9cf4622e27183e4c4db24fa323
|
7
|
+
data.tar.gz: 27a9faadcf29db90b72d14a1b775c10ac9004a31f98562f1906c771a8f923124f1290feef5df5e2e8aefc39912ccaedc2b783b8461573eab71b2afc9770d6f4a
|
data/ext/extconf.rb
CHANGED
@@ -7,12 +7,70 @@ if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')
|
|
7
7
|
$CPPFLAGS += $CXXFLAGS
|
8
8
|
end
|
9
9
|
|
10
|
+
brew = find_executable('brew')
|
11
|
+
|
12
|
+
# Automatically use homebrew to discover thrift package if it is
|
13
|
+
# available and not disabled via --disable-homebrew.
|
14
|
+
use_homebrew = enable_config('homebrew', brew)
|
15
|
+
|
16
|
+
if use_homebrew
|
17
|
+
$stderr.puts "Using #{brew} to locate thrift and boost packages"
|
18
|
+
$stderr.puts '(disable Homebrew integration via --disable-homebrew)'
|
19
|
+
|
20
|
+
thrift_package = with_config('homebrew-thrift-package', 'thrift@0.9')
|
21
|
+
$stderr.puts "looking for Homebrew thrift package '#{thrift_package}'"
|
22
|
+
$stderr.puts '(change Homebrew thrift package name via --with-homebrew-thrift-package=<package>)'
|
23
|
+
|
24
|
+
thrift_prefix = `#{brew} --prefix #{thrift_package}`.strip
|
25
|
+
|
26
|
+
unless File.exists?(thrift_prefix)
|
27
|
+
$stderr.puts "#{thrift_prefix} does not exist"
|
28
|
+
$stderr.puts "To resolve, `brew install #{thrift_package}` or pass"
|
29
|
+
$stderr.puts '--with-homebrew-thrift-package=<package> to this build to specify'
|
30
|
+
$stderr.puts 'an alternative thrift package to build against. e.g.:'
|
31
|
+
$stderr.puts
|
32
|
+
$stderr.puts ' $ bundle config --global build.sparsam --with-homebrew-thrift-package=mythrift'
|
33
|
+
|
34
|
+
raise "Homebrew package #{thrift_package} not installed"
|
35
|
+
end
|
36
|
+
|
37
|
+
$stderr.puts "using Homebrew thrift at #{thrift_prefix}"
|
38
|
+
$CFLAGS << " -I#{thrift_prefix}/include"
|
39
|
+
$CXXFLAGS << " -I#{thrift_prefix}/include"
|
40
|
+
$CPPFLAGS << " -I#{thrift_prefix}/include"
|
41
|
+
$LDFLAGS << " -L#{thrift_prefix}/lib"
|
42
|
+
|
43
|
+
# Also add boost to the includes search path if it is installed.
|
44
|
+
boost_package = with_config('homebrew-boost-package', 'boost')
|
45
|
+
$stderr.puts "looking for Homebrew boost package '#{boost_package}'"
|
46
|
+
$stderr.puts '(change Homebrew boost package name via --with-homebrew-boost-package=<package>)'
|
47
|
+
|
48
|
+
boost_prefix = `#{brew} --prefix #{boost_package}`.strip
|
49
|
+
|
50
|
+
if File.exists?(boost_prefix)
|
51
|
+
$stderr.puts("using Homebrew boost at #{boost_prefix}")
|
52
|
+
$CFLAGS << " -I#{boost_prefix}/include"
|
53
|
+
$CXXFLAGS << " -I#{boost_prefix}/include"
|
54
|
+
$CPPFLAGS << " -I#{boost_prefix}/include"
|
55
|
+
else
|
56
|
+
$stderr.puts 'Homebrew boost not found; assuming boost is in default search paths'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
10
60
|
have_func("strlcpy", "string.h")
|
11
|
-
|
61
|
+
|
62
|
+
unless have_library("thrift")
|
63
|
+
raise 'thrift library not found; aborting since compile would fail'
|
64
|
+
end
|
65
|
+
|
12
66
|
libs = ['-lthrift']
|
13
67
|
|
14
68
|
libs.each do |lib|
|
15
69
|
$LOCAL_LIBS << "#{lib} "
|
16
70
|
end
|
17
71
|
|
72
|
+
# Ideally we'd validate boost as well. But boost is header only and
|
73
|
+
# mkmf's have_header() doesn't work with C++ headers.
|
74
|
+
# https://bugs.ruby-lang.org/issues/4924
|
75
|
+
|
18
76
|
create_makefile 'sparsam_native'
|
data/ext/serializer.cpp
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
extern "C" {
|
2
1
|
#include <ruby.h>
|
3
2
|
#include <ruby/intern.h>
|
4
|
-
}
|
5
3
|
#include <ruby/encoding.h>
|
6
4
|
#include <stdio.h>
|
7
5
|
#include <thrift/protocol/TBinaryProtocol.h>
|
@@ -51,6 +49,8 @@ VALUE SetClass;
|
|
51
49
|
KlassFieldsCache klassCache; // consider the memory leaked.
|
52
50
|
std::unordered_set<VALUE> unions;
|
53
51
|
|
52
|
+
#define SPARSAM_CHECK_TYPE(x, t, outer_struct, field_sym) if (!(RB_TYPE_P(x, t))) { raise_type_mismatch(outer_struct, field_sym, t, x); }
|
53
|
+
|
54
54
|
void *serializer_create() { return (void *)(new ThriftSerializer()); }
|
55
55
|
|
56
56
|
void serializer_free(void *data) {
|
@@ -185,12 +185,6 @@ static inline long raise_type_mismatch_as_value(VALUE outer_struct,
|
|
185
185
|
return 0;
|
186
186
|
}
|
187
187
|
|
188
|
-
static inline void Sparsam_Check_Type(VALUE x, int t, VALUE outer_struct,
|
189
|
-
VALUE field_sym) {
|
190
|
-
if (!(RB_TYPE_P(x, t))) {
|
191
|
-
raise_type_mismatch(outer_struct, field_sym, t, x);
|
192
|
-
}
|
193
|
-
}
|
194
188
|
|
195
189
|
static inline VALUE make_ruby_bool(bool val) { return val ? Qtrue : Qfalse; }
|
196
190
|
|
@@ -513,7 +507,7 @@ void ThriftSerializer::writeAny(TType ttype, FieldInfo *field_info,
|
|
513
507
|
HANDLE_TYPE(BYTE, Byte, CONVERT_FIXNUM(byte_convert, protocol::T_BYTE))
|
514
508
|
|
515
509
|
case protocol::T_STRING: {
|
516
|
-
|
510
|
+
SPARSAM_CHECK_TYPE(actual, T_STRING, outer_struct, field_sym);
|
517
511
|
|
518
512
|
string data = string(StringValuePtr(actual), RSTRING_LEN(actual));
|
519
513
|
if (field_info->isBinaryString) {
|
@@ -525,7 +519,7 @@ void ThriftSerializer::writeAny(TType ttype, FieldInfo *field_info,
|
|
525
519
|
}
|
526
520
|
|
527
521
|
case protocol::T_LIST: {
|
528
|
-
|
522
|
+
SPARSAM_CHECK_TYPE(actual, T_ARRAY, outer_struct, field_sym);
|
529
523
|
|
530
524
|
long length = RARRAY_LEN(actual);
|
531
525
|
TType elem = field_info->elementType->ftype;
|
@@ -556,7 +550,7 @@ void ThriftSerializer::writeAny(TType ttype, FieldInfo *field_info,
|
|
556
550
|
}
|
557
551
|
|
558
552
|
case protocol::T_MAP: {
|
559
|
-
|
553
|
+
SPARSAM_CHECK_TYPE(actual, T_HASH, outer_struct, field_sym);
|
560
554
|
|
561
555
|
TType keyTType = field_info->keyType->ftype,
|
562
556
|
valueTType = field_info->elementType->ftype;
|
data/lib/sparsam/struct.rb
CHANGED
data/spec/gen-ruby/user_types.rb
CHANGED
@@ -13,6 +13,7 @@ module Magic
|
|
13
13
|
Blue = 3
|
14
14
|
Green = 4
|
15
15
|
VALUE_MAP = {0 => "Black", 1 => "White", 2 => "Red", 3 => "Blue", 4 => "Green"}
|
16
|
+
INVERTED_VALUE_MAP = {"Black" => 0, "White" => 1, "Red" => 2, "Blue" => 3, "Green" => 4}
|
16
17
|
VALID_VALUES = Set.new([Black, White, Red, Blue, Green]).freeze
|
17
18
|
end
|
18
19
|
|
data/spec/sparsam_spec.rb
CHANGED
@@ -546,4 +546,76 @@ describe 'Sparsam' do
|
|
546
546
|
end
|
547
547
|
end
|
548
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
|
549
621
|
end
|
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.10
|
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-05-19 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.5.1
|
167
|
+
rubygems_version: 3.0.3.1
|
169
168
|
signing_key:
|
170
169
|
specification_version: 4
|
171
170
|
summary: Ruby bindings for Apache Thrift
|