protobuf 3.3.6 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +48 -0
  3. data/.rubocop_todo.yml +79 -0
  4. data/.travis.yml +12 -4
  5. data/Rakefile +14 -11
  6. data/bin/protoc-gen-ruby +0 -1
  7. data/bin/rpc_server +1 -0
  8. data/install-protobuf.sh +8 -0
  9. data/lib/protobuf.rb +30 -24
  10. data/lib/protobuf/cli.rb +35 -35
  11. data/lib/protobuf/code_generator.rb +11 -8
  12. data/lib/protobuf/decoder.rb +4 -5
  13. data/lib/protobuf/deprecation.rb +20 -0
  14. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +2 -0
  15. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +2 -0
  16. data/lib/protobuf/encoder.rb +9 -4
  17. data/lib/protobuf/enum.rb +38 -54
  18. data/lib/protobuf/field.rb +2 -2
  19. data/lib/protobuf/field/base_field.rb +28 -32
  20. data/lib/protobuf/field/bool_field.rb +4 -4
  21. data/lib/protobuf/field/bytes_field.rb +5 -4
  22. data/lib/protobuf/field/double_field.rb +0 -1
  23. data/lib/protobuf/field/enum_field.rb +4 -7
  24. data/lib/protobuf/field/field_array.rb +3 -4
  25. data/lib/protobuf/field/fixed32_field.rb +1 -1
  26. data/lib/protobuf/field/fixed64_field.rb +0 -1
  27. data/lib/protobuf/field/float_field.rb +0 -1
  28. data/lib/protobuf/field/int32_field.rb +0 -1
  29. data/lib/protobuf/field/int64_field.rb +0 -1
  30. data/lib/protobuf/field/integer_field.rb +0 -1
  31. data/lib/protobuf/field/message_field.rb +2 -3
  32. data/lib/protobuf/field/sfixed32_field.rb +0 -1
  33. data/lib/protobuf/field/sfixed64_field.rb +0 -1
  34. data/lib/protobuf/field/signed_integer_field.rb +0 -1
  35. data/lib/protobuf/field/sint32_field.rb +0 -1
  36. data/lib/protobuf/field/sint64_field.rb +0 -1
  37. data/lib/protobuf/field/string_field.rb +0 -1
  38. data/lib/protobuf/field/uint32_field.rb +0 -1
  39. data/lib/protobuf/field/uint64_field.rb +0 -1
  40. data/lib/protobuf/field/varint_field.rb +0 -1
  41. data/lib/protobuf/generators/base.rb +1 -2
  42. data/lib/protobuf/generators/enum_generator.rb +1 -2
  43. data/lib/protobuf/generators/extension_generator.rb +1 -2
  44. data/lib/protobuf/generators/field_generator.rb +4 -5
  45. data/lib/protobuf/generators/file_generator.rb +22 -27
  46. data/lib/protobuf/generators/group_generator.rb +15 -16
  47. data/lib/protobuf/generators/message_generator.rb +13 -14
  48. data/lib/protobuf/generators/printable.rb +9 -10
  49. data/lib/protobuf/generators/service_generator.rb +1 -2
  50. data/lib/protobuf/lifecycle.rb +20 -33
  51. data/lib/protobuf/logging.rb +4 -6
  52. data/lib/protobuf/message.rb +22 -16
  53. data/lib/protobuf/message/fields.rb +14 -17
  54. data/lib/protobuf/message/serialization.rb +6 -5
  55. data/lib/protobuf/rpc/buffer.rb +10 -12
  56. data/lib/protobuf/rpc/client.rb +12 -12
  57. data/lib/protobuf/rpc/connectors/base.rb +4 -3
  58. data/lib/protobuf/rpc/connectors/common.rb +15 -17
  59. data/lib/protobuf/rpc/connectors/socket.rb +2 -2
  60. data/lib/protobuf/rpc/connectors/zmq.rb +118 -108
  61. data/lib/protobuf/rpc/dynamic_discovery.pb.rb +2 -0
  62. data/lib/protobuf/rpc/env.rb +12 -12
  63. data/lib/protobuf/rpc/error.rb +1 -1
  64. data/lib/protobuf/rpc/error/client_error.rb +4 -4
  65. data/lib/protobuf/rpc/error/server_error.rb +6 -6
  66. data/lib/protobuf/rpc/middleware/exception_handler.rb +1 -1
  67. data/lib/protobuf/rpc/middleware/logger.rb +3 -3
  68. data/lib/protobuf/rpc/middleware/request_decoder.rb +5 -5
  69. data/lib/protobuf/rpc/middleware/response_encoder.rb +3 -3
  70. data/lib/protobuf/rpc/rpc.pb.rb +2 -0
  71. data/lib/protobuf/rpc/servers/socket/server.rb +75 -65
  72. data/lib/protobuf/rpc/servers/socket/worker.rb +2 -2
  73. data/lib/protobuf/rpc/servers/socket_runner.rb +12 -6
  74. data/lib/protobuf/rpc/servers/zmq/broker.rb +10 -6
  75. data/lib/protobuf/rpc/servers/zmq/server.rb +20 -26
  76. data/lib/protobuf/rpc/servers/zmq/util.rb +7 -7
  77. data/lib/protobuf/rpc/servers/zmq/worker.rb +5 -7
  78. data/lib/protobuf/rpc/servers/zmq_runner.rb +14 -3
  79. data/lib/protobuf/rpc/service.rb +15 -15
  80. data/lib/protobuf/rpc/service_directory.rb +7 -11
  81. data/lib/protobuf/rpc/service_dispatcher.rb +3 -3
  82. data/lib/protobuf/rpc/service_filters.rb +27 -28
  83. data/lib/protobuf/rpc/stat.rb +4 -7
  84. data/lib/protobuf/socket.rb +0 -1
  85. data/lib/protobuf/tasks/compile.rake +2 -2
  86. data/lib/protobuf/version.rb +1 -1
  87. data/protobuf.gemspec +20 -4
  88. data/spec/benchmark/tasks.rb +49 -23
  89. data/spec/bin/protoc-gen-ruby_spec.rb +11 -6
  90. data/spec/encoding/all_types_spec.rb +91 -77
  91. data/spec/encoding/extreme_values_spec.rb +0 -0
  92. data/spec/functional/socket_server_spec.rb +9 -10
  93. data/spec/functional/zmq_server_spec.rb +21 -19
  94. data/spec/lib/protobuf/cli_spec.rb +20 -20
  95. data/spec/lib/protobuf/code_generator_spec.rb +6 -6
  96. data/spec/lib/protobuf/enum_spec.rb +57 -31
  97. data/spec/lib/protobuf/field/float_field_spec.rb +2 -2
  98. data/spec/lib/protobuf/field/int32_field_spec.rb +1 -1
  99. data/spec/lib/protobuf/field/string_field_spec.rb +7 -8
  100. data/spec/lib/protobuf/field_spec.rb +3 -6
  101. data/spec/lib/protobuf/generators/base_spec.rb +6 -6
  102. data/spec/lib/protobuf/generators/enum_generator_spec.rb +22 -17
  103. data/spec/lib/protobuf/generators/extension_generator_spec.rb +8 -9
  104. data/spec/lib/protobuf/generators/field_generator_spec.rb +14 -11
  105. data/spec/lib/protobuf/generators/file_generator_spec.rb +7 -4
  106. data/spec/lib/protobuf/generators/service_generator_spec.rb +14 -11
  107. data/spec/lib/protobuf/lifecycle_spec.rb +9 -4
  108. data/spec/lib/protobuf/message_spec.rb +63 -35
  109. data/spec/lib/protobuf/optionable_spec.rb +3 -3
  110. data/spec/lib/protobuf/rpc/client_spec.rb +2 -2
  111. data/spec/lib/protobuf/rpc/connector_spec.rb +1 -1
  112. data/spec/lib/protobuf/rpc/connectors/base_spec.rb +6 -6
  113. data/spec/lib/protobuf/rpc/connectors/common_spec.rb +26 -18
  114. data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +4 -4
  115. data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +11 -9
  116. data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +2 -2
  117. data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +7 -7
  118. data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +14 -14
  119. data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +5 -5
  120. data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +1 -1
  121. data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +9 -7
  122. data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +9 -9
  123. data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +2 -2
  124. data/spec/lib/protobuf/rpc/service_directory_spec.rb +24 -23
  125. data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +4 -4
  126. data/spec/lib/protobuf/rpc/service_filters_spec.rb +84 -51
  127. data/spec/lib/protobuf/rpc/service_spec.rb +15 -14
  128. data/spec/lib/protobuf/rpc/stat_spec.rb +1 -1
  129. data/spec/lib/protobuf_spec.rb +9 -9
  130. data/spec/spec_helper.rb +7 -19
  131. data/spec/support/server.rb +29 -59
  132. data/spec/support/test/defaults.pb.rb +2 -0
  133. data/spec/support/test/enum.pb.rb +2 -0
  134. data/spec/support/test/extended.pb.rb +2 -0
  135. data/spec/support/test/google_unittest_import.pb.rb +2 -0
  136. data/spec/support/test/google_unittest_import_public.pb.rb +2 -0
  137. data/spec/support/test/multi_field_extensions.pb.rb +2 -0
  138. data/spec/support/test/resource.pb.rb +2 -0
  139. data/spec/support/test/resource_service.rb +17 -20
  140. metadata +153 -112
  141. data/lib/protobuf/deprecator.rb +0 -42
