google-protobuf 3.7.0 → 3.11.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of google-protobuf might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/ext/google/protobuf_c/defs.c +851 -830
- data/ext/google/protobuf_c/encode_decode.c +477 -293
- data/ext/google/protobuf_c/extconf.rb +2 -4
- data/ext/google/protobuf_c/map.c +21 -8
- data/ext/google/protobuf_c/message.c +194 -77
- data/ext/google/protobuf_c/protobuf.c +30 -15
- data/ext/google/protobuf_c/protobuf.h +113 -60
- data/ext/google/protobuf_c/repeated_field.c +55 -23
- data/ext/google/protobuf_c/storage.c +291 -161
- data/ext/google/protobuf_c/upb.c +4824 -8853
- data/ext/google/protobuf_c/upb.h +4699 -7369
- data/lib/google/protobuf/any_pb.rb +1 -1
- data/lib/google/protobuf/api_pb.rb +3 -3
- data/lib/google/protobuf/duration_pb.rb +1 -1
- data/lib/google/protobuf/empty_pb.rb +1 -1
- data/lib/google/protobuf/field_mask_pb.rb +1 -1
- data/lib/google/protobuf/source_context_pb.rb +1 -1
- data/lib/google/protobuf/struct_pb.rb +4 -4
- data/lib/google/protobuf/timestamp_pb.rb +1 -1
- data/lib/google/protobuf/type_pb.rb +8 -8
- data/lib/google/protobuf/well_known_types.rb +8 -2
- data/lib/google/protobuf/wrappers_pb.rb +9 -9
- data/lib/google/protobuf.rb +70 -0
- data/tests/basic.rb +104 -20
- metadata +6 -6
@@ -34,8 +34,8 @@ end
|
|
34
34
|
|
35
35
|
module Google
|
36
36
|
module Protobuf
|
37
|
-
Api = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Api").msgclass
|
38
|
-
Method = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Method").msgclass
|
39
|
-
Mixin = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Mixin").msgclass
|
37
|
+
Api = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Api").msgclass
|
38
|
+
Method = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Method").msgclass
|
39
|
+
Mixin = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Mixin").msgclass
|
40
40
|
end
|
41
41
|
end
|
@@ -14,6 +14,6 @@ end
|
|
14
14
|
|
15
15
|
module Google
|
16
16
|
module Protobuf
|
17
|
-
Duration = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Duration").msgclass
|
17
|
+
Duration = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Duration").msgclass
|
18
18
|
end
|
19
19
|
end
|
@@ -13,6 +13,6 @@ end
|
|
13
13
|
|
14
14
|
module Google
|
15
15
|
module Protobuf
|
16
|
-
FieldMask = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldMask").msgclass
|
16
|
+
FieldMask = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldMask").msgclass
|
17
17
|
end
|
18
18
|
end
|
@@ -13,6 +13,6 @@ end
|
|
13
13
|
|
14
14
|
module Google
|
15
15
|
module Protobuf
|
16
|
-
SourceContext = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.SourceContext").msgclass
|
16
|
+
SourceContext = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.SourceContext").msgclass
|
17
17
|
end
|
18
18
|
end
|
@@ -29,9 +29,9 @@ end
|
|
29
29
|
|
30
30
|
module Google
|
31
31
|
module Protobuf
|
32
|
-
Struct = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Struct").msgclass
|
33
|
-
Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Value").msgclass
|
34
|
-
ListValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ListValue").msgclass
|
35
|
-
NullValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.NullValue").enummodule
|
32
|
+
Struct = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Struct").msgclass
|
33
|
+
Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Value").msgclass
|
34
|
+
ListValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.ListValue").msgclass
|
35
|
+
NullValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.NullValue").enummodule
|
36
36
|
end
|
37
37
|
end
|
@@ -14,6 +14,6 @@ end
|
|
14
14
|
|
15
15
|
module Google
|
16
16
|
module Protobuf
|
17
|
-
Timestamp = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Timestamp").msgclass
|
17
|
+
Timestamp = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Timestamp").msgclass
|
18
18
|
end
|
19
19
|
end
|
@@ -79,13 +79,13 @@ end
|
|
79
79
|
|
80
80
|
module Google
|
81
81
|
module Protobuf
|
82
|
-
Type = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Type").msgclass
|
83
|
-
Field = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field").msgclass
|
84
|
-
Field::Kind = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field.Kind").enummodule
|
85
|
-
Field::Cardinality = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field.Cardinality").enummodule
|
86
|
-
Enum = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Enum").msgclass
|
87
|
-
EnumValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumValue").msgclass
|
88
|
-
Option = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Option").msgclass
|
89
|
-
Syntax = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Syntax").enummodule
|
82
|
+
Type = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Type").msgclass
|
83
|
+
Field = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field").msgclass
|
84
|
+
Field::Kind = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field.Kind").enummodule
|
85
|
+
Field::Cardinality = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Field.Cardinality").enummodule
|
86
|
+
Enum = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Enum").msgclass
|
87
|
+
EnumValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumValue").msgclass
|
88
|
+
Option = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Option").msgclass
|
89
|
+
Syntax = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Syntax").enummodule
|
90
90
|
end
|
91
91
|
end
|
@@ -72,8 +72,14 @@ module Google
|
|
72
72
|
end
|
73
73
|
|
74
74
|
Timestamp.class_eval do
|
75
|
-
|
76
|
-
|
75
|
+
if RUBY_VERSION < "2.5"
|
76
|
+
def to_time
|
77
|
+
Time.at(self.to_f)
|
78
|
+
end
|
79
|
+
else
|
80
|
+
def to_time
|
81
|
+
Time.at(seconds, nanos, :nanosecond)
|
82
|
+
end
|
77
83
|
end
|
78
84
|
|
79
85
|
def from_time(time)
|
@@ -37,14 +37,14 @@ end
|
|
37
37
|
|
38
38
|
module Google
|
39
39
|
module Protobuf
|
40
|
-
DoubleValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DoubleValue").msgclass
|
41
|
-
FloatValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FloatValue").msgclass
|
42
|
-
Int64Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Int64Value").msgclass
|
43
|
-
UInt64Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UInt64Value").msgclass
|
44
|
-
Int32Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Int32Value").msgclass
|
45
|
-
UInt32Value = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UInt32Value").msgclass
|
46
|
-
BoolValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.BoolValue").msgclass
|
47
|
-
StringValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.StringValue").msgclass
|
48
|
-
BytesValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.BytesValue").msgclass
|
40
|
+
DoubleValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.DoubleValue").msgclass
|
41
|
+
FloatValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FloatValue").msgclass
|
42
|
+
Int64Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Int64Value").msgclass
|
43
|
+
UInt64Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UInt64Value").msgclass
|
44
|
+
Int32Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Int32Value").msgclass
|
45
|
+
UInt32Value = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.UInt32Value").msgclass
|
46
|
+
BoolValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.BoolValue").msgclass
|
47
|
+
StringValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.StringValue").msgclass
|
48
|
+
BytesValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.BytesValue").msgclass
|
49
49
|
end
|
50
50
|
end
|
data/lib/google/protobuf.rb
CHANGED
@@ -50,6 +50,76 @@ else
|
|
50
50
|
rescue LoadError
|
51
51
|
require 'google/protobuf_c'
|
52
52
|
end
|
53
|
+
|
54
|
+
module Google
|
55
|
+
module Protobuf
|
56
|
+
module Internal
|
57
|
+
def self.infer_package(names)
|
58
|
+
# Package is longest common prefix ending in '.', if any.
|
59
|
+
if not names.empty?
|
60
|
+
min, max = names.minmax
|
61
|
+
last_common_dot = nil
|
62
|
+
min.size.times { |i|
|
63
|
+
if min[i] != max[i] then break end
|
64
|
+
if min[i] == ?. then last_common_dot = i end
|
65
|
+
}
|
66
|
+
if last_common_dot
|
67
|
+
return min.slice(0, last_common_dot)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
nil
|
72
|
+
end
|
73
|
+
|
74
|
+
class NestingBuilder
|
75
|
+
def initialize(msg_names, enum_names)
|
76
|
+
@to_pos = {nil=>nil}
|
77
|
+
@msg_children = Hash.new { |hash, key| hash[key] = [] }
|
78
|
+
@enum_children = Hash.new { |hash, key| hash[key] = [] }
|
79
|
+
|
80
|
+
msg_names.each_with_index { |name, idx| @to_pos[name] = idx }
|
81
|
+
enum_names.each_with_index { |name, idx| @to_pos[name] = idx }
|
82
|
+
|
83
|
+
msg_names.each { |name| @msg_children[parent(name)] << name }
|
84
|
+
enum_names.each { |name| @enum_children[parent(name)] << name }
|
85
|
+
end
|
86
|
+
|
87
|
+
def build(package)
|
88
|
+
return build_msg(package)
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
def build_msg(msg)
|
93
|
+
return {
|
94
|
+
:pos => @to_pos[msg],
|
95
|
+
:msgs => @msg_children[msg].map { |child| build_msg(child) },
|
96
|
+
:enums => @enum_children[msg].map { |child| @to_pos[child] },
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
def parent(name)
|
102
|
+
idx = name.rindex(?.)
|
103
|
+
if idx
|
104
|
+
return name.slice(0, idx)
|
105
|
+
else
|
106
|
+
return nil
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.fixup_descriptor(package, msg_names, enum_names)
|
112
|
+
if package.nil?
|
113
|
+
package = self.infer_package(msg_names + enum_names)
|
114
|
+
end
|
115
|
+
|
116
|
+
nesting = NestingBuilder.new(msg_names, enum_names).build(package)
|
117
|
+
|
118
|
+
return package, nesting
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
53
123
|
end
|
54
124
|
|
55
125
|
require 'google/protobuf/repeated_field'
|
data/tests/basic.rb
CHANGED
@@ -17,7 +17,6 @@ module BasicTest
|
|
17
17
|
add_message "BadFieldNames" do
|
18
18
|
optional :dup, :int32, 1
|
19
19
|
optional :class, :int32, 2
|
20
|
-
optional :"a.b", :int32, 3
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
@@ -154,12 +153,12 @@ module BasicTest
|
|
154
153
|
e = assert_raise ArgumentError do
|
155
154
|
MapMessage.new(:map_string_int32 => "hello")
|
156
155
|
end
|
157
|
-
assert_equal e.message, "Expected Hash object as initializer value for map field 'map_string_int32'."
|
156
|
+
assert_equal e.message, "Expected Hash object as initializer value for map field 'map_string_int32' (given String)."
|
158
157
|
|
159
158
|
e = assert_raise ArgumentError do
|
160
159
|
TestMessage.new(:repeated_uint32 => "hello")
|
161
160
|
end
|
162
|
-
assert_equal e.message, "Expected array as initializer value for repeated field 'repeated_uint32'."
|
161
|
+
assert_equal e.message, "Expected array as initializer value for repeated field 'repeated_uint32' (given String)."
|
163
162
|
end
|
164
163
|
|
165
164
|
def test_map_field
|
@@ -170,10 +169,12 @@ module BasicTest
|
|
170
169
|
m = MapMessage.new(
|
171
170
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
172
171
|
:map_string_msg => {"a" => TestMessage2.new(:foo => 1),
|
173
|
-
"b" => TestMessage2.new(:foo => 2)}
|
172
|
+
"b" => TestMessage2.new(:foo => 2)},
|
173
|
+
:map_string_enum => {"a" => :A, "b" => :B})
|
174
174
|
assert m.map_string_int32.keys.sort == ["a", "b"]
|
175
175
|
assert m.map_string_int32["a"] == 1
|
176
176
|
assert m.map_string_msg["b"].foo == 2
|
177
|
+
assert m.map_string_enum["a"] == :A
|
177
178
|
|
178
179
|
m.map_string_int32["c"] = 3
|
179
180
|
assert m.map_string_int32["c"] == 3
|
@@ -202,12 +203,27 @@ module BasicTest
|
|
202
203
|
end
|
203
204
|
end
|
204
205
|
|
206
|
+
def test_map_field_with_symbol
|
207
|
+
m = MapMessage.new
|
208
|
+
assert m.map_string_int32 == {}
|
209
|
+
assert m.map_string_msg == {}
|
210
|
+
|
211
|
+
m = MapMessage.new(
|
212
|
+
:map_string_int32 => {a: 1, "b" => 2},
|
213
|
+
:map_string_msg => {a: TestMessage2.new(:foo => 1),
|
214
|
+
b: TestMessage2.new(:foo => 10)})
|
215
|
+
assert_equal 1, m.map_string_int32[:a]
|
216
|
+
assert_equal 2, m.map_string_int32[:b]
|
217
|
+
assert_equal 10, m.map_string_msg[:b].foo
|
218
|
+
end
|
219
|
+
|
205
220
|
def test_map_inspect
|
206
221
|
m = MapMessage.new(
|
207
222
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
208
223
|
:map_string_msg => {"a" => TestMessage2.new(:foo => 1),
|
209
|
-
"b" => TestMessage2.new(:foo => 2)}
|
210
|
-
|
224
|
+
"b" => TestMessage2.new(:foo => 2)},
|
225
|
+
:map_string_enum => {"a" => :A, "b" => :B})
|
226
|
+
expected = "<BasicTest::MapMessage: map_string_int32: {\"b\"=>2, \"a\"=>1}, map_string_msg: {\"b\"=><BasicTest::TestMessage2: foo: 2>, \"a\"=><BasicTest::TestMessage2: foo: 1>}, map_string_enum: {\"b\"=>:B, \"a\"=>:A}>"
|
211
227
|
assert_equal expected, m.inspect
|
212
228
|
end
|
213
229
|
|
@@ -218,6 +234,48 @@ module BasicTest
|
|
218
234
|
m.map_string_int32['aaa'] = 3
|
219
235
|
end
|
220
236
|
|
237
|
+
def test_map_wrappers
|
238
|
+
run_asserts = ->(m) {
|
239
|
+
assert_equal 2.0, m.map_double[0].value
|
240
|
+
assert_equal 4.0, m.map_float[0].value
|
241
|
+
assert_equal 3, m.map_int32[0].value
|
242
|
+
assert_equal 4, m.map_int64[0].value
|
243
|
+
assert_equal 5, m.map_uint32[0].value
|
244
|
+
assert_equal 6, m.map_uint64[0].value
|
245
|
+
assert_equal true, m.map_bool[0].value
|
246
|
+
assert_equal 'str', m.map_string[0].value
|
247
|
+
assert_equal 'fun', m.map_bytes[0].value
|
248
|
+
}
|
249
|
+
|
250
|
+
m = proto_module::Wrapper.new(
|
251
|
+
map_double: {0 => Google::Protobuf::DoubleValue.new(value: 2.0)},
|
252
|
+
map_float: {0 => Google::Protobuf::FloatValue.new(value: 4.0)},
|
253
|
+
map_int32: {0 => Google::Protobuf::Int32Value.new(value: 3)},
|
254
|
+
map_int64: {0 => Google::Protobuf::Int64Value.new(value: 4)},
|
255
|
+
map_uint32: {0 => Google::Protobuf::UInt32Value.new(value: 5)},
|
256
|
+
map_uint64: {0 => Google::Protobuf::UInt64Value.new(value: 6)},
|
257
|
+
map_bool: {0 => Google::Protobuf::BoolValue.new(value: true)},
|
258
|
+
map_string: {0 => Google::Protobuf::StringValue.new(value: 'str')},
|
259
|
+
map_bytes: {0 => Google::Protobuf::BytesValue.new(value: 'fun')},
|
260
|
+
)
|
261
|
+
|
262
|
+
run_asserts.call(m)
|
263
|
+
serialized = proto_module::Wrapper::encode(m)
|
264
|
+
m2 = proto_module::Wrapper::decode(serialized)
|
265
|
+
run_asserts.call(m2)
|
266
|
+
|
267
|
+
# Test the case where we are serializing directly from the parsed form
|
268
|
+
# (before anything lazy is materialized).
|
269
|
+
m3 = proto_module::Wrapper::decode(serialized)
|
270
|
+
serialized2 = proto_module::Wrapper::encode(m3)
|
271
|
+
m4 = proto_module::Wrapper::decode(serialized2)
|
272
|
+
run_asserts.call(m4)
|
273
|
+
|
274
|
+
# Test that the lazy form compares equal to the expanded form.
|
275
|
+
m5 = proto_module::Wrapper::decode(serialized2)
|
276
|
+
assert_equal m5, m
|
277
|
+
end
|
278
|
+
|
221
279
|
def test_concurrent_decoding
|
222
280
|
o = Outer.new
|
223
281
|
o.items[0] = Inner.new
|
@@ -237,7 +295,8 @@ module BasicTest
|
|
237
295
|
m = MapMessage.new(
|
238
296
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
239
297
|
:map_string_msg => {"a" => TestMessage2.new(:foo => 1),
|
240
|
-
"b" => TestMessage2.new(:foo => 2)}
|
298
|
+
"b" => TestMessage2.new(:foo => 2)},
|
299
|
+
:map_string_enum => {"a" => :A, "b" => :B})
|
241
300
|
m2 = MapMessage.decode(MapMessage.encode(m))
|
242
301
|
assert m == m2
|
243
302
|
|
@@ -267,6 +326,14 @@ module BasicTest
|
|
267
326
|
assert_match(/No such field: not_in_message/, e.message)
|
268
327
|
end
|
269
328
|
|
329
|
+
#def test_json_quoted_string
|
330
|
+
# m = TestMessage.decode_json(%q(
|
331
|
+
# "optionalInt64": "1",,
|
332
|
+
# }))
|
333
|
+
# puts(m)
|
334
|
+
# assert_equal 1, m.optional_int32
|
335
|
+
#end
|
336
|
+
|
270
337
|
def test_to_h
|
271
338
|
m = TestMessage.new(:optional_bool => true, :optional_double => -10.100001, :optional_string => 'foo', :repeated_string => ['bar1', 'bar2'], :repeated_msg => [TestMessage2.new(:foo => 100)])
|
272
339
|
expected_result = {
|
@@ -298,10 +365,12 @@ module BasicTest
|
|
298
365
|
m = MapMessage.new(
|
299
366
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
300
367
|
:map_string_msg => {"a" => TestMessage2.new(:foo => 1),
|
301
|
-
"b" => TestMessage2.new(:foo => 2)}
|
368
|
+
"b" => TestMessage2.new(:foo => 2)},
|
369
|
+
:map_string_enum => {"a" => :A, "b" => :B})
|
302
370
|
expected_result = {
|
303
371
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
304
|
-
:map_string_msg => {"a" => {:foo => 1}, "b" => {:foo => 2}}
|
372
|
+
:map_string_msg => {"a" => {:foo => 1}, "b" => {:foo => 2}},
|
373
|
+
:map_string_enum => {"a" => :A, "b" => :B}
|
305
374
|
}
|
306
375
|
assert_equal expected_result, m.to_h
|
307
376
|
end
|
@@ -311,26 +380,26 @@ module BasicTest
|
|
311
380
|
# TODO: Fix JSON in JRuby version.
|
312
381
|
return if RUBY_PLATFORM == "java"
|
313
382
|
m = MapMessage.new(:map_string_int32 => {"a" => 1})
|
314
|
-
expected = {mapStringInt32: {a: 1}, mapStringMsg: {}}
|
315
|
-
expected_preserve = {map_string_int32: {a: 1}, map_string_msg: {}}
|
316
|
-
|
383
|
+
expected = {mapStringInt32: {a: 1}, mapStringMsg: {}, mapStringEnum: {}}
|
384
|
+
expected_preserve = {map_string_int32: {a: 1}, map_string_msg: {}, map_string_enum: {}}
|
385
|
+
assert_equal JSON.parse(MapMessage.encode_json(m), :symbolize_names => true), expected
|
317
386
|
|
318
387
|
json = MapMessage.encode_json(m, :preserve_proto_fieldnames => true)
|
319
|
-
|
388
|
+
assert_equal JSON.parse(json, :symbolize_names => true), expected_preserve
|
320
389
|
|
321
390
|
m2 = MapMessage.decode_json(MapMessage.encode_json(m))
|
322
|
-
|
391
|
+
assert_equal m, m2
|
323
392
|
end
|
324
393
|
|
325
394
|
def test_json_maps_emit_defaults_submsg
|
326
395
|
# TODO: Fix JSON in JRuby version.
|
327
396
|
return if RUBY_PLATFORM == "java"
|
328
397
|
m = MapMessage.new(:map_string_msg => {"a" => TestMessage2.new})
|
329
|
-
expected = {mapStringInt32: {}, mapStringMsg: {a: {foo: 0}}}
|
398
|
+
expected = {mapStringInt32: {}, mapStringMsg: {a: {foo: 0}}, mapStringEnum: {}}
|
330
399
|
|
331
400
|
actual = MapMessage.encode_json(m, :emit_defaults => true)
|
332
401
|
|
333
|
-
|
402
|
+
assert_equal JSON.parse(actual, :symbolize_names => true), expected
|
334
403
|
end
|
335
404
|
|
336
405
|
def test_respond_to
|
@@ -351,11 +420,26 @@ module BasicTest
|
|
351
420
|
assert nil != file_descriptor
|
352
421
|
assert_equal "tests/basic_test.proto", file_descriptor.name
|
353
422
|
assert_equal :proto3, file_descriptor.syntax
|
423
|
+
end
|
354
424
|
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
425
|
+
# Ruby 2.5 changed to raise FrozenError instead of RuntimeError
|
426
|
+
FrozenErrorType = Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.5') ? RuntimeError : FrozenError
|
427
|
+
|
428
|
+
def test_map_freeze
|
429
|
+
m = proto_module::MapMessage.new
|
430
|
+
m.map_string_int32['a'] = 5
|
431
|
+
m.map_string_msg['b'] = proto_module::TestMessage2.new
|
432
|
+
|
433
|
+
m.map_string_int32.freeze
|
434
|
+
m.map_string_msg.freeze
|
435
|
+
|
436
|
+
assert m.map_string_int32.frozen?
|
437
|
+
assert m.map_string_msg.frozen?
|
438
|
+
|
439
|
+
assert_raise(FrozenErrorType) { m.map_string_int32['foo'] = 1 }
|
440
|
+
assert_raise(FrozenErrorType) { m.map_string_msg['bar'] = proto_module::TestMessage2.new }
|
441
|
+
assert_raise(FrozenErrorType) { m.map_string_int32.delete('a') }
|
442
|
+
assert_raise(FrozenErrorType) { m.map_string_int32.clear }
|
359
443
|
end
|
360
444
|
end
|
361
445
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-protobuf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Protobuf Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler-dock
|
@@ -111,7 +111,8 @@ files:
|
|
111
111
|
homepage: https://developers.google.com/protocol-buffers
|
112
112
|
licenses:
|
113
113
|
- BSD-3-Clause
|
114
|
-
metadata:
|
114
|
+
metadata:
|
115
|
+
source_code_uri: https://github.com/protocolbuffers/protobuf/tree/v3.11.0/ruby
|
115
116
|
post_install_message:
|
116
117
|
rdoc_options: []
|
117
118
|
require_paths:
|
@@ -120,15 +121,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
121
|
requirements:
|
121
122
|
- - ">="
|
122
123
|
- !ruby/object:Gem::Version
|
123
|
-
version: '
|
124
|
+
version: '2.3'
|
124
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
126
|
requirements:
|
126
127
|
- - ">="
|
127
128
|
- !ruby/object:Gem::Version
|
128
129
|
version: '0'
|
129
130
|
requirements: []
|
130
|
-
|
131
|
-
rubygems_version: 2.7.8
|
131
|
+
rubygems_version: 3.0.6
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: Protocol Buffers
|