protobuf 3.6.12 → 3.7.0.pre0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +4 -4
  3. data/CHANGES.md +14 -3
  4. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +39 -2
  5. data/lib/protobuf/field.rb +2 -2
  6. data/lib/protobuf/field/base_field.rb +27 -84
  7. data/lib/protobuf/field/bool_field.rb +3 -13
  8. data/lib/protobuf/field/bytes_field.rb +10 -26
  9. data/lib/protobuf/field/enum_field.rb +10 -20
  10. data/lib/protobuf/field/message_field.rb +13 -23
  11. data/lib/protobuf/generators/enum_generator.rb +1 -0
  12. data/lib/protobuf/generators/field_generator.rb +8 -2
  13. data/lib/protobuf/generators/file_generator.rb +8 -0
  14. data/lib/protobuf/generators/service_generator.rb +2 -2
  15. data/lib/protobuf/message.rb +47 -12
  16. data/lib/protobuf/message/fields.rb +80 -8
  17. data/lib/protobuf/rpc/connectors/common.rb +1 -1
  18. data/lib/protobuf/rpc/connectors/ping.rb +2 -2
  19. data/lib/protobuf/rpc/connectors/zmq.rb +1 -1
  20. data/lib/protobuf/rpc/middleware/exception_handler.rb +0 -4
  21. data/lib/protobuf/rpc/middleware/logger.rb +0 -4
  22. data/lib/protobuf/rpc/middleware/request_decoder.rb +16 -11
  23. data/lib/protobuf/rpc/middleware/response_encoder.rb +20 -15
  24. data/lib/protobuf/rpc/service.rb +10 -2
  25. data/lib/protobuf/rpc/service_directory.rb +0 -8
  26. data/lib/protobuf/rpc/service_dispatcher.rb +6 -5
  27. data/lib/protobuf/rpc/service_filters.rb +30 -8
  28. data/lib/protobuf/version.rb +1 -1
  29. data/proto/google/protobuf/descriptor.proto +190 -31
  30. data/spec/lib/protobuf/field/bool_field_spec.rb +33 -7
  31. data/spec/lib/protobuf/field/enum_field_spec.rb +26 -0
  32. data/spec/lib/protobuf/field/float_field_spec.rb +32 -1
  33. data/spec/lib/protobuf/field/int32_field_spec.rb +32 -1
  34. data/spec/lib/protobuf/field/message_field_spec.rb +79 -0
  35. data/spec/lib/protobuf/field/string_field_spec.rb +34 -0
  36. data/spec/lib/protobuf/field_spec.rb +1 -0
  37. data/spec/lib/protobuf/generators/enum_generator_spec.rb +9 -0
  38. data/spec/lib/protobuf/generators/service_generator_spec.rb +9 -0
  39. data/spec/lib/protobuf/message_spec.rb +328 -63
  40. data/spec/lib/protobuf/rpc/connectors/ping_spec.rb +3 -3
  41. data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +18 -1
  42. data/spec/support/protos/enum.pb.rb +1 -1
  43. data/spec/support/protos/google_unittest.pb.rb +113 -111
  44. data/spec/support/protos/google_unittest.proto +7 -0
  45. data/spec/support/protos/multi_field_extensions.pb.rb +1 -1
  46. data/spec/support/protos/resource.pb.rb +9 -9
  47. metadata +79 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c7ec12754d8e386bf82f3a710819b2f443932e5
4
- data.tar.gz: 527a850ab4d8a1f01469adfc60047c5d2d21b536
3
+ metadata.gz: 49fd33e80978059efd20c7e085db8567e84b3bf4
4
+ data.tar.gz: c56d562e6ba4814d8b023a9761b14d5eef3d719f
5
5
  SHA512:
6
- metadata.gz: aa0059ae03b3dfdb3119542ad22afa6cbc0d9132f1d1733853ca97b4a690359ff0f796863770fafab961733807389d251e81a7ae5962c0117087447c2811980b
7
- data.tar.gz: 49fa4a8044113cf26b7e9b42c70bd3edbef04699c4e34c1938bbe6b3a6111ad8ad135b1439348ad8405d2af6f100f8d2a0bff9aecf24ed88df037fcaa3046849
6
+ metadata.gz: 56a1dfac3b2e3db4eb26115ecae1ced9585797651551df00b13eabbb2ecaafa8e61ef7ee3e396f1ea9df1377e1c4180983fe79e698e7bcb402042307fed05dc8
7
+ data.tar.gz: a4cca36a18e7f24e2ed319323bbf0c41c61730d23555d3b52965b93eaf6baea0336af4beb66fe96422f78204d547684b642b74e4dd725e04e4c48b2825e756c9
data/.rubocop_todo.yml CHANGED
@@ -16,12 +16,12 @@ Metrics/BlockNesting:
16
16
 
17
17
  # Offense count: 6
18
18
  Metrics/CyclomaticComplexity:
19
- Max: 10
19
+ Max: 12
20
20
 
21
21
  # Offense count: 493
22
22
  # Configuration parameters: AllowURI, URISchemes.
23
23
  Metrics/LineLength:
24
- Max: 196
24
+ Max: 199
25
25
 
26
26
  # Offense count: 44
27
27
  # Configuration parameters: CountComments.
@@ -31,11 +31,11 @@ Metrics/MethodLength:
31
31
  # Offense count: 2
32
32
  # Configuration parameters: CountKeywordArgs.
33
33
  Metrics/ParameterLists:
34
- Max: 6
34
+ Max: 7
35
35
 
36
36
  # Offense count: 6
37
37
  Metrics/PerceivedComplexity:
38
- Max: 11
38
+ Max: 17
39
39
 
40
40
  # Offense count: 1
41
41
  # Cop supports --auto-correct.
data/CHANGES.md CHANGED
@@ -1,8 +1,19 @@
1
1
  # Stable (3.x)
2
2
 
3
- 3.6.9
4
- --------
5
- - Make protobuf serivce directory pluggable.
3
+ 3.7.0 (pre0)
4
+ -----------
5
+ - Add `PB_USE_RAW_RPC_NAMES` option to preserve raw RPC name (since #underscore can be lossy).
6
+ - Add `PB_ENUM_UPCASE` option to generate enum values as upcased.
7
+ - Clean up dynamic code generation in prep for extension namespacing.
8
+ - Namespace extension fields.
9
+ - Field values should be stored via their fully qualified names
10
+ - Refresh google/protobuf/descriptor.{proto,pb.rb}
11
+ - Properly encode and decode negative enum values.
12
+
13
+ 3.6.7
14
+ -----
15
+ - An issue was reported with the encode memoization added in #293 with using any array modification
16
+ method on repeated fields. Remove memoization on encode (#305) until we can find a better solution.
6
17
 
7
18
  3.5.5
8
19
  --------
@@ -15,6 +15,7 @@ module Google
15
15
  class FileDescriptorProto < ::Protobuf::Message; end
16
16
  class DescriptorProto < ::Protobuf::Message
17
17
  class ExtensionRange < ::Protobuf::Message; end
18
+ class ReservedRange < ::Protobuf::Message; end
18
19
 
19
20
  end
20
21
 
@@ -48,6 +49,7 @@ module Google
48
49
 
49
50
  end
50
51
 
52
+ class OneofDescriptorProto < ::Protobuf::Message; end
51
53
  class EnumDescriptorProto < ::Protobuf::Message; end
52
54
  class EnumValueDescriptorProto < ::Protobuf::Message; end
53
55
  class ServiceDescriptorProto < ::Protobuf::Message; end
@@ -69,6 +71,12 @@ module Google
69
71
  define :STRING_PIECE, 2
70
72
  end
71
73
 
74
+ class JSType < ::Protobuf::Enum
75
+ define :JS_NORMAL, 0
76
+ define :JS_STRING, 1
77
+ define :JS_NUMBER, 2
78
+ end
79
+
72
80
  end
73
81
 
74
82
  class EnumOptions < ::Protobuf::Message; end
@@ -106,6 +114,7 @@ module Google
106
114
  repeated ::Google::Protobuf::FieldDescriptorProto, :extension, 7
107
115
  optional ::Google::Protobuf::FileOptions, :options, 8
108
116
  optional ::Google::Protobuf::SourceCodeInfo, :source_code_info, 9
117
+ optional :string, :syntax, 12
109
118
  end
110
119
 
111
120
  class DescriptorProto
@@ -114,13 +123,21 @@ module Google
114
123
  optional :int32, :end, 2
115
124
  end
116
125
 
126
+ class ReservedRange
127
+ optional :int32, :start, 1
128
+ optional :int32, :end, 2
129
+ end
130
+
117
131
  optional :string, :name, 1
118
132
  repeated ::Google::Protobuf::FieldDescriptorProto, :field, 2
119
133
  repeated ::Google::Protobuf::FieldDescriptorProto, :extension, 6
120
134
  repeated ::Google::Protobuf::DescriptorProto, :nested_type, 3
121
135
  repeated ::Google::Protobuf::EnumDescriptorProto, :enum_type, 4
122
136
  repeated ::Google::Protobuf::DescriptorProto::ExtensionRange, :extension_range, 5
137
+ repeated ::Google::Protobuf::OneofDescriptorProto, :oneof_decl, 8
123
138
  optional ::Google::Protobuf::MessageOptions, :options, 7
139
+ repeated ::Google::Protobuf::DescriptorProto::ReservedRange, :reserved_range, 9
140
+ repeated :string, :reserved_name, 10
124
141
  end
125
142
 
126
143
  class FieldDescriptorProto
@@ -131,9 +148,14 @@ module Google
131
148
  optional :string, :type_name, 6
132
149
  optional :string, :extendee, 2
133
150
  optional :string, :default_value, 7
151
+ optional :int32, :oneof_index, 9
134
152
  optional ::Google::Protobuf::FieldOptions, :options, 8
135
153
  end
136
154
 
155
+ class OneofDescriptorProto
156
+ optional :string, :name, 1
157
+ end
158
+
137
159
  class EnumDescriptorProto
138
160
  optional :string, :name, 1
139
161
  repeated ::Google::Protobuf::EnumValueDescriptorProto, :value, 2
@@ -157,6 +179,8 @@ module Google
157
179
  optional :string, :input_type, 2
158
180
  optional :string, :output_type, 3
159
181
  optional ::Google::Protobuf::MethodOptions, :options, 4
182
+ optional :bool, :client_streaming, 5, :default => false
183
+ optional :bool, :server_streaming, 6, :default => false
160
184
  end
161
185
 
162
186
  class FileOptions
@@ -164,11 +188,17 @@ module Google
164
188
  optional :string, :java_outer_classname, 8
165
189
  optional :bool, :java_multiple_files, 10, :default => false
166
190
  optional :bool, :java_generate_equals_and_hash, 20, :default => false
191
+ optional :bool, :java_string_check_utf8, 27, :default => false
167
192
  optional ::Google::Protobuf::FileOptions::OptimizeMode, :optimize_for, 9, :default => ::Google::Protobuf::FileOptions::OptimizeMode::SPEED
168
193
  optional :string, :go_package, 11
169
194
  optional :bool, :cc_generic_services, 16, :default => false
170
195
  optional :bool, :java_generic_services, 17, :default => false
171
196
  optional :bool, :py_generic_services, 18, :default => false
197
+ optional :bool, :deprecated, 23, :default => false
198
+ optional :bool, :cc_enable_arenas, 31, :default => false
199
+ optional :string, :objc_class_prefix, 36
200
+ optional :string, :csharp_namespace, 37
201
+ optional :bool, :javanano_use_deprecated_package, 38
172
202
  repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
173
203
  # Extension Fields
174
204
  extensions 1000...536870912
@@ -177,6 +207,8 @@ module Google
177
207
  class MessageOptions
178
208
  optional :bool, :message_set_wire_format, 1, :default => false
179
209
  optional :bool, :no_standard_descriptor_accessor, 2, :default => false
210
+ optional :bool, :deprecated, 3, :default => false
211
+ optional :bool, :map_entry, 7
180
212
  repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
181
213
  # Extension Fields
182
214
  extensions 1000...536870912
@@ -185,9 +217,9 @@ module Google
185
217
  class FieldOptions
186
218
  optional ::Google::Protobuf::FieldOptions::CType, :ctype, 1, :default => ::Google::Protobuf::FieldOptions::CType::STRING
187
219
  optional :bool, :packed, 2
220
+ optional ::Google::Protobuf::FieldOptions::JSType, :jstype, 6, :default => ::Google::Protobuf::FieldOptions::JSType::JS_NORMAL
188
221
  optional :bool, :lazy, 5, :default => false
189
222
  optional :bool, :deprecated, 3, :default => false
190
- optional :string, :experimental_map_key, 9
191
223
  optional :bool, :weak, 10, :default => false
192
224
  repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
193
225
  # Extension Fields
@@ -195,25 +227,29 @@ module Google
195
227
  end
196
228
 
197
229
  class EnumOptions
198
- optional :bool, :allow_alias, 2, :default => true
230
+ optional :bool, :allow_alias, 2
231
+ optional :bool, :deprecated, 3, :default => false
199
232
  repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
200
233
  # Extension Fields
201
234
  extensions 1000...536870912
202
235
  end
203
236
 
204
237
  class EnumValueOptions
238
+ optional :bool, :deprecated, 1, :default => false
205
239
  repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
206
240
  # Extension Fields
207
241
  extensions 1000...536870912
208
242
  end
209
243
 
210
244
  class ServiceOptions
245
+ optional :bool, :deprecated, 33, :default => false
211
246
  repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
212
247
  # Extension Fields
213
248
  extensions 1000...536870912
214
249
  end
215
250
 
216
251
  class MethodOptions
252
+ optional :bool, :deprecated, 33, :default => false
217
253
  repeated ::Google::Protobuf::UninterpretedOption, :uninterpreted_option, 999
218
254
  # Extension Fields
219
255
  extensions 1000...536870912
@@ -240,6 +276,7 @@ module Google
240
276
  repeated :int32, :span, 2, :packed => true
241
277
  optional :string, :leading_comments, 3
242
278
  optional :string, :trailing_comments, 4
279
+ repeated :string, :leading_detached_comments, 6
243
280
  end
244
281
 
245
282
  repeated ::Google::Protobuf::SourceCodeInfo::Location, :location, 1
@@ -41,8 +41,8 @@ module Protobuf
41
41
  :bool => ::Protobuf::Field::BoolField,
42
42
  }.freeze
43
43
 
44
- def self.build(message_class, rule, type, name, tag, options = {})
45
- field_class(type).new(message_class, rule, field_type(type), name, tag, options)
44
+ def self.build(message_class, rule, type, name, tag, simple_name, options = {})
45
+ field_class(type).new(message_class, rule, field_type(type), name, tag, simple_name, options)
46
46
  end
47
47
 
48
48
  # Returns the field class for primitives,
@@ -21,7 +21,7 @@ module Protobuf
21
21
  ##
22
22
  # Attributes
23
23
  #
24
- attr_reader :message_class, :name, :options, :rule, :tag, :type_class
24
+ attr_reader :message_class, :name, :fully_qualified_name, :options, :rule, :tag, :type_class
25
25
 
26
26
  ##
27
27
  # Class Methods
@@ -35,16 +35,17 @@ module Protobuf
35
35
  # Constructor
36
36
  #
37
37
 
38
- def initialize(message_class, rule, type_class, name, tag, options)
38
+ def initialize(message_class, rule, type_class, fully_qualified_name, tag, simple_name, options)
39
39
  @message_class = message_class
40
- @name = name
40
+ @name = simple_name || fully_qualified_name
41
+ @fully_qualified_name = fully_qualified_name
41
42
  @rule = rule
42
43
  @tag = tag
43
44
  @type_class = type_class
44
45
  @options = options
45
46
 
46
47
  validate_packed_field if packed?
47
- define_accessor
48
+ define_accessor(simple_name, fully_qualified_name) if simple_name
48
49
  tag_encoded
49
50
  end
50
51
 
@@ -69,10 +70,12 @@ module Protobuf
69
70
  end
70
71
 
71
72
  def default_value
72
- @default_value ||= case
73
- when optional? then typed_default_value
74
- when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze
75
- when required? then nil
73
+ @default_value ||= if optional? || required?
74
+ typed_default_value
75
+ elsif repeated?
76
+ ::Protobuf::Field::FieldArray.new(self).freeze
77
+ else
78
+ fail "Unknown field label -- something went very wrong"
76
79
  end
77
80
  end
78
81
 
@@ -122,10 +125,10 @@ module Protobuf
122
125
 
123
126
  # FIXME: need to cleanup (rename) this warthog of a method.
124
127
  def set(message_instance, bytes)
125
- return message_instance.__send__(setter, decode(bytes)) unless repeated?
126
- return message_instance.__send__(getter) << decode(bytes) unless packed?
128
+ return message_instance[name] = decode(bytes) unless repeated?
129
+ return message_instance[name] << decode(bytes) unless packed?
127
130
 
128
- array = message_instance.__send__(getter)
131
+ array = message_instance[name]
129
132
  stream = StringIO.new(bytes)
130
133
 
131
134
  if wire_type == ::Protobuf::WireType::VARINT
@@ -163,93 +166,33 @@ module Protobuf
163
166
  ::Protobuf::WireType::VARINT
164
167
  end
165
168
 
169
+ def fully_qualified_name_only!
170
+ @name = @fully_qualified_name
171
+ end
172
+
166
173
  private
167
174
 
168
175
  ##
169
176
  # Private Instance Methods
170
177
  #
171
178
 
172
- def define_accessor
173
- if repeated?
174
- define_array_getter
175
- define_array_setter
176
- else
177
- define_getter
178
- define_setter
179
- end
180
- end
181
-
182
- def define_array_getter
183
- field = self
184
- method_name = field.getter
185
-
179
+ def define_accessor(simple_field_name, fully_qualified_field_name)
186
180
  message_class.class_eval do
187
- define_method(method_name) do
188
- @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field)
181
+ define_method("#{simple_field_name}!") do
182
+ @values[fully_qualified_field_name]
189
183
  end