@@ -6,7 +6,7 @@ module Protobuf
6
6
  CodeGeneratorFatalError = Class.new(RuntimeError)
7
7
 
8
8
  def self.fatal(message)
9
- raise CodeGeneratorFatalError, message
9
+ fail CodeGeneratorFatalError, message
10
10
  end
11
11
 
12
12
  def self.print_tag_warning_suppress
@@ -18,24 +18,27 @@ module Protobuf
18
18
  STDERR.puts("[WARN] #{message}")
19
19
  end
20
20
 
21
+ private
22
+
23
+ attr_accessor :request
24
+
25
+ public
26
+
21
27
  def initialize(request_bytes)
22
- @request = ::Google::Protobuf::Compiler::CodeGeneratorRequest.decode(request_bytes)
23
- @generated_files = []
28
+ self.request = ::Google::Protobuf::Compiler::CodeGeneratorRequest.decode(request_bytes)
24
29
  end
25
30
 
26
31
  def generate_file(file_descriptor)
27
- file_generator = ::Protobuf::Generators::FileGenerator.new(file_descriptor)
28
- @generated_files << file_generator.generate_output_file
32
+ ::Protobuf::Generators::FileGenerator.new(file_descriptor).generate_output_file
29
33
  end
30
34
 
31
35
  def response_bytes
