google-protobuf 4.27.2 → 4.35.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/ext/google/protobuf_c/convert.c +32 -14
  3. data/ext/google/protobuf_c/defs.c +475 -133
  4. data/ext/google/protobuf_c/extconf.rb +20 -10
  5. data/ext/google/protobuf_c/glue.c +63 -0
  6. data/ext/google/protobuf_c/map.c +145 -56
  7. data/ext/google/protobuf_c/map.h +6 -2
  8. data/ext/google/protobuf_c/message.c +180 -97
  9. data/ext/google/protobuf_c/message.h +2 -2
  10. data/ext/google/protobuf_c/protobuf.c +14 -13
  11. data/ext/google/protobuf_c/protobuf.h +3 -15
  12. data/ext/google/protobuf_c/repeated_field.c +134 -53
  13. data/ext/google/protobuf_c/repeated_field.h +5 -1
  14. data/ext/google/protobuf_c/ruby-upb.c +14522 -12698
  15. data/ext/google/protobuf_c/ruby-upb.h +8273 -4619
  16. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +22 -282
  17. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +2 -1
  18. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_neon.inc +117 -0
  19. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_sse.inc +272 -0
  20. data/lib/google/protobuf/any_pb.rb +1 -1
  21. data/lib/google/protobuf/api_pb.rb +2 -2
  22. data/lib/google/protobuf/descriptor_pb.rb +6 -2
  23. data/lib/google/protobuf/duration_pb.rb +1 -1
  24. data/lib/google/protobuf/empty_pb.rb +1 -1
  25. data/lib/google/protobuf/ffi/descriptor.rb +11 -2
  26. data/lib/google/protobuf/ffi/descriptor_pool.rb +7 -1
  27. data/lib/google/protobuf/ffi/enum_descriptor.rb +10 -0
  28. data/lib/google/protobuf/ffi/ffi.rb +5 -2
  29. data/lib/google/protobuf/ffi/field_descriptor.rb +16 -0
  30. data/lib/google/protobuf/ffi/file_descriptor.rb +36 -0
  31. data/lib/google/protobuf/ffi/internal/arena.rb +0 -6
  32. data/lib/google/protobuf/ffi/internal/convert.rb +9 -6
  33. data/lib/google/protobuf/ffi/internal/pointer_helper.rb +2 -1
  34. data/lib/google/protobuf/ffi/map.rb +47 -23
  35. data/lib/google/protobuf/ffi/message.rb +188 -64
  36. data/lib/google/protobuf/ffi/method_descriptor.rb +11 -1
  37. data/lib/google/protobuf/ffi/oneof_descriptor.rb +10 -0
  38. data/lib/google/protobuf/ffi/repeated_field.rb +42 -16
  39. data/lib/google/protobuf/ffi/service_descriptor.rb +11 -1
  40. data/lib/google/protobuf/field_mask_pb.rb +1 -1
  41. data/lib/google/protobuf/message_exts.rb +4 -0
  42. data/lib/google/protobuf/plugin_pb.rb +1 -1
  43. data/lib/google/protobuf/source_context_pb.rb +1 -1
  44. data/lib/google/protobuf/struct_pb.rb +1 -1
  45. data/lib/google/protobuf/timestamp_pb.rb +1 -1
  46. data/lib/google/protobuf/type_pb.rb +1 -1
  47. data/lib/google/protobuf/wrappers_pb.rb +1 -1
  48. data/lib/google/protobuf_ffi.rb +3 -2
  49. data/lib/google/tasks/ffi.rake +1 -1
  50. metadata +29 -34
  51. data/ext/google/protobuf_c/wrap_memcpy.c +0 -29
@@ -7,7 +7,6 @@
7
7
 
8
8
  #include <ctype.h>
9
9
  #include <errno.h>
10
- #include <ruby/version.h>
11
10
 
12
11
  #include "convert.h"
13
12
  #include "message.h"
@@ -94,9 +93,15 @@ const upb_DefPool* DescriptorPool_GetSymtab(VALUE desc_pool_rb) {
94
93
  return pool->symtab;
95
94
  }
96
95
 
96
+ /**
97
+ * ruby-doc: DescriptorPool
98
+ *
99
+ * A DescriptorPool is the registry of all known Protobuf descriptor objects.
100
+ *
101
+ */
102
+
97
103
  /*
98
- * call-seq:
99
- * DescriptorPool.new => pool
104
+ * ruby-doc: DescriptorPool.new
100
105
  *
101
106
  * Creates a new, empty, descriptor pool.
102
107
  */
@@ -109,14 +114,22 @@ static VALUE DescriptorPool_alloc(VALUE klass) {
109
114
 
110
115
  RB_OBJ_WRITE(ret, &self->def_to_descriptor, rb_hash_new());
111
116
  self->symtab = upb_DefPool_New();
117
+
118
+ // Ruby treats all enums as open.
119
+ upb_DefPool_DisableClosedEnumChecking(self->symtab);
120
+
112
121
  return ObjectCache_TryAdd(self->symtab, ret);
113
122
  }
114
123
 
115
124
  /*
116
- * call-seq:
117
- * DescriptorPool.add_serialized_file(serialized_file_proto)
125
+ * ruby-doc: DescriptorPool#add_serialized_file
126
+ *
127
+ * Adds the given serialized
128
+ * {https://protobuf.com/docs/descriptors#file-descriptors FileDescriptorProto}
129
+ * to the pool.
118
130
  *
119
- * Adds the given serialized FileDescriptorProto to the pool.
131
+ * @param serialized_file_proto [String]
132
+ * @return [FileDescriptor]
120
133
  */
