google-protobuf 3.25.0.rc.2-java → 3.25.2-java
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of google-protobuf might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/ext/google/protobuf_c/glue.c +37 -2
- data/ext/google/protobuf_c/message.c +46 -8
- data/ext/google/protobuf_c/message.h +7 -0
- data/lib/google/protobuf/ffi/descriptor.rb +11 -0
- data/lib/google/protobuf/ffi/descriptor_pool.rb +14 -9
- data/lib/google/protobuf/ffi/enum_descriptor.rb +11 -1
- data/lib/google/protobuf/ffi/field_descriptor.rb +25 -15
- data/lib/google/protobuf/ffi/file_descriptor.rb +11 -0
- data/lib/google/protobuf/ffi/map.rb +11 -0
- data/lib/google/protobuf/ffi/message.rb +23 -2
- data/lib/google/protobuf/ffi/oneof_descriptor.rb +18 -11
- data/lib/google/protobuf/ffi/repeated_field.rb +12 -132
- data/lib/google/protobuf_java.jar +0 -0
- data/lib/google/tasks/ffi.rake +45 -37
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02ad8ba5913acd67e758f55de627b570f80de510945cf07b1fe34dea1c3bc8a6
|
4
|
+
data.tar.gz: 5eb6973284aeef112085210c1ecb3d93363c1fd93048c0f87fb9385473b87cf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03475d3e04fcc0a7216442ebe962867fbcd6290282bb7124b5f0cf100bdc0de64d48c05680532e9f4171f77114eca06a3c930763eeb02179d203996fade829da
|
7
|
+
data.tar.gz: 19eee11d54ce48118eae3d79c8ed88a5ba36696d5ef1952b53c2b5b020cd4dd41e7e26171af511737c46a2227680aeb811f375a8a09bd9e4ffa873c7b3eeaada
|
@@ -14,8 +14,43 @@
|
|
14
14
|
upb_Arena* Arena_create() { return upb_Arena_Init(NULL, 0, &upb_alloc_global); }
|
15
15
|
|
16
16
|
google_protobuf_FileDescriptorProto* FileDescriptorProto_parse(
|
17
|
-
const char* serialized_file_proto, size_t length) {
|
18
|
-
upb_Arena* arena = Arena_create();
|
17
|
+
const char* serialized_file_proto, size_t length, upb_Arena* arena) {
|
19
18
|
return google_protobuf_FileDescriptorProto_parse(serialized_file_proto,
|
20
19
|
length, arena);
|
21
20
|
}
|
21
|
+
|
22
|
+
char* EnumDescriptor_serialized_options(const upb_EnumDef* enumdef,
|
23
|
+
size_t* size, upb_Arena* arena) {
|
24
|
+
const google_protobuf_EnumOptions* opts = upb_EnumDef_Options(enumdef);
|
25
|
+
char* serialized = google_protobuf_EnumOptions_serialize(opts, arena, size);
|
26
|
+
return serialized;
|
27
|
+
}
|
28
|
+
|
29
|
+
char* FileDescriptor_serialized_options(const upb_FileDef* filedef,
|
30
|
+
size_t* size, upb_Arena* arena) {
|
31
|
+
const google_protobuf_FileOptions* opts = upb_FileDef_Options(filedef);
|
32
|
+
char* serialized = google_protobuf_FileOptions_serialize(opts, arena, size);
|
33
|
+
return serialized;
|
34
|
+
}
|
35
|
+
|
36
|
+
char* Descriptor_serialized_options(const upb_MessageDef* msgdef, size_t* size,
|
37
|
+
upb_Arena* arena) {
|
38
|
+
const google_protobuf_MessageOptions* opts = upb_MessageDef_Options(msgdef);
|
39
|
+
char* serialized =
|
40
|
+
google_protobuf_MessageOptions_serialize(opts, arena, size);
|
41
|
+
return serialized;
|
42
|
+
}
|
43
|
+
|
44
|
+
char* OneOfDescriptor_serialized_options(const upb_OneofDef* oneofdef,
|
45
|
+
size_t* size, upb_Arena* arena) {
|
46
|
+
const google_protobuf_OneofOptions* opts = upb_OneofDef_Options(oneofdef);
|
47
|
+
char* serialized = google_protobuf_OneofOptions_serialize(opts, arena, size);
|
48
|
+
return serialized;
|
49
|
+
}
|
50
|
+
|
51
|
+
char* FieldDescriptor_serialized_options(const upb_FieldDef* fielddef,
|
52
|
+
size_t* size, upb_Arena* arena) {
|
53
|
+
const google_protobuf_FieldOptions* opts = upb_FieldDef_Options(fielddef);
|
54
|
+
char* serialized = google_protobuf_FieldOptions_serialize(opts, arena, size);
|
55
|
+
return serialized;
|
56
|
+
}
|
@@ -859,6 +859,32 @@ static VALUE Message_freeze(VALUE _self) {
|
|
859
859
|
return _self;
|
860
860
|
}
|
861
861
|
|
862
|
+
/*
|
863
|
+
* Deep freezes the message object recursively.
|
864
|
+
* Internal use only.
|
865
|
+
*/
|
866
|
+
VALUE Message_internal_deep_freeze(VALUE _self) {
|
867
|
+
Message* self = ruby_to_Message(_self);
|
868
|
+
Message_freeze(_self);
|
869
|
+
|
870
|
+
int n = upb_MessageDef_FieldCount(self->msgdef);
|
871
|
+
for (int i = 0; i < n; i++) {
|
872
|
+
const upb_FieldDef* f = upb_MessageDef_Field(self->msgdef, i);
|
873
|
+
VALUE field = Message_getfield(_self, f);
|
874
|
+
|
875
|
+
if (field != Qnil) {
|
876
|
+
if (upb_FieldDef_IsMap(f)) {
|
877
|
+
Map_internal_deep_freeze(field);
|
878
|
+
} else if (upb_FieldDef_IsRepeated(f)) {
|
879
|
+
RepeatedField_internal_deep_freeze(field);
|
880
|
+
} else if (upb_FieldDef_IsSubMessage(f)) {
|
881
|
+
Message_internal_deep_freeze(field);
|
882
|
+
}
|
883
|
+
}
|
884
|
+
}
|
885
|
+
return _self;
|
886
|
+
}
|
887
|
+
|
862
888
|
/*
|
863
889
|
* call-seq:
|
864
890
|
* Message.[](index) => value
|
@@ -911,7 +937,7 @@ static VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value) {
|
|
911
937
|
* MessageClass.decode(data, options) => message
|
912
938
|
*
|
913
939
|
* Decodes the given data (as a string containing bytes in protocol buffers wire
|
914
|
-
* format) under the
|
940
|
+
* format) under the interpretation given by this message class's definition
|
915
941
|
* and returns a message object with the corresponding field values.
|
916
942
|
* @param options [Hash] options for the decoder
|
917
943
|
* recursion_limit: set to maximum decoding depth for message (default is 64)
|
@@ -942,18 +968,27 @@ static VALUE Message_decode(int argc, VALUE* argv, VALUE klass) {
|
|
942
968
|
rb_raise(rb_eArgError, "Expected string for binary protobuf data.");
|
943
969
|
}
|
944
970
|
|
971
|
+
return Message_decode_bytes(RSTRING_LEN(data), RSTRING_PTR(data), options,
|
972
|
+
klass, /*freeze*/ false);
|
973
|
+
}
|
974
|
+
|
975
|
+
VALUE Message_decode_bytes(int size, const char* bytes, int options,
|
976
|
+
VALUE klass, bool freeze) {
|
945
977
|
VALUE msg_rb = initialize_rb_class_with_no_args(klass);
|
946
978
|
Message* msg = ruby_to_Message(msg_rb);
|
947
979
|
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
980
|
+
const upb_FileDef* file = upb_MessageDef_File(msg->msgdef);
|
981
|
+
const upb_ExtensionRegistry* extreg =
|
982
|
+
upb_DefPool_ExtensionRegistry(upb_FileDef_Pool(file));
|
983
|
+
upb_DecodeStatus status = upb_Decode(bytes, size, (upb_Message*)msg->msg,
|
984
|
+
upb_MessageDef_MiniTable(msg->msgdef),
|
985
|
+
extreg, options, Arena_get(msg->arena));
|
953
986
|
if (status != kUpb_DecodeStatus_Ok) {
|
954
987
|
rb_raise(cParseError, "Error occurred during parsing");
|
955
988
|
}
|
956
|
-
|
989
|
+
if (freeze) {
|
990
|
+
Message_internal_deep_freeze(msg_rb);
|
991
|
+
}
|
957
992
|
return msg_rb;
|
958
993
|
}
|
959
994
|
|
@@ -1271,9 +1306,12 @@ upb_Message* Message_deep_copy(const upb_Message* msg, const upb_MessageDef* m,
|
|
1271
1306
|
upb_Message* new_msg = upb_Message_New(layout, arena);
|
1272
1307
|
char* data;
|
1273
1308
|
|
1309
|
+
const upb_FileDef* file = upb_MessageDef_File(m);
|
1310
|
+
const upb_ExtensionRegistry* extreg =
|
1311
|
+
upb_DefPool_ExtensionRegistry(upb_FileDef_Pool(file));
|
1274
1312
|
if (upb_Encode(msg, layout, 0, tmp_arena, &data, &size) !=
|
1275
1313
|
kUpb_EncodeStatus_Ok ||
|
1276
|
-
upb_Decode(data, size, new_msg, layout,
|
1314
|
+
upb_Decode(data, size, new_msg, layout, extreg, 0, arena) !=
|
1277
1315
|
kUpb_DecodeStatus_Ok) {
|
1278
1316
|
upb_Arena_Free(tmp_arena);
|
1279
1317
|
rb_raise(cParseError, "Error occurred copying proto");
|
@@ -73,6 +73,13 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc);
|
|
73
73
|
// module.
|
74
74
|
VALUE MessageOrEnum_GetDescriptor(VALUE klass);
|
75
75
|
|
76
|
+
// Decodes a Message from a byte sequence.
|
77
|
+
VALUE Message_decode_bytes(int size, const char* bytes, int options,
|
78
|
+
VALUE klass, bool freeze);
|
79
|
+
|
80
|
+
// Recursively freeze message
|
81
|
+
VALUE Message_internal_deep_freeze(VALUE _self);
|
82
|
+
|
76
83
|
// Call at startup to register all types in this module.
|
77
84
|
void Message_register(VALUE protobuf);
|
78
85
|
|
@@ -95,6 +95,15 @@ module Google
|
|
95
95
|
@msg_class ||= build_message_class
|
96
96
|
end
|
97
97
|
|
98
|
+
def options
|
99
|
+
@options ||= begin
|
100
|
+
size_ptr = ::FFI::MemoryPointer.new(:size_t, 1)
|
101
|
+
temporary_arena = Google::Protobuf::FFI.create_arena
|
102
|
+
buffer = Google::Protobuf::FFI.message_options(self, size_ptr, temporary_arena)
|
103
|
+
Google::Protobuf::MessageOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze).send(:internal_deep_freeze)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
98
107
|
private
|
99
108
|
|
100
109
|
extend Google::Protobuf::Internal::Convert
|
@@ -129,6 +138,7 @@ module Google
|
|
129
138
|
message = OBJECT_CACHE.get(msg.address)
|
130
139
|
if message.nil?
|
131
140
|
message = descriptor.msgclass.send(:private_constructor, arena, msg: msg)
|
141
|
+
message.send :internal_deep_freeze if frozen?
|
132
142
|
end
|
133
143
|
message
|
134
144
|
end
|
@@ -146,6 +156,7 @@ module Google
|
|
146
156
|
attach_function :get_message_fullname, :upb_MessageDef_FullName, [Descriptor], :string
|
147
157
|
attach_function :get_mini_table, :upb_MessageDef_MiniTable, [Descriptor], MiniTable.ptr
|
148
158
|
attach_function :oneof_count, :upb_MessageDef_OneofCount, [Descriptor], :int
|
159
|
+
attach_function :message_options, :Descriptor_serialized_options, [Descriptor, :pointer, Internal::Arena], :pointer
|
149
160
|
attach_function :get_well_known_type, :upb_MessageDef_WellKnownType, [Descriptor], WellKnown
|
150
161
|
attach_function :message_def_syntax, :upb_MessageDef_Syntax, [Descriptor], Syntax
|
151
162
|
attach_function :find_msg_def_by_name, :upb_MessageDef_FindByNameWithSize, [Descriptor, :string, :size_t, :FieldDefPointer, :OneofDefPointer], :bool
|
@@ -9,13 +9,16 @@ module Google
|
|
9
9
|
module Protobuf
|
10
10
|
class FFI
|
11
11
|
# DefPool
|
12
|
-
attach_function :add_serialized_file, :upb_DefPool_AddFile,
|
13
|
-
attach_function :free_descriptor_pool, :upb_DefPool_Free,
|
14
|
-
attach_function :create_descriptor_pool,:upb_DefPool_New,
|
15
|
-
attach_function :
|
16
|
-
attach_function :
|
17
|
-
|
18
|
-
attach_function :
|
12
|
+
attach_function :add_serialized_file, :upb_DefPool_AddFile, [:DefPool, :FileDescriptorProto, Status.by_ref], :FileDef
|
13
|
+
attach_function :free_descriptor_pool, :upb_DefPool_Free, [:DefPool], :void
|
14
|
+
attach_function :create_descriptor_pool,:upb_DefPool_New, [], :DefPool
|
15
|
+
attach_function :get_extension_registry,:upb_DefPool_ExtensionRegistry, [:DefPool], :ExtensionRegistry
|
16
|
+
attach_function :lookup_enum, :upb_DefPool_FindEnumByName, [:DefPool, :string], EnumDescriptor
|
17
|
+
attach_function :lookup_extension, :upb_DefPool_FindExtensionByName,[:DefPool, :string], FieldDescriptor
|
18
|
+
attach_function :lookup_msg, :upb_DefPool_FindMessageByName, [:DefPool, :string], Descriptor
|
19
|
+
|
20
|
+
# FileDescriptorProto
|
21
|
+
attach_function :parse, :FileDescriptorProto_parse, [:binary_string, :size_t, Internal::Arena], :FileDescriptorProto
|
19
22
|
end
|
20
23
|
class DescriptorPool
|
21
24
|
attr :descriptor_pool
|
@@ -35,7 +38,8 @@ module Google
|
|
35
38
|
memBuf = ::FFI::MemoryPointer.new(:char, file_contents.bytesize)
|
36
39
|
# Insert the data
|
37
40
|
memBuf.put_bytes(0, file_contents)
|
38
|
-
|
41
|
+
temporary_arena = Google::Protobuf::FFI.create_arena
|
42
|
+
file_descriptor_proto = Google::Protobuf::FFI.parse memBuf, file_contents.bytesize, temporary_arena
|
39
43
|
raise ArgumentError.new("Unable to parse FileDescriptorProto") if file_descriptor_proto.null?
|
40
44
|
|
41
45
|
status = Google::Protobuf::FFI::Status.new
|
@@ -49,7 +53,8 @@ module Google
|
|
49
53
|
|
50
54
|
def lookup name
|
51
55
|
Google::Protobuf::FFI.lookup_msg(@descriptor_pool, name) ||
|
52
|
-
Google::Protobuf::FFI.lookup_enum(@descriptor_pool, name)
|
56
|
+
Google::Protobuf::FFI.lookup_enum(@descriptor_pool, name) ||
|
57
|
+
Google::Protobuf::FFI.lookup_extension(@descriptor_pool, name)
|
53
58
|
end
|
54
59
|
|
55
60
|
def self.generated_pool
|
@@ -19,7 +19,7 @@ module Google
|
|
19
19
|
prepend Google::Protobuf::Internal::TypeSafety
|
20
20
|
include Google::Protobuf::Internal::PointerHelper
|
21
21
|
|
22
|
-
# @param value [
|
22
|
+
# @param value [EnumDescriptor] EnumDescriptor to convert to an FFI native type
|
23
23
|
# @param _ [Object] Unused
|
24
24
|
def to_native(value, _)
|
25
25
|
value.instance_variable_get(:@enum_def) || ::FFI::Pointer::NULL
|
@@ -79,6 +79,15 @@ module Google
|
|
79
79
|
@module
|
80
80
|
end
|
81
81
|
|
82
|
+
def options
|
83
|
+
@options ||= begin
|
84
|
+
size_ptr = ::FFI::MemoryPointer.new(:size_t, 1)
|
85
|
+
temporary_arena = Google::Protobuf::FFI.create_arena
|
86
|
+
buffer = Google::Protobuf::FFI.enum_options(self, size_ptr, temporary_arena)
|
87
|
+
Google::Protobuf::EnumOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze).send(:internal_deep_freeze)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
82
91
|
private
|
83
92
|
|
84
93
|
def initialize(enum_def, descriptor_pool)
|
@@ -152,6 +161,7 @@ module Google
|
|
152
161
|
attach_function :enum_value_by_name, :upb_EnumDef_FindValueByNameWithSize,[EnumDescriptor, :string, :size_t], :EnumValueDef
|
153
162
|
attach_function :enum_value_by_number, :upb_EnumDef_FindValueByNumber, [EnumDescriptor, :int], :EnumValueDef
|
154
163
|
attach_function :get_enum_fullname, :upb_EnumDef_FullName, [EnumDescriptor], :string
|
164
|
+
attach_function :enum_options, :EnumDescriptor_serialized_options, [EnumDescriptor, :pointer, Internal::Arena], :pointer
|
155
165
|
attach_function :enum_value_by_index, :upb_EnumDef_Value, [EnumDescriptor, :int], :EnumValueDef
|
156
166
|
attach_function :enum_value_count, :upb_EnumDef_ValueCount, [EnumDescriptor], :int
|
157
167
|
attach_function :enum_name, :upb_EnumValueDef_Name, [:EnumValueDef], :string
|
@@ -206,6 +206,15 @@ module Google
|
|
206
206
|
end
|
207
207
|
end
|
208
208
|
|
209
|
+
def options
|
210
|
+
@options ||= begin
|
211
|
+
size_ptr = ::FFI::MemoryPointer.new(:size_t, 1)
|
212
|
+
temporary_arena = Google::Protobuf::FFI.create_arena
|
213
|
+
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).send(:internal_deep_freeze)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
209
218
|
private
|
210
219
|
|
211
220
|
def initialize(field_def, descriptor_pool)
|
@@ -289,21 +298,22 @@ module Google
|
|
289
298
|
attach_function :get_field_by_number, :upb_MessageDef_FindFieldByNumber, [Descriptor, :uint32_t], FieldDescriptor
|
290
299
|
|
291
300
|
# FieldDescriptor
|
292
|
-
attach_function :
|
293
|
-
attach_function :
|
294
|
-
attach_function :
|
295
|
-
attach_function :
|
296
|
-
attach_function :
|
297
|
-
attach_function :
|
298
|
-
attach_function :
|
299
|
-
attach_function :
|
300
|
-
attach_function :
|
301
|
-
attach_function :
|
302
|
-
attach_function :
|
303
|
-
attach_function :
|
304
|
-
attach_function :
|
305
|
-
attach_function :
|
306
|
-
attach_function :
|
301
|
+
attach_function :field_options, :FieldDescriptor_serialized_options, [FieldDescriptor, :pointer, Internal::Arena], :pointer
|
302
|
+
attach_function :get_containing_message_def, :upb_FieldDef_ContainingType, [FieldDescriptor], Descriptor
|
303
|
+
attach_function :get_c_type, :upb_FieldDef_CType, [FieldDescriptor], CType
|
304
|
+
attach_function :get_default, :upb_FieldDef_Default, [FieldDescriptor], MessageValue.by_value
|
305
|
+
attach_function :get_subtype_as_enum, :upb_FieldDef_EnumSubDef, [FieldDescriptor], EnumDescriptor
|
306
|
+
attach_function :get_has_presence, :upb_FieldDef_HasPresence, [FieldDescriptor], :bool
|
307
|
+
attach_function :is_map, :upb_FieldDef_IsMap, [FieldDescriptor], :bool
|
308
|
+
attach_function :is_repeated, :upb_FieldDef_IsRepeated, [FieldDescriptor], :bool
|
309
|
+
attach_function :is_sub_message, :upb_FieldDef_IsSubMessage, [FieldDescriptor], :bool
|
310
|
+
attach_function :get_json_name, :upb_FieldDef_JsonName, [FieldDescriptor], :string
|
311
|
+
attach_function :get_label, :upb_FieldDef_Label, [FieldDescriptor], Label
|
312
|
+
attach_function :get_subtype_as_message, :upb_FieldDef_MessageSubDef, [FieldDescriptor], Descriptor
|
313
|
+
attach_function :get_full_name, :upb_FieldDef_Name, [FieldDescriptor], :string
|
314
|
+
attach_function :get_number, :upb_FieldDef_Number, [FieldDescriptor], :uint32_t
|
315
|
+
attach_function :get_type, :upb_FieldDef_Type, [FieldDescriptor], FieldType
|
316
|
+
attach_function :file_def_by_raw_field_def, :upb_FieldDef_File, [:pointer], :FileDef
|
307
317
|
end
|
308
318
|
end
|
309
319
|
end
|
@@ -12,7 +12,9 @@ module Google
|
|
12
12
|
attach_function :file_def_name, :upb_FileDef_Name, [:FileDef], :string
|
13
13
|
attach_function :file_def_syntax, :upb_FileDef_Syntax, [:FileDef], Syntax
|
14
14
|
attach_function :file_def_pool, :upb_FileDef_Pool, [:FileDef], :DefPool
|
15
|
+
attach_function :file_options, :FileDescriptor_serialized_options, [:FileDef, :pointer, Internal::Arena], :pointer
|
15
16
|
end
|
17
|
+
|
16
18
|
class FileDescriptor
|
17
19
|
attr :descriptor_pool, :file_def
|
18
20
|
|
@@ -43,6 +45,15 @@ module Google
|
|
43
45
|
def name
|
44
46
|
Google::Protobuf::FFI.file_def_name(@file_def)
|
45
47
|
end
|
48
|
+
|
49
|
+
def options
|
50
|
+
@options ||= begin
|
51
|
+
size_ptr = ::FFI::MemoryPointer.new(:size_t, 1)
|
52
|
+
temporary_arena = Google::Protobuf::FFI.create_arena
|
53
|
+
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).send(:internal_deep_freeze)
|
55
|
+
end
|
56
|
+
end
|
46
57
|
end
|
47
58
|
end
|
48
59
|
end
|
@@ -269,6 +269,17 @@ module Google
|
|
269
269
|
|
270
270
|
include Google::Protobuf::Internal::Convert
|
271
271
|
|
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
|
+
|
272
283
|
def internal_iterator
|
273
284
|
iter = ::FFI::MemoryPointer.new(:size_t, 1)
|
274
285
|
iter.write(:size_t, Google::Protobuf::FFI::Upb_Map_Begin)
|
@@ -19,7 +19,7 @@ module Google
|
|
19
19
|
attach_function :encode_message, :upb_Encode, [:Message, MiniTable.by_ref, :size_t, Internal::Arena, :pointer, :pointer], EncodeStatus
|
20
20
|
attach_function :json_decode_message, :upb_JsonDecode, [:binary_string, :size_t, :Message, Descriptor, :DefPool, :int, Internal::Arena, Status.by_ref], :bool
|
21
21
|
attach_function :json_encode_message, :upb_JsonEncode, [:Message, Descriptor, :DefPool, :int, :binary_string, :size_t, Status.by_ref], :size_t
|
22
|
-
attach_function :decode_message, :upb_Decode,
|
22
|
+
attach_function :decode_message, :upb_Decode, [:binary_string, :size_t, :Message, MiniTable.by_ref, :ExtensionRegistry, :int, Internal::Arena], DecodeStatus
|
23
23
|
attach_function :get_mutable_message, :upb_Message_Mutable, [:Message, FieldDescriptor, Internal::Arena], MutableMessageValue.by_value
|
24
24
|
attach_function :get_message_which_oneof, :upb_Message_WhichOneof, [:Message, OneofDescriptor], FieldDescriptor
|
25
25
|
attach_function :message_discard_unknown, :upb_Message_DiscardUnknown, [:Message, Descriptor, :int], :bool
|
@@ -170,7 +170,15 @@ module Google
|
|
170
170
|
|
171
171
|
message = new
|
172
172
|
mini_table_ptr = Google::Protobuf::FFI.get_mini_table(message.class.descriptor)
|
173
|
-
status = Google::Protobuf::FFI.decode_message(
|
173
|
+
status = Google::Protobuf::FFI.decode_message(
|
174
|
+
data,
|
175
|
+
data.bytesize,
|
176
|
+
message.instance_variable_get(:@msg),
|
177
|
+
mini_table_ptr,
|
178
|
+
Google::Protobuf::FFI.get_extension_registry(message.class.descriptor.send(:pool).descriptor_pool),
|
179
|
+
decoding_options,
|
180
|
+
message.instance_variable_get(:@arena)
|
181
|
+
)
|
174
182
|
raise ParseError.new "Error occurred during parsing" unless status == :Ok
|
175
183
|
message
|
176
184
|
end
|
@@ -293,6 +301,17 @@ module Google
|
|
293
301
|
|
294
302
|
include Google::Protobuf::Internal::Convert
|
295
303
|
|
304
|
+
def internal_deep_freeze
|
305
|
+
freeze
|
306
|
+
self.class.descriptor.each do |field_descriptor|
|
307
|
+
next if field_descriptor.has_presence? && !Google::Protobuf::FFI.get_message_has(@msg, field_descriptor)
|
308
|
+
if field_descriptor.map? or field_descriptor.repeated? or field_descriptor.sub_message?
|
309
|
+
get_field(field_descriptor).send :internal_deep_freeze
|
310
|
+
end
|
311
|
+
end
|
312
|
+
self
|
313
|
+
end
|
314
|
+
|
296
315
|
def self.setup_accessors!
|
297
316
|
@descriptor.each do |field_descriptor|
|
298
317
|
field_name = field_descriptor.name
|
@@ -619,6 +638,7 @@ module Google
|
|
619
638
|
repeated_field = OBJECT_CACHE.get(array.address)
|
620
639
|
if repeated_field.nil?
|
621
640
|
repeated_field = RepeatedField.send(:construct_for_field, field, @arena, array: array)
|
641
|
+
repeated_field.send :internal_deep_freeze if frozen?
|
622
642
|
end
|
623
643
|
repeated_field
|
624
644
|
end
|
@@ -631,6 +651,7 @@ module Google
|
|
631
651
|
map_field = OBJECT_CACHE.get(map.address)
|
632
652
|
if map_field.nil?
|
633
653
|
map_field = Google::Protobuf::Map.send(:construct_for_field, field, @arena, map: map)
|
654
|
+
map_field.send :internal_deep_freeze if frozen?
|
634
655
|
end
|
635
656
|
map_field
|
636
657
|
end
|
@@ -22,10 +22,7 @@ module Google
|
|
22
22
|
# @param value [OneofDescriptor] FieldDescriptor to convert to an FFI native type
|
23
23
|
# @param _ [Object] Unused
|
24
24
|
def to_native(value, _ = nil)
|
25
|
-
|
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
|
25
|
+
value.instance_variable_get(:@oneof_def) || ::FFI::Pointer::NULL
|
29
26
|
end
|
30
27
|
|
31
28
|
##
|
@@ -56,6 +53,15 @@ module Google
|
|
56
53
|
nil
|
57
54
|
end
|
58
55
|
|
56
|
+
def options
|
57
|
+
@options ||= begin
|
58
|
+
size_ptr = ::FFI::MemoryPointer.new(:size_t, 1)
|
59
|
+
temporary_arena = Google::Protobuf::FFI.create_arena
|
60
|
+
buffer = Google::Protobuf::FFI.oneof_options(self, size_ptr, temporary_arena)
|
61
|
+
Google::Protobuf::OneofOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze).send(:internal_deep_freeze)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
59
65
|
private
|
60
66
|
|
61
67
|
def initialize(oneof_def, descriptor_pool)
|
@@ -72,17 +78,18 @@ module Google
|
|
72
78
|
|
73
79
|
class FFI
|
74
80
|
# MessageDef
|
75
|
-
attach_function :get_oneof_by_name,
|
76
|
-
attach_function :get_oneof_by_index,
|
81
|
+
attach_function :get_oneof_by_name, :upb_MessageDef_FindOneofByNameWithSize, [Descriptor, :string, :size_t], OneofDescriptor
|
82
|
+
attach_function :get_oneof_by_index, :upb_MessageDef_Oneof, [Descriptor, :int], OneofDescriptor
|
77
83
|
|
78
84
|
# OneofDescriptor
|
79
|
-
attach_function :get_oneof_name, :upb_OneofDef_Name,
|
80
|
-
attach_function :get_oneof_field_count, :upb_OneofDef_FieldCount,
|
81
|
-
attach_function :get_oneof_field_by_index, :upb_OneofDef_Field,
|
82
|
-
attach_function :get_oneof_containing_type,:upb_OneofDef_ContainingType,[:pointer], Descriptor
|
85
|
+
attach_function :get_oneof_name, :upb_OneofDef_Name, [OneofDescriptor], :string
|
86
|
+
attach_function :get_oneof_field_count, :upb_OneofDef_FieldCount, [OneofDescriptor], :int
|
87
|
+
attach_function :get_oneof_field_by_index, :upb_OneofDef_Field, [OneofDescriptor, :int], FieldDescriptor
|
88
|
+
attach_function :get_oneof_containing_type,:upb_OneofDef_ContainingType, [:pointer], Descriptor
|
89
|
+
attach_function :oneof_options, :OneOfDescriptor_serialized_options, [OneofDescriptor, :pointer, Internal::Arena], :pointer
|
83
90
|
|
84
91
|
# FieldDescriptor
|
85
|
-
attach_function :real_containing_oneof,
|
92
|
+
attach_function :real_containing_oneof, :upb_FieldDef_RealContainingOneof, [FieldDescriptor], OneofDescriptor
|
86
93
|
end
|
87
94
|
end
|
88
95
|
end
|
@@ -5,8 +5,6 @@
|
|
5
5
|
# license that can be found in the LICENSE file or at
|
6
6
|
# https://developers.google.com/open-source/licenses/bsd
|
7
7
|
|
8
|
-
require 'forwardable'
|
9
|
-
|
10
8
|
#
|
11
9
|
# This class makes RepeatedField act (almost-) like a Ruby Array.
|
12
10
|
# It has convenience methods that extend the core C or Java based
|
@@ -15,7 +13,7 @@ require 'forwardable'
|
|
15
13
|
# This is a best-effort to mirror Array behavior. Two comments:
|
16
14
|
# 1) patches always welcome :)
|
17
15
|
# 2) if performance is an issue, feel free to rewrite the method
|
18
|
-
# in
|
16
|
+
# in C. The source code has plenty of examples
|
19
17
|
#
|
20
18
|
# KNOWN ISSUES
|
21
19
|
# - #[]= doesn't allow less used approaches such as `arr[1, 2] = 'fizz'`
|
@@ -35,19 +33,6 @@ module Google
|
|
35
33
|
end
|
36
34
|
|
37
35
|
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
36
|
include Enumerable
|
52
37
|
|
53
38
|
##
|
@@ -262,128 +247,21 @@ module Google
|
|
262
247
|
push(*other.to_a)
|
263
248
|
end
|
264
249
|
|
265
|
-
|
266
|
-
|
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
|
250
|
+
private
|
251
|
+
include Google::Protobuf::Internal::Convert
|
353
252
|
|
253
|
+
attr :name, :arena, :array, :type, :descriptor
|
354
254
|
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
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
|
255
|
+
def internal_deep_freeze
|
256
|
+
freeze
|
257
|
+
if type == :message
|
258
|
+
each do |element|
|
259
|
+
element.send :internal_deep_freeze
|
377
260
|
end
|
378
|
-
results
|
379
261
|
end
|
262
|
+
self
|
380
263
|
end
|
381
264
|
|
382
|
-
private
|
383
|
-
include Google::Protobuf::Internal::Convert
|
384
|
-
|
385
|
-
attr :name, :arena, :array, :type, :descriptor
|
386
|
-
|
387
265
|
def internal_push(*elements)
|
388
266
|
elements.each do |element|
|
389
267
|
append_msg_val convert_ruby_to_upb(element, arena, type, descriptor)
|
@@ -501,3 +379,5 @@ module Google
|
|
501
379
|
end
|
502
380
|
end
|
503
381
|
end
|
382
|
+
|
383
|
+
require 'google/protobuf/repeated_field'
|
Binary file
|
data/lib/google/tasks/ffi.rake
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require "ffi-compiler/compile_task"
|
2
|
-
|
3
1
|
# # @param task [FFI::Compiler::CompileTask] task to configure
|
4
2
|
def configure_common_compile_task(task)
|
5
3
|
if FileUtils.pwd.include? 'ext'
|
@@ -49,46 +47,56 @@ def with_generated_files
|
|
49
47
|
end
|
50
48
|
end
|
51
49
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
c.
|
50
|
+
begin
|
51
|
+
require "ffi-compiler/compile_task"
|
52
|
+
|
53
|
+
desc "Compile Protobuf library for FFI"
|
54
|
+
namespace "ffi-protobuf" do
|
55
|
+
with_generated_files do
|
56
|
+
# Compile Ruby UPB separately in order to limit use of -DUPB_BUILD_API to one
|
57
|
+
# compilation unit.
|
58
|
+
desc "Compile UPB library for FFI"
|
59
|
+
namespace "ffi-upb" do
|
60
|
+
with_generated_files do
|
61
|
+
FFI::Compiler::CompileTask.new('ruby-upb') do |c|
|
62
|
+
configure_common_compile_task c
|
63
|
+
c.add_define "UPB_BUILD_API"
|
64
|
+
c.exclude << "/glue.c"
|
65
|
+
c.exclude << "/shared_message.c"
|
66
|
+
c.exclude << "/shared_convert.c"
|
67
|
+
if RbConfig::CONFIG['target_os'] =~ /darwin|linux/
|
68
|
+
c.cflags << "-fvisibility=hidden"
|
69
|
+
end
|
68
70
|
end
|
69
71
|
end
|
70
72
|
end
|
71
|
-
end
|
72
73
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
74
|
+
FFI::Compiler::CompileTask.new 'protobuf_c_ffi' do |c|
|
75
|
+
configure_common_compile_task c
|
76
|
+
# Ruby UPB was already compiled with different flags.
|
77
|
+
c.exclude << "/range2-neon.c"
|
78
|
+
c.exclude << "/range2-sse.c"
|
79
|
+
c.exclude << "/naive.c"
|
80
|
+
c.exclude << "/ruby-upb.c"
|
81
|
+
end
|
81
82
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
83
|
+
# Setup dependencies so that the .o files generated by building ffi-upb are
|
84
|
+
# available to link here.
|
85
|
+
# TODO Can this be simplified? Can the single shared library be used
|
86
|
+
# instead of the object files?
|
87
|
+
protobuf_c_task = Rake::Task[:default]
|
88
|
+
protobuf_c_shared_lib_task = Rake::Task[protobuf_c_task.prereqs.last]
|
89
|
+
ruby_upb_shared_lib_task = Rake::Task[:"ffi-upb:default"].prereqs.first
|
90
|
+
Rake::Task[ruby_upb_shared_lib_task].prereqs.each do |dependency|
|
91
|
+
protobuf_c_shared_lib_task.prereqs.prepend dependency
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
rescue LoadError
|
96
|
+
desc "Compile Protobuf library for FFI"
|
97
|
+
namespace "ffi-protobuf" do
|
98
|
+
task :default do
|
99
|
+
warn "Skipping build of FFI; `gem install ffi-compiler` to enable."
|
91
100
|
end
|
92
101
|
end
|
93
102
|
end
|
94
|
-
|
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.25.
|
4
|
+
version: 3.25.2
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Protobuf Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -179,7 +179,7 @@ homepage: https://developers.google.com/protocol-buffers
|
|
179
179
|
licenses:
|
180
180
|
- BSD-3-Clause
|
181
181
|
metadata:
|
182
|
-
source_code_uri: https://github.com/protocolbuffers/protobuf/tree/v3.25.
|
182
|
+
source_code_uri: https://github.com/protocolbuffers/protobuf/tree/v3.25.2/ruby
|
183
183
|
post_install_message:
|
184
184
|
rdoc_options: []
|
185
185
|
require_paths:
|
@@ -191,9 +191,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
191
191
|
version: '2.7'
|
192
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
193
|
requirements:
|
194
|
-
- - "
|
194
|
+
- - ">="
|
195
195
|
- !ruby/object:Gem::Version
|
196
|
-
version:
|
196
|
+
version: '0'
|
197
197
|
requirements: []
|
198
198
|
rubygems_version: 3.2.29
|
199
199
|
signing_key:
|