google-protobuf 3.8.0 → 3.15.0
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.
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/convert.c +349 -0
- data/ext/google/protobuf_c/convert.h +72 -0
- data/ext/google/protobuf_c/defs.c +1525 -1223
- data/ext/google/protobuf_c/defs.h +107 -0
- data/ext/google/protobuf_c/extconf.rb +4 -7
- data/ext/google/protobuf_c/map.c +309 -476
- data/ext/google/protobuf_c/map.h +66 -0
- data/ext/google/protobuf_c/message.c +912 -446
- data/ext/google/protobuf_c/message.h +98 -0
- data/ext/google/protobuf_c/protobuf.c +326 -51
- data/ext/google/protobuf_c/protobuf.h +46 -549
- data/ext/google/protobuf_c/repeated_field.c +308 -312
- data/ext/google/protobuf_c/repeated_field.h +62 -0
- data/ext/google/protobuf_c/ruby-upb.c +8915 -0
- data/ext/google/protobuf_c/ruby-upb.h +4452 -0
- data/ext/google/protobuf_c/third_party/wyhash/wyhash.h +145 -0
- 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 +262 -71
- data/tests/generated_code_test.rb +0 -0
- data/tests/stress.rb +0 -0
- metadata +26 -14
- data/ext/google/protobuf_c/encode_decode.c +0 -1614
- data/ext/google/protobuf_c/storage.c +0 -1062
- data/ext/google/protobuf_c/upb.c +0 -17480
- data/ext/google/protobuf_c/upb.h +0 -10641
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
|
|
@@ -33,11 +32,11 @@ module BasicTest
|
|
33
32
|
include CommonTests
|
34
33
|
|
35
34
|
def test_has_field
|
36
|
-
m =
|
37
|
-
assert !m.
|
38
|
-
m.
|
39
|
-
assert m.
|
40
|
-
assert
|
35
|
+
m = TestSingularFields.new
|
36
|
+
assert !m.has_singular_msg?
|
37
|
+
m.singular_msg = TestMessage2.new
|
38
|
+
assert m.has_singular_msg?
|
39
|
+
assert TestSingularFields.descriptor.lookup('singular_msg').has?(m)
|
41
40
|
|
42
41
|
m = OneofMessage.new
|
43
42
|
assert !m.has_my_oneof?
|
@@ -46,32 +45,31 @@ module BasicTest
|
|
46
45
|
assert_raise NoMethodError do
|
47
46
|
m.has_a?
|
48
47
|
end
|
49
|
-
|
50
|
-
OneofMessage.descriptor.lookup('a').has?(m)
|
51
|
-
end
|
48
|
+
assert_true OneofMessage.descriptor.lookup('a').has?(m)
|
52
49
|
|
53
|
-
m =
|
50
|
+
m = TestSingularFields.new
|
54
51
|
assert_raise NoMethodError do
|
55
|
-
m.
|
52
|
+
m.has_singular_int32?
|
56
53
|
end
|
57
54
|
assert_raise ArgumentError do
|
58
|
-
|
55
|
+
TestSingularFields.descriptor.lookup('singular_int32').has?(m)
|
59
56
|
end
|
60
57
|
|
61
58
|
assert_raise NoMethodError do
|
62
|
-
m.
|
59
|
+
m.has_singular_string?
|
63
60
|
end
|
64
61
|
assert_raise ArgumentError do
|
65
|
-
|
62
|
+
TestSingularFields.descriptor.lookup('singular_string').has?(m)
|
66
63
|
end
|
67
64
|
|
68
65
|
assert_raise NoMethodError do
|
69
|
-
m.
|
66
|
+
m.has_singular_bool?
|
70
67
|
end
|
71
68
|
assert_raise ArgumentError do
|
72
|
-
|
69
|
+
TestSingularFields.descriptor.lookup('singular_bool').has?(m)
|
73
70
|
end
|
74
71
|
|
72
|
+
m = TestMessage.new
|
75
73
|
assert_raise NoMethodError do
|
76
74
|
m.has_repeated_msg?
|
77
75
|
end
|
@@ -80,40 +78,59 @@ module BasicTest
|
|
80
78
|
end
|
81
79
|
end
|
82
80
|
|
81
|
+
def test_no_presence
|
82
|
+
m = TestSingularFields.new
|
83
|
+
|
84
|
+
# Explicitly setting to zero does not cause anything to be serialized.
|
85
|
+
m.singular_int32 = 0
|
86
|
+
assert_equal "", TestSingularFields.encode(m)
|
87
|
+
|
88
|
+
# Explicitly setting to a non-zero value *does* cause serialization.
|
89
|
+
m.singular_int32 = 1
|
90
|
+
assert_not_equal "", TestSingularFields.encode(m)
|
91
|
+
|
92
|
+
m.singular_int32 = 0
|
93
|
+
assert_equal "", TestSingularFields.encode(m)
|
94
|
+
end
|
95
|
+
|
83
96
|
def test_set_clear_defaults
|
84
|
-
m =
|
97
|
+
m = TestSingularFields.new
|
98
|
+
|
99
|
+
m.singular_int32 = -42
|
100
|
+
assert_equal -42, m.singular_int32
|
101
|
+
m.clear_singular_int32
|
102
|
+
assert_equal 0, m.singular_int32
|
103
|
+
|
104
|
+
m.singular_int32 = 50
|
105
|
+
assert_equal 50, m.singular_int32
|
106
|
+
TestSingularFields.descriptor.lookup('singular_int32').clear(m)
|
107
|
+
assert_equal 0, m.singular_int32
|
108
|
+
|
109
|
+
m.singular_string = "foo bar"
|
110
|
+
assert_equal "foo bar", m.singular_string
|
111
|
+
m.clear_singular_string
|
112
|
+
assert_equal "", m.singular_string
|
113
|
+
|
114
|
+
m.singular_string = "foo"
|
115
|
+
assert_equal "foo", m.singular_string
|
116
|
+
TestSingularFields.descriptor.lookup('singular_string').clear(m)
|
117
|
+
assert_equal "", m.singular_string
|
118
|
+
|
119
|
+
m.singular_msg = TestMessage2.new(:foo => 42)
|
120
|
+
assert_equal TestMessage2.new(:foo => 42), m.singular_msg
|
121
|
+
assert m.has_singular_msg?
|
122
|
+
m.clear_singular_msg
|
123
|
+
assert_equal nil, m.singular_msg
|
124
|
+
assert !m.has_singular_msg?
|
125
|
+
|
126
|
+
m.singular_msg = TestMessage2.new(:foo => 42)
|
127
|
+
assert_equal TestMessage2.new(:foo => 42), m.singular_msg
|
128
|
+
TestSingularFields.descriptor.lookup('singular_msg').clear(m)
|
129
|
+
assert_equal nil, m.singular_msg
|
130
|
+
end
|
85
131
|
|
86
|
-
|
87
|
-
|
88
|
-
m.clear_optional_int32
|
89
|
-
assert_equal 0, m.optional_int32
|
90
|
-
|
91
|
-
m.optional_int32 = 50
|
92
|
-
assert_equal 50, m.optional_int32
|
93
|
-
TestMessage.descriptor.lookup('optional_int32').clear(m)
|
94
|
-
assert_equal 0, m.optional_int32
|
95
|
-
|
96
|
-
m.optional_string = "foo bar"
|
97
|
-
assert_equal "foo bar", m.optional_string
|
98
|
-
m.clear_optional_string
|
99
|
-
assert_equal "", m.optional_string
|
100
|
-
|
101
|
-
m.optional_string = "foo"
|
102
|
-
assert_equal "foo", m.optional_string
|
103
|
-
TestMessage.descriptor.lookup('optional_string').clear(m)
|
104
|
-
assert_equal "", m.optional_string
|
105
|
-
|
106
|
-
m.optional_msg = TestMessage2.new(:foo => 42)
|
107
|
-
assert_equal TestMessage2.new(:foo => 42), m.optional_msg
|
108
|
-
assert m.has_optional_msg?
|
109
|
-
m.clear_optional_msg
|
110
|
-
assert_equal nil, m.optional_msg
|
111
|
-
assert !m.has_optional_msg?
|
112
|
-
|
113
|
-
m.optional_msg = TestMessage2.new(:foo => 42)
|
114
|
-
assert_equal TestMessage2.new(:foo => 42), m.optional_msg
|
115
|
-
TestMessage.descriptor.lookup('optional_msg').clear(m)
|
116
|
-
assert_equal nil, m.optional_msg
|
132
|
+
def test_clear_repeated_fields
|
133
|
+
m = TestMessage.new
|
117
134
|
|
118
135
|
m.repeated_int32.push(1)
|
119
136
|
assert_equal [1], m.repeated_int32
|
@@ -129,6 +146,7 @@ module BasicTest
|
|
129
146
|
m.a = "foo"
|
130
147
|
assert_equal "foo", m.a
|
131
148
|
assert m.has_my_oneof?
|
149
|
+
assert_equal :a, m.my_oneof
|
132
150
|
m.clear_a
|
133
151
|
assert !m.has_my_oneof?
|
134
152
|
|
@@ -144,7 +162,6 @@ module BasicTest
|
|
144
162
|
assert !m.has_my_oneof?
|
145
163
|
end
|
146
164
|
|
147
|
-
|
148
165
|
def test_initialization_map_errors
|
149
166
|
e = assert_raise ArgumentError do
|
150
167
|
TestMessage.new(:hello => "world")
|
@@ -170,10 +187,12 @@ module BasicTest
|
|
170
187
|
m = MapMessage.new(
|
171
188
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
172
189
|
:map_string_msg => {"a" => TestMessage2.new(:foo => 1),
|
173
|
-
"b" => TestMessage2.new(:foo => 2)}
|
190
|
+
"b" => TestMessage2.new(:foo => 2)},
|
191
|
+
:map_string_enum => {"a" => :A, "b" => :B})
|
174
192
|
assert m.map_string_int32.keys.sort == ["a", "b"]
|
175
193
|
assert m.map_string_int32["a"] == 1
|
176
194
|
assert m.map_string_msg["b"].foo == 2
|
195
|
+
assert m.map_string_enum["a"] == :A
|
177
196
|
|
178
197
|
m.map_string_int32["c"] = 3
|
179
198
|
assert m.map_string_int32["c"] == 3
|
@@ -197,18 +216,37 @@ module BasicTest
|
|
197
216
|
m.map_string_int32 = {}
|
198
217
|
end
|
199
218
|
|
200
|
-
assert_raise TypeError do
|
219
|
+
assert_raise Google::Protobuf::TypeError do
|
201
220
|
m = MapMessage.new(:map_string_int32 => { 1 => "I am not a number" })
|
202
221
|
end
|
203
222
|
end
|
204
223
|
|
224
|
+
def test_map_field_with_symbol
|
225
|
+
m = MapMessage.new
|
226
|
+
assert m.map_string_int32 == {}
|
227
|
+
assert m.map_string_msg == {}
|
228
|
+
|
229
|
+
m = MapMessage.new(
|
230
|
+
:map_string_int32 => {a: 1, "b" => 2},
|
231
|
+
:map_string_msg => {a: TestMessage2.new(:foo => 1),
|
232
|
+
b: TestMessage2.new(:foo => 10)})
|
233
|
+
assert_equal 1, m.map_string_int32[:a]
|
234
|
+
assert_equal 2, m.map_string_int32[:b]
|
235
|
+
assert_equal 10, m.map_string_msg[:b].foo
|
236
|
+
end
|
237
|
+
|
205
238
|
def test_map_inspect
|
206
239
|
m = MapMessage.new(
|
207
240
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
208
241
|
:map_string_msg => {"a" => TestMessage2.new(:foo => 1),
|
209
|
-
"b" => TestMessage2.new(:foo => 2)}
|
210
|
-
|
211
|
-
|
242
|
+
"b" => TestMessage2.new(:foo => 2)},
|
243
|
+
:map_string_enum => {"a" => :A, "b" => :B})
|
244
|
+
|
245
|
+
# JRuby doesn't keep consistent ordering so check for either version
|
246
|
+
expected_a = "<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}>"
|
247
|
+
expected_b = "<BasicTest::MapMessage: map_string_int32: {\"a\"=>1, \"b\"=>2}, map_string_msg: {\"a\"=><BasicTest::TestMessage2: foo: 1>, \"b\"=><BasicTest::TestMessage2: foo: 2>}, map_string_enum: {\"a\"=>:A, \"b\"=>:B}>"
|
248
|
+
inspect_result = m.inspect
|
249
|
+
assert expected_a == inspect_result || expected_b == inspect_result, "Incorrect inspect result: #{inspect_result}"
|
212
250
|
end
|
213
251
|
|
214
252
|
def test_map_corruption
|
@@ -218,6 +256,128 @@ module BasicTest
|
|
218
256
|
m.map_string_int32['aaa'] = 3
|
219
257
|
end
|
220
258
|
|
259
|
+
def test_map_wrappers
|
260
|
+
run_asserts = ->(m) {
|
261
|
+
assert_equal 2.0, m.map_double[0].value
|
262
|
+
assert_equal 4.0, m.map_float[0].value
|
263
|
+
assert_equal 3, m.map_int32[0].value
|
264
|
+
assert_equal 4, m.map_int64[0].value
|
265
|
+
assert_equal 5, m.map_uint32[0].value
|
266
|
+
assert_equal 6, m.map_uint64[0].value
|
267
|
+
assert_equal true, m.map_bool[0].value
|
268
|
+
assert_equal 'str', m.map_string[0].value
|
269
|
+
assert_equal 'fun', m.map_bytes[0].value
|
270
|
+
}
|
271
|
+
|
272
|
+
m = proto_module::Wrapper.new(
|
273
|
+
map_double: {0 => Google::Protobuf::DoubleValue.new(value: 2.0)},
|
274
|
+
map_float: {0 => Google::Protobuf::FloatValue.new(value: 4.0)},
|
275
|
+
map_int32: {0 => Google::Protobuf::Int32Value.new(value: 3)},
|
276
|
+
map_int64: {0 => Google::Protobuf::Int64Value.new(value: 4)},
|
277
|
+
map_uint32: {0 => Google::Protobuf::UInt32Value.new(value: 5)},
|
278
|
+
map_uint64: {0 => Google::Protobuf::UInt64Value.new(value: 6)},
|
279
|
+
map_bool: {0 => Google::Protobuf::BoolValue.new(value: true)},
|
280
|
+
map_string: {0 => Google::Protobuf::StringValue.new(value: 'str')},
|
281
|
+
map_bytes: {0 => Google::Protobuf::BytesValue.new(value: 'fun')},
|
282
|
+
)
|
283
|
+
|
284
|
+
run_asserts.call(m)
|
285
|
+
serialized = proto_module::Wrapper::encode(m)
|
286
|
+
m2 = proto_module::Wrapper::decode(serialized)
|
287
|
+
run_asserts.call(m2)
|
288
|
+
|
289
|
+
# Test the case where we are serializing directly from the parsed form
|
290
|
+
# (before anything lazy is materialized).
|
291
|
+
m3 = proto_module::Wrapper::decode(serialized)
|
292
|
+
serialized2 = proto_module::Wrapper::encode(m3)
|
293
|
+
m4 = proto_module::Wrapper::decode(serialized2)
|
294
|
+
run_asserts.call(m4)
|
295
|
+
|
296
|
+
# Test that the lazy form compares equal to the expanded form.
|
297
|
+
m5 = proto_module::Wrapper::decode(serialized2)
|
298
|
+
assert_equal m5, m
|
299
|
+
end
|
300
|
+
|
301
|
+
def test_map_wrappers_with_default_values
|
302
|
+
run_asserts = ->(m) {
|
303
|
+
assert_equal 0.0, m.map_double[0].value
|
304
|
+
assert_equal 0.0, m.map_float[0].value
|
305
|
+
assert_equal 0, m.map_int32[0].value
|
306
|
+
assert_equal 0, m.map_int64[0].value
|
307
|
+
assert_equal 0, m.map_uint32[0].value
|
308
|
+
assert_equal 0, m.map_uint64[0].value
|
309
|
+
assert_equal false, m.map_bool[0].value
|
310
|
+
assert_equal '', m.map_string[0].value
|
311
|
+
assert_equal '', m.map_bytes[0].value
|
312
|
+
}
|
313
|
+
|
314
|
+
m = proto_module::Wrapper.new(
|
315
|
+
map_double: {0 => Google::Protobuf::DoubleValue.new(value: 0.0)},
|
316
|
+
map_float: {0 => Google::Protobuf::FloatValue.new(value: 0.0)},
|
317
|
+
map_int32: {0 => Google::Protobuf::Int32Value.new(value: 0)},
|
318
|
+
map_int64: {0 => Google::Protobuf::Int64Value.new(value: 0)},
|
319
|
+
map_uint32: {0 => Google::Protobuf::UInt32Value.new(value: 0)},
|
320
|
+
map_uint64: {0 => Google::Protobuf::UInt64Value.new(value: 0)},
|
321
|
+
map_bool: {0 => Google::Protobuf::BoolValue.new(value: false)},
|
322
|
+
map_string: {0 => Google::Protobuf::StringValue.new(value: '')},
|
323
|
+
map_bytes: {0 => Google::Protobuf::BytesValue.new(value: '')},
|
324
|
+
)
|
325
|
+
|
326
|
+
run_asserts.call(m)
|
327
|
+
serialized = proto_module::Wrapper::encode(m)
|
328
|
+
m2 = proto_module::Wrapper::decode(serialized)
|
329
|
+
run_asserts.call(m2)
|
330
|
+
|
331
|
+
# Test the case where we are serializing directly from the parsed form
|
332
|
+
# (before anything lazy is materialized).
|
333
|
+
m3 = proto_module::Wrapper::decode(serialized)
|
334
|
+
serialized2 = proto_module::Wrapper::encode(m3)
|
335
|
+
m4 = proto_module::Wrapper::decode(serialized2)
|
336
|
+
run_asserts.call(m4)
|
337
|
+
|
338
|
+
# Test that the lazy form compares equal to the expanded form.
|
339
|
+
m5 = proto_module::Wrapper::decode(serialized2)
|
340
|
+
assert_equal m5, m
|
341
|
+
end
|
342
|
+
|
343
|
+
def test_map_wrappers_with_no_value
|
344
|
+
run_asserts = ->(m) {
|
345
|
+
assert_equal 0.0, m.map_double[0].value
|
346
|
+
assert_equal 0.0, m.map_float[0].value
|
347
|
+
assert_equal 0, m.map_int32[0].value
|
348
|
+
assert_equal 0, m.map_int64[0].value
|
349
|
+
assert_equal 0, m.map_uint32[0].value
|
350
|
+
assert_equal 0, m.map_uint64[0].value
|
351
|
+
assert_equal false, m.map_bool[0].value
|
352
|
+
assert_equal '', m.map_string[0].value
|
353
|
+
assert_equal '', m.map_bytes[0].value
|
354
|
+
}
|
355
|
+
|
356
|
+
m = proto_module::Wrapper.new(
|
357
|
+
map_double: {0 => Google::Protobuf::DoubleValue.new()},
|
358
|
+
map_float: {0 => Google::Protobuf::FloatValue.new()},
|
359
|
+
map_int32: {0 => Google::Protobuf::Int32Value.new()},
|
360
|
+
map_int64: {0 => Google::Protobuf::Int64Value.new()},
|
361
|
+
map_uint32: {0 => Google::Protobuf::UInt32Value.new()},
|
362
|
+
map_uint64: {0 => Google::Protobuf::UInt64Value.new()},
|
363
|
+
map_bool: {0 => Google::Protobuf::BoolValue.new()},
|
364
|
+
map_string: {0 => Google::Protobuf::StringValue.new()},
|
365
|
+
map_bytes: {0 => Google::Protobuf::BytesValue.new()},
|
366
|
+
)
|
367
|
+
run_asserts.call(m)
|
368
|
+
|
369
|
+
serialized = proto_module::Wrapper::encode(m)
|
370
|
+
m2 = proto_module::Wrapper::decode(serialized)
|
371
|
+
run_asserts.call(m2)
|
372
|
+
|
373
|
+
# Test the case where we are serializing directly from the parsed form
|
374
|
+
# (before anything lazy is materialized).
|
375
|
+
m3 = proto_module::Wrapper::decode(serialized)
|
376
|
+
serialized2 = proto_module::Wrapper::encode(m3)
|
377
|
+
m4 = proto_module::Wrapper::decode(serialized2)
|
378
|
+
run_asserts.call(m4)
|
379
|
+
end
|
380
|
+
|
221
381
|
def test_concurrent_decoding
|
222
382
|
o = Outer.new
|
223
383
|
o.items[0] = Inner.new
|
@@ -237,7 +397,8 @@ module BasicTest
|
|
237
397
|
m = MapMessage.new(
|
238
398
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
239
399
|
:map_string_msg => {"a" => TestMessage2.new(:foo => 1),
|
240
|
-
"b" => TestMessage2.new(:foo => 2)}
|
400
|
+
"b" => TestMessage2.new(:foo => 2)},
|
401
|
+
:map_string_enum => {"a" => :A, "b" => :B})
|
241
402
|
m2 = MapMessage.decode(MapMessage.encode(m))
|
242
403
|
assert m == m2
|
243
404
|
|
@@ -267,6 +428,14 @@ module BasicTest
|
|
267
428
|
assert_match(/No such field: not_in_message/, e.message)
|
268
429
|
end
|
269
430
|
|
431
|
+
#def test_json_quoted_string
|
432
|
+
# m = TestMessage.decode_json(%q(
|
433
|
+
# "optionalInt64": "1",,
|
434
|
+
# }))
|
435
|
+
# puts(m)
|
436
|
+
# assert_equal 1, m.optional_int32
|
437
|
+
#end
|
438
|
+
|
270
439
|
def test_to_h
|
271
440
|
m = TestMessage.new(:optional_bool => true, :optional_double => -10.100001, :optional_string => 'foo', :repeated_string => ['bar1', 'bar2'], :repeated_msg => [TestMessage2.new(:foo => 100)])
|
272
441
|
expected_result = {
|
@@ -278,6 +447,7 @@ module BasicTest
|
|
278
447
|
:optional_int32=>0,
|
279
448
|
:optional_int64=>0,
|
280
449
|
:optional_msg=>nil,
|
450
|
+
:optional_msg2=>nil,
|
281
451
|
:optional_string=>"foo",
|
282
452
|
:optional_uint32=>0,
|
283
453
|
:optional_uint64=>0,
|
@@ -298,10 +468,12 @@ module BasicTest
|
|
298
468
|
m = MapMessage.new(
|
299
469
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
300
470
|
:map_string_msg => {"a" => TestMessage2.new(:foo => 1),
|
301
|
-
"b" => TestMessage2.new(:foo => 2)}
|
471
|
+
"b" => TestMessage2.new(:foo => 2)},
|
472
|
+
:map_string_enum => {"a" => :A, "b" => :B})
|
302
473
|
expected_result = {
|
303
474
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
304
|
-
:map_string_msg => {"a" => {:foo => 1}, "b" => {:foo => 2}}
|
475
|
+
:map_string_msg => {"a" => {:foo => 1}, "b" => {:foo => 2}},
|
476
|
+
:map_string_enum => {"a" => :A, "b" => :B}
|
305
477
|
}
|
306
478
|
assert_equal expected_result, m.to_h
|
307
479
|
end
|
@@ -311,26 +483,50 @@ module BasicTest
|
|
311
483
|
# TODO: Fix JSON in JRuby version.
|
312
484
|
return if RUBY_PLATFORM == "java"
|
313
485
|
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
|
-
|
486
|
+
expected = {mapStringInt32: {a: 1}, mapStringMsg: {}, mapStringEnum: {}}
|
487
|
+
expected_preserve = {map_string_int32: {a: 1}, map_string_msg: {}, map_string_enum: {}}
|
488
|
+
assert_equal JSON.parse(MapMessage.encode_json(m, :emit_defaults=>true), :symbolize_names => true), expected
|
317
489
|
|
318
|
-
json = MapMessage.encode_json(m, :preserve_proto_fieldnames => true)
|
319
|
-
|
490
|
+
json = MapMessage.encode_json(m, :preserve_proto_fieldnames => true, :emit_defaults=>true)
|
491
|
+
assert_equal JSON.parse(json, :symbolize_names => true), expected_preserve
|
320
492
|
|
321
493
|
m2 = MapMessage.decode_json(MapMessage.encode_json(m))
|
322
|
-
|
494
|
+
assert_equal m, m2
|
323
495
|
end
|
324
496
|
|
325
497
|
def test_json_maps_emit_defaults_submsg
|
326
498
|
# TODO: Fix JSON in JRuby version.
|
327
499
|
return if RUBY_PLATFORM == "java"
|
328
|
-
m = MapMessage.new(:map_string_msg => {"a" => TestMessage2.new})
|
329
|
-
expected = {mapStringInt32: {}, mapStringMsg: {a: {foo: 0}}}
|
500
|
+
m = MapMessage.new(:map_string_msg => {"a" => TestMessage2.new(foo: 0)})
|
501
|
+
expected = {mapStringInt32: {}, mapStringMsg: {a: {foo: 0}}, mapStringEnum: {}}
|
330
502
|
|
331
503
|
actual = MapMessage.encode_json(m, :emit_defaults => true)
|
332
504
|
|
333
|
-
|
505
|
+
assert_equal JSON.parse(actual, :symbolize_names => true), expected
|
506
|
+
end
|
507
|
+
|
508
|
+
def test_json_emit_defaults_submsg
|
509
|
+
# TODO: Fix JSON in JRuby version.
|
510
|
+
return if RUBY_PLATFORM == "java"
|
511
|
+
m = TestSingularFields.new(singular_msg: proto_module::TestMessage2.new)
|
512
|
+
|
513
|
+
expected = {
|
514
|
+
singularInt32: 0,
|
515
|
+
singularInt64: "0",
|
516
|
+
singularUint32: 0,
|
517
|
+
singularUint64: "0",
|
518
|
+
singularBool: false,
|
519
|
+
singularFloat: 0,
|
520
|
+
singularDouble: 0,
|
521
|
+
singularString: "",
|
522
|
+
singularBytes: "",
|
523
|
+
singularMsg: {},
|
524
|
+
singularEnum: "Default",
|
525
|
+
}
|
526
|
+
|
527
|
+
actual = proto_module::TestMessage.encode_json(m, :emit_defaults => true)
|
528
|
+
|
529
|
+
assert_equal expected, JSON.parse(actual, :symbolize_names => true)
|
334
530
|
end
|
335
531
|
|
336
532
|
def test_respond_to
|
@@ -351,11 +547,6 @@ module BasicTest
|
|
351
547
|
assert nil != file_descriptor
|
352
548
|
assert_equal "tests/basic_test.proto", file_descriptor.name
|
353
549
|
assert_equal :proto3, file_descriptor.syntax
|
354
|
-
|
355
|
-
file_descriptor = BadFieldNames.descriptor.file_descriptor
|
356
|
-
assert nil != file_descriptor
|
357
|
-
assert_equal nil, file_descriptor.name
|
358
|
-
assert_equal :proto3, file_descriptor.syntax
|
359
550
|
end
|
360
551
|
|
361
552
|
# Ruby 2.5 changed to raise FrozenError instead of RuntimeError
|
File without changes
|
data/tests/stress.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,43 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-protobuf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.15.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:
|
11
|
+
date: 2021-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler-dock
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.0
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
22
|
+
version: '2.0'
|
20
23
|
type: :development
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.1.0
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
32
|
+
version: '2.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rake-compiler
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
39
|
+
version: 1.1.0
|
34
40
|
type: :development
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
46
|
+
version: 1.1.0
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: test-unit
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -79,17 +85,22 @@ extensions:
|
|
79
85
|
- ext/google/protobuf_c/extconf.rb
|
80
86
|
extra_rdoc_files: []
|
81
87
|
files:
|
88
|
+
- ext/google/protobuf_c/convert.c
|
89
|
+
- ext/google/protobuf_c/convert.h
|
82
90
|
- ext/google/protobuf_c/defs.c
|
83
|
-
- ext/google/protobuf_c/
|
91
|
+
- ext/google/protobuf_c/defs.h
|
84
92
|
- ext/google/protobuf_c/extconf.rb
|
85
93
|
- ext/google/protobuf_c/map.c
|
94
|
+
- ext/google/protobuf_c/map.h
|
86
95
|
- ext/google/protobuf_c/message.c
|
96
|
+
- ext/google/protobuf_c/message.h
|
87
97
|
- ext/google/protobuf_c/protobuf.c
|
88
98
|
- ext/google/protobuf_c/protobuf.h
|
89
99
|
- ext/google/protobuf_c/repeated_field.c
|
90
|
-
- ext/google/protobuf_c/
|
91
|
-
- ext/google/protobuf_c/upb.c
|
92
|
-
- ext/google/protobuf_c/upb.h
|
100
|
+
- ext/google/protobuf_c/repeated_field.h
|
101
|
+
- ext/google/protobuf_c/ruby-upb.c
|
102
|
+
- ext/google/protobuf_c/ruby-upb.h
|
103
|
+
- ext/google/protobuf_c/third_party/wyhash/wyhash.h
|
93
104
|
- ext/google/protobuf_c/wrap_memcpy.c
|
94
105
|
- lib/google/protobuf.rb
|
95
106
|
- lib/google/protobuf/any_pb.rb
|
@@ -111,7 +122,8 @@ files:
|
|
111
122
|
homepage: https://developers.google.com/protocol-buffers
|
112
123
|
licenses:
|
113
124
|
- BSD-3-Clause
|
114
|
-
metadata:
|
125
|
+
metadata:
|
126
|
+
source_code_uri: https://github.com/protocolbuffers/protobuf/tree/v3.15.0/ruby
|
115
127
|
post_install_message:
|
116
128
|
rdoc_options: []
|
117
129
|
require_paths:
|
@@ -127,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
139
|
- !ruby/object:Gem::Version
|
128
140
|
version: '0'
|
129
141
|
requirements: []
|
130
|
-
rubygems_version: 3.
|
142
|
+
rubygems_version: 3.2.11
|
131
143
|
signing_key:
|
132
144
|
specification_version: 4
|
133
145
|
summary: Protocol Buffers
|