google-protobuf 3.9.2 → 3.10.1

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.

@@ -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'
@@ -14,6 +14,6 @@ end
14
14
 
15
15
  module Google
16
16
  module Protobuf
17
- Any = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Any").msgclass
17
+ Any = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Any").msgclass
18
18
  end
19
19
  end
@@ -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
@@ -12,6 +12,6 @@ end
12
12
 
13
13
  module Google
14
14
  module Protobuf
15
- Empty = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Empty").msgclass
15
+ Empty = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.Empty").msgclass
16
16
  end
17
17
  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
- def to_time
76
- Time.at(self.to_f)
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
@@ -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
 
@@ -204,6 +203,20 @@ module BasicTest
204
203
  end
205
204
  end
206
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
+
207
220
  def test_map_inspect
208
221
  m = MapMessage.new(
209
222
  :map_string_int32 => {"a" => 1, "b" => 2},
@@ -271,6 +284,14 @@ module BasicTest
271
284
  assert_match(/No such field: not_in_message/, e.message)
272
285
  end
273
286
 
287
+ #def test_json_quoted_string
288
+ # m = TestMessage.decode_json(%q(
289
+ # "optionalInt64": "1",,
290
+ # }))
291
+ # puts(m)
292
+ # assert_equal 1, m.optional_int32
293
+ #end
294
+
274
295
  def test_to_h
275
296
  m = TestMessage.new(:optional_bool => true, :optional_double => -10.100001, :optional_string => 'foo', :repeated_string => ['bar1', 'bar2'], :repeated_msg => [TestMessage2.new(:foo => 100)])
276
297
  expected_result = {
@@ -357,11 +378,6 @@ module BasicTest
357
378
  assert nil != file_descriptor
358
379
  assert_equal "tests/basic_test.proto", file_descriptor.name
359
380
  assert_equal :proto3, file_descriptor.syntax
360
-
361
- file_descriptor = BadFieldNames.descriptor.file_descriptor
362
- assert nil != file_descriptor
363
- assert_equal nil, file_descriptor.name
364
- assert_equal :proto3, file_descriptor.syntax
365
381
  end
366
382
 
367
383
  # Ruby 2.5 changed to raise FrozenError instead of RuntimeError
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.9.2
4
+ version: 3.10.1
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-09-23 00:00:00.000000000 Z
11
+ date: 2019-10-29 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.10.1/ruby
115
116
  post_install_message:
116
117
  rdoc_options: []
117
118
  require_paths: