google-protobuf 3.25.0-x86_64-darwin → 3.25.1-x86_64-darwin

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1234ae67ff8bd99f2a19f67ec069e0160c88bfd23e17a4bbbb10fdb0a680d399
4
- data.tar.gz: 271bf0c185fd3481c0c1f37a777fcef92ca4b39f022cce0955d346ce6e8e4577
3
+ metadata.gz: c0635f7f3874e8a6192332f3de29ec67ecf1e06c5b8df6118af06c1cba174afe
4
+ data.tar.gz: '02942c535feb84fc781b9e187bfe8cd0c5e34c0e10afea9a39e6d310b6df1d26'
5
5
  SHA512:
6
- metadata.gz: 0cfbe3350f512b8a440b51d3de9392cb38b401ce3e1828a3b3eee3d598356fa3ab289e5c9b6eff25f6c2366cc4aa09a9edb7a6d9c7e560b570223fb1278dfed2
7
- data.tar.gz: 96347b794b251610fe786eb53a6c57518ddf242fba9dca3f2cb4e999238691392c817e06802e046147043cb74053ebbc81ed7c8bf45877648266a3f673dccf48
6
+ metadata.gz: e46d3461562609901a3581ea70739ddce0348456340db466156c6564a0473a9209ce2e5e4770a612cb94f6931e7eb6ed39244b55ebe19f027352c9098665932e
7
+ data.tar.gz: 34109535d8b297e8c47063d7a44f07a79352eb3fe3aa15db94f4234319878f83f67c69b6098eccac984a60a380d640b9395ffca555e6b38f432da8df1aad2129
@@ -44,7 +44,7 @@ static VALUE rb_str_maybe_null(const char* s) {
44
44
  }
45
45
  return rb_str_new2(s);
46
46
  }
47
-
47
+ static ID options_instancevar_interned;
48
48
  // -----------------------------------------------------------------------------
49
49
  // DescriptorPool.
50
50
  // -----------------------------------------------------------------------------
