google-protobuf 3.24.1 → 3.25.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/ext/google/protobuf_c/Rakefile +3 -0
  3. data/ext/google/protobuf_c/convert.c +23 -70
  4. data/ext/google/protobuf_c/convert.h +3 -26
  5. data/ext/google/protobuf_c/defs.c +142 -30
  6. data/ext/google/protobuf_c/defs.h +3 -26
  7. data/ext/google/protobuf_c/extconf.rb +2 -1
  8. data/ext/google/protobuf_c/glue.c +56 -0
  9. data/ext/google/protobuf_c/map.c +23 -26
  10. data/ext/google/protobuf_c/map.h +6 -26
  11. data/ext/google/protobuf_c/message.c +67 -77
  12. data/ext/google/protobuf_c/message.h +10 -26
  13. data/ext/google/protobuf_c/protobuf.c +3 -26
  14. data/ext/google/protobuf_c/protobuf.h +3 -26
  15. data/ext/google/protobuf_c/repeated_field.c +23 -27
  16. data/ext/google/protobuf_c/repeated_field.h +6 -26
  17. data/ext/google/protobuf_c/ruby-upb.c +8351 -8160
  18. data/ext/google/protobuf_c/ruby-upb.h +4077 -3784
  19. data/ext/google/protobuf_c/shared_convert.c +64 -0
  20. data/ext/google/protobuf_c/shared_convert.h +26 -0
  21. data/ext/google/protobuf_c/shared_message.c +65 -0
  22. data/ext/google/protobuf_c/shared_message.h +25 -0
  23. data/ext/google/protobuf_c/wrap_memcpy.c +3 -26
  24. data/lib/google/protobuf/any_pb.rb +1 -1
  25. data/lib/google/protobuf/api_pb.rb +1 -1
  26. data/lib/google/protobuf/descriptor_pb.rb +6 -3
  27. data/lib/google/protobuf/duration_pb.rb +1 -1
  28. data/lib/google/protobuf/empty_pb.rb +1 -1
  29. data/lib/google/protobuf/ffi/descriptor.rb +165 -0
  30. data/lib/google/protobuf/ffi/descriptor_pool.rb +75 -0
  31. data/lib/google/protobuf/ffi/enum_descriptor.rb +171 -0
  32. data/lib/google/protobuf/ffi/ffi.rb +213 -0
  33. data/lib/google/protobuf/ffi/field_descriptor.rb +319 -0
  34. data/lib/google/protobuf/ffi/file_descriptor.rb +59 -0
  35. data/lib/google/protobuf/ffi/internal/arena.rb +66 -0
  36. data/lib/google/protobuf/ffi/internal/convert.rb +305 -0
  37. data/lib/google/protobuf/ffi/internal/pointer_helper.rb +35 -0
  38. data/lib/google/protobuf/ffi/internal/type_safety.rb +25 -0
  39. data/lib/google/protobuf/ffi/map.rb +407 -0
  40. data/lib/google/protobuf/ffi/message.rb +662 -0
  41. data/lib/google/protobuf/ffi/object_cache.rb +30 -0
  42. data/lib/google/protobuf/ffi/oneof_descriptor.rb +95 -0
  43. data/lib/google/protobuf/ffi/repeated_field.rb +383 -0
  44. data/lib/google/protobuf/field_mask_pb.rb +1 -1
  45. data/lib/google/protobuf/message_exts.rb +3 -26
  46. data/lib/google/protobuf/object_cache.rb +3 -26
  47. data/lib/google/protobuf/plugin_pb.rb +1 -1
  48. data/lib/google/protobuf/repeated_field.rb +3 -26
  49. data/lib/google/protobuf/source_context_pb.rb +1 -1
  50. data/lib/google/protobuf/struct_pb.rb +1 -1
  51. data/lib/google/protobuf/timestamp_pb.rb +1 -1
  52. data/lib/google/protobuf/type_pb.rb +1 -1
  53. data/lib/google/protobuf/well_known_types.rb +3 -26
  54. data/lib/google/protobuf/wrappers_pb.rb +1 -1
  55. data/lib/google/protobuf.rb +26 -45
  56. data/lib/google/protobuf_ffi.rb +50 -0
  57. data/lib/google/protobuf_native.rb +20 -0
  58. data/lib/google/tasks/ffi.rake +102 -0
  59. metadata +70 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab19f3d9a087b8f4b288ba5a610f1d85d5fc71f1939b34891bea8e8be9736069
4
- data.tar.gz: 26e9e6b1108d10b1a1098af1820bfd6b4e7a6c892ae9bb946897d78ca765f624
3
+ metadata.gz: 7cabebe8487759e6e7876a1a4c69fd7751bb22aad693fbe82e91e14c984bbf8e
4
+ data.tar.gz: 9e57bf2ee2ebef1063605d28ecb713c0851f94d0d66222d0fc24841b9b868089
5
5
  SHA512:
6
- metadata.gz: ff7e8795da8bc005ccf210891a7ef2e325a5e372ca1e6f66c00611ae2743680c7f276e2352502bdf20c23a74a0e8f6910f35b03165baf43860da797044594826
7
- data.tar.gz: 8c0d6011a2b6f407e06fec6779f0dbdc5f6400a4afa04edc9cc63023785ab51eac053159c7c5c0297726e6ff83a1a71c0fdf17c3b2b7ef644c5623f72f560778
6
+ metadata.gz: 8a76ee7003807d5b6e37da0bf6129a761f08ac00b26e9df59e33f8f6325a642dd501655accc7d2943ec233518e9d6d10fe6c21efbe6b91b860f101fff8fca9ee
7
+ data.tar.gz: 41dd9a63af13bc7e88c765254fd15bc62f588cc3ab14b0696632fe93d2de00b3e1c9e7bfe01b48b13dc0943176bf86e2cfdba011046c94d11eefabd320e2391b
@@ -0,0 +1,3 @@
1
+ import '../../../lib/google/tasks/ffi.rake'
2
+
3
+ task default: ['ffi-protobuf:default']
@@ -1,32 +1,9 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2008 Google Inc. All rights reserved.
3
- // https://developers.google.com/protocol-buffers/
4
3
  //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  // -----------------------------------------------------------------------------
32
9
  // Ruby <-> upb data conversion functions.
@@ -41,6 +18,7 @@
41
18
 
42
19
  #include "message.h"
43
20
  #include "protobuf.h"
21
+ #include "shared_convert.h"
44
22
 