32
- @request.proto_file.each do |file_descriptor|
36
+ generated_files = request.proto_file.map do |file_descriptor|
33
37
  generate_file(file_descriptor)
34
38
  end
35
39
 
36
- return ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => @generated_files)
40
+ ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => generated_files)
37
41
  end
38
42
 
39
43
  end
40
44
  end
41
-
@@ -24,14 +24,14 @@ module Protobuf
24
24
  when ::Protobuf::WireType::FIXED32 then
25
25
  read_fixed32(stream)
26
26
  when ::Protobuf::WireType::START_GROUP then
27
- raise NotImplementedError, 'Group is deprecated.'
27
+ fail NotImplementedError, 'Group is deprecated.'
28
28
  when ::Protobuf::WireType::END_GROUP then
29
- raise NotImplementedError, 'Group is deprecated.'
29
+ fail NotImplementedError, 'Group is deprecated.'
30
30
  else
31
- raise InvalidWireType, wire_type
31
+ fail InvalidWireType, wire_type
32
32
  end
33
33
 
34
- return tag, bytes
34
+ [tag, bytes]
35
35
  end
36
36
 
37
37
  # Read 32-bit string value from +stream+.
@@ -71,4 +71,3 @@ module Protobuf
71
71
 
72
72
  end
73
73
  end
74
-
@@ -0,0 +1,20 @@
1
+ require 'active_support/deprecation'
2
+
3
+ module Protobuf
4
+ class Deprecation < ::ActiveSupport::Deprecation
5
+ def deprecate_methods(*args)
6
+ args.last.merge!(:deprecator => self) if args.last.is_a?(Hash)
7
+ super
8
+ end
9
+
10
+ def define_deprecated_methods(target_module, method_hash)
11
+ target_module.module_eval do
12
+ method_hash.each do |old_method, new_method|
13
+ alias_method old_method, new_method
14
+ end
15
+ end
16
+
17
+ deprecate_methods(target_module, method_hash)
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  ##
2
4
  # This file is auto-generated. DO NOT EDIT!
3
5
  #
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  ##
2
4
  # This file is auto-generated. DO NOT EDIT!
3
5
  #
@@ -5,15 +5,21 @@ module Protobuf
5
5
  new(stream, message).encode
6
6
  end
7
7
 
8
+ private
9
+
10
+ attr_writer :message, :stream
11
+
12
+ public
13
+
8
14
  attr_reader :message, :stream
9
15
 
10
16
  def initialize(message, stream)
11
17
  unless message.respond_to?(:each_field_for_serialization)
12
- raise ArgumentError, "Message instance must respond to :each_field_for_serialization"
18
+ fail ArgumentError, "Message instance must respond to :each_field_for_serialization"
13
19
  end
14
20
 
15
- @message = message
16
- @stream = stream
21
+ self.message = message
22
+ self.stream = stream
17
23
  end
18
24
 
19
25
  def encode
@@ -59,4 +65,3 @@ module Protobuf
59
65
 
60
66
  end
61
67
  end
62
-
@@ -1,38 +1,20 @@
1
1
  require 'delegate'
2
2
  require 'protobuf/optionable'
3
- require 'protobuf/deprecator'
4
3
 
5
4
  ##
6
5
  # Adding extension to Numeric until
7
6
  # we can get people to stop calling #value
8
7
  # on Enum instances.
9
8
  #
10
- class Numeric
11
- unless method_defined?(:value)
12
- def value
13
- $stderr.puts <<-DEPRECATION
14
- [DEPRECATED] Enum#value is deprecated and will be removed in the next release.
15
- Use Enum#to_i instead.
16
- DEPRECATION
17
- self
18
- end
19
- end
20
- end
9
+ ::Protobuf.deprecator.define_deprecated_methods(Numeric, :value => :to_int)
21
10
 
22
11
  module Protobuf
23
12
  class Enum < SimpleDelegator
24
-
25
- ##
26
- # Deprecations
27
- #
28
-
29
- extend ::Protobuf::Deprecator
30
-
31
13
  # Public: Allows setting Options on the Enum class.
32
14
  include ::Protobuf::Optionable
33
15
 
34
16
  def self.aliases_allowed?
35
- self.get_option(:allow_alias)
17
+ get_option(:allow_alias)
36
18
  end
37
19
 
38
20
  # Public: Get all integer tags defined by this enum.
@@ -51,7 +33,7 @@ module Protobuf
51
33
  # Returns an array of unique integers.
52
34
  #
53
35
  def self.all_tags
54
- @all_tags ||= self.enums.map(&:to_i).uniq
36
+ @all_tags ||= enums.map(&:to_i).uniq
55
37
  end
56
38
 
57
39
  # Internal: DSL method to create a new Enum. The given name will
@@ -70,7 +52,7 @@ module Protobuf
70
52
  # Returns nothing.
71
53
  #
72
54
  def self.define(name, tag)
73
- enum = self.new(self, name, tag)
55
+ enum = new(self, name, tag)
74
56
  @enums ||= []
75
57
  @enums << enum
76
58
  const_set(name, enum)
@@ -78,8 +60,8 @@ module Protobuf
78
60
 