@@ -144,20 +144,26 @@ VALUE DescriptorPool_add_serialized_file(VALUE _self,
144
144
  * call-seq:
145
145
  * DescriptorPool.lookup(name) => descriptor
146
146
  *
147
- * Finds a Descriptor or EnumDescriptor by name and returns it, or nil if none
148
- * exists with the given name.
147
+ * Finds a Descriptor, EnumDescriptor or FieldDescriptor by name and returns it,
148
+ * or nil if none exists with the given name.
149
149
  */
150
150
  static VALUE DescriptorPool_lookup(VALUE _self, VALUE name) {
151
151
  DescriptorPool* self = ruby_to_DescriptorPool(_self);
152
152
  const char* name_str = get_str(name);
153
153
  const upb_MessageDef* msgdef;
154
154
  const upb_EnumDef* enumdef;
155
+ const upb_FieldDef* fielddef;
155
156
 
156
157
  msgdef = upb_DefPool_FindMessageByName(self->symtab, name_str);
157
158
  if (msgdef) {
158
159
  return get_msgdef_obj(_self, msgdef);
159
160
  }
160
161
 
162
+ fielddef = upb_DefPool_FindExtensionByName(self->symtab, name_str);
163
+ if (fielddef) {
164
+ return get_fielddef_obj(_self, fielddef);
165
+ }
166
+
161
167
  enumdef = upb_DefPool_FindEnumByName(self->symtab, name_str);
162
168
  if (enumdef) {
163
169
  return get_enumdef_obj(_self, enumdef);
@@ -192,6 +198,7 @@ static void DescriptorPool_register(VALUE module) {
192
198
 
193
199
  rb_gc_register_address(&generated_pool);
194
200
  generated_pool = rb_class_new_instance(0, NULL, klass);
201
+ options_instancevar_interned = rb_intern("options");
195
202
  }
196
203
 
197
204
  // -----------------------------------------------------------------------------
@@ -226,6 +233,35 @@ static Descriptor* ruby_to_Descriptor(VALUE val) {
226
233
  return ret;
227
234
  }
228
235
 
236
+ // Decode and return a frozen instance of a Descriptor Option for the given pool
237
+ static VALUE decode_options(VALUE self, const char* option_type, int size,
238
+ const char* bytes, VALUE descriptor_pool) {
239
+ VALUE options_rb = rb_ivar_get(self, options_instancevar_interned);
240
+ if (options_rb != Qnil) {
241
+ return options_rb;
242
+ }
243
+
244
+ static const char* prefix = "google.protobuf.";
245
+ char fullname
246
+ [/*strlen(prefix)*/ 16 +
247
+ /*strln(longest option type supported e.g. "MessageOptions")*/ 14 +
248
+ /*null terminator*/ 1];
249
+
250
+ snprintf(fullname, sizeof(fullname), "%s%s", prefix, option_type);
251
+ const upb_MessageDef* msgdef = upb_DefPool_FindMessageByName(
252
+ ruby_to_DescriptorPool(descriptor_pool)->symtab, fullname);
253
+ if (!msgdef) {
254
+ rb_raise(rb_eRuntimeError, "Cannot find %s in DescriptorPool", option_type);
255
+ }
256
+
257
+ VALUE desc_rb = get_msgdef_obj(descriptor_pool, msgdef);
258
+ const Descriptor* desc = ruby_to_Descriptor(desc_rb);
259
+
260
+ options_rb = Message_decode_bytes(size, bytes, 0, desc->klass, true);
261
+ rb_ivar_set(self, options_instancevar_interned, options_rb);
262
+ return options_rb;
263
+ }
264
+
229
265
  /*
230
266
  * call-seq:
231
267
  * Descriptor.new => descriptor
@@ -374,6 +410,26 @@ static VALUE Descriptor_msgclass(VALUE _self) {
374
410
  return self->klass;
375
411
  }
376
412
 
413
+ /*
414
+ * call-seq:
415
+ * Descriptor.options => options
416
+ *
417
+ * Returns the `MessageOptions` for this `Descriptor`.
418
+ */
419
+ static VALUE Descriptor_options(VALUE _self) {
420
+ Descriptor* self = ruby_to_Descriptor(_self);
421
+ const google_protobuf_MessageOptions* opts =
422
+ upb_MessageDef_Options(self->msgdef);
423
+ upb_Arena* arena = upb_Arena_New();
424
+ size_t size;
425
+ char* serialized =
426
+ google_protobuf_MessageOptions_serialize(opts, arena, &size);
427
+ VALUE message_options = decode_options(_self, "MessageOptions", size,
428
+ serialized, self->descriptor_pool);
429
+ upb_Arena_Free(arena);
430
+ return message_options;
431
+ }
432
+
377
433
  static void Descriptor_register(VALUE module) {
378
434
  VALUE klass = rb_define_class_under(module, "Descriptor", rb_cObject);
379
435
  rb_define_alloc_func(klass, Descriptor_alloc);
@@ -385,6 +441,7 @@ static void Descriptor_register(VALUE module) {
385
441
  rb_define_method(klass, "msgclass", Descriptor_msgclass, 0);
386
442
  rb_define_method(klass, "name", Descriptor_name, 0);
387
443
  rb_define_method(klass, "file_descriptor", Descriptor_file_descriptor, 0);
444
+ rb_define_method(klass, "options", Descriptor_options, 0);
388
445
  rb_include_module(klass, rb_mEnumerable);
389
446
  rb_gc_register_address(&cDescriptor);
390
447
  cDescriptor = klass;
@@ -484,12 +541,31 @@ static VALUE FileDescriptor_syntax(VALUE _self) {
484
541
  }
485
542
  }
486
543
 
544
+ /*
545
+ * call-seq:
546
+ * FileDescriptor.options => options
547
+ *
548
+ * Returns the `FileOptions` for this `FileDescriptor`.
549
+ */
550
+ static VALUE FileDescriptor_options(VALUE _self) {
551
+ FileDescriptor* self = ruby_to_FileDescriptor(_self);
552
+ const google_protobuf_FileOptions* opts = upb_FileDef_Options(self->filedef);
553
+ upb_Arena* arena = upb_Arena_New();
554
+ size_t size;
555
+ char* serialized = google_protobuf_FileOptions_serialize(opts, arena, &size);
556
+ VALUE file_options = decode_options(_self, "FileOptions", size, serialized,
557
+ self->descriptor_pool);
558
+ upb_Arena_Free(arena);
559
+ return file_options;
560
+ }
561
+
487
562
  static void FileDescriptor_register(VALUE module) {
488
563
  VALUE klass = rb_define_class_under(module, "FileDescriptor", rb_cObject);
489
564
  rb_define_alloc_func(klass, FileDescriptor_alloc);
490
565
  rb_define_method(klass, "initialize", FileDescriptor_initialize, 3);
491
566
  rb_define_method(klass, "name", FileDescriptor_name, 0);
492
567
  rb_define_method(klass, "syntax", FileDescriptor_syntax, 0);
568
+ rb_define_method(klass, "options", FileDescriptor_options, 0);
493
569
  rb_gc_register_address(&cFileDescriptor);
494
570
  cFileDescriptor = klass;
495
571
  }
@@ -540,7 +616,7 @@ static VALUE FieldDescriptor_alloc(VALUE klass) {
540
616
 
541
617
  /*
542
618
  * call-seq:
543
- * EnumDescriptor.new(c_only_cookie, pool, ptr) => EnumDescriptor
619
+ * FieldDescriptor.new(c_only_cookie, pool, ptr) => FieldDescriptor
544
620
  *
545
621
  * Creates a descriptor wrapper object. May only be called from C.
546
622
  */
@@ -841,6 +917,25 @@ static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) {
841
917
  return Qnil;
842
918
  }
843
919
 
920
+ /*
921
+ * call-seq:
922
+ * FieldDescriptor.options => options
923
+ *
924
+ * Returns the `FieldOptions` for this `FieldDescriptor`.
925
+ */
926
+ static VALUE FieldDescriptor_options(VALUE _self) {
927
+ FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
928
+ const google_protobuf_FieldOptions* opts =
929
+ upb_FieldDef_Options(self->fielddef);
930
+ upb_Arena* arena = upb_Arena_New();
931
+ size_t size;
932
+ char* serialized = google_protobuf_FieldOptions_serialize(opts, arena, &size);
933
+ VALUE field_options = decode_options(_self, "FieldOptions", size, serialized,
934
+ self->descriptor_pool);
935
+ upb_Arena_Free(arena);
936
+ return field_options;
937
+ }
938
+
844
939
  static void FieldDescriptor_register(VALUE module) {
845
940
  VALUE klass = rb_define_class_under(module, "FieldDescriptor", rb_cObject);
846
941
  rb_define_alloc_func(klass, FieldDescriptor_alloc);
@@ -857,6 +952,7 @@ static void FieldDescriptor_register(VALUE module) {
857
952
  rb_define_method(klass, "clear", FieldDescriptor_clear, 1);
858
953
  rb_define_method(klass, "get", FieldDescriptor_get, 1);
859
954
  rb_define_method(klass, "set", FieldDescriptor_set, 2);
955
+ rb_define_method(klass, "options", FieldDescriptor_options, 0);
860
956
  rb_gc_register_address(&cFieldDescriptor);
861
957
  cFieldDescriptor = klass;
862
958
  }
@@ -956,12 +1052,32 @@ static VALUE OneofDescriptor_each(VALUE _self) {
956
1052
  return Qnil;
957
1053
  }
958
1054
 
1055
+ /*
1056
+ * call-seq:
1057
+ * OneofDescriptor.options => options
1058
+ *
1059
+ * Returns the `OneofOptions` for this `OneofDescriptor`.
1060
+ */
1061
+ static VALUE OneOfDescriptor_options(VALUE _self) {
1062
+ OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
1063
+ const google_protobuf_OneofOptions* opts =
1064
+ upb_OneofDef_Options(self->oneofdef);
1065
+ upb_Arena* arena = upb_Arena_New();
1066
+ size_t size;
1067
+ char* serialized = google_protobuf_OneofOptions_serialize(opts, arena, &size);
1068
+ VALUE oneof_options = decode_options(_self, "OneofOptions", size, serialized,
1069
+ self->descriptor_pool);
1070
+ upb_Arena_Free(arena);
1071
+ return oneof_options;
1072
+ }
1073
+
959
1074
  static void OneofDescriptor_register(VALUE module) {
960
1075
  VALUE klass = rb_define_class_under(module, "OneofDescriptor", rb_cObject);
961
1076
  rb_define_alloc_func(klass, OneofDescriptor_alloc);
962
1077
  rb_define_method(klass, "initialize", OneofDescriptor_initialize, 3);
963
1078
  rb_define_method(klass, "name", OneofDescriptor_name, 0);
964
1079
  rb_define_method(klass, "each", OneofDescriptor_each, 0);
1080
+ rb_define_method(klass, "options", OneOfDescriptor_options, 0);
965
1081
  rb_include_module(klass, rb_mEnumerable);
966
1082
  rb_gc_register_address(&cOneofDescriptor);
967
1083
  cOneofDescriptor = klass;
@@ -1131,6 +1247,24 @@ static VALUE EnumDescriptor_enummodule(VALUE _self) {
1131
1247
  return self->module;
1132
1248
  }
1133
1249
 
1250
+ /*
1251
+ * call-seq:
1252
+ * EnumDescriptor.options => options
1253
+ *
1254
+ * Returns the `EnumOptions` for this `EnumDescriptor`.
1255
+ */
1256
+ static VALUE EnumDescriptor_options(VALUE _self) {
1257
+ EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
1258
+ const google_protobuf_EnumOptions* opts = upb_EnumDef_Options(self->enumdef);
1259
+ upb_Arena* arena = upb_Arena_New();
1260
+ size_t size;
1261
+ char* serialized = google_protobuf_EnumOptions_serialize(opts, arena, &size);
1262
+ VALUE enum_options = decode_options(_self, "EnumOptions", size, serialized,
1263
+ self->descriptor_pool);
1264
+ upb_Arena_Free(arena);
1265
+ return enum_options;
1266
+ }
1267
+
1134
1268
  static void EnumDescriptor_register(VALUE module) {
1135
1269
  VALUE klass = rb_define_class_under(module, "EnumDescriptor", rb_cObject);
1136
1270
  rb_define_alloc_func(klass, EnumDescriptor_alloc);
@@ -1141,6 +1275,7 @@ static void EnumDescriptor_register(VALUE module) {
1141
1275
  rb_define_method(klass, "each", EnumDescriptor_each, 0);
1142
1276
  rb_define_method(klass, "enummodule", EnumDescriptor_enummodule, 0);
1143
1277
  rb_define_method(klass, "file_descriptor", EnumDescriptor_file_descriptor, 0);
1278
+ rb_define_method(klass, "options", EnumDescriptor_options, 0);
1144
1279
  rb_include_module(klass, rb_mEnumerable);
1145
1280
  rb_gc_register_address(&cEnumDescriptor);
1146
1281
  cEnumDescriptor = klass;
@@ -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
+ }
@@ -572,6 +572,26 @@ static VALUE Map_freeze(VALUE _self) {
572
572
  return _self;
573
573
  }
574
574
 
575
+ /*
576
+ * Deep freezes the map and values recursively.
577
+ * Internal use only.
578
+ */
579
+ VALUE Map_internal_deep_freeze(VALUE _self) {
580
+ Map* self = ruby_to_Map(_self);
581
+ Map_freeze(_self);
582
+ if (self->value_type_info.type == kUpb_CType_Message) {
583
+ size_t iter = kUpb_Map_Begin;
584
+ upb_MessageValue key, val;
585
+
586
+ while (upb_Map_Next(self->map, &key, &val, &iter)) {
587
+ VALUE val_val =
588
+ Convert_UpbToRuby(val, self->value_type_info, self->arena);
589
+ Message_internal_deep_freeze(val_val);
590
+ }
591
+ }
592
+ return _self;
593
+ }
594
+
575
595
  /*
576
596
  * call-seq:
577
597
  * Map.hash => hash_value
@@ -38,4 +38,7 @@ extern VALUE cMap;
38
38
  // Call at startup to register all types in this module.
39
39
  void Map_register(VALUE module);
40
40
 
41
+ // Recursively freeze map
42
+ VALUE Map_internal_deep_freeze(VALUE _self);
43
+
41
44
  #endif // RUBY_PROTOBUF_MAP_H_
@@ -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 interpretration given by this message class's definition
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
- upb_DecodeStatus status =
949
- upb_Decode(RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg,
950
- upb_MessageDef_MiniTable(msg->msgdef), NULL, options,
951
- Arena_get(msg->arena));
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, NULL, 0, arena) !=
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
 
@@ -487,6 +487,25 @@ static VALUE RepeatedField_freeze(VALUE _self) {
487
487
  return _self;
488
488
  }
489
489
 
490
+ /*
491
+ * Deep freezes the repeated field and values recursively.
492
+ * Internal use only.
493
+ */
494
+ VALUE RepeatedField_internal_deep_freeze(VALUE _self) {
495
+ RepeatedField* self = ruby_to_RepeatedField(_self);
496
+ RepeatedField_freeze(_self);
497
+ if (self->type_info.type == kUpb_CType_Message) {
498
+ int size = upb_Array_Size(self->array);
499
+ int i;
500
+ for (i = 0; i < size; i++) {
501
+ upb_MessageValue msgval = upb_Array_Get(self->array, i);
502
+ VALUE val = Convert_UpbToRuby(msgval, self->type_info, self->arena);
503
+ Message_internal_deep_freeze(val);
504
+ }
505
+ }
506
+ return _self;
507
+ }
508
+
490
509
  /*
491
510
  * call-seq:
492
511
  * RepeatedField.hash => hash_value
@@ -35,4 +35,7 @@ extern VALUE cRepeatedField;
35
35
  // Call at startup to register all types in this module.
36
36
  void RepeatedField_register(VALUE module);
37
37
 
38
+ // Recursively freeze RepeatedField.
39
+ VALUE RepeatedField_internal_deep_freeze(VALUE _self);
40
+
38
41
  #endif // RUBY_PROTOBUF_REPEATED_FIELD_H_
Binary file
Binary file
Binary file
Binary file
@@ -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, [: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 :lookup_enum, :upb_DefPool_FindEnumByName, [:DefPool, :string], EnumDescriptor
16
- attach_function :lookup_msg, :upb_DefPool_FindMessageByName, [:DefPool, :string], Descriptor
17
- # FileDescriptorProto
18
- attach_function :parse, :FileDescriptorProto_parse, [:binary_string, :size_t], :FileDescriptorProto
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
- file_descriptor_proto = Google::Protobuf::FFI.parse memBuf, file_contents.bytesize
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 [Arena] Arena to convert to an FFI native type
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 :get_containing_message_def, :upb_FieldDef_ContainingType, [FieldDescriptor], Descriptor
293
- attach_function :get_c_type, :upb_FieldDef_CType, [FieldDescriptor], CType
294
- attach_function :get_default, :upb_FieldDef_Default, [FieldDescriptor], MessageValue.by_value
295
- attach_function :get_subtype_as_enum, :upb_FieldDef_EnumSubDef, [FieldDescriptor], EnumDescriptor
296
- attach_function :get_has_presence, :upb_FieldDef_HasPresence, [FieldDescriptor], :bool
297
- attach_function :is_map, :upb_FieldDef_IsMap, [FieldDescriptor], :bool
298
- attach_function :is_repeated, :upb_FieldDef_IsRepeated, [FieldDescriptor], :bool
299
- attach_function :is_sub_message, :upb_FieldDef_IsSubMessage, [FieldDescriptor], :bool
300
- attach_function :get_json_name, :upb_FieldDef_JsonName, [FieldDescriptor], :string
301
- attach_function :get_label, :upb_FieldDef_Label, [FieldDescriptor], Label
302
- attach_function :get_subtype_as_message, :upb_FieldDef_MessageSubDef, [FieldDescriptor], Descriptor
303
- attach_function :get_full_name, :upb_FieldDef_Name, [FieldDescriptor], :string
304
- attach_function :get_number, :upb_FieldDef_Number, [FieldDescriptor], :uint32_t
305
- attach_function :get_type, :upb_FieldDef_Type, [FieldDescriptor], FieldType
306
- attach_function :file_def_by_raw_field_def, :upb_FieldDef_File, [:pointer], :FileDef
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, [:binary_string, :size_t, :Message, MiniTable.by_ref, :ExtensionRegistry, :int, Internal::Arena], DecodeStatus
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(data, data.bytesize, message.instance_variable_get(:@msg), mini_table_ptr, nil, decoding_options, message.instance_variable_get(:@arena))
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
- 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
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, :upb_MessageDef_FindOneofByNameWithSize, [Descriptor, :string, :size_t], OneofDescriptor
76
- attach_function :get_oneof_by_index, :upb_MessageDef_Oneof, [Descriptor, :int], OneofDescriptor
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, [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
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, :upb_FieldDef_RealContainingOneof,[FieldDescriptor], OneofDescriptor
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 jruby and C. The source code has plenty of examples
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
- 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
250
+ private
251
+ include Google::Protobuf::Internal::Convert
353
252
 
253
+ attr :name, :arena, :array, :type, :descriptor
354
254
 
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
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'
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.0
4
+ version: 3.25.1
5
5
  platform: x86_64-darwin
6
6
  authors:
7
7
  - Protobuf Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-01 00:00:00.000000000 Z
11
+ date: 2023-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler-dock
@@ -177,7 +177,7 @@ homepage: https://developers.google.com/protocol-buffers
177
177
  licenses:
178
178
  - BSD-3-Clause
179
179
  metadata:
180
- source_code_uri: https://github.com/protocolbuffers/protobuf/tree/v3.25.0/ruby
180
+ source_code_uri: https://github.com/protocolbuffers/protobuf/tree/v3.25.1/ruby
181
181
  post_install_message:
182
182
  rdoc_options: []
183
183
  require_paths: