google-protobuf 3.25.6 → 4.30.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.
- checksums.yaml +4 -4
- data/ext/google/protobuf_c/convert.c +33 -15
- data/ext/google/protobuf_c/defs.c +526 -29
- data/ext/google/protobuf_c/extconf.rb +13 -1
- data/ext/google/protobuf_c/glue.c +79 -0
- data/ext/google/protobuf_c/map.c +72 -27
- data/ext/google/protobuf_c/map.h +7 -3
- data/ext/google/protobuf_c/message.c +113 -116
- data/ext/google/protobuf_c/message.h +2 -6
- data/ext/google/protobuf_c/protobuf.c +32 -18
- data/ext/google/protobuf_c/protobuf.h +3 -7
- data/ext/google/protobuf_c/repeated_field.c +58 -23
- data/ext/google/protobuf_c/repeated_field.h +6 -2
- data/ext/google/protobuf_c/ruby-upb.c +14926 -11596
- data/ext/google/protobuf_c/ruby-upb.h +8701 -5832
- data/ext/google/protobuf_c/shared_convert.c +7 -2
- data/ext/google/protobuf_c/shared_message.c +3 -32
- data/ext/google/protobuf_c/shared_message.h +0 -4
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +207 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +9 -8
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_neon.inc +117 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_sse.inc +272 -0
- data/lib/google/protobuf/any_pb.rb +1 -22
- data/lib/google/protobuf/api_pb.rb +1 -24
- data/lib/google/protobuf/descriptor_pb.rb +4 -23
- data/lib/google/protobuf/duration_pb.rb +1 -22
- data/lib/google/protobuf/empty_pb.rb +1 -22
- data/lib/google/protobuf/ffi/descriptor.rb +14 -4
- data/lib/google/protobuf/ffi/descriptor_pool.rb +3 -1
- data/lib/google/protobuf/ffi/enum_descriptor.rb +13 -1
- data/lib/google/protobuf/ffi/ffi.rb +7 -6
- data/lib/google/protobuf/ffi/field_descriptor.rb +23 -2
- data/lib/google/protobuf/ffi/file_descriptor.rb +13 -13
- data/lib/google/protobuf/ffi/internal/arena.rb +0 -6
- data/lib/google/protobuf/ffi/internal/convert.rb +17 -30
- data/lib/google/protobuf/ffi/map.rb +50 -24
- data/lib/google/protobuf/ffi/message.rb +188 -67
- data/lib/google/protobuf/ffi/method_descriptor.rb +124 -0
- data/lib/google/protobuf/ffi/object_cache.rb +3 -3
- data/lib/google/protobuf/ffi/oneof_descriptor.rb +13 -1
- data/lib/google/protobuf/ffi/repeated_field.rb +47 -19
- data/lib/google/protobuf/ffi/service_descriptor.rb +117 -0
- data/lib/google/protobuf/field_mask_pb.rb +1 -22
- data/lib/google/protobuf/internal/object_cache.rb +99 -0
- data/lib/google/protobuf/plugin_pb.rb +2 -24
- data/lib/google/protobuf/repeated_field.rb +4 -5
- data/lib/google/protobuf/source_context_pb.rb +1 -22
- data/lib/google/protobuf/struct_pb.rb +1 -22
- data/lib/google/protobuf/timestamp_pb.rb +1 -22
- data/lib/google/protobuf/type_pb.rb +1 -24
- data/lib/google/protobuf/wrappers_pb.rb +1 -22
- data/lib/google/protobuf.rb +1 -1
- data/lib/google/protobuf_ffi.rb +5 -3
- data/lib/google/protobuf_native.rb +0 -1
- data/lib/google/tasks/ffi.rake +1 -3
- metadata +28 -13
- data/ext/google/protobuf_c/third_party/utf8_range/naive.c +0 -92
- data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +0 -157
- data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +0 -170
- data/lib/google/protobuf/descriptor_dsl.rb +0 -465
- data/lib/google/protobuf/object_cache.rb +0 -97
@@ -21,7 +21,7 @@ module Google
|
|
21
21
|
Upb_Map_Begin = -1
|
22
22
|
|
23
23
|
## Encoding Status
|
24
|
-
Upb_Status_MaxMessage =
|
24
|
+
Upb_Status_MaxMessage = 511
|
25
25
|
Upb_Encode_Deterministic = 1
|
26
26
|
Upb_Encode_SkipUnknown = 2
|
27
27
|
|
@@ -36,6 +36,10 @@ module Google
|
|
36
36
|
## JSON Decoding options
|
37
37
|
Upb_JsonDecode_IgnoreUnknown = 1
|
38
38
|
|
39
|
+
## JSON Decoding results
|
40
|
+
Upb_JsonDecodeResult_Ok = 0
|
41
|
+
Upb_JsonDecodeResult_Error = 2
|
42
|
+
|
39
43
|
typedef :pointer, :Array
|
40
44
|
typedef :pointer, :DefPool
|
41
45
|
typedef :pointer, :EnumValueDef
|
@@ -95,11 +99,6 @@ module Google
|
|
95
99
|
:repeated
|
96
100
|
)
|
97
101
|
|
98
|
-
Syntax = enum(
|
99
|
-
:Proto2, 2,
|
100
|
-
:Proto3
|
101
|
-
)
|
102
|
-
|
103
102
|
# All the different kind of well known type messages. For simplicity of check,
|
104
103
|
# number wrappers and string wrappers are grouped together. Make sure the
|
105
104
|
# order and merber of these groups are not changed.
|
@@ -190,6 +189,8 @@ module Google
|
|
190
189
|
:str_val, StringView
|
191
190
|
end
|
192
191
|
|
192
|
+
Upb_Message_Begin = -1
|
193
|
+
|
193
194
|
class MutableMessageValue < ::FFI::Union
|
194
195
|
layout :map, :Map,
|
195
196
|
:msg, :Message,
|
@@ -68,7 +68,7 @@ module Google
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def label
|
71
|
-
@label ||= Google::Protobuf::FFI
|
71
|
+
@label ||= Google::Protobuf::FFI.get_label(self)
|
72
72
|
end
|
73
73
|
|
74
74
|
def default
|
@@ -156,6 +156,14 @@ module Google
|
|
156
156
|
@has_presence ||= Google::Protobuf::FFI.get_has_presence(self)
|
157
157
|
end
|
158
158
|
|
159
|
+
##
|
160
|
+
# Tests if this is a repeated field that uses packed encoding.
|
161
|
+
#
|
162
|
+
# @return [Boolean] True iff this field is packed
|
163
|
+
def is_packed?
|
164
|
+
@is_packed ||= Google::Protobuf::FFI.get_is_packed(self)
|
165
|
+
end
|
166
|
+
|
159
167
|
# @param msg [Google::Protobuf::Message]
|
160
168
|
def clear(msg)
|
161
169
|
if msg.class.descriptor != Google::Protobuf::FFI.get_containing_message_def(self)
|
@@ -211,7 +219,18 @@ module Google
|
|
211
219
|
size_ptr = ::FFI::MemoryPointer.new(:size_t, 1)
|
212
220
|
temporary_arena = Google::Protobuf::FFI.create_arena
|
213
221
|
buffer = Google::Protobuf::FFI.field_options(self, size_ptr, temporary_arena)
|
214
|
-
Google::Protobuf::FieldOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze)
|
222
|
+
opts = Google::Protobuf::FieldOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze)
|
223
|
+
opts.clear_features()
|
224
|
+
opts.freeze
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def to_proto
|
229
|
+
@to_proto ||= begin
|
230
|
+
size_ptr = ::FFI::MemoryPointer.new(:size_t, 1)
|
231
|
+
temporary_arena = Google::Protobuf::FFI.create_arena
|
232
|
+
buffer = Google::Protobuf::FFI.field_to_proto(self, size_ptr, temporary_arena)
|
233
|
+
Google::Protobuf::FieldDescriptorProto.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze)
|
215
234
|
end
|
216
235
|
end
|
217
236
|
|
@@ -304,6 +323,7 @@ module Google
|
|
304
323
|
attach_function :get_default, :upb_FieldDef_Default, [FieldDescriptor], MessageValue.by_value
|
305
324
|
attach_function :get_subtype_as_enum, :upb_FieldDef_EnumSubDef, [FieldDescriptor], EnumDescriptor
|
306
325
|
attach_function :get_has_presence, :upb_FieldDef_HasPresence, [FieldDescriptor], :bool
|
326
|
+
attach_function :get_is_packed, :upb_FieldDef_IsPacked, [FieldDescriptor], :bool
|
307
327
|
attach_function :is_map, :upb_FieldDef_IsMap, [FieldDescriptor], :bool
|
308
328
|
attach_function :is_repeated, :upb_FieldDef_IsRepeated, [FieldDescriptor], :bool
|
309
329
|
attach_function :is_sub_message, :upb_FieldDef_IsSubMessage, [FieldDescriptor], :bool
|
@@ -314,6 +334,7 @@ module Google
|
|
314
334
|
attach_function :get_number, :upb_FieldDef_Number, [FieldDescriptor], :uint32_t
|
315
335
|
attach_function :get_type, :upb_FieldDef_Type, [FieldDescriptor], FieldType
|
316
336
|
attach_function :file_def_by_raw_field_def, :upb_FieldDef_File, [:pointer], :FileDef
|
337
|
+
attach_function :field_to_proto, :FieldDescriptor_serialized_to_proto,[FieldDescriptor, :pointer, Internal::Arena], :pointer
|
317
338
|
end
|
318
339
|
end
|
319
340
|
end
|
@@ -10,9 +10,9 @@ module Google
|
|
10
10
|
class FFI
|
11
11
|
# FileDescriptor
|
12
12
|
attach_function :file_def_name, :upb_FileDef_Name, [:FileDef], :string
|
13
|
-
attach_function :file_def_syntax, :upb_FileDef_Syntax, [:FileDef], Syntax
|
14
13
|
attach_function :file_def_pool, :upb_FileDef_Pool, [:FileDef], :DefPool
|
15
14
|
attach_function :file_options, :FileDescriptor_serialized_options, [:FileDef, :pointer, Internal::Arena], :pointer
|
15
|
+
attach_function :file_to_proto, :FileDescriptor_serialized_to_proto, [:FileDef, :pointer, Internal::Arena], :pointer
|
16
16
|
end
|
17
17
|
|
18
18
|
class FileDescriptor
|
@@ -31,17 +31,6 @@ module Google
|
|
31
31
|
"#{self.class.name}: #{name}"
|
32
32
|
end
|
33
33
|
|
34
|
-
def syntax
|
35
|
-
case Google::Protobuf::FFI.file_def_syntax(@file_def)
|
36
|
-
when :Proto3
|
37
|
-
:proto3
|
38
|
-
when :Proto2
|
39
|
-
:proto2
|
40
|
-
else
|
41
|
-
nil
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
34
|
def name
|
46
35
|
Google::Protobuf::FFI.file_def_name(@file_def)
|
47
36
|
end
|
@@ -51,7 +40,18 @@ module Google
|
|
51
40
|
size_ptr = ::FFI::MemoryPointer.new(:size_t, 1)
|
52
41
|
temporary_arena = Google::Protobuf::FFI.create_arena
|
53
42
|
buffer = Google::Protobuf::FFI.file_options(@file_def, size_ptr, temporary_arena)
|
54
|
-
Google::Protobuf::FileOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze)
|
43
|
+
opts = Google::Protobuf::FileOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze)
|
44
|
+
opts.clear_features()
|
45
|
+
opts.freeze
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_proto
|
50
|
+
@to_proto ||= begin
|
51
|
+
size_ptr = ::FFI::MemoryPointer.new(:size_t, 1)
|
52
|
+
temporary_arena = Google::Protobuf::FFI.create_arena
|
53
|
+
buffer = Google::Protobuf::FFI.file_to_proto(@file_def, size_ptr, temporary_arena)
|
54
|
+
Google::Protobuf::FileDescriptorProto.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -12,8 +12,6 @@ module Google
|
|
12
12
|
module Protobuf
|
13
13
|
module Internal
|
14
14
|
class Arena
|
15
|
-
attr :pinned_messages
|
16
|
-
|
17
15
|
# FFI Interface methods and setup
|
18
16
|
extend ::FFI::DataConverter
|
19
17
|
native_type ::FFI::Type::POINTER
|
@@ -46,10 +44,6 @@ module Google
|
|
46
44
|
raise RuntimeError.new "Unable to fuse arenas. This should never happen since Ruby does not use initial blocks"
|
47
45
|
end
|
48
46
|
end
|
49
|
-
|
50
|
-
def pin(message)
|
51
|
-
pinned_messages.push message
|
52
|
-
end
|
53
47
|
end
|
54
48
|
end
|
55
49
|
|
@@ -32,12 +32,15 @@ module Google
|
|
32
32
|
raise TypeError.new "Invalid argument for boolean field '#{name}' (given #{value.class})." unless [TrueClass, FalseClass].include? value.class
|
33
33
|
return_value[:bool_val] = value
|
34
34
|
when :string
|
35
|
-
raise TypeError.new "Invalid argument for string field '#{name}' (given #{value.class})." unless
|
36
|
-
|
35
|
+
raise TypeError.new "Invalid argument for string field '#{name}' (given #{value.class})." unless value.is_a?(String) or value.is_a?(Symbol)
|
36
|
+
value = value.to_s if value.is_a?(Symbol)
|
37
|
+
if value.encoding == Encoding::UTF_8
|
38
|
+
unless value.valid_encoding?
|
39
|
+
raise Encoding::InvalidByteSequenceError.new "String is invalid UTF-8"
|
40
|
+
end
|
41
|
+
string_value = value
|
42
|
+
else
|
37
43
|
string_value = value.to_s.encode("UTF-8")
|
38
|
-
rescue Encoding::UndefinedConversionError
|
39
|
-
# TODO - why not include the field name here?
|
40
|
-
raise Encoding::UndefinedConversionError.new "String is invalid UTF-8"
|
41
44
|
end
|
42
45
|
return_value[:str_val][:size] = string_value.bytesize
|
43
46
|
return_value[:str_val][:data] = Google::Protobuf::FFI.arena_malloc(arena, string_value.bytesize)
|
@@ -70,7 +73,7 @@ module Google
|
|
70
73
|
case wkt
|
71
74
|
when :Timestamp
|
72
75
|
raise TypeError.new "Invalid type #{value.class} to assign to submessage field '#{name}'." unless value.kind_of? Time
|
73
|
-
new_message = Google::Protobuf::FFI.new_message_from_def msg_or_enum_def, arena
|
76
|
+
new_message = Google::Protobuf::FFI.new_message_from_def Google::Protobuf::FFI.get_mini_table(msg_or_enum_def), arena
|
74
77
|
sec = Google::Protobuf::FFI::MessageValue.new
|
75
78
|
sec[:int64_val] = value.tv_sec
|
76
79
|
sec_field_def = Google::Protobuf::FFI.get_field_by_number msg_or_enum_def, 1
|
@@ -82,7 +85,7 @@ module Google
|
|
82
85
|
return_value[:msg_val] = new_message
|
83
86
|
when :Duration
|
84
87
|
raise TypeError.new "Invalid type #{value.class} to assign to submessage field '#{name}'." unless value.kind_of? Numeric
|
85
|
-
new_message = Google::Protobuf::FFI.new_message_from_def msg_or_enum_def, arena
|
88
|
+
new_message = Google::Protobuf::FFI.new_message_from_def Google::Protobuf::FFI.get_mini_table(msg_or_enum_def), arena
|
86
89
|
sec = Google::Protobuf::FFI::MessageValue.new
|
87
90
|
sec[:int64_val] = value
|
88
91
|
sec_field_def = Google::Protobuf::FFI.get_field_by_number msg_or_enum_def, 1
|
@@ -190,39 +193,23 @@ module Google
|
|
190
193
|
def to_h_internal(msg, message_descriptor)
|
191
194
|
return nil if msg.nil? or msg.null?
|
192
195
|
hash = {}
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
field_descriptor.sub_message? and
|
198
|
-
!field_descriptor.repeated? and
|
199
|
-
!Google::Protobuf::FFI.get_message_has(msg, field_descriptor)
|
200
|
-
hash[field_descriptor.name.to_sym] = nil
|
201
|
-
next
|
202
|
-
end
|
203
|
-
|
204
|
-
# Do not include fields that are not present (oneof or optional fields).
|
205
|
-
if is_proto2 and field_descriptor.has_presence? and !Google::Protobuf::FFI.get_message_has(msg, field_descriptor)
|
206
|
-
next
|
207
|
-
end
|
196
|
+
iter = ::FFI::MemoryPointer.new(:size_t, 1)
|
197
|
+
iter.write(:size_t, Google::Protobuf::FFI::Upb_Message_Begin)
|
198
|
+
message_value = Google::Protobuf::FFI::MessageValue.new
|
199
|
+
field_def_ptr = ::FFI::MemoryPointer.new :pointer
|
208
200
|
|
209
|
-
|
201
|
+
while Google::Protobuf::FFI::message_next(msg, message_descriptor, nil, field_def_ptr, message_value, iter) do
|
202
|
+
field_descriptor = FieldDescriptor.from_native field_def_ptr.get_pointer(0)
|
210
203
|
|
211
|
-
# Proto2 omits empty map/repeated fields also.
|
212
204
|
if field_descriptor.map?
|
213
205
|
hash_entry = map_create_hash(message_value[:map_val], field_descriptor)
|
214
206
|
elsif field_descriptor.repeated?
|
215
|
-
|
216
|
-
if is_proto2 and (array.null? || Google::Protobuf::FFI.array_size(array).zero?)
|
217
|
-
next
|
218
|
-
end
|
219
|
-
hash_entry = repeated_field_create_array(array, field_descriptor, field_descriptor.type)
|
207
|
+
hash_entry = repeated_field_create_array(message_value[:array_val], field_descriptor, field_descriptor.type)
|
220
208
|
else
|
221
209
|
hash_entry = scalar_create_hash(message_value, field_descriptor.type, field_descriptor: field_descriptor)
|
222
210
|
end
|
223
211
|
|
224
212
|
hash[field_descriptor.name.to_sym] = hash_entry
|
225
|
-
|
226
213
|
end
|
227
214
|
|
228
215
|
hash
|
@@ -9,18 +9,20 @@ module Google
|
|
9
9
|
module Protobuf
|
10
10
|
class FFI
|
11
11
|
# Map
|
12
|
-
attach_function :map_clear,
|
13
|
-
attach_function :map_delete,
|
14
|
-
attach_function :map_get,
|
15
|
-
attach_function :create_map,
|
16
|
-
attach_function :map_size,
|
17
|
-
attach_function :map_set,
|
12
|
+
attach_function :map_clear, :upb_Map_Clear, [:Map], :void
|
13
|
+
attach_function :map_delete, :upb_Map_Delete, [:Map, MessageValue.by_value, MessageValue.by_ref], :bool
|
14
|
+
attach_function :map_get, :upb_Map_Get, [:Map, MessageValue.by_value, MessageValue.by_ref], :bool
|
15
|
+
attach_function :create_map, :upb_Map_New, [Internal::Arena, CType, CType], :Map
|
16
|
+
attach_function :map_size, :upb_Map_Size, [:Map], :size_t
|
17
|
+
attach_function :map_set, :upb_Map_Set, [:Map, MessageValue.by_value, MessageValue.by_value, Internal::Arena], :bool
|
18
|
+
attach_function :map_freeze, :upb_Map_Freeze, [:Map, MiniTable.by_ref], :void
|
19
|
+
attach_function :map_frozen?, :upb_Map_IsFrozen, [:Map], :bool
|
18
20
|
|
19
21
|
# MapIterator
|
20
|
-
attach_function :map_next,
|
21
|
-
attach_function :map_done,
|
22
|
-
attach_function :map_key,
|
23
|
-
attach_function :map_value,
|
22
|
+
attach_function :map_next, :upb_MapIterator_Next, [:Map, :pointer], :bool
|
23
|
+
attach_function :map_done, :upb_MapIterator_Done, [:Map, :size_t], :bool
|
24
|
+
attach_function :map_key, :upb_MapIterator_Key, [:Map, :size_t], MessageValue.by_value
|
25
|
+
attach_function :map_value, :upb_MapIterator_Value, [:Map, :size_t], MessageValue.by_value
|
24
26
|
end
|
25
27
|
class Map
|
26
28
|
include Enumerable
|
@@ -155,6 +157,37 @@ module Google
|
|
155
157
|
end
|
156
158
|
alias size length
|
157
159
|
|
160
|
+
##
|
161
|
+
# Is this object frozen?
|
162
|
+
# Returns true if either this Ruby wrapper or the underlying
|
163
|
+
# representation are frozen. Freezes the wrapper if the underlying
|
164
|
+
# representation is already frozen but this wrapper isn't.
|
165
|
+
def frozen?
|
166
|
+
unless Google::Protobuf::FFI.map_frozen? @map_ptr
|
167
|
+
raise RuntimeError.new "Ruby frozen Map with mutable representation" if super
|
168
|
+
return false
|
169
|
+
end
|
170
|
+
method(:freeze).super_method.call unless super
|
171
|
+
true
|
172
|
+
end
|
173
|
+
|
174
|
+
##
|
175
|
+
# Freezes the map object. We have to intercept this so we can freeze the
|
176
|
+
# underlying representation, not just the Ruby wrapper. Returns self.
|
177
|
+
def freeze
|
178
|
+
if method(:frozen?).super_method.call
|
179
|
+
unless Google::Protobuf::FFI.map_frozen? @map_ptr
|
180
|
+
raise RuntimeError.new "Underlying representation of map still mutable despite frozen wrapper"
|
181
|
+
end
|
182
|
+
return self
|
183
|
+
end
|
184
|
+
unless Google::Protobuf::FFI.map_frozen? @map_ptr
|
185
|
+
mini_table = (value_type == :message) ? Google::Protobuf::FFI.get_mini_table(@descriptor) : nil
|
186
|
+
Google::Protobuf::FFI.map_freeze(@map_ptr, mini_table)
|
187
|
+
end
|
188
|
+
super
|
189
|
+
end
|
190
|
+
|
158
191
|
##
|
159
192
|
# call-seq:
|
160
193
|
# Map.dup => new_map
|
@@ -269,17 +302,6 @@ module Google
|
|
269
302
|
|
270
303
|
include Google::Protobuf::Internal::Convert
|
271
304
|
|
272
|
-
def internal_deep_freeze
|
273
|
-
freeze
|
274
|
-
if value_type == :message
|
275
|
-
internal_iterator do |iterator|
|
276
|
-
value_message_value = Google::Protobuf::FFI.map_value(@map_ptr, iterator)
|
277
|
-
convert_upb_to_ruby(value_message_value, value_type, descriptor, arena).send :internal_deep_freeze
|
278
|
-
end
|
279
|
-
end
|
280
|
-
self
|
281
|
-
end
|
282
|
-
|
283
305
|
def internal_iterator
|
284
306
|
iter = ::FFI::MemoryPointer.new(:size_t, 1)
|
285
307
|
iter.write(:size_t, Google::Protobuf::FFI::Upb_Map_Begin)
|
@@ -369,10 +391,14 @@ module Google
|
|
369
391
|
OBJECT_CACHE.try_add(@map_ptr.address, self)
|
370
392
|
end
|
371
393
|
|
372
|
-
|
373
|
-
#
|
394
|
+
##
|
395
|
+
# Constructor that uses the type information from the given
|
396
|
+
# FieldDescriptor to configure the new Map instance.
|
397
|
+
# @param field [FieldDescriptor] Type information for the new Map
|
374
398
|
# @param arena [Arena] Owning message's arena
|
375
|
-
|
399
|
+
# @param value [Hash|Map] Initial value
|
400
|
+
# @param map [::FFI::Pointer] Existing upb_Map
|
401
|
+
def self.construct_for_field(field, arena: nil, value: nil, map: nil)
|
376
402
|
raise ArgumentError.new "Expected Hash object as initializer value for map field '#{field.name}' (given #{value.class})." unless value.nil? or value.is_a? Hash
|
377
403
|
instance = allocate
|
378
404
|
raise ArgumentError.new "Expected field with type :message, instead got #{field.class}" unless field.type == :message
|