google-protobuf 3.24.4-java → 3.25.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/ext/google/protobuf_c/Rakefile +3 -0
  3. data/ext/google/protobuf_c/glue.c +21 -0
  4. data/ext/google/protobuf_c/message.c +1388 -0
  5. data/ext/google/protobuf_c/message.h +79 -0
  6. data/ext/google/protobuf_c/protobuf.c +343 -0
  7. data/ext/google/protobuf_c/protobuf.h +112 -0
  8. data/ext/google/protobuf_c/ruby-upb.c +14414 -0
  9. data/ext/google/protobuf_c/ruby-upb.h +13044 -0
  10. data/ext/google/protobuf_c/shared_convert.c +64 -0
  11. data/ext/google/protobuf_c/shared_convert.h +26 -0
  12. data/ext/google/protobuf_c/shared_message.c +65 -0
  13. data/ext/google/protobuf_c/shared_message.h +25 -0
  14. data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +22 -0
  15. data/ext/google/protobuf_c/third_party/utf8_range/naive.c +92 -0
  16. data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +157 -0
  17. data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +170 -0
  18. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +21 -0
  19. data/lib/google/protobuf/any_pb.rb +1 -1
  20. data/lib/google/protobuf/api_pb.rb +1 -1
  21. data/lib/google/protobuf/descriptor_pb.rb +6 -3
  22. data/lib/google/protobuf/duration_pb.rb +1 -1
  23. data/lib/google/protobuf/empty_pb.rb +1 -1
  24. data/lib/google/protobuf/ffi/descriptor.rb +154 -0
  25. data/lib/google/protobuf/ffi/descriptor_pool.rb +70 -0
  26. data/lib/google/protobuf/ffi/enum_descriptor.rb +161 -0
  27. data/lib/google/protobuf/ffi/ffi.rb +213 -0
  28. data/lib/google/protobuf/ffi/field_descriptor.rb +309 -0
  29. data/lib/google/protobuf/ffi/file_descriptor.rb +48 -0
  30. data/lib/google/protobuf/ffi/internal/arena.rb +66 -0
  31. data/lib/google/protobuf/ffi/internal/convert.rb +305 -0
  32. data/lib/google/protobuf/ffi/internal/pointer_helper.rb +35 -0
  33. data/lib/google/protobuf/ffi/internal/type_safety.rb +25 -0
  34. data/lib/google/protobuf/ffi/map.rb +396 -0
  35. data/lib/google/protobuf/ffi/message.rb +641 -0
  36. data/lib/google/protobuf/ffi/object_cache.rb +30 -0
  37. data/lib/google/protobuf/ffi/oneof_descriptor.rb +88 -0
  38. data/lib/google/protobuf/ffi/repeated_field.rb +503 -0
  39. data/lib/google/protobuf/field_mask_pb.rb +1 -1
  40. data/lib/google/protobuf/message_exts.rb +3 -26
  41. data/lib/google/protobuf/object_cache.rb +3 -26
  42. data/lib/google/protobuf/plugin_pb.rb +1 -1
  43. data/lib/google/protobuf/repeated_field.rb +3 -26
  44. data/lib/google/protobuf/source_context_pb.rb +1 -1
  45. data/lib/google/protobuf/struct_pb.rb +1 -1
  46. data/lib/google/protobuf/timestamp_pb.rb +1 -1
  47. data/lib/google/protobuf/type_pb.rb +1 -1
  48. data/lib/google/protobuf/well_known_types.rb +3 -26
  49. data/lib/google/protobuf/wrappers_pb.rb +1 -1
  50. data/lib/google/protobuf.rb +26 -45
  51. data/lib/google/protobuf_ffi.rb +50 -0
  52. data/lib/google/protobuf_java.jar +0 -0
  53. data/lib/google/protobuf_native.rb +20 -0
  54. data/lib/google/tasks/ffi.rake +102 -0
  55. metadata +110 -4
@@ -0,0 +1,88 @@
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2022 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+
8
+ module Google
9
+ module Protobuf
10
+ class OneofDescriptor
11
+ attr :descriptor_pool, :oneof_def
12
+ include Enumerable
13
+
14
+ # FFI Interface methods and setup
15
+ extend ::FFI::DataConverter
16
+ native_type ::FFI::Type::POINTER
17
+
18
+ class << self
19
+ prepend Google::Protobuf::Internal::TypeSafety
20
+ include Google::Protobuf::Internal::PointerHelper
21
+
22
+ # @param value [OneofDescriptor] FieldDescriptor to convert to an FFI native type
23
+ # @param _ [Object] Unused
24
+ def to_native(value, _ = nil)
25
+ oneof_def_ptr = value.instance_variable_get(:@oneof_def)
26
+ warn "Underlying oneof_def was nil!" if oneof_def_ptr.nil?
27
+ raise "Underlying oneof_def was null!" if !oneof_def_ptr.nil? and oneof_def_ptr.null?
28
+ oneof_def_ptr
29
+ end
30
+
31
+ ##
32
+ # @param oneof_def [::FFI::Pointer] OneofDef pointer to be wrapped
33
+ # @param _ [Object] Unused
34
+ def from_native(oneof_def, _ = nil)
35
+ return nil if oneof_def.nil? or oneof_def.null?
36
+ message_descriptor = Google::Protobuf::FFI.get_oneof_containing_type oneof_def
37
+ raise RuntimeError.new "Message Descriptor is nil" if message_descriptor.nil?
38
+ file_def = Google::Protobuf::FFI.get_message_file_def message_descriptor.to_native
39
+ descriptor_from_file_def(file_def, oneof_def)
40
+ end
41
+ end
42
+
43
+ def self.new(*arguments, &block)
44
+ raise "OneofDescriptor objects may not be created from Ruby."
45
+ end
46
+
47
+ def name
48
+ Google::Protobuf::FFI.get_oneof_name(self)
49
+ end
50
+
51
+ def each &block
52
+ n = Google::Protobuf::FFI.get_oneof_field_count(self)
53
+ 0.upto(n-1) do |i|
54
+ yield(Google::Protobuf::FFI.get_oneof_field_by_index(self, i))
55
+ end
56
+ nil
57
+ end
58
+
59
+ private
60
+
61
+ def initialize(oneof_def, descriptor_pool)
62
+ @descriptor_pool = descriptor_pool
63
+ @oneof_def = oneof_def
64
+ end
65
+
66
+ def self.private_constructor(oneof_def, descriptor_pool)
67
+ instance = allocate
68
+ instance.send(:initialize, oneof_def, descriptor_pool)
69
+ instance
70
+ end
71
+ end
72
+
73
+ class FFI
74
+ # MessageDef
75
+ attach_function :get_oneof_by_name, :upb_MessageDef_FindOneofByNameWithSize, [Descriptor, :string, :size_t], OneofDescriptor
76
+ attach_function :get_oneof_by_index, :upb_MessageDef_Oneof, [Descriptor, :int], OneofDescriptor
77
+
78
+ # OneofDescriptor
79
+ attach_function :get_oneof_name, :upb_OneofDef_Name, [OneofDescriptor], :string
80
+ attach_function :get_oneof_field_count, :upb_OneofDef_FieldCount, [OneofDescriptor], :int
81
+ attach_function :get_oneof_field_by_index, :upb_OneofDef_Field, [OneofDescriptor, :int], FieldDescriptor
82
+ attach_function :get_oneof_containing_type,:upb_OneofDef_ContainingType,[:pointer], Descriptor
83
+
84
+ # FieldDescriptor
85
+ attach_function :real_containing_oneof, :upb_FieldDef_RealContainingOneof,[FieldDescriptor], OneofDescriptor
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,503 @@
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2008 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+
8
+ require 'forwardable'
9
+
10
+ #
11
+ # This class makes RepeatedField act (almost-) like a Ruby Array.
12
+ # It has convenience methods that extend the core C or Java based
13
+ # methods.
14
+ #
15
+ # This is a best-effort to mirror Array behavior. Two comments:
16
+ # 1) patches always welcome :)
17
+ # 2) if performance is an issue, feel free to rewrite the method
18
+ # in jruby and C. The source code has plenty of examples
19
+ #
20
+ # KNOWN ISSUES
21
+ # - #[]= doesn't allow less used approaches such as `arr[1, 2] = 'fizz'`
22
+ # - #concat should return the orig array
23
+ # - #push should accept multiple arguments and push them all at the same time
24
+ #
25
+ module Google
26
+ module Protobuf
27
+ class FFI
28
+ # Array
29
+ attach_function :append_array, :upb_Array_Append, [:Array, MessageValue.by_value, Internal::Arena], :bool
30
+ attach_function :get_msgval_at,:upb_Array_Get, [:Array, :size_t], MessageValue.by_value
31
+ attach_function :create_array, :upb_Array_New, [Internal::Arena, CType], :Array
32
+ attach_function :array_resize, :upb_Array_Resize, [:Array, :size_t, Internal::Arena], :bool
33
+ attach_function :array_set, :upb_Array_Set, [:Array, :size_t, MessageValue.by_value], :void
34
+ attach_function :array_size, :upb_Array_Size, [:Array], :size_t
35
+ end
36
+
37
+ class RepeatedField
38
+ extend Forwardable
39
+ # NOTE: using delegators rather than method_missing to make the
40
+ # relationship explicit instead of implicit
41
+ def_delegators :to_ary,
42
+ :&, :*, :-, :'<=>',
43
+ :assoc, :bsearch, :bsearch_index, :combination, :compact, :count,
44
+ :cycle, :dig, :drop, :drop_while, :eql?, :fetch, :find_index, :flatten,
45
+ :include?, :index, :inspect, :join,
46
+ :pack, :permutation, :product, :pretty_print, :pretty_print_cycle,
47
+ :rassoc, :repeated_combination, :repeated_permutation, :reverse,
48
+ :rindex, :rotate, :sample, :shuffle, :shelljoin,
49
+ :to_s, :transpose, :uniq, :|
50
+
51
+ include Enumerable
52
+
53
+ ##
54
+ # call-seq:
55
+ # RepeatedField.new(type, type_class = nil, initial_values = [])
56
+ #
57
+ # Creates a new repeated field. The provided type must be a Ruby symbol, and
58
+ # an take on the same values as those accepted by FieldDescriptor#type=. If
59
+ # the type is :message or :enum, type_class must be non-nil, and must be the
60
+ # Ruby class or module returned by Descriptor#msgclass or
61
+ # EnumDescriptor#enummodule, respectively. An initial list of elements may also
62
+ # be provided.
63
+ def self.new(type, type_class = nil, initial_values = [])
64
+ instance = allocate
65
+ # TODO This argument mangling doesn't agree with the type signature in the comments
66
+ # but is required to make unit tests pass;
67
+ if type_class.is_a?(Enumerable) and initial_values.empty? and ![:enum, :message].include?(type)
68
+ initial_values = type_class
69
+ type_class = nil
70
+ end
71
+ instance.send(:initialize, type, type_class: type_class, initial_values: initial_values)
72
+ instance
73
+ end
74
+
75
+ ##
76
+ # call-seq:
77
+ # RepeatedField.each(&block)
78
+ #
79
+ # Invokes the block once for each element of the repeated field. RepeatedField
80
+ # also includes Enumerable; combined with this method, the repeated field thus
81
+ # acts like an ordinary Ruby sequence.
82
+ def each &block
83
+ each_msg_val do |element|
84
+ yield(convert_upb_to_ruby(element, type, descriptor, arena))
85
+ end
86
+ self
87
+ end
88
+
89
+ def [](*args)
90
+ count = length
91
+ if args.size < 1
92
+ raise ArgumentError.new "Index or range is a required argument."
93
+ end
94
+ if args[0].is_a? Range
95
+ if args.size > 1
96
+ raise ArgumentError.new "Expected 1 when passing Range argument, but got #{args.size}"
97
+ end
98
+ range = args[0]
99
+ # Handle begin-less and/or endless ranges, when supported.
100
+ index_of_first = range.respond_to?(:begin) ? range.begin : range.last
101
+ index_of_first = 0 if index_of_first.nil?
102
+ end_of_range = range.respond_to?(:end) ? range.end : range.last
103
+ index_of_last = end_of_range.nil? ? -1 : end_of_range
104
+
105
+ if index_of_last < 0
106
+ index_of_last += count
107
+ end
108
+ unless range.exclude_end? and !end_of_range.nil?
109
+ index_of_last += 1
110
+ end
111
+ index_of_first += count if index_of_first < 0
112
+ length = index_of_last - index_of_first
113
+ return [] if length.zero?
114
+ elsif args[0].is_a? Integer
115
+ index_of_first = args[0]
116
+ index_of_first += count if index_of_first < 0
117
+ if args.size > 2
118
+ raise ArgumentError.new "Expected 1 or 2 arguments, but got #{args.size}"
119
+ end
120
+ if args.size == 1 # No length specified, return one element
121
+ if array.null? or index_of_first < 0 or index_of_first >= count
122
+ return nil
123
+ else
124
+ return convert_upb_to_ruby(Google::Protobuf::FFI.get_msgval_at(array, index_of_first), type, descriptor, arena)
125
+ end
126
+ else
127
+ length = [args[1],count].min
128
+ end
129
+ else
130
+ raise NotImplementedError
131
+ end
132
+
133
+ if array.null? or index_of_first < 0 or index_of_first >= count
134
+ nil
135
+ else
136
+ if index_of_first + length > count
137
+ length = count - index_of_first
138
+ end
139
+ if length < 0
140
+ nil
141
+ else
142
+ subarray(index_of_first, length)
143
+ end
144
+ end
145
+ end
146
+ alias at []
147
+
148
+
149
+ def []=(index, value)
150
+ raise FrozenError if frozen?
151
+ count = length
152
+ index += count if index < 0
153
+ return nil if index < 0
154
+ if index >= count
155
+ resize(index+1)
156
+ empty_message_value = Google::Protobuf::FFI::MessageValue.new # Implicitly clear
157
+ count.upto(index-1) do |i|
158
+ Google::Protobuf::FFI.array_set(array, i, empty_message_value)
159
+ end
160
+ end
161
+ Google::Protobuf::FFI.array_set(array, index, convert_ruby_to_upb(value, arena, type, descriptor))
162
+ nil
163
+ end
164
+
165
+ def push(*elements)
166
+ raise FrozenError if frozen?
167
+ internal_push(*elements)
168
+ end
169
+
170
+ def <<(element)
171
+ raise FrozenError if frozen?
172
+ push element
173
+ end
174
+
175
+ def replace(replacements)
176
+ raise FrozenError if frozen?
177
+ clear
178
+ push(*replacements)
179
+ end
180
+
181
+ def clear
182
+ raise FrozenError if frozen?
183
+ resize 0
184
+ self
185
+ end
186
+
187
+ def length
188
+ array.null? ? 0 : Google::Protobuf::FFI.array_size(array)
189
+ end
190
+ alias size :length
191
+
192
+ def dup
193
+ instance = self.class.allocate
194
+ instance.send(:initialize, type, descriptor: descriptor, arena: arena)
195
+ each_msg_val do |element|
196
+ instance.send(:append_msg_val, element)
197
+ end
198
+ instance
199
+ end
200
+ alias clone dup
201
+
202
+ def ==(other)
203
+ return true if other.object_id == object_id
204
+ if other.is_a? RepeatedField
205
+ return false unless other.length == length
206
+ each_msg_val_with_index do |msg_val, i|
207
+ other_msg_val = Google::Protobuf::FFI.get_msgval_at(other.send(:array), i)
208
+ unless Google::Protobuf::FFI.message_value_equal(msg_val, other_msg_val, type, descriptor)
209
+ return false
210
+ end
211
+ end
212
+ return true
213
+ elsif other.is_a? Enumerable
214
+ return to_ary == other.to_a
215
+ end
216
+ false
217
+ end
218
+
219
+ ##
220
+ # call-seq:
221
+ # RepeatedField.to_ary => array
222
+ #
223
+ # Used when converted implicitly into array, e.g. compared to an Array.
224
+ # Also called as a fallback of Object#to_a
225
+ def to_ary
226
+ return_value = []
227
+ each do |element|
228
+ return_value << element
229
+ end
230
+ return_value
231
+ end
232
+
233
+ def hash
234
+ return_value = 0
235
+ each_msg_val do |msg_val|
236
+ return_value = Google::Protobuf::FFI.message_value_hash(msg_val, type, descriptor, return_value)
237
+ end
238
+ return_value
239
+ end
240
+
241
+ def +(other)
242
+ if other.is_a? RepeatedField
243
+ if type != other.instance_variable_get(:@type) or descriptor != other.instance_variable_get(:@descriptor)
244
+ raise ArgumentError.new "Attempt to append RepeatedField with different element type."
245
+ end
246
+ fuse_arena(other.send(:arena))
247
+ super_set = dup
248
+ other.send(:each_msg_val) do |msg_val|
249
+ super_set.send(:append_msg_val, msg_val)
250
+ end
251
+ super_set
252
+ elsif other.is_a? Enumerable
253
+ super_set = dup
254
+ super_set.push(*other.to_a)
255
+ else
256
+ raise ArgumentError.new "Unknown type appending to RepeatedField"
257
+ end
258
+ end
259
+
260
+ def concat(other)
261
+ raise ArgumentError.new "Expected Enumerable, but got #{other.class}" unless other.is_a? Enumerable
262
+ push(*other.to_a)
263
+ end
264
+
265
+ def first(n=nil)
266
+ if n.nil?
267
+ return self[0]
268
+ elsif n < 0
269
+ raise ArgumentError, "negative array size"
270
+ else
271
+ return self[0...n]
272
+ end
273
+ end
274
+
275
+
276
+ def last(n=nil)
277
+ if n.nil?
278
+ return self[-1]
279
+ elsif n < 0
280
+ raise ArgumentError, "negative array size"
281
+ else
282
+ start = [self.size-n, 0].max
283
+ return self[start...self.size]
284
+ end
285
+ end
286
+
287
+
288
+ def pop(n=nil)
289
+ if n
290
+ results = []
291
+ n.times{ results << pop_one }
292
+ return results
293
+ else
294
+ return pop_one
295
+ end
296
+ end
297
+
298
+
299
+ def empty?
300
+ self.size == 0
301
+ end
302
+
303
+ # array aliases into enumerable
304
+ alias_method :each_index, :each_with_index
305
+ alias_method :slice, :[]
306
+ alias_method :values_at, :select
307
+ alias_method :map, :collect
308
+
309
+
310
+ class << self
311
+ def define_array_wrapper_method(method_name)
312
+ define_method(method_name) do |*args, &block|
313
+ arr = self.to_a
314
+ result = arr.send(method_name, *args)
315
+ self.replace(arr)
316
+ return result if result
317
+ return block ? block.call : result
318
+ end
319
+ end
320
+ private :define_array_wrapper_method
321
+
322
+
323
+ def define_array_wrapper_with_result_method(method_name)
324
+ define_method(method_name) do |*args, &block|
325
+ # result can be an Enumerator, Array, or nil
326
+ # Enumerator can sometimes be returned if a block is an optional argument and it is not passed in
327
+ # nil usually specifies that no change was made
328
+ result = self.to_a.send(method_name, *args, &block)
329
+ if result
330
+ new_arr = result.to_a
331
+ self.replace(new_arr)
332
+ if result.is_a?(Enumerator)
333
+ # generate a fresh enum; rewinding the exiting one, in Ruby 2.2, will
334
+ # reset the enum with the same length, but all the #next calls will
335
+ # return nil
336
+ result = new_arr.to_enum
337
+ # generate a wrapper enum so any changes which occur by a chained
338
+ # enum can be captured
339
+ ie = ProxyingEnumerator.new(self, result)
340
+ result = ie.to_enum
341
+ end
342
+ end
343
+ result
344
+ end
345
+ end
346
+ private :define_array_wrapper_with_result_method
347
+ end
348
+
349
+
350
+ %w(delete delete_at shift slice! unshift).each do |method_name|
351
+ define_array_wrapper_method(method_name)
352
+ end
353
+
354
+
355
+ %w(collect! compact! delete_if fill flatten! insert reverse!
356
+ rotate! select! shuffle! sort! sort_by! uniq!).each do |method_name|
357
+ define_array_wrapper_with_result_method(method_name)
358
+ end
359
+ alias_method :keep_if, :select!
360
+ alias_method :map!, :collect!
361
+ alias_method :reject!, :delete_if
362
+
363
+
364
+ # propagates changes made by user of enumerator back to the original repeated field.
365
+ # This only applies in cases where the calling function which created the enumerator,
366
+ # such as #sort!, modifies itself rather than a new array, such as #sort
367
+ class ProxyingEnumerator < Struct.new(:repeated_field, :external_enumerator)
368
+ def each(*args, &block)
369
+ results = []
370
+ external_enumerator.each_with_index do |val, i|
371
+ result = yield(val)
372
+ results << result
373
+ #nil means no change occurred from yield; usually occurs when #to_a is called
374
+ if result
375
+ repeated_field[i] = result if result != val
376
+ end
377
+ end
378
+ results
379
+ end
380
+ end
381
+
382
+ private
383
+ include Google::Protobuf::Internal::Convert
384
+
385
+ attr :name, :arena, :array, :type, :descriptor
386
+
387
+ def internal_push(*elements)
388
+ elements.each do |element|
389
+ append_msg_val convert_ruby_to_upb(element, arena, type, descriptor)
390
+ end
391
+ self
392
+ end
393
+
394
+ def pop_one
395
+ raise FrozenError if frozen?
396
+ count = length
397
+ return nil if length.zero?
398
+ last_element = Google::Protobuf::FFI.get_msgval_at(array, count-1)
399
+ return_value = convert_upb_to_ruby(last_element, type, descriptor, arena)
400
+ resize(count-1)
401
+ return_value
402
+ end
403
+
404
+ def subarray(start, length)
405
+ return_result = []
406
+ (start..(start + length - 1)).each do |i|
407
+ element = Google::Protobuf::FFI.get_msgval_at(array, i)
408
+ return_result << convert_upb_to_ruby(element, type, descriptor, arena)
409
+ end
410
+ return_result
411
+ end
412
+
413
+ def each_msg_val_with_index &block
414
+ n = array.null? ? 0 : Google::Protobuf::FFI.array_size(array)
415
+ 0.upto(n-1) do |i|
416
+ yield Google::Protobuf::FFI.get_msgval_at(array, i), i
417
+ end
418
+ end
419
+
420
+ def each_msg_val &block
421
+ each_msg_val_with_index do |msg_val, _|
422
+ yield msg_val
423
+ end
424
+ end
425
+
426
+ # @param msg_val [Google::Protobuf::FFI::MessageValue] Value to append
427
+ def append_msg_val(msg_val)
428
+ unless Google::Protobuf::FFI.append_array(array, msg_val, arena)
429
+ raise NoMemoryError.new "Could not allocate room for #{msg_val} in Arena"
430
+ end
431
+ end
432
+
433
+ # @param new_size [Integer] New size of the array
434
+ def resize(new_size)
435
+ unless Google::Protobuf::FFI.array_resize(array, new_size, arena)
436
+ raise NoMemoryError.new "Array resize to #{new_size} failed!"
437
+ end
438
+ end
439
+
440
+ def initialize(type, type_class: nil, initial_values: nil, name: nil, arena: nil, array: nil, descriptor: nil)
441
+ @name = name || 'RepeatedField'
442
+ raise ArgumentError.new "Expected argument type to be a Symbol" unless type.is_a? Symbol
443
+ field_number = Google::Protobuf::FFI::FieldType[type]
444
+ raise ArgumentError.new "Unsupported type '#{type}'" if field_number.nil?
445
+ if !descriptor.nil?
446
+ @descriptor = descriptor
447
+ elsif [:message, :enum].include? type
448
+ raise ArgumentError.new "Expected at least 2 arguments for message/enum." if type_class.nil?
449
+ descriptor = type_class.respond_to?(:descriptor) ? type_class.descriptor : nil
450
+ raise ArgumentError.new "Type class #{type_class} has no descriptor. Please pass a class or enum as returned by the DescriptorPool." if descriptor.nil?
451
+ @descriptor = descriptor
452
+ else
453
+ @descriptor = nil
454
+ end
455
+ @type = type
456
+
457
+ @arena = arena || Google::Protobuf::FFI.create_arena
458
+ @array = array || Google::Protobuf::FFI.create_array(@arena, @type)
459
+ unless initial_values.nil?
460
+ unless initial_values.is_a? Enumerable
461
+ raise ArgumentError.new "Expected array as initializer value for repeated field '#{name}' (given #{initial_values.class})."
462
+ end
463
+ internal_push(*initial_values)
464
+ end
465
+
466
+ # Should always be the last expression of the initializer to avoid
467
+ # leaking references to this object before construction is complete.
468
+ OBJECT_CACHE.try_add(@array.address, self)
469
+ end
470
+
471
+ # @param field [FieldDescriptor] Descriptor of the field where the RepeatedField will be assigned
472
+ # @param values [Enumerable] Initial values; may be nil or empty
473
+ # @param arena [Arena] Owning message's arena
474
+ def self.construct_for_field(field, arena, values: nil, array: nil)
475
+ instance = allocate
476
+ options = {initial_values: values, name: field.name, arena: arena, array: array}
477
+ if [:enum, :message].include? field.type
478
+ options[:descriptor] = field.subtype
479
+ end
480
+ instance.send(:initialize, field.type, **options)
481
+ instance
482
+ end
483
+
484
+ def fuse_arena(arena)
485
+ arena.fuse(arena)
486
+ end
487
+
488
+ extend Google::Protobuf::Internal::Convert
489
+
490
+ def self.deep_copy(repeated_field)
491
+ instance = allocate
492
+ instance.send(:initialize, repeated_field.send(:type), descriptor: repeated_field.send(:descriptor))
493
+ instance.send(:resize, repeated_field.length)
494
+ new_array = instance.send(:array)
495
+ repeated_field.send(:each_msg_val_with_index) do |element, i|
496
+ Google::Protobuf::FFI.array_set(new_array, i, message_value_deep_copy(element, repeated_field.send(:type), repeated_field.send(:descriptor), instance.send(:arena)))
497
+ end
498
+ instance
499
+ end
500
+
501
+ end
502
+ end
503
+ end
@@ -11,7 +11,7 @@ pool = Google::Protobuf::DescriptorPool.generated_pool
11
11
 
12
12
  begin
13
13
  pool.add_serialized_file(descriptor_data)
14
- rescue TypeError => e
14
+ rescue TypeError
15
15
  # Compatibility code: will be removed in the next major version.
16
16
  require 'google/protobuf/descriptor_pb'
17
17
  parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data)
@@ -1,32 +1,9 @@
1
1
  # Protocol Buffers - Google's data interchange format
2
2
  # Copyright 2008 Google Inc. All rights reserved.
3
- # https://developers.google.com/protocol-buffers/
4
3
  #
5
- # Redistribution and use in source and binary forms, with or without
6
- # modification, are permitted provided that the following conditions are
7
- # met:
8
- #
9
- # * Redistributions of source code must retain the above copyright
10
- # notice, this list of conditions and the following disclaimer.
11
- # * Redistributions in binary form must reproduce the above
12
- # copyright notice, this list of conditions and the following disclaimer
13
- # in the documentation and/or other materials provided with the
14
- # distribution.
15
- # * Neither the name of Google Inc. nor the names of its
16
- # contributors may be used to endorse or promote products derived from
17
- # this software without specific prior written permission.
18
- #
19
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  module Google
32
9
  module Protobuf
@@ -1,32 +1,9 @@
1
1
  # Protocol Buffers - Google's data interchange format
2
2
  # Copyright 2023 Google Inc. All rights reserved.
3
- # https://developers.google.com/protocol-buffers/
4
3
  #
5
- # Redistribution and use in source and binary forms, with or without
6
- # modification, are permitted provided that the following conditions are
7
- # met:
8
- #
9
- # * Redistributions of source code must retain the above copyright
10
- # notice, this list of conditions and the following disclaimer.
11
- # * Redistributions in binary form must reproduce the above
12
- # copyright notice, this list of conditions and the following disclaimer
13
- # in the documentation and/or other materials provided with the
14
- # distribution.
15
- # * Neither the name of Google Inc. nor the names of its
16
- # contributors may be used to endorse or promote products derived from
17
- # this software without specific prior written permission.
18
- #
19
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  module Google
32
9
  module Protobuf
@@ -13,7 +13,7 @@ pool = Google::Protobuf::DescriptorPool.generated_pool
13
13
 
14
14
  begin
15
15
  pool.add_serialized_file(descriptor_data)
16
- rescue TypeError => e
16
+ rescue TypeError
17
17
  # Compatibility code: will be removed in the next major version.
18
18
  require 'google/protobuf/descriptor_pb'
19
19
  parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data)