79
61
  # Public: All defined enums.
80
62
  #
81
- def self.enums
82
- @enums
63
+ class << self
64
+ attr_reader :enums
83
65
  end
84
66
 
85
67
  # Public: Get an array of Enum objects with the given tag.
@@ -101,9 +83,9 @@ module Protobuf
101
83
  # Returns an array with zero or more Enum objects or nil.
102
84
  #
103
85
  def self.enums_for_tag(tag)
104
- self.enums.select { |enum|
86
+ enums.select do |enum|
105
87
  enum.to_i == tag.to_i
106
- }
88
+ end
107
89
  end
108
90
 
109
91
  # Public: Get the Enum associated with the given name.
@@ -125,7 +107,7 @@ module Protobuf
125
107
  # Returns the Enum object with the given name or nil.
126
108
  #
127
109
  def self.enum_for_name(name)
128
- self.const_get(name)
110
+ const_get(name)
129
111
  rescue ::NameError
130
112
  nil
131
113
  end
@@ -138,7 +120,7 @@ module Protobuf
138
120
  # Enums, the first enum defined will be returned.
139
121
  #
140
122
  def self.enum_for_tag(tag)
141
- self.enums_for_tag(tag).first
123
+ enums_for_tag(tag).first
142
124
  end
143
125
 
144
126
  # Public: Get an Enum by a variety of type-checking mechanisms.
@@ -206,7 +188,7 @@ module Protobuf
206
188
  # the first defined name will be returned.
207
189
  #
208
190
  def self.name_for_tag(tag)
209
- self.enum_for_tag(tag).try(:name)
191
+ enum_for_tag(tag).try(:name)
210
192
  end
211
193
 
212
194
  # Public: Check if the given tag is defined by this Enum.
@@ -216,37 +198,43 @@ module Protobuf
216
198
  # Returns a boolean.
217
199
  #
218
200
  def self.valid_tag?(tag)
219
- tag.respond_to?(:to_i) && self.all_tags.include?(tag.to_i)
201
+ tag.respond_to?(:to_i) && all_tags.include?(tag.to_i)
220
202
  end
221
203
 
222
204
  # Public: [DEPRECATED] Return a hash of Enum objects keyed
223
205
  # by their :name.
224
206
  #
225
207
  def self.values
226
- self.warn_deprecated(:values, :enums)
227
-
228
- @values ||= begin
229
- self.enums.inject({}) do |hash, enum|
230
- hash[enum.name] = enum
231
- hash
232
- end
233
- end
208
+ @values ||= enums.each_with_object({}) do |enum, hash|
209
+ hash[enum.name] = enum
210
+ end
234
211
  end
235
212
 
236
213
  ##
237
214
  # Class Deprecations
238
215
  #
216
+ class << self
217
+ ::Protobuf.deprecator.define_deprecated_methods(
218
+ self,
219
+ :enum_by_value => :enum_for_tag,
220
+ :name_by_value => :name_for_tag,
221
+ :get_name_by_tag => :name_for_tag,
222
+ :value_by_name => :enum_for_name,
223
+ )
239
224
 
240
- deprecate_class_method :enum_by_value, :enum_for_tag
241
- deprecate_class_method :name_by_value, :name_for_tag
242
- deprecate_class_method :get_name_by_tag, :name_for_tag
243
- deprecate_class_method :value_by_name, :enum_for_name
244
-
225
+ ::Protobuf.deprecator.deprecate_methods(self, :values => :enums)
226
+ end
245
227
 
246
228
  ##
247
229
  # Attributes
248
230
  #
249
231
 
232
+ private
233
+
234
+ attr_writer :parent_class, :name, :tag
235
+
236
+ public
237
+
250
238
  attr_reader :parent_class, :name, :tag
251
239
 
252
240
  ##
@@ -254,10 +242,10 @@ module Protobuf
254
242
  #
255
243
 
256
244
  def initialize(parent_class, name, tag)