190
184
  end
191
185
 
192
- ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated?
193
- end
194
-
195
- def define_array_setter
196
- field = self
197
- method_name = field.setter
198
-
199
186
  message_class.class_eval do
200
- define_method(method_name) do |val|
201
- if val.is_a?(Array)
202
- val = val.dup
203
- val.compact!
204
- else
205
- fail TypeError, <<-TYPE_ERROR
206
- Expected repeated value of type '#{field.type_class}'
207
- Got '#{val.class}' for repeated protobuf field #{field.name}
208
- TYPE_ERROR
209
- end
210
-
211
- if val.nil? || (val.respond_to?(:empty?) && val.empty?)
212
- @values.delete(field.name)
213
- else
214
- @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field)
215
- @values[field.name].replace(val)
216
- end
217
- end
187
+ define_method(simple_field_name) { self[fully_qualified_field_name] }
188
+ define_method("#{simple_field_name}=") { |v| self[fully_qualified_field_name] = v }
218
189
  end
219
190
 
220
- ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated?
221
- end
222
-
223
- def define_getter
224
- field = self
225
- method_name = field.getter
226
-
227
- message_class.class_eval do
228
- define_method(method_name) do
229
- @values[field.name] || field.default_value
230
- end
231
- end
232
-
233
- ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated?
234
- end
235
-
236
- def define_setter
237
- field = self
238
- method_name = field.setter
239
-
240
- message_class.class_eval do
241
- define_method(method_name) do |val|
242
- if val.nil? || (val.respond_to?(:empty?) && val.empty?)
243
- @values.delete(field.name)
244
- elsif field.acceptable?(val)
245
- @values[field.name] = field.coerce!(val)
246
- else
247
- fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}"
248
- end
249
- end
250
- end
191
+ return unless deprecated?
251
192
 