45
23
  static upb_StringView Convert_StringData(VALUE str, upb_Arena* arena) {
46
24
  upb_StringView ret;
@@ -111,8 +89,7 @@ static int32_t Convert_ToEnum(VALUE value, const char* name,
111
89
  case T_SYMBOL: {
112
90
  const upb_EnumValueDef* ev =
113
91
  upb_EnumDef_FindValueByName(e, rb_id2name(SYM2ID(value)));
114
- if (!ev)
115
- goto unknownval;
92
+ if (!ev) goto unknownval;
116
93
  val = upb_EnumValueDef_Number(ev);
117
94
  break;
118
95
  }
@@ -194,7 +171,7 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
194
171
  if (rb_obj_encoding(value) != bytes) {
195
172
  // Note: this will not duplicate underlying string data unless
196
173
  // necessary.
197
- // TODO(haberman): is this really necessary to get raw bytes?
174
+ // TODO: is this really necessary to get raw bytes?
198
175
  value = rb_str_encode(value, bytes, 0, Qnil);
199
176
  }
200
177
 
@@ -255,7 +232,7 @@ VALUE Convert_UpbToRuby(upb_MessageValue upb_val, TypeInfo type_info,
255
232
  case kUpb_CType_UInt64:
256
233
  return ULL2NUM(upb_val.int64_val);
257
234
  case kUpb_CType_Enum: {
258
- const upb_EnumValueDef *ev = upb_EnumDef_FindValueByNumber(
235
+ const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNumber(
259
236
  type_info.def.enumdef, upb_val.int32_val);
260
237
  if (ev) {
261
238
  return ID2SYM(rb_intern(upb_EnumValueDef_Name(ev)));
@@ -312,50 +289,26 @@ upb_MessageValue Msgval_DeepCopy(upb_MessageValue msgval, TypeInfo type_info,
312
289
 
313
290
  bool Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2,
314
291
  TypeInfo type_info) {
315
- switch (type_info.type) {
316
- case kUpb_CType_Bool:
317
- return memcmp(&val1, &val2, 1) == 0;
318
- case kUpb_CType_Float:
319
- case kUpb_CType_Int32:
320
- case kUpb_CType_UInt32:
321
- case kUpb_CType_Enum:
322
- return memcmp(&val1, &val2, 4) == 0;
323
- case kUpb_CType_Double:
324
- case kUpb_CType_Int64:
325
- case kUpb_CType_UInt64:
326
- return memcmp(&val1, &val2, 8) == 0;
327
- case kUpb_CType_String:
328
- case kUpb_CType_Bytes:
329
- return val1.str_val.size == val2.str_val.size &&
330
- memcmp(val1.str_val.data, val2.str_val.data, val1.str_val.size) ==
331
- 0;
332
- case kUpb_CType_Message:
333
- return Message_Equal(val1.msg_val, val2.msg_val, type_info.def.msgdef);
334
- default:
335
- rb_raise(rb_eRuntimeError, "Internal error, unexpected type");
292
+ upb_Status status;
293
+ upb_Status_Clear(&status);
294
+ bool return_value = shared_Msgval_IsEqual(val1, val2, type_info.type,
295
+ type_info.def.msgdef, &status);
296
+ if (upb_Status_IsOk(&status)) {
297
+ return return_value;
298
+ } else {
299
+ rb_raise(rb_eRuntimeError, upb_Status_ErrorMessage(&status));
336
300
  }
337
301
  }
338
302
 
339
303
  uint64_t Msgval_GetHash(upb_MessageValue val, TypeInfo type_info,
340
304
  uint64_t seed) {
341
- switch (type_info.type) {
342
- case kUpb_CType_Bool:
343
- return _upb_Hash(&val, 1, seed);
344
- case kUpb_CType_Float:
345
- case kUpb_CType_Int32:
346
- case kUpb_CType_UInt32:
347
- case kUpb_CType_Enum:
348
- return _upb_Hash(&val, 4, seed);
349
- case kUpb_CType_Double:
350
- case kUpb_CType_Int64:
351
- case kUpb_CType_UInt64:
352
- return _upb_Hash(&val, 8, seed);
353
- case kUpb_CType_String:
354
- case kUpb_CType_Bytes:
355
- return _upb_Hash(val.str_val.data, val.str_val.size, seed);
356
- case kUpb_CType_Message:
357
- return Message_Hash(val.msg_val, type_info.def.msgdef, seed);
358
- default:
359
- rb_raise(rb_eRuntimeError, "Internal error, unexpected type");
305
+ upb_Status status;
306
+ upb_Status_Clear(&status);
307
+ uint64_t return_value = shared_Msgval_GetHash(
308
+ val, type_info.type, type_info.def.msgdef, seed, &status);
309
+ if (upb_Status_IsOk(&status)) {
310
+ return return_value;
311
+ } else {
312
+ rb_raise(rb_eRuntimeError, upb_Status_ErrorMessage(&status));
360
313
  }
361
314
  }
@@ -1,32 +1,9 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2008 Google Inc. All rights reserved.
3
- // https://developers.google.com/protocol-buffers/
4
3
  //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  #ifndef RUBY_PROTOBUF_CONVERT_H_
32
9
  #define RUBY_PROTOBUF_CONVERT_H_
@@ -1,32 +1,9 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2014 Google Inc. All rights reserved.
3
- // https://developers.google.com/protocol-buffers/
4
3
  //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  #include <ctype.h>
32
9
  #include <errno.h>
@@ -67,7 +44,7 @@ static VALUE rb_str_maybe_null(const char* s) {
67
44
  }
68
45
  return rb_str_new2(s);
69
46
  }
70
-
47
+ static ID options_instancevar_interned;
71
48
  // -----------------------------------------------------------------------------
72
49
  // DescriptorPool.
73
50
  // -----------------------------------------------------------------------------
@@ -167,20 +144,26 @@ VALUE DescriptorPool_add_serialized_file(VALUE _self,
167
144
  * call-seq:
168
145
  * DescriptorPool.lookup(name) => descriptor
169
146
  *
170
- * Finds a Descriptor or EnumDescriptor by name and returns it, or nil if none
171
- * 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.
172
149
  */
173
150
  static VALUE DescriptorPool_lookup(VALUE _self, VALUE name) {
174
151
  DescriptorPool* self = ruby_to_DescriptorPool(_self);
175
152
  const char* name_str = get_str(name);
176
153
  const upb_MessageDef* msgdef;
177
154
  const upb_EnumDef* enumdef;
155
+ const upb_FieldDef* fielddef;
178
156
 
179
157
  msgdef = upb_DefPool_FindMessageByName(self->symtab, name_str);
180
158
  if (msgdef) {
181
159
  return get_msgdef_obj(_self, msgdef);
182
160
  }
183
161
 
162
+ fielddef = upb_DefPool_FindExtensionByName(self->symtab, name_str);
163
+ if (fielddef) {
164
+ return get_fielddef_obj(_self, fielddef);
165
+ }
166
+
184
167
  enumdef = upb_DefPool_FindEnumByName(self->symtab, name_str);
185
168
  if (enumdef) {
186
169
  return get_enumdef_obj(_self, enumdef);
@@ -215,6 +198,7 @@ static void DescriptorPool_register(VALUE module) {
215
198
 
216
199
  rb_gc_register_address(&generated_pool);
217
200
  generated_pool = rb_class_new_instance(0, NULL, klass);
201
+ options_instancevar_interned = rb_intern("options");
218
202
  }
219
203
 
220
204
  // -----------------------------------------------------------------------------
@@ -249,6 +233,35 @@ static Descriptor* ruby_to_Descriptor(VALUE val) {
249
233
  return ret;
250
234
  }
251
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
+
252
265
  /*
253
266
  * call-seq:
254
267
  * Descriptor.new => descriptor
@@ -397,6 +410,26 @@ static VALUE Descriptor_msgclass(VALUE _self) {
397
410
  return self->klass;
398
411
  }
399
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
+
400
433
  static void Descriptor_register(VALUE module) {
401
434
  VALUE klass = rb_define_class_under(module, "Descriptor", rb_cObject);
402
435
  rb_define_alloc_func(klass, Descriptor_alloc);
@@ -408,6 +441,7 @@ static void Descriptor_register(VALUE module) {
408
441
  rb_define_method(klass, "msgclass", Descriptor_msgclass, 0);
409
442
  rb_define_method(klass, "name", Descriptor_name, 0);
410
443
  rb_define_method(klass, "file_descriptor", Descriptor_file_descriptor, 0);
444
+ rb_define_method(klass, "options", Descriptor_options, 0);
411
445
  rb_include_module(klass, rb_mEnumerable);
412
446
  rb_gc_register_address(&cDescriptor);
413
447
  cDescriptor = klass;
@@ -507,12 +541,31 @@ static VALUE FileDescriptor_syntax(VALUE _self) {
507
541
  }
508
542
  }
509
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
+
510
562
  static void FileDescriptor_register(VALUE module) {
511
563
  VALUE klass = rb_define_class_under(module, "FileDescriptor", rb_cObject);
512
564
  rb_define_alloc_func(klass, FileDescriptor_alloc);
513
565
  rb_define_method(klass, "initialize", FileDescriptor_initialize, 3);
514
566
  rb_define_method(klass, "name", FileDescriptor_name, 0);
515
567
  rb_define_method(klass, "syntax", FileDescriptor_syntax, 0);
568
+ rb_define_method(klass, "options", FileDescriptor_options, 0);
516
569
  rb_gc_register_address(&cFileDescriptor);
517
570
  cFileDescriptor = klass;
518
571
  }
@@ -563,7 +616,7 @@ static VALUE FieldDescriptor_alloc(VALUE klass) {
563
616
 
564
617
  /*
565
618
  * call-seq:
566
- * EnumDescriptor.new(c_only_cookie, pool, ptr) => EnumDescriptor
619
+ * FieldDescriptor.new(c_only_cookie, pool, ptr) => FieldDescriptor
567
620
  *
568
621
  * Creates a descriptor wrapper object. May only be called from C.
569
622
  */
@@ -864,6 +917,25 @@ static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) {
864
917
  return Qnil;
865
918
  }
866
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
+
867
939
  static void FieldDescriptor_register(VALUE module) {
868
940
  VALUE klass = rb_define_class_under(module, "FieldDescriptor", rb_cObject);
869
941
  rb_define_alloc_func(klass, FieldDescriptor_alloc);
@@ -880,6 +952,7 @@ static void FieldDescriptor_register(VALUE module) {
880
952
  rb_define_method(klass, "clear", FieldDescriptor_clear, 1);
881
953
  rb_define_method(klass, "get", FieldDescriptor_get, 1);
882
954
  rb_define_method(klass, "set", FieldDescriptor_set, 2);
955
+ rb_define_method(klass, "options", FieldDescriptor_options, 0);
883
956
  rb_gc_register_address(&cFieldDescriptor);
884
957
  cFieldDescriptor = klass;
885
958
  }
@@ -979,12 +1052,32 @@ static VALUE OneofDescriptor_each(VALUE _self) {
979
1052
  return Qnil;
980
1053
  }
981
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
+
982
1074
  static void OneofDescriptor_register(VALUE module) {
983
1075
  VALUE klass = rb_define_class_under(module, "OneofDescriptor", rb_cObject);
984
1076
  rb_define_alloc_func(klass, OneofDescriptor_alloc);
985
1077
  rb_define_method(klass, "initialize", OneofDescriptor_initialize, 3);
986
1078
  rb_define_method(klass, "name", OneofDescriptor_name, 0);
987
1079
  rb_define_method(klass, "each", OneofDescriptor_each, 0);
1080
+ rb_define_method(klass, "options", OneOfDescriptor_options, 0);
988
1081
  rb_include_module(klass, rb_mEnumerable);
989
1082
  rb_gc_register_address(&cOneofDescriptor);
990
1083
  cOneofDescriptor = klass;
@@ -1154,6 +1247,24 @@ static VALUE EnumDescriptor_enummodule(VALUE _self) {
1154
1247
  return self->module;
1155
1248
  }
1156
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
+
1157
1268
  static void EnumDescriptor_register(VALUE module) {
1158
1269
  VALUE klass = rb_define_class_under(module, "EnumDescriptor", rb_cObject);
1159
1270
  rb_define_alloc_func(klass, EnumDescriptor_alloc);
@@ -1164,6 +1275,7 @@ static void EnumDescriptor_register(VALUE module) {
1164
1275
  rb_define_method(klass, "each", EnumDescriptor_each, 0);
1165
1276
  rb_define_method(klass, "enummodule", EnumDescriptor_enummodule, 0);
1166
1277
  rb_define_method(klass, "file_descriptor", EnumDescriptor_file_descriptor, 0);
1278
+ rb_define_method(klass, "options", EnumDescriptor_options, 0);
1167
1279
  rb_include_module(klass, rb_mEnumerable);
1168
1280
  rb_gc_register_address(&cEnumDescriptor);
1169
1281
  cEnumDescriptor = klass;
@@ -1,32 +1,9 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2008 Google Inc. All rights reserved.
3
- // https://developers.google.com/protocol-buffers/
4
3
  //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  #ifndef RUBY_PROTOBUF_DEFS_H_
32
9
  #define RUBY_PROTOBUF_DEFS_H_
@@ -22,6 +22,7 @@ $INCFLAGS += " -I$(srcdir)/third_party/utf8_range"
22
22
 
23
23
  $srcs = ["protobuf.c", "convert.c", "defs.c", "message.c",
24
24
  "repeated_field.c", "map.c", "ruby-upb.c", "wrap_memcpy.c",
25
- "naive.c", "range2-neon.c", "range2-sse.c"]
25
+ "naive.c", "range2-neon.c", "range2-sse.c", "shared_convert.c",
26
+ "shared_message.c"]
26
27
 
27
28
  create_makefile(ext_name)
@@ -0,0 +1,56 @@
1
+ // Protocol Buffers - Google's data interchange format
2
+ // Copyright 2023 Google Inc. All rights reserved.
3
+ //
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
7
+
8
+ // -----------------------------------------------------------------------------
9
+ // Exposing inlined UPB functions. Strictly free of dependencies on
10
+ // Ruby interpreter internals.
11
+
12
+ #include "ruby-upb.h"
13
+
14
+ upb_Arena* Arena_create() { return upb_Arena_Init(NULL, 0, &upb_alloc_global); }
15
+
16
+ google_protobuf_FileDescriptorProto* FileDescriptorProto_parse(
17
+ const char* serialized_file_proto, size_t length, upb_Arena* arena) {
18
+ return google_protobuf_FileDescriptorProto_parse(serialized_file_proto,
19
+ length, arena);
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
+ }
@@ -1,32 +1,9 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2014 Google Inc. All rights reserved.
3
- // https://developers.google.com/protocol-buffers/
4
3
  //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  #include "convert.h"
32
9
  #include "defs.h"
@@ -595,6 +572,26 @@ static VALUE Map_freeze(VALUE _self) {
595
572
  return _self;
596
573
  }
597
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
+
598
595
  /*
599
596
  * call-seq:
600
597
  * Map.hash => hash_value