257
- @parent_class = parent_class
258
- @name = name
259
- @tag = tag
260
- super(@tag)
245
+ self.parent_class = parent_class
246
+ self.name = name
247
+ self.tag = tag
248
+ super(tag)
261
249
  end
262
250
 
263
251
  # Overriding the class so ActiveRecord/Arel visitor will visit the enum as a Fixnum
@@ -281,11 +269,11 @@ module Protobuf
281
269
  def to_s(format = :tag)
282
270
  case format
283
271
  when :tag then
284
- self.to_i.to_s
272
+ to_i.to_s
285
273
  when :name then
286
274
  name.to_s
287
275
  else
288
- self.to_i.to_s
276
+ to_i.to_s
289
277
  end
290
278
  end
291
279
 
@@ -305,10 +293,7 @@ module Protobuf
305
293
  end
306
294
  end
307
295
 
308
- def value
309
- parent_class.warn_deprecated(:value, :to_i)
310
- to_i
311
- end
296
+ ::Protobuf.deprecator.define_deprecated_methods(self, :value => :to_i)
312
297
 
313
298
  ##
314
299
  # Instance Aliases
@@ -316,4 +301,3 @@ module Protobuf
316
301
  alias_method :to_hash_value, :to_i
317
302
  end
318
303
  end
319
-
@@ -38,7 +38,7 @@ module Protobuf
38
38
  :sfixed64 => ::Protobuf::Field::Sfixed64Field,
39
39
  :string => ::Protobuf::Field::StringField,
40
40
  :bytes => ::Protobuf::Field::BytesField,
41
- :bool => ::Protobuf::Field::BoolField
41
+ :bool => ::Protobuf::Field::BoolField,
42
42
  }.freeze
43
43
 
44
44
  def self.build(message_class, rule, type, name, tag, options = {})
@@ -59,7 +59,7 @@ module Protobuf
59
59
  elsif type < ::Protobuf::Field::BaseField
60
60
  type
61
61
  else
62
- raise ArgumentError, "Invalid field type #{type}"
62
+ fail ArgumentError, "Invalid field type #{type}"
63
63
  end
64
64
  end
65
65
 
@@ -14,7 +14,7 @@ module Protobuf
14
14
  PACKED_TYPES = [
15
15
  ::Protobuf::WireType::VARINT,
16
16
  ::Protobuf::WireType::FIXED32,
17
- ::Protobuf::WireType::FIXED64
17
+ ::Protobuf::WireType::FIXED64,
18
18
  ].freeze
19
19
 
20
20
  ##
@@ -51,7 +51,7 @@ module Protobuf
51
51
  # Public Instance Methods
52
52
  #
53
53
 
54
- def acceptable?(value)
54
+ def acceptable?(_value)
55
55
  true
56
56
  end
57
57
 
@@ -59,8 +59,8 @@ module Protobuf
59
59
  value
60
60
  end
61
61
 
62
- def decode(bytes)
63
- raise NotImplementedError, "#{self.class.name}\#decode"
62
+ def decode(_bytes)
63
+ fail NotImplementedError, "#{self.class.name}##{__method__}"
64
64
  end
65
65
 
66
66
  def default
@@ -79,8 +79,8 @@ module Protobuf
79
79
  options.key?(:deprecated)
80
80
  end
81
81
 
82
- def encode(value)
83
- raise NotImplementedError, "#{self.class.name}\#encode"
82
+ def encode(_value)
83
+ fail NotImplementedError, "#{self.class.name}##{__method__}"
84
84
  end
85
85
 
86
86
  def extension?
@@ -119,7 +119,7 @@ module Protobuf
119
119
  rule == :required
120
120
  end
121
121
 
122
- # FIXME need to cleanup (rename) this warthog of a method.
122
+ # FIXME: need to cleanup (rename) this warthog of a method.
123
123
  def set(message_instance, bytes)
124
124
  if packed?
125
125
  array = message_instance.__send__(getter)
@@ -148,21 +148,12 @@ module Protobuf
148
148
  @setter ||= "#{name}="
149
149
  end
150
150
 