121
134
  VALUE DescriptorPool_add_serialized_file(VALUE _self,
122
135
  VALUE serialized_file_proto) {
@@ -144,11 +157,14 @@ VALUE DescriptorPool_add_serialized_file(VALUE _self,
144
157
  }
145
158
 
146
159
  /*
147
- * call-seq:
148
- * DescriptorPool.lookup(name) => descriptor
160
+ * ruby-doc: DescriptorPool#lookup
161
+ *
162
+ * Finds a {Descriptor}, {EnumDescriptor},
163
+ * {FieldDescriptor} or {ServiceDescriptor} by
164
+ * name and returns it, or nil if none exists with the given name.
149
165
  *
150
- * Finds a Descriptor, EnumDescriptor or FieldDescriptor by name and returns it,
151
- * or nil if none exists with the given name.
166
+ * @param name [String]
167
+ * @return [Descriptor,EnumDescriptor,FieldDescriptor,ServiceDescriptor]
152
168
  */
153
169
  static VALUE DescriptorPool_lookup(VALUE _self, VALUE name) {
154
170
  DescriptorPool* self = ruby_to_DescriptorPool(_self);
@@ -157,6 +173,7 @@ static VALUE DescriptorPool_lookup(VALUE _self, VALUE name) {
157
173
  const upb_EnumDef* enumdef;
158
174
  const upb_FieldDef* fielddef;
159
175
  const upb_ServiceDef* servicedef;
176
+ const upb_FileDef* filedef;
160
177
 
161
178
  msgdef = upb_DefPool_FindMessageByName(self->symtab, name_str);
162
179
  if (msgdef) {
@@ -178,17 +195,23 @@ static VALUE DescriptorPool_lookup(VALUE _self, VALUE name) {
178
195
  return get_servicedef_obj(_self, servicedef);
179
196
  }
180
197
 
198
+ filedef = upb_DefPool_FindFileByName(self->symtab, name_str);
199
+ if (filedef) {
200
+ return get_filedef_obj(_self, filedef);
201
+ }
202
+
181
203
  return Qnil;
182
204
  }
183
205
 
184
206
  /*
185
- * call-seq:
186
- * DescriptorPool.generated_pool => descriptor_pool
207
+ * ruby-doc: DescriptorPool.generated_pool
208
+ *
209
+ * Class method that returns the global {DescriptorPool}. This is a singleton
210
+ * into which generated-code message and enum types are registered. The user may
211
+ * also register types in this pool for convenience so that they do not have to
212
+ * hold a reference to a private pool instance.
187
213
  *
188
- * Class method that returns the global DescriptorPool. This is a singleton into
189
- * which generated-code message and enum types are registered. The user may also
190
- * register types in this pool for convenience so that they do not have to hold
191
- * a reference to a private pool instance.
214
+ * @return [DescriptorPool]
192
215
  */
193
216
  static VALUE DescriptorPool_generated_pool(VALUE _self) {
194
217
  return generated_pool;
@@ -285,8 +308,13 @@ static VALUE decode_options(VALUE self, const char* option_type, int size,
285
308
  }
286
309
 
287
310
  /*
288
- * call-seq:
289
- * Descriptor.new => descriptor
311
+ * ruby-doc: Descriptor
312
+ *
313
+ * A Descriptor provides information about a given Protobuf definition.
314
+ */
315
+
316
+ /*
317
+ * ruby-doc: Descriptor.initialize
290
318
  *
291
319
  * Creates a new, empty, message type descriptor. At a minimum, its name must be
292
320
  * set before it is added to a pool. It cannot be used to create messages until
@@ -324,10 +352,11 @@ static VALUE Descriptor_initialize(VALUE _self, VALUE cookie,
324
352
  }
325
353
 
326
354
  /*
327
- * call-seq:
328
- * Descriptor.file_descriptor
355
+ * ruby-doc: Descriptor#file_descriptor
356
+ *
357
+ * Returns the {FileDescriptor} object this message belongs to.
329
358
  *
330
- * Returns the FileDescriptor object this message belongs to.
359
+ * @return [FileDescriptor]
331
360
  */
332
361
  static VALUE Descriptor_file_descriptor(VALUE _self) {
333
362
  Descriptor* self = ruby_to_Descriptor(_self);
@@ -336,11 +365,12 @@ static VALUE Descriptor_file_descriptor(VALUE _self) {
336
365
  }
337
366
 
338
367
  /*
339
- * call-seq:
340
- * Descriptor.name => name
368
+ * ruby-doc: Descriptor#name
341
369
  *
342
370
  * Returns the name of this message type as a fully-qualified string (e.g.,
343
371
  * My.Package.MessageType).
372
+ *
373
+ * @return [String]
344
374
  */
345
375
  static VALUE Descriptor_name(VALUE _self) {
346
376
  Descriptor* self = ruby_to_Descriptor(_self);
@@ -348,10 +378,12 @@ static VALUE Descriptor_name(VALUE _self) {
348
378
  }
349
379
 
350
380
  /*
351
- * call-seq:
352
- * Descriptor.each(&block)
381
+ * ruby-doc: Descriptor#each
353
382
  *
354
383
  * Iterates over fields in this message type, yielding to the block on each one.
384
+ *
385
+ * @yield [FieldDescriptor]
386
+ * @return [nil]
355
387
  */
356
388
  static VALUE Descriptor_each(VALUE _self) {
357
389
  Descriptor* self = ruby_to_Descriptor(_self);
@@ -366,11 +398,13 @@ static VALUE Descriptor_each(VALUE _self) {
366
398
  }
367
399
 
368
400
  /*
369
- * call-seq:
370
- * Descriptor.lookup(name) => FieldDescriptor
401
+ * ruby-doc: Descriptor#lookup
371
402
  *
372
403
  * Returns the field descriptor for the field with the given name, if present,
373
404
  * or nil if none.
405
+ *
406
+ * @param name [String]
407
+ * @return [FieldDescriptor]
374
408
  */
375
409
  static VALUE Descriptor_lookup(VALUE _self, VALUE name) {
376
410
  Descriptor* self = ruby_to_Descriptor(_self);
@@ -383,11 +417,13 @@ static VALUE Descriptor_lookup(VALUE _self, VALUE name) {
383
417
  }
384
418
 
385
419
  /*
386
- * call-seq:
387
- * Descriptor.each_oneof(&block) => nil
420
+ * ruby-doc: Descriptor#each_oneof
388
421
  *
389
422
  * Invokes the given block for each oneof in this message type, passing the
390
- * corresponding OneofDescriptor.
423
+ * corresponding {OneofDescriptor}.
424
+ *
425
+ * @yield [OneofDescriptor]
426
+ * @return [nil]
391
427
  */
392
428
  static VALUE Descriptor_each_oneof(VALUE _self) {
393
429
  Descriptor* self = ruby_to_Descriptor(_self);
@@ -402,11 +438,13 @@ static VALUE Descriptor_each_oneof(VALUE _self) {
402
438
  }
403
439
 
404
440
  /*
405
- * call-seq:
406
- * Descriptor.lookup_oneof(name) => OneofDescriptor
441
+ * ruby-doc: Descriptor#lookup_oneof
407
442
  *
408
443
  * Returns the oneof descriptor for the oneof with the given name, if present,
409
444
  * or nil if none.
445
+ *
446
+ * @param name [String]
447
+ * @return [OneofDescriptor]
410
448
  */
411
449
  static VALUE Descriptor_lookup_oneof(VALUE _self, VALUE name) {
412
450
  Descriptor* self = ruby_to_Descriptor(_self);
@@ -419,10 +457,11 @@ static VALUE Descriptor_lookup_oneof(VALUE _self, VALUE name) {
419
457
  }
420
458
 
421
459
  /*
422
- * call-seq:
423
- * Descriptor.msgclass => message_klass
460
+ * ruby-doc: Descriptor#msgclass
424
461
  *
425
462
  * Returns the Ruby class created for this message type.
463
+ *
464
+ * @return [Class<Google::Protobuf::AbstractMessage>]
426
465
  */
427
466
  static VALUE Descriptor_msgclass(VALUE _self) {
428
467
  Descriptor* self = ruby_to_Descriptor(_self);
@@ -433,10 +472,13 @@ static VALUE Descriptor_msgclass(VALUE _self) {
433
472
  }
434
473
 
435
474
  /*
436
- * call-seq:
437
- * Descriptor.options => options
475
+ * ruby-doc: Descriptor#options
476
+ *
477
+ * Returns the
478
+ * {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L571
479
+ * MessageOptions} for this {Descriptor}.
438
480
  *
439
- * Returns the `MessageOptions` for this `Descriptor`.
481
+ * @return [MessageOptions]
440
482
  */
441
483
  static VALUE Descriptor_options(VALUE _self) {
442
484
  Descriptor* self = ruby_to_Descriptor(_self);
@@ -452,6 +494,30 @@ static VALUE Descriptor_options(VALUE _self) {
452
494
  return message_options;
453
495
  }
454
496
 
497
+ /*
498
+ * ruby-doc: Descriptor#to_proto
499
+ *
500
+ * Returns the
501
+ * {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L147
502
+ * DescriptorProto} of this {Descriptor}.
503
+ *
504
+ * @return [DescriptorProto]
505
+ */
506
+ static VALUE Descriptor_to_proto(VALUE _self) {
507
+ Descriptor* self = ruby_to_Descriptor(_self);
508
+ upb_Arena* arena = upb_Arena_New();
509
+ google_protobuf_DescriptorProto* proto =
510
+ upb_MessageDef_ToProto(self->msgdef, arena);
511
+ size_t size;
512
+ const char* serialized =
513
+ google_protobuf_DescriptorProto_serialize(proto, arena, &size);
514
+ VALUE proto_class = rb_path2class("Google::Protobuf::DescriptorProto");
515
+ VALUE proto_rb =
516
+ Message_decode_bytes(size, serialized, 0, proto_class, false);
517
+ upb_Arena_Free(arena);
518
+ return proto_rb;
519
+ }
520
+
455
521
  static void Descriptor_register(VALUE module) {
456
522
  VALUE klass = rb_define_class_under(module, "Descriptor", rb_cObject);
457
523
  rb_define_alloc_func(klass, Descriptor_alloc);
@@ -464,6 +530,7 @@ static void Descriptor_register(VALUE module) {
464
530
  rb_define_method(klass, "name", Descriptor_name, 0);
465
531
  rb_define_method(klass, "file_descriptor", Descriptor_file_descriptor, 0);
466
532
  rb_define_method(klass, "options", Descriptor_options, 0);
533
+ rb_define_method(klass, "to_proto", Descriptor_to_proto, 0);
467
534
  rb_include_module(klass, rb_mEnumerable);
468
535
  rb_gc_register_address(&cDescriptor);
469
536
  cDescriptor = klass;
@@ -507,9 +574,15 @@ static VALUE FileDescriptor_alloc(VALUE klass) {
507
574
  return ret;
508
575
  }
509
576
 
577
+ /**
578
+ * ruby-doc: FileDescriptor
579
+ *
580
+ * A FileDescriptor provides information about all Protobuf definitions in a
581
+ * particular file.
582
+ */
583
+
510
584
  /*
511
- * call-seq:
512
- * FileDescriptor.new => file
585
+ * ruby-doc: FileDescriptor#initialize
513
586
  *
514
587
  * Returns a new file descriptor. May
515
588
  * to a builder.
@@ -530,10 +603,11 @@ static VALUE FileDescriptor_initialize(VALUE _self, VALUE cookie,
530
603
  }
531
604
 
532
605
  /*
533
- * call-seq:
534
- * FileDescriptor.name => name
606
+ * ruby-doc: FileDescriptor#name
535
607
  *
536
608
  * Returns the name of the file.
609
+ *
610
+ * @return [String]
537
611
  */
538
612
  static VALUE FileDescriptor_name(VALUE _self) {
539
613
  FileDescriptor* self = ruby_to_FileDescriptor(_self);
@@ -542,10 +616,13 @@ static VALUE FileDescriptor_name(VALUE _self) {
542
616
  }
543
617
 
544
618
  /*
545
- * call-seq:
546
- * FileDescriptor.options => options
619
+ * ruby-doc: FileDescriptor#options
620
+ *
621
+ * Returns the
622
+ * {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L442
623
+ * FileOptions} for this {FileDescriptor}.
547
624
  *
548
- * Returns the `FileOptions` for this `FileDescriptor`.
625
+ * @return [FileOptions]
549
626
  */
550
627
  static VALUE FileDescriptor_options(VALUE _self) {
551
628
  FileDescriptor* self = ruby_to_FileDescriptor(_self);
@@ -559,12 +636,40 @@ static VALUE FileDescriptor_options(VALUE _self) {
559
636
  return file_options;
560
637
  }
561
638
 
639
+ /*
640
+ * ruby-doc: FileDescriptor#to_proto
641
+ *
642
+ * Returns the
643
+ * {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L104
644
+ * FileDescriptorProto} of this {FileDescriptor}.
645
+ *
646
+ * @return [FileDescriptorProto]
647
+ */
648
+ static VALUE FileDescriptor_to_proto(VALUE _self) {
649
+ FileDescriptor* self = ruby_to_FileDescriptor(_self);
650
+ upb_Arena* arena = upb_Arena_New();
651
+ google_protobuf_FileDescriptorProto* file_proto =
652
+ upb_FileDef_ToProto(self->filedef, arena);
653
+
654
+ size_t size;
655
+ const char* serialized =
656
+ google_protobuf_FileDescriptorProto_serialize(file_proto, arena, &size);
657
+
658
+ VALUE file_proto_class =
659
+ rb_path2class("Google::Protobuf::FileDescriptorProto");
660
+ VALUE proto_rb =
661
+ Message_decode_bytes(size, serialized, 0, file_proto_class, false);
662
+ upb_Arena_Free(arena);
663
+ return proto_rb;
664
+ }
665
+
562
666
  static void FileDescriptor_register(VALUE module) {
563
667
  VALUE klass = rb_define_class_under(module, "FileDescriptor", rb_cObject);
564
668
  rb_define_alloc_func(klass, FileDescriptor_alloc);
565
669
  rb_define_method(klass, "initialize", FileDescriptor_initialize, 3);
566
670
  rb_define_method(klass, "name", FileDescriptor_name, 0);
567
671
  rb_define_method(klass, "options", FileDescriptor_options, 0);
672
+ rb_define_method(klass, "to_proto", FileDescriptor_to_proto, 0);
568
673
  rb_gc_register_address(&cFileDescriptor);
569
674
  cFileDescriptor = klass;
570
675
  }
@@ -599,9 +704,15 @@ static FieldDescriptor* ruby_to_FieldDescriptor(VALUE val) {
599
704
  return ret;
600
705
  }
601
706
 
707
+ /**
708
+ * ruby-doc: FieldDescriptor
709
+ *
710
+ * A FieldDescriptor provides information about the Protobuf definition of a
711
+ * field inside a {Descriptor}.
712
+ */
713
+
602
714
  /*
603
- * call-seq:
604
- * FieldDescriptor.new => field
715
+ * ruby-doc: FieldDescriptor#initialize
605
716
  *
606
717
  * Returns a new field descriptor. Its name, type, etc. must be set before it is
607
718
  * added to a message type.
@@ -635,10 +746,11 @@ static VALUE FieldDescriptor_initialize(VALUE _self, VALUE cookie,
635
746
  }
636
747
 
637
748
  /*
638
- * call-seq:
639
- * FieldDescriptor.name => name
749
+ * ruby-doc: FieldDescriptor#name
640
750
  *
641
751
  * Returns the name of this field.
752
+ *
753
+ * @return [String]
642
754
  */
643
755
  static VALUE FieldDescriptor_name(VALUE _self) {
644
756
  FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
@@ -703,14 +815,15 @@ static VALUE descriptortype_to_ruby(upb_FieldType type) {
703
815
  }
704
816
 
705
817
  /*
706
- * call-seq:
707
- * FieldDescriptor.type => type
818
+ * ruby-doc: FieldDescriptor#type
708
819
  *
709
820
  * Returns this field's type, as a Ruby symbol, or nil if not yet set.
710
821
  *
711
822
  * Valid field types are:
712
823
  * :int32, :int64, :uint32, :uint64, :float, :double, :bool, :string,
713
824
  * :bytes, :message.
825
+ *
826
+ * @return [Symbol]
714
827
  */
715
828
  static VALUE FieldDescriptor__type(VALUE _self) {
716
829
  FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
@@ -718,15 +831,16 @@ static VALUE FieldDescriptor__type(VALUE _self) {
718
831
  }
719
832
 
720
833
  /*
721
- * call-seq:
722
- * FieldDescriptor.default => default
834
+ * ruby-doc: FieldDescriptor#default
723
835
  *
724
836
  * Returns this field's default, as a Ruby object, or nil if not yet set.
837
+ *
838
+ * @return [Object,nil]
725
839
  */
726
840
  static VALUE FieldDescriptor_default(VALUE _self) {
727
841
  FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
728
842
  const upb_FieldDef* f = self->fielddef;
729
- upb_MessageValue default_val = {0};
843
+ upb_MessageValue default_val = upb_MessageValue_Zero();
730
844
  if (upb_FieldDef_IsSubMessage(f)) {
731
845
  return Qnil;
732
846
  } else if (!upb_FieldDef_IsRepeated(f)) {
@@ -736,10 +850,11 @@ static VALUE FieldDescriptor_default(VALUE _self) {
736
850
  }
737
851
 
738
852
  /*
739
- * call-seq:
740
- * FieldDescriptor.has_presence? => bool
853
+ * ruby-doc: FieldDescriptor.has_presence?
741
854
  *
742
855
  * Returns whether this field tracks presence.
856
+ *
857
+ * @return [Boolean]
743
858
  */
744
859
  static VALUE FieldDescriptor_has_presence(VALUE _self) {
745
860
  FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
@@ -747,10 +862,33 @@ static VALUE FieldDescriptor_has_presence(VALUE _self) {
747
862
  }
748
863
 
749
864
  /*
750
- * call-seq:
751
- * FieldDescriptor.is_packed? => bool
865
+ * ruby-doc: FieldDescriptor#required?
866
+ *
867
+ * Returns whether this is a required field.
868
+ *
869
+ * @return [Boolean]
870
+ */
871
+ static VALUE FieldDescriptor_is_required(VALUE _self) {
872
+ FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
873
+ return upb_FieldDef_IsRequired(self->fielddef) ? Qtrue : Qfalse;
874
+ }
875
+
876
+ /*
877
+ * ruby-doc: FieldDescriptor#repeated?
878
+ *
879
+ * Returns whether this is a repeated field.
880
+ * @return [Boolean]
881
+ */
882
+ static VALUE FieldDescriptor_is_repeated(VALUE _self) {
883
+ FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
884
+ return upb_FieldDef_IsRepeated(self->fielddef) ? Qtrue : Qfalse;
885
+ }
886
+
887
+ /*
888
+ * ruby-doc: FieldDescriptor#is_packed?
752
889
  *
753
890
  * Returns whether this is a repeated field that uses packed encoding.
891
+ * @return [Boolean]
754
892
  */
755
893
  static VALUE FieldDescriptor_is_packed(VALUE _self) {
756
894
  FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
@@ -758,10 +896,11 @@ static VALUE FieldDescriptor_is_packed(VALUE _self) {
758
896
  }
759
897
 
760
898
  /*
761
- * call-seq:
762
- * FieldDescriptor.json_name => json_name
899
+ * ruby-doc: FieldDescriptor#json_name
763
900
  *
764
901
  * Returns this field's json_name, as a Ruby string, or nil if not yet set.
902
+ *
903
+ * @return [String,nil]
765
904
  */
766
905
  static VALUE FieldDescriptor_json_name(VALUE _self) {
767
906
  FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
@@ -771,13 +910,14 @@ static VALUE FieldDescriptor_json_name(VALUE _self) {
771
910
  }
772
911
 
773
912
  /*
774
- * call-seq:
775
- * FieldDescriptor.label => label
913
+ * ruby-doc: FieldDescriptor#label
776
914
  *
777
915
  * Returns this field's label (i.e., plurality), as a Ruby symbol.
778
- *
779
916
  * Valid field labels are:
780
- * :optional, :repeated
917
+ * :optional, :repeated
918
+ *
919
+ * @return [Symbol]
920
+ * @deprecated Use {#repeated?} or {#required?} instead.
781
921
  */
782
922
  static VALUE FieldDescriptor_label(VALUE _self) {
783
923
  FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
@@ -797,10 +937,11 @@ static VALUE FieldDescriptor_label(VALUE _self) {
797
937
  }
798
938
 
799
939
  /*
800
- * call-seq:
801
- * FieldDescriptor.number => number
940
+ * ruby-doc: FieldDescriptor#number
802
941
  *
803
942
  * Returns the tag number for this field.
943
+ *
944
+ * @return [Integer]
804
945
  */
805
946
  static VALUE FieldDescriptor_number(VALUE _self) {
806
947
  FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
@@ -808,13 +949,14 @@ static VALUE FieldDescriptor_number(VALUE _self) {
808
949
  }
809
950
 
810
951
  /*
811
- * call-seq:
812
- * FieldDescriptor.submsg_name => submsg_name
952
+ * ruby-doc: FieldDescriptor#submsg_name
813
953
  *
814
954
  * Returns the name of the message or enum type corresponding to this field, if
815
955
  * it is a message or enum field (respectively), or nil otherwise. This type
816
956
  * name will be resolved within the context of the pool to which the containing
817
957
  * message type is added.
958
+ *
959
+ * @return [String,nil]
818
960
  */
819
961
  static VALUE FieldDescriptor_submsg_name(VALUE _self) {
820
962
  FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
@@ -831,13 +973,14 @@ static VALUE FieldDescriptor_submsg_name(VALUE _self) {
831
973
  }
832
974
 
833
975
  /*
834
- * call-seq:
835
- * FieldDescriptor.subtype => message_or_enum_descriptor
976
+ * ruby-doc: FieldDescriptor#subtype
836
977
  *
837
978
  * Returns the message or enum descriptor corresponding to this field's type if
838
979
  * it is a message or enum field, respectively, or nil otherwise. Cannot be
839
980
  * called *until* the containing message type is added to a pool (and thus
840
981
  * resolved).
982
+ *
983
+ * @return [Descriptor,EnumDescriptor,nil]
841
984
  */
842
985
  static VALUE FieldDescriptor_subtype(VALUE _self) {
843
986
  FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
@@ -854,11 +997,13 @@ static VALUE FieldDescriptor_subtype(VALUE _self) {
854
997
  }
855
998
 
856
999
  /*
857
- * call-seq:
858
- * FieldDescriptor.get(message) => value
1000
+ * ruby-doc: FieldDescriptor#get
859
1001
  *
860
1002
  * Returns the value set for this field on the given message. Raises an
861
1003
  * exception if message is of the wrong type.
1004
+ *
1005
+ * @param message [AbstractMessage]
1006
+ * @return [Object]
862
1007
  */
863
1008
  static VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) {
864
1009
  FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
@@ -874,11 +1019,13 @@ static VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) {
874
1019
  }
875
1020
 
876
1021
  /*
877
- * call-seq:
878
- * FieldDescriptor.has?(message) => boolean
1022
+ * ruby-doc: FieldDescriptor.has?
879
1023
  *
880
1024
  * Returns whether the value is set on the given message. Raises an
881
1025
  * exception when calling for fields that do not have presence.
1026
+ *
1027
+ * @param message [AbstractMessage]
1028
+ * @return [Boolean]
882
1029
  */
883
1030
  static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
884
1031
  FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
@@ -895,10 +1042,12 @@ static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
895
1042
  }
896
1043
 
897
1044
  /*
898
- * call-seq:
899
- * FieldDescriptor.clear(message)
1045
+ * ruby-doc: FieldDescriptor#clear
900
1046
  *
901
1047
  * Clears the field from the message if it's set.
1048
+ *
1049
+ * @param message [AbstractMessage]
1050
+ * @return [nil]
902
1051
  */
903
1052
  static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
904
1053
  FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
@@ -914,12 +1063,14 @@ static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
914
1063
  }
915
1064
 
916
1065
  /*
917
- * call-seq:
918
- * FieldDescriptor.set(message, value)
1066
+ * ruby-doc: FieldDescriptor#set
919
1067
  *
920
1068
  * Sets the value corresponding to this field to the given value on the given
921
1069
  * message. Raises an exception if message is of the wrong type. Performs the
922
1070
  * ordinary type-checks for field setting.
1071
+ *
1072
+ * @param message [AbstractMessage]
1073
+ * @param value [Object]
923
1074
  */
924
1075
  static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) {
925
1076
  FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
@@ -939,10 +1090,13 @@ static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) {
939
1090
  }
940
1091
 
941
1092
  /*
942
- * call-seq:
943
- * FieldDescriptor.options => options
1093
+ * ruby-doc: FieldDescriptor#options
944
1094
  *
945
- * Returns the `FieldOptions` for this `FieldDescriptor`.
1095
+ * Returns the
1096
+ * {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L656
1097
+ * FieldOptions} for this {FieldDescriptor}.
1098
+ *
1099
+ * @return [FieldOptions]
946
1100
  */
947
1101
  static VALUE FieldDescriptor_options(VALUE _self) {
948
1102
  FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
@@ -957,6 +1111,30 @@ static VALUE FieldDescriptor_options(VALUE _self) {
957
1111
  return field_options;
958
1112
  }
959
1113
 
1114
+ /*
1115
+ * ruby-doc: FieldDescriptor#to_proto
1116
+ *
1117
+ * Returns the
1118
+ * {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L236
1119
+ * FieldDescriptorProto} of this {FieldDescriptor}.
1120
+ *
1121
+ * @return [FieldDescriptorProto]
1122
+ */
1123
+ static VALUE FieldDescriptor_to_proto(VALUE _self) {
1124
+ FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
1125
+ upb_Arena* arena = upb_Arena_New();
1126
+ google_protobuf_FieldDescriptorProto* proto =
1127
+ upb_FieldDef_ToProto(self->fielddef, arena);
1128
+ size_t size;
1129
+ const char* serialized =
1130
+ google_protobuf_FieldDescriptorProto_serialize(proto, arena, &size);
1131
+ VALUE proto_class = rb_path2class("Google::Protobuf::FieldDescriptorProto");
1132
+ VALUE proto_rb =
1133
+ Message_decode_bytes(size, serialized, 0, proto_class, false);
1134
+ upb_Arena_Free(arena);
1135
+ return proto_rb;
1136
+ }
1137
+
960
1138
  static void FieldDescriptor_register(VALUE module) {
961
1139
  VALUE klass = rb_define_class_under(module, "FieldDescriptor", rb_cObject);
962
1140
  rb_define_alloc_func(klass, FieldDescriptor_alloc);
@@ -965,6 +1143,8 @@ static void FieldDescriptor_register(VALUE module) {
965
1143
  rb_define_method(klass, "type", FieldDescriptor__type, 0);
966
1144
  rb_define_method(klass, "default", FieldDescriptor_default, 0);
967
1145
  rb_define_method(klass, "has_presence?", FieldDescriptor_has_presence, 0);
1146
+ rb_define_method(klass, "required?", FieldDescriptor_is_required, 0);
1147
+ rb_define_method(klass, "repeated?", FieldDescriptor_is_repeated, 0);
968
1148
  rb_define_method(klass, "is_packed?", FieldDescriptor_is_packed, 0);
969
1149
  rb_define_method(klass, "json_name", FieldDescriptor_json_name, 0);
970
1150
  rb_define_method(klass, "label", FieldDescriptor_label, 0);
@@ -976,6 +1156,7 @@ static void FieldDescriptor_register(VALUE module) {
976
1156
  rb_define_method(klass, "get", FieldDescriptor_get, 1);
977
1157
  rb_define_method(klass, "set", FieldDescriptor_set, 2);
978
1158
  rb_define_method(klass, "options", FieldDescriptor_options, 0);
1159
+ rb_define_method(klass, "to_proto", FieldDescriptor_to_proto, 0);
979
1160
  rb_gc_register_address(&cFieldDescriptor);
980
1161
  cFieldDescriptor = klass;
981
1162
  }
@@ -1010,9 +1191,15 @@ static OneofDescriptor* ruby_to_OneofDescriptor(VALUE val) {
1010
1191
  return ret;
1011
1192
  }
1012
1193
 
1194
+ /**
1195
+ * ruby-doc: OneofDescriptor
1196
+ *
1197
+ * A OneofDescriptor provides information about the Protobuf definition of a
1198
+ * oneof inside a {Descriptor}.
1199
+ */
1200
+
1013
1201
  /*
1014
- * call-seq:
1015
- * OneofDescriptor.new => oneof_descriptor
1202
+ * ruby-doc: OneofDescriptor#initialize
1016
1203
  *
1017
1204
  * Creates a new, empty, oneof descriptor. The oneof may only be modified prior
1018
1205
  * to being added to a message descriptor which is subsequently added to a pool.
@@ -1047,10 +1234,11 @@ static VALUE OneofDescriptor_initialize(VALUE _self, VALUE cookie,
1047
1234
  }
1048
1235
 
1049
1236
  /*
1050
- * call-seq:
1051
- * OneofDescriptor.name => name
1237
+ * ruby-doc: OneofDescriptor#name
1052
1238
  *
1053
1239
  * Returns the name of this oneof.
1240
+ *
1241
+ * @return [String]
1054
1242
  */
1055
1243
  static VALUE OneofDescriptor_name(VALUE _self) {
1056
1244
  OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
@@ -1058,10 +1246,12 @@ static VALUE OneofDescriptor_name(VALUE _self) {
1058
1246
  }
1059
1247
 
1060
1248
  /*
1061
- * call-seq:
1062
- * OneofDescriptor.each(&block) => nil
1249
+ * ruby-doc: OneofDescriptor#each
1063
1250
  *
1064
1251
  * Iterates through fields in this oneof, yielding to the block on each one.
1252
+ *
1253
+ * @yield [FieldDescriptor]
1254
+ * @return [nil]
1065
1255
  */
1066
1256
  static VALUE OneofDescriptor_each(VALUE _self) {
1067
1257
  OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
@@ -1076,10 +1266,13 @@ static VALUE OneofDescriptor_each(VALUE _self) {
1076
1266
  }
1077
1267
 
1078
1268
  /*
1079
- * call-seq:
1080
- * OneofDescriptor.options => options
1269
+ * ruby-doc: OneofDescriptor#options
1270
+ *
1271
+ * Returns the
1272
+ * {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L824
1273
+ * OneofOptions} for this {OneofDescriptor}.
1081
1274
  *
1082
- * Returns the `OneofOptions` for this `OneofDescriptor`.
1275
+ * @return [OneofOptions]
1083
1276
  */
1084
1277
  static VALUE OneOfDescriptor_options(VALUE _self) {
1085
1278
  OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
@@ -1094,6 +1287,30 @@ static VALUE OneOfDescriptor_options(VALUE _self) {
1094
1287
  return oneof_options;
1095
1288
  }
1096
1289
 
1290
+ /*
1291
+ * ruby-doc: OneofDescriptor#to_proto
1292
+ *
1293
+ * Returns the
1294
+ * {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L343
1295
+ * OneofDescriptorProto} of this {OneofDescriptor}.
1296
+ *
1297
+ * @return [OneofDescriptorProto]
1298
+ */
1299
+ static VALUE OneOfDescriptor_to_proto(VALUE _self) {
1300
+ OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
1301
+ upb_Arena* arena = upb_Arena_New();
1302
+ google_protobuf_OneofDescriptorProto* proto =
1303
+ upb_OneofDef_ToProto(self->oneofdef, arena);
1304
+ size_t size;
1305
+ const char* serialized =
1306
+ google_protobuf_OneofDescriptorProto_serialize(proto, arena, &size);
1307
+ VALUE proto_class = rb_path2class("Google::Protobuf::OneofDescriptorProto");
1308
+ VALUE proto_rb =
1309
+ Message_decode_bytes(size, serialized, 0, proto_class, false);
1310
+ upb_Arena_Free(arena);
1311
+ return proto_rb;
1312
+ }
1313
+
1097
1314
  static void OneofDescriptor_register(VALUE module) {
1098
1315
  VALUE klass = rb_define_class_under(module, "OneofDescriptor", rb_cObject);
1099
1316
  rb_define_alloc_func(klass, OneofDescriptor_alloc);
@@ -1101,6 +1318,7 @@ static void OneofDescriptor_register(VALUE module) {
1101
1318
  rb_define_method(klass, "name", OneofDescriptor_name, 0);
1102
1319
  rb_define_method(klass, "each", OneofDescriptor_each, 0);
1103
1320
  rb_define_method(klass, "options", OneOfDescriptor_options, 0);
1321
+ rb_define_method(klass, "to_proto", OneOfDescriptor_to_proto, 0);
1104
1322
  rb_include_module(klass, rb_mEnumerable);
1105
1323
  rb_gc_register_address(&cOneofDescriptor);
1106
1324
  cOneofDescriptor = klass;
@@ -1153,6 +1371,13 @@ const upb_EnumDef* EnumDescriptor_GetEnumDef(VALUE enum_desc_rb) {
1153
1371
  return desc->enumdef;
1154
1372
  }
1155
1373
 
1374
+ /**
1375
+ * ruby-doc: EnumDescriptor
1376
+ *
1377
+ * An EnumDescriptor provides information about the Protobuf definition of an
1378
+ * enum inside a {Descriptor}.
1379
+ */
1380
+
1156
1381
  /*
1157
1382
  * call-seq:
1158
1383
  * EnumDescriptor.new(c_only_cookie, ptr) => EnumDescriptor
@@ -1175,10 +1400,11 @@ static VALUE EnumDescriptor_initialize(VALUE _self, VALUE cookie,
1175
1400
  }
1176
1401
 
1177
1402
  /*
1178
- * call-seq:
1179
- * EnumDescriptor.file_descriptor
1403
+ * ruby-doc: EnumDescriptor#file_descriptor
1180
1404
  *
1181
- * Returns the FileDescriptor object this enum belongs to.
1405
+ * Returns the {FileDescriptor} object this enum belongs to.
1406
+ *
1407
+ * @return [FileDescriptor]
1182
1408
  */
1183
1409
  static VALUE EnumDescriptor_file_descriptor(VALUE _self) {
1184
1410
  EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
@@ -1187,10 +1413,11 @@ static VALUE EnumDescriptor_file_descriptor(VALUE _self) {
1187
1413
  }
1188
1414
 
1189
1415
  /*
1190
- * call-seq:
1191
- * EnumDescriptor.is_closed? => bool
1416
+ * ruby-doc: EnumDescriptor#is_closed?
1192
1417
  *
1193
1418
  * Returns whether this enum is open or closed.
1419
+ *
1420
+ * @return [Boolean]
1194
1421
  */
1195
1422
  static VALUE EnumDescriptor_is_closed(VALUE _self) {
1196
1423
  EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
@@ -1198,10 +1425,11 @@ static VALUE EnumDescriptor_is_closed(VALUE _self) {
1198
1425
  }
1199
1426
 
1200
1427
  /*
1201
- * call-seq:
1202
- * EnumDescriptor.name => name
1428
+ * ruby-doc: EnumDescriptor#name
1203
1429
  *
1204
1430
  * Returns the name of this enum type.
1431
+ *
1432
+ * @return [String]
1205
1433
  */
1206
1434
  static VALUE EnumDescriptor_name(VALUE _self) {
1207
1435
  EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
@@ -1209,11 +1437,13 @@ static VALUE EnumDescriptor_name(VALUE _self) {
1209
1437
  }
1210
1438
 
1211
1439
  /*
1212
- * call-seq:
1213
- * EnumDescriptor.lookup_name(name) => value
1440
+ * ruby-doc: EnumDescriptor#lookup_name
1214
1441
  *
1215
1442
  * Returns the numeric value corresponding to the given key name (as a Ruby
1216
1443
  * symbol), or nil if none.
1444
+ *
1445
+ * @param name [Symbol]
1446
+ * @return [Integer,nil]
1217
1447
  */
1218
1448
  static VALUE EnumDescriptor_lookup_name(VALUE _self, VALUE name) {
1219
1449
  EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
@@ -1228,11 +1458,13 @@ static VALUE EnumDescriptor_lookup_name(VALUE _self, VALUE name) {
1228
1458
  }
1229
1459
 
1230
1460
  /*
1231
- * call-seq:
1232
- * EnumDescriptor.lookup_value(name) => value
1461
+ * ruby-doc: EnumDescriptor#lookup_value
1233
1462
  *
1234
1463
  * Returns the key name (as a Ruby symbol) corresponding to the integer value,
1235
1464
  * or nil if none.
1465
+ *
1466
+ * @param name [Integer]
1467
+ * @return [Symbol,nil]
1236
1468
  */
1237
1469
  static VALUE EnumDescriptor_lookup_value(VALUE _self, VALUE number) {
1238
1470
  EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
@@ -1247,11 +1479,13 @@ static VALUE EnumDescriptor_lookup_value(VALUE _self, VALUE number) {
1247
1479
  }
1248
1480
 
1249
1481
  /*
1250
- * call-seq:
1251
- * EnumDescriptor.each(&block)
1482
+ * ruby-doc: EnumDescriptor#each
1252
1483
  *
1253
1484
  * Iterates over key => value mappings in this enum's definition, yielding to
1254
1485
  * the block with (key, value) arguments for each one.
1486
+ *
1487
+ * @yield [Symbol, Integer]
1488
+ * @return [nil]
1255
1489
  */
1256
1490
  static VALUE EnumDescriptor_each(VALUE _self) {
1257
1491
  EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
@@ -1268,10 +1502,11 @@ static VALUE EnumDescriptor_each(VALUE _self) {
1268
1502
  }
1269
1503
 
1270
1504
  /*
1271
- * call-seq:
1272
- * EnumDescriptor.enummodule => module
1505
+ * ruby-doc: EnumDescriptor#enummodule
1273
1506
  *
1274
1507
  * Returns the Ruby module corresponding to this enum type.
1508
+ *
1509
+ * @return [Module]
1275
1510
  */
1276
1511
  static VALUE EnumDescriptor_enummodule(VALUE _self) {
1277
1512
  EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
@@ -1282,10 +1517,13 @@ static VALUE EnumDescriptor_enummodule(VALUE _self) {
1282
1517
  }
1283
1518
 
1284
1519
  /*
1285
- * call-seq:
1286
- * EnumDescriptor.options => options
1520
+ * ruby-doc: EnumDescriptor#options
1521
+ *
1522
+ * Returns the
1523
+ * {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L838
1524
+ * EnumOptions} for this {EnumDescriptor}.
1287
1525
  *
1288
- * Returns the `EnumOptions` for this `EnumDescriptor`.
1526
+ * @return [EnumOptions]
1289
1527
  */
1290
1528
  static VALUE EnumDescriptor_options(VALUE _self) {
1291
1529
  EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
@@ -1299,6 +1537,31 @@ static VALUE EnumDescriptor_options(VALUE _self) {
1299
1537
  return enum_options;
1300
1538
  }
1301
1539
 
1540
+ /*
1541
+ * ruby-doc: EnumDescriptor#to_proto
1542
+ *
1543
+ * Returns the
1544
+ * {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L349
1545
+ * EnumDescriptorProto} of this {EnumDescriptor}.
1546
+ * @return [EnumDescriptorProto]
1547
+ */
1548
+ static VALUE EnumDescriptor_to_proto(VALUE _self) {
1549
+ EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
1550
+ upb_Arena* arena = upb_Arena_New();
1551
+ google_protobuf_EnumDescriptorProto* proto =
1552
+ upb_EnumDef_ToProto(self->enumdef, arena);
1553
+
1554
+ size_t size;
1555
+ const char* serialized =
1556
+ google_protobuf_EnumDescriptorProto_serialize(proto, arena, &size);
1557
+
1558
+ VALUE proto_class = rb_path2class("Google::Protobuf::EnumDescriptorProto");
1559
+ VALUE proto_rb =
1560
+ Message_decode_bytes(size, serialized, 0, proto_class, false);
1561
+ upb_Arena_Free(arena);
1562
+ return proto_rb;
1563
+ }
1564
+
1302
1565
  static void EnumDescriptor_register(VALUE module) {
1303
1566
  VALUE klass = rb_define_class_under(module, "EnumDescriptor", rb_cObject);
1304
1567
  rb_define_alloc_func(klass, EnumDescriptor_alloc);
@@ -1311,6 +1574,7 @@ static void EnumDescriptor_register(VALUE module) {
1311
1574
  rb_define_method(klass, "file_descriptor", EnumDescriptor_file_descriptor, 0);
1312
1575
  rb_define_method(klass, "is_closed?", EnumDescriptor_is_closed, 0);
1313
1576
  rb_define_method(klass, "options", EnumDescriptor_options, 0);
1577
+ rb_define_method(klass, "to_proto", EnumDescriptor_to_proto, 0);
1314
1578
  rb_include_module(klass, rb_mEnumerable);
1315
1579
  rb_gc_register_address(&cEnumDescriptor);
1316
1580
  cEnumDescriptor = klass;
@@ -1357,6 +1621,13 @@ static VALUE ServiceDescriptor_alloc(VALUE klass) {
1357
1621
  return ret;
1358
1622
  }
1359
1623
 
1624
+ /**
1625
+ * ruby-doc: ServiceDescriptor
1626
+ *
1627
+ * A ServiceDescriptor provides information about the Protobuf definition of an
1628
+ * RPC service.
1629
+ */
1630
+
1360
1631
  /*
1361
1632
  * call-seq:
1362
1633
  * ServiceDescriptor.new(c_only_cookie, ptr) => ServiceDescriptor
@@ -1379,10 +1650,11 @@ static VALUE ServiceDescriptor_initialize(VALUE _self, VALUE cookie,
1379
1650
  }
1380
1651
 
1381
1652
  /*
1382
- * call-seq:
1383
- * ServiceDescriptor.name => name
1653
+ * ruby-doc: ServiceDescriptor#name
1384
1654
  *
1385
1655
  * Returns the name of this service.
1656
+ *
1657
+ * @return [String]
1386
1658
  */
1387
1659
  static VALUE ServiceDescriptor_name(VALUE _self) {
1388
1660
  ServiceDescriptor* self = ruby_to_ServiceDescriptor(_self);
@@ -1390,10 +1662,10 @@ static VALUE ServiceDescriptor_name(VALUE _self) {
1390
1662
  }
1391
1663
 
1392
1664
  /*
1393
- * call-seq:
1394
- * ServiceDescriptor.file_descriptor
1665
+ * ruby-doc: ServiceDescriptor#file_descriptor
1395
1666
  *
1396
- * Returns the FileDescriptor object this service belongs to.
1667
+ * Returns the {FileDescriptor} object this service belongs to.
1668
+ * @return [FileDescriptor]
1397
1669
  */
1398
1670
  static VALUE ServiceDescriptor_file_descriptor(VALUE _self) {
1399
1671
  ServiceDescriptor* self = ruby_to_ServiceDescriptor(_self);
@@ -1402,10 +1674,12 @@ static VALUE ServiceDescriptor_file_descriptor(VALUE _self) {
1402
1674
  }
1403
1675
 
1404
1676
  /*
1405
- * call-seq:
1406
- * ServiceDescriptor.each(&block)
1677
+ * ruby-doc: ServiceDescriptor#each
1407
1678
  *
1408
1679
  * Iterates over methods in this service, yielding to the block on each one.
1680
+ *
1681
+ * @yield [MethodDescriptor]
1682
+ * @return [nil]
1409
1683
  */
1410
1684
  static VALUE ServiceDescriptor_each(VALUE _self) {
1411
1685
  ServiceDescriptor* self = ruby_to_ServiceDescriptor(_self);
@@ -1420,10 +1694,13 @@ static VALUE ServiceDescriptor_each(VALUE _self) {
1420
1694
  }
1421
1695
 
1422
1696
  /*
1423
- * call-seq:
1424
- * ServiceDescriptor.options => options
1697
+ * ruby-doc: ServiceDescriptor#options
1698
+ *
1699
+ * Returns the
1700
+ * {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L901
1701
+ * ServiceOptions} for this {ServiceDescriptor}.
1425
1702
  *
1426
- * Returns the `ServiceOptions` for this `ServiceDescriptor`.
1703
+ * @return [ServiceOptions]
1427
1704
  */
1428
1705
  static VALUE ServiceDescriptor_options(VALUE _self) {
1429
1706
  ServiceDescriptor* self = ruby_to_ServiceDescriptor(_self);
@@ -1439,6 +1716,30 @@ static VALUE ServiceDescriptor_options(VALUE _self) {
1439
1716
  return service_options;
1440
1717
  }
1441
1718
 
1719
+ /*
1720
+ * ruby-doc: ServiceDescriptor#to_proto
1721
+ *
1722
+ * Returns the
1723
+ * {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L386
1724
+ * ServiceDescriptorProto} of this {ServiceDescriptor}.
1725
+ *
1726
+ * @return [ServiceDescriptorProto]
1727
+ */
1728
+ static VALUE ServiceDescriptor_to_proto(VALUE _self) {
1729
+ ServiceDescriptor* self = ruby_to_ServiceDescriptor(_self);
1730
+ upb_Arena* arena = upb_Arena_New();
1731
+ google_protobuf_ServiceDescriptorProto* proto =
1732
+ upb_ServiceDef_ToProto(self->servicedef, arena);
1733
+ size_t size;
1734
+ const char* serialized =
1735
+ google_protobuf_ServiceDescriptorProto_serialize(proto, arena, &size);
1736
+ VALUE proto_class = rb_path2class("Google::Protobuf::ServiceDescriptorProto");
1737
+ VALUE proto_rb =
1738
+ Message_decode_bytes(size, serialized, 0, proto_class, false);
1739
+ upb_Arena_Free(arena);
1740
+ return proto_rb;
1741
+ }
1742
+
1442
1743
  static void ServiceDescriptor_register(VALUE module) {
1443
1744
  VALUE klass = rb_define_class_under(module, "ServiceDescriptor", rb_cObject);
1444
1745
  rb_define_alloc_func(klass, ServiceDescriptor_alloc);
@@ -1448,6 +1749,7 @@ static void ServiceDescriptor_register(VALUE module) {
1448
1749
  rb_define_method(klass, "file_descriptor", ServiceDescriptor_file_descriptor,
1449
1750
  0);
1450
1751
  rb_define_method(klass, "options", ServiceDescriptor_options, 0);
1752
+ rb_define_method(klass, "to_proto", ServiceDescriptor_to_proto, 0);
1451
1753
  rb_include_module(klass, rb_mEnumerable);
1452
1754
  rb_gc_register_address(&cServiceDescriptor);
1453
1755
  cServiceDescriptor = klass;
@@ -1494,6 +1796,13 @@ static VALUE MethodDescriptor_alloc(VALUE klass) {
1494
1796
  return ret;
1495
1797
  }
1496
1798
 
1799
+ /**
1800
+ * ruby-doc: MethodDescriptor
1801
+ *
1802
+ * A MethodDescriptor provides information about the Protobuf definition of a
1803
+ * method inside an RPC service.
1804
+ */
1805
+
1497
1806
  /*
1498
1807
  * call-seq:
1499
1808
  * MethodDescriptor.new(c_only_cookie, ptr) => MethodDescriptor
@@ -1510,16 +1819,17 @@ static VALUE MethodDescriptor_initialize(VALUE _self, VALUE cookie,
1510
1819
  }
1511
1820
 
1512
1821
  RB_OBJ_WRITE(_self, &self->descriptor_pool, descriptor_pool);
1513
- self->methoddef = (const upb_ServiceDef*)NUM2ULL(ptr);
1822
+ self->methoddef = (const upb_MethodDef*)NUM2ULL(ptr);
1514
1823
 
1515
1824
  return Qnil;
1516
1825
  }
1517
1826
 
1518
1827
  /*
1519
- * call-seq:
1520
- * MethodDescriptor.name => name
1828
+ * ruby-doc: MethodDescriptor#name
1521
1829
  *
1522
1830
  * Returns the name of this method
1831
+ *
1832
+ * @return [String]
1523
1833
  */
1524
1834
  static VALUE MethodDescriptor_name(VALUE _self) {
1525
1835
  MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
@@ -1527,10 +1837,13 @@ static VALUE MethodDescriptor_name(VALUE _self) {
1527
1837
  }
1528
1838
 
1529
1839
  /*
1530
- * call-seq:
1531
- * MethodDescriptor.options => options
1840
+ * ruby-doc: MethodDescriptor#options
1841
+ *
1842
+ * Returns the
1843
+ * {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L927
1844
+ * MethodOptions} for this {MethodDescriptor}.
1532
1845
  *
1533
- * Returns the `MethodOptions` for this `MethodDescriptor`.
1846
+ * @return [MethodOptions]
1534
1847
  */
1535
1848
  static VALUE MethodDescriptor_options(VALUE _self) {
1536
1849
  MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
@@ -1547,10 +1860,11 @@ static VALUE MethodDescriptor_options(VALUE _self) {
1547
1860
  }
1548
1861
 
1549
1862
  /*
1550
- * call-seq:
1551
- * MethodDescriptor.input_type => Descriptor
1863
+ * ruby-doc: MethodDescriptor#input_type
1864
+ *
1865
+ * Returns the {Descriptor} for the request message type of this method
1552
1866
  *
1553
- * Returns the `Descriptor` for the request message type of this method
1867
+ * @return [Descriptor]
1554
1868
  */
1555
1869
  static VALUE MethodDescriptor_input_type(VALUE _self) {
1556
1870
  MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
@@ -1559,10 +1873,11 @@ static VALUE MethodDescriptor_input_type(VALUE _self) {
1559
1873
  }
1560
1874
 
1561
1875
  /*
1562
- * call-seq:
1563
- * MethodDescriptor.output_type => Descriptor
1876
+ * ruby-doc: MethodDescriptor#output_type
1877
+ *
1878
+ * Returns the {Descriptor} for the response message type of this method
1564
1879
  *
1565
- * Returns the `Descriptor` for the response message type of this method
1880
+ * @return [Descriptor]
1566
1881
  */
1567
1882
  static VALUE MethodDescriptor_output_type(VALUE _self) {
1568
1883
  MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
@@ -1571,10 +1886,11 @@ static VALUE MethodDescriptor_output_type(VALUE _self) {
1571
1886
  }
1572
1887
 
1573
1888
  /*
1574
- * call-seq:
1575
- * MethodDescriptor.client_streaming => bool
1889
+ * ruby-doc: MethodDescriptor#client_streaming
1576
1890
  *
1577
1891
  * Returns whether or not this is a streaming request method
1892
+ *
1893
+ * @return [Boolean]
1578
1894
  */
1579
1895
  static VALUE MethodDescriptor_client_streaming(VALUE _self) {
1580
1896
  MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
@@ -1582,10 +1898,35 @@ static VALUE MethodDescriptor_client_streaming(VALUE _self) {
1582
1898
  }
1583
1899
 
1584
1900
  /*
1585
- * call-seq:
1586
- * MethodDescriptor.server_streaming => bool
1901
+ * ruby-doc: MethodDescriptor#to_proto
1902
+ *
1903
+ * Returns the
1904
+ * {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L394
1905
+ * MethodDescriptorProto} of this {MethodDescriptor}.
1906
+ *
1907
+ * @return [MethodDescriptorProto]
1908
+ */
1909
+ static VALUE MethodDescriptor_to_proto(VALUE _self) {
1910
+ MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
1911
+ upb_Arena* arena = upb_Arena_New();
1912
+ google_protobuf_MethodDescriptorProto* proto =
1913
+ upb_MethodDef_ToProto(self->methoddef, arena);
1914
+ size_t size;
1915
+ const char* serialized =
1916
+ google_protobuf_MethodDescriptorProto_serialize(proto, arena, &size);
1917
+ VALUE proto_class = rb_path2class("Google::Protobuf::MethodDescriptorProto");
1918
+ VALUE proto_rb =
1919
+ Message_decode_bytes(size, serialized, 0, proto_class, false);
1920
+ upb_Arena_Free(arena);
1921
+ return proto_rb;
1922
+ }
1923
+
1924
+ /*
1925
+ * ruby-doc: MethodDescriptor#server_streaming
1587
1926
  *
1588
1927
  * Returns whether or not this is a streaming response method
1928
+ *
1929
+ * @return [Boolean]
1589
1930
  */
1590
1931
  static VALUE MethodDescriptor_server_streaming(VALUE _self) {
1591
1932
  MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
@@ -1604,6 +1945,7 @@ static void MethodDescriptor_register(VALUE module) {
1604
1945
  0);
1605
1946
  rb_define_method(klass, "server_streaming", MethodDescriptor_server_streaming,
1606
1947
  0);
1948
+ rb_define_method(klass, "to_proto", MethodDescriptor_to_proto, 0);
1607
1949
  rb_gc_register_address(&cMethodDescriptor);
1608
1950
  cMethodDescriptor = klass;
1609
1951
  }