252
- ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated?
193
+ ::Protobuf.field_deprecator.deprecate_method(message_class, simple_field_name)
194
+ ::Protobuf.field_deprecator.deprecate_method(message_class, "#{simple_field_name}!")
195
+ ::Protobuf.field_deprecator.deprecate_method(message_class, "#{simple_field_name}=")
253
196
  end
254
197
 
255
198
  def typed_default_value
@@ -45,21 +45,11 @@ module Protobuf
45
45
  # Private Instance Methods
46
46
  #
47
47
 
48
- def define_getter
49
- field = self
50
- method_name = field.getter
51
-
48
+ def define_accessor(simple_field_name, _fully_qualified_field_name)
49
+ super
52
50
  message_class.class_eval do
53
- define_method(method_name) do
54
- @values.fetch(field.name, field.default_value)
55
- end
51
+ alias_method "#{simple_field_name}?", simple_field_name
56
52
  end
57
-
58
- message_class.class_eval do
59
- alias_method "#{method_name}?", method_name
60
- end
61
-
62
- ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated?
63
53
  end
64
54
 
65
55
  end
@@ -33,7 +33,6 @@ module Protobuf
33
33
  end
34
34
 
35
35
  def encode(value)
36
- value_to_encode = ""
37
36
  if value.is_a?(::Protobuf::Message)
38
37
  value_to_encode = value.encode
39
38
  else
@@ -50,32 +49,17 @@ module Protobuf
50
49
  ::Protobuf::WireType::LENGTH_DELIMITED
51
50
  end
52
51
 
53
- private
54
-
55
- ##
56
- # Private Instance Methods
57
- #
58
-
59
- def define_setter
60
- field = self
61
- method_name = field.setter
62
-
63
- message_class.class_eval do
64
- define_method(method_name) do |val|
65
- case val
66
- when String, Symbol
67
- @values[field.name] = "#{val}"
68
- when NilClass
69
- @values.delete(field.name)
70
- when ::Protobuf::Message
71
- @values[field.name] = val.dup
72
- else
73
- fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}"
74
- end
75
- end
52
+ def coerce!(value)
53
+ case value
54
+ when String, Symbol
55
+ "#{value}"
56
+ when NilClass
57
+ nil
58
+ when ::Protobuf::Message
59
+ value.dup
60
+ else
61
+ fail TypeError, "Unacceptable value #{value} for field #{name} of type #{type_class}"
76
62
  end
77
-
78
- ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated?
79
63
  end
80
64
  end
81
65
  end