151
- # FIXME add packed, deprecated, extension options to to_s output
151
+ # FIXME: add packed, deprecated, extension options to to_s output
152
152
  def to_s
153
153
  "#{rule} #{type_class} #{name} = #{tag} #{default ? "[default=#{default.inspect}]" : ''}"
154
154
  end
155
155
 
156
- def type
157
- $stderr.puts("[DEPRECATED] #{self.class.name}#type usage is deprecated.\nPlease use #type_class instead.")
158
- type_class
159
- end
160
-
161
- def warn_if_deprecated
162
- if ::Protobuf.print_deprecation_warnings? && deprecated?
163
- $stderr.puts("[WARNING] #{message_class.name}##{name} field usage is deprecated.")
164
- end
165
- end
156
+ ::Protobuf.deprecator.define_deprecated_methods(self, :type => :type_class)
166
157
 
167
158
  def wire_type
168
159
  ::Protobuf::WireType::VARINT
@@ -186,25 +177,27 @@ module Protobuf
186
177
 
187
178
  def define_array_getter
188
179
  field = self
180
+ method_name = field.getter
181
+
189
182
  message_class.class_eval do
190
- define_method(field.getter) do
191
- field.warn_if_deprecated
183
+ define_method(method_name) do
192
184
  @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field)
193
185
  end
186
+ ::Protobuf.deprecator.deprecate_methods(method_name)
194
187
  end
195
188
  end
196
189
 
197
190
  def define_array_setter
198
191
  field = self
199
- message_class.class_eval do
200
- define_method(field.setter) do |val|
201
- field.warn_if_deprecated
192
+ method_name = field.setter
202
193
 
194
+ message_class.class_eval do
195
+ define_method(method_name) do |val|
203
196
  if val.is_a?(Array)
204
197
  val = val.dup
205
198
  val.compact!
206
199
  else
207
- raise TypeError, <<-TYPE_ERROR
200
+ fail TypeError, <<-TYPE_ERROR
208
201
  Expected repeated value of type '#{field.type_class}'
209
202
  Got '#{val.class}' for repeated protobuf field #{field.name}
210
203
  TYPE_ERROR
@@ -217,33 +210,37 @@ module Protobuf
217
210
  @values[field.name].replace(val)
218
211
  end
219
212
  end
213
+ ::Protobuf.deprecator.deprecate_methods(method_name)
220
214
  end
221
215
  end
222
216
 
223
217
  def define_getter
224
218
  field = self
219
+ method_name = field.getter
220
+
225
221
  message_class.class_eval do
226
- define_method(field.getter) do
227
- field.warn_if_deprecated
222
+ define_method(method_name) do
228
223
  @values.fetch(field.name, field.default_value)
229
224
  end
225
+ ::Protobuf.deprecator.deprecate_methods(method_name)
230
226
  end
231
227
  end
232
228
 
233
229
  def define_setter
234
230
  field = self
235
- message_class.class_eval do
236
- define_method(field.setter) do |val|
237
- field.warn_if_deprecated
231
+ method_name = field.setter
238
232
 
233
+ message_class.class_eval do
234
+ define_method(method_name) do |val|
239
235
  if val.nil? || (val.respond_to?(:empty?) && val.empty?)
240
236
  @values.delete(field.name)
241
237
  elsif field.acceptable?(val)
242
238
  @values[field.name] = field.coerce!(val)
243
239
  else
244
- raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}"
240
+ fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}"
245
241
  end
246
242
  end
243
+ ::Protobuf.deprecator.deprecate_methods(method_name)
247
244
  end
248
245
  end
249
246
 
@@ -257,11 +254,10 @@ module Protobuf
257
254
 
258
255
  def validate_packed_field
259
256
  if packed? && ! ::Protobuf::Field::BaseField::PACKED_TYPES.include?(wire_type)
260
- raise "Can't use packed encoding for '#{type_class}' type"
257
+ fail "Can't use packed encoding for '#{type_class}' type"
261
258
  end
262
259
  end
263
260
 
264
261
  end
265
262
  end
266
263
  end
267
-