google-protobuf 3.25.8 → 4.32.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/google/protobuf_c/convert.c +33 -15
- data/ext/google/protobuf_c/defs.c +802 -125
- data/ext/google/protobuf_c/extconf.rb +20 -10
- data/ext/google/protobuf_c/glue.c +79 -0
- data/ext/google/protobuf_c/map.c +145 -63
- data/ext/google/protobuf_c/map.h +7 -3
- data/ext/google/protobuf_c/message.c +204 -171
- data/ext/google/protobuf_c/message.h +2 -6
- data/ext/google/protobuf_c/protobuf.c +33 -19
- data/ext/google/protobuf_c/protobuf.h +3 -15
- data/ext/google/protobuf_c/repeated_field.c +130 -58
- data/ext/google/protobuf_c/repeated_field.h +6 -2
- data/ext/google/protobuf_c/ruby-upb.c +10324 -7764
- data/ext/google/protobuf_c/ruby-upb.h +9959 -6442
- data/ext/google/protobuf_c/shared_convert.c +7 -2
- data/ext/google/protobuf_c/shared_message.c +3 -32
- data/ext/google/protobuf_c/shared_message.h +0 -4
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +207 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +9 -8
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_neon.inc +117 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_sse.inc +272 -0
- data/lib/google/protobuf/any_pb.rb +2 -23
- data/lib/google/protobuf/api_pb.rb +3 -26
- data/lib/google/protobuf/descriptor_pb.rb +8 -24
- data/lib/google/protobuf/duration_pb.rb +2 -23
- data/lib/google/protobuf/empty_pb.rb +2 -23
- data/lib/google/protobuf/ffi/descriptor.rb +14 -4
- data/lib/google/protobuf/ffi/descriptor_pool.rb +5 -1
- data/lib/google/protobuf/ffi/enum_descriptor.rb +13 -1
- data/lib/google/protobuf/ffi/ffi.rb +7 -6
- data/lib/google/protobuf/ffi/field_descriptor.rb +29 -2
- data/lib/google/protobuf/ffi/file_descriptor.rb +39 -13
- data/lib/google/protobuf/ffi/internal/arena.rb +0 -6
- data/lib/google/protobuf/ffi/internal/convert.rb +17 -30
- data/lib/google/protobuf/ffi/internal/pointer_helper.rb +2 -1
- data/lib/google/protobuf/ffi/map.rb +52 -26
- data/lib/google/protobuf/ffi/message.rb +188 -67
- data/lib/google/protobuf/ffi/method_descriptor.rb +124 -0
- data/lib/google/protobuf/ffi/object_cache.rb +3 -3
- data/lib/google/protobuf/ffi/oneof_descriptor.rb +13 -1
- data/lib/google/protobuf/ffi/repeated_field.rb +47 -19
- data/lib/google/protobuf/ffi/service_descriptor.rb +117 -0
- data/lib/google/protobuf/field_mask_pb.rb +2 -23
- data/lib/google/protobuf/internal/object_cache.rb +99 -0
- data/lib/google/protobuf/message_exts.rb +4 -0
- data/lib/google/protobuf/plugin_pb.rb +3 -25
- data/lib/google/protobuf/repeated_field.rb +4 -5
- data/lib/google/protobuf/source_context_pb.rb +2 -23
- data/lib/google/protobuf/struct_pb.rb +2 -23
- data/lib/google/protobuf/timestamp_pb.rb +2 -23
- data/lib/google/protobuf/type_pb.rb +2 -25
- data/lib/google/protobuf/wrappers_pb.rb +2 -23
- data/lib/google/protobuf.rb +1 -1
- data/lib/google/protobuf_ffi.rb +6 -4
- data/lib/google/protobuf_native.rb +0 -1
- data/lib/google/tasks/ffi.rake +2 -4
- metadata +36 -22
- data/ext/google/protobuf_c/third_party/utf8_range/naive.c +0 -92
- data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +0 -157
- data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +0 -170
- data/ext/google/protobuf_c/wrap_memcpy.c +0 -29
- data/lib/google/protobuf/descriptor_dsl.rb +0 -465
- data/lib/google/protobuf/object_cache.rb +0 -97
@@ -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"
|
@@ -23,6 +22,9 @@ static VALUE get_enumdef_obj(VALUE descriptor_pool, const upb_EnumDef* def);
|
|
23
22
|
static VALUE get_fielddef_obj(VALUE descriptor_pool, const upb_FieldDef* def);
|
24
23
|
static VALUE get_filedef_obj(VALUE descriptor_pool, const upb_FileDef* def);
|
25
24
|
static VALUE get_oneofdef_obj(VALUE descriptor_pool, const upb_OneofDef* def);
|
25
|
+
static VALUE get_servicedef_obj(VALUE descriptor_pool,
|
26
|
+
const upb_ServiceDef* def);
|
27
|
+
static VALUE get_methoddef_obj(VALUE descriptor_pool, const upb_MethodDef* def);
|
26
28
|
|
27
29
|
// A distinct object that is not accessible from Ruby. We use this as a
|
28
30
|
// constructor argument to enforce that certain objects cannot be created from
|
@@ -91,9 +93,15 @@ const upb_DefPool* DescriptorPool_GetSymtab(VALUE desc_pool_rb) {
|
|
91
93
|
return pool->symtab;
|
92
94
|
}
|
93
95
|
|
96
|
+
/**
|
97
|
+
* ruby-doc: DescriptorPool
|
98
|
+
*
|
99
|
+
* A DescriptorPool is the registry of all known Protobuf descriptor objects.
|
100
|
+
*
|
101
|
+
*/
|
102
|
+
|
94
103
|
/*
|
95
|
-
*
|
96
|
-
* DescriptorPool.new => pool
|
104
|
+
* ruby-doc: DescriptorPool.new
|
97
105
|
*
|
98
106
|
* Creates a new, empty, descriptor pool.
|
99
107
|
*/
|
@@ -110,10 +118,14 @@ static VALUE DescriptorPool_alloc(VALUE klass) {
|
|
110
118
|
}
|
111
119
|
|
112
120
|
/*
|
113
|
-
*
|
114
|
-
*
|
121
|
+
* ruby-doc: DescriptorPool#add_serialized_file
|
122
|
+
*
|
123
|
+
* Adds the given serialized
|
124
|
+
* {https://protobuf.com/docs/descriptors#file-descriptors FileDescriptorProto}
|
125
|
+
* to the pool.
|
115
126
|
*
|
116
|
-
*
|
127
|
+
* @param serialized_file_proto [String]
|
128
|
+
* @return [FileDescriptor]
|
117
129
|
*/
|
118
130
|
VALUE DescriptorPool_add_serialized_file(VALUE _self,
|
119
131
|
VALUE serialized_file_proto) {
|
@@ -141,11 +153,14 @@ VALUE DescriptorPool_add_serialized_file(VALUE _self,
|
|
141
153
|
}
|
142
154
|
|
143
155
|
/*
|
144
|
-
*
|
145
|
-
*
|
156
|
+
* ruby-doc: DescriptorPool#lookup
|
157
|
+
*
|
158
|
+
* Finds a {Descriptor}, {EnumDescriptor},
|
159
|
+
* {FieldDescriptor} or {ServiceDescriptor} by
|
160
|
+
* name and returns it, or nil if none exists with the given name.
|
146
161
|
*
|
147
|
-
*
|
148
|
-
*
|
162
|
+
* @param name [String]
|
163
|
+
* @return [Descriptor,EnumDescriptor,FieldDescriptor,ServiceDescriptor]
|
149
164
|
*/
|
150
165
|
static VALUE DescriptorPool_lookup(VALUE _self, VALUE name) {
|
151
166
|
DescriptorPool* self = ruby_to_DescriptorPool(_self);
|
@@ -153,6 +168,8 @@ static VALUE DescriptorPool_lookup(VALUE _self, VALUE name) {
|
|
153
168
|
const upb_MessageDef* msgdef;
|
154
169
|
const upb_EnumDef* enumdef;
|
155
170
|
const upb_FieldDef* fielddef;
|
171
|
+
const upb_ServiceDef* servicedef;
|
172
|
+
const upb_FileDef* filedef;
|
156
173
|
|
157
174
|
msgdef = upb_DefPool_FindMessageByName(self->symtab, name_str);
|
158
175
|
if (msgdef) {
|
@@ -169,17 +186,28 @@ static VALUE DescriptorPool_lookup(VALUE _self, VALUE name) {
|
|
169
186
|
return get_enumdef_obj(_self, enumdef);
|
170
187
|
}
|
171
188
|
|
189
|
+
servicedef = upb_DefPool_FindServiceByName(self->symtab, name_str);
|
190
|
+
if (servicedef) {
|
191
|
+
return get_servicedef_obj(_self, servicedef);
|
192
|
+
}
|
193
|
+
|
194
|
+
filedef = upb_DefPool_FindFileByName(self->symtab, name_str);
|
195
|
+
if (filedef) {
|
196
|
+
return get_filedef_obj(_self, filedef);
|
197
|
+
}
|
198
|
+
|
172
199
|
return Qnil;
|
173
200
|
}
|
174
201
|
|
175
202
|
/*
|
176
|
-
*
|
177
|
-
*
|
203
|
+
* ruby-doc: DescriptorPool.generated_pool
|
204
|
+
*
|
205
|
+
* Class method that returns the global {DescriptorPool}. This is a singleton
|
206
|
+
* into which generated-code message and enum types are registered. The user may
|
207
|
+
* also register types in this pool for convenience so that they do not have to
|
208
|
+
* hold a reference to a private pool instance.
|
178
209
|
*
|
179
|
-
*
|
180
|
-
* which generated-code message and enum types are registered. The user may also
|
181
|
-
* register types in this pool for convenience so that they do not have to hold
|
182
|
-
* a reference to a private pool instance.
|
210
|
+
* @return [DescriptorPool]
|
183
211
|
*/
|
184
212
|
static VALUE DescriptorPool_generated_pool(VALUE _self) {
|
185
213
|
return generated_pool;
|
@@ -257,14 +285,32 @@ static VALUE decode_options(VALUE self, const char* option_type, int size,
|
|
257
285
|
VALUE desc_rb = get_msgdef_obj(descriptor_pool, msgdef);
|
258
286
|
const Descriptor* desc = ruby_to_Descriptor(desc_rb);
|
259
287
|
|
260
|
-
options_rb = Message_decode_bytes(size, bytes, 0, desc->klass,
|
288
|
+
options_rb = Message_decode_bytes(size, bytes, 0, desc->klass, false);
|
289
|
+
|
290
|
+
// Strip features from the options proto to keep it internal.
|
291
|
+
const upb_MessageDef* decoded_desc = NULL;
|
292
|
+
upb_Message* options = Message_GetMutable(options_rb, &decoded_desc);
|
293
|
+
PBRUBY_ASSERT(options != NULL);
|
294
|
+
PBRUBY_ASSERT(decoded_desc == msgdef);
|
295
|
+
const upb_FieldDef* field =
|
296
|
+
upb_MessageDef_FindFieldByName(decoded_desc, "features");
|
297
|
+
PBRUBY_ASSERT(field != NULL);
|
298
|
+
upb_Message_ClearFieldByDef(options, field);
|
299
|
+
|
300
|
+
Message_freeze(options_rb);
|
301
|
+
|
261
302
|
rb_ivar_set(self, options_instancevar_interned, options_rb);
|
262
303
|
return options_rb;
|
263
304
|
}
|
264
305
|
|
265
306
|
/*
|
266
|
-
*
|
267
|
-
*
|
307
|
+
* ruby-doc: Descriptor
|
308
|
+
*
|
309
|
+
* A Descriptor provides information about a given Protobuf definition.
|
310
|
+
*/
|
311
|
+
|
312
|
+
/*
|
313
|
+
* ruby-doc: Descriptor.initialize
|
268
314
|
*
|
269
315
|
* Creates a new, empty, message type descriptor. At a minimum, its name must be
|
270
316
|
* set before it is added to a pool. It cannot be used to create messages until
|
@@ -302,10 +348,11 @@ static VALUE Descriptor_initialize(VALUE _self, VALUE cookie,
|
|
302
348
|
}
|
303
349
|
|
304
350
|
/*
|
305
|
-
*
|
306
|
-
* Descriptor.file_descriptor
|
351
|
+
* ruby-doc: Descriptor#file_descriptor
|
307
352
|
*
|
308
|
-
* Returns the FileDescriptor object this message belongs to.
|
353
|
+
* Returns the {FileDescriptor} object this message belongs to.
|
354
|
+
*
|
355
|
+
* @return [FileDescriptor]
|
309
356
|
*/
|
310
357
|
static VALUE Descriptor_file_descriptor(VALUE _self) {
|
311
358
|
Descriptor* self = ruby_to_Descriptor(_self);
|
@@ -314,11 +361,12 @@ static VALUE Descriptor_file_descriptor(VALUE _self) {
|
|
314
361
|
}
|
315
362
|
|
316
363
|
/*
|
317
|
-
*
|
318
|
-
* Descriptor.name => name
|
364
|
+
* ruby-doc: Descriptor#name
|
319
365
|
*
|
320
366
|
* Returns the name of this message type as a fully-qualified string (e.g.,
|
321
367
|
* My.Package.MessageType).
|
368
|
+
*
|
369
|
+
* @return [String]
|
322
370
|
*/
|
323
371
|
static VALUE Descriptor_name(VALUE _self) {
|
324
372
|
Descriptor* self = ruby_to_Descriptor(_self);
|
@@ -326,10 +374,12 @@ static VALUE Descriptor_name(VALUE _self) {
|
|
326
374
|
}
|
327
375
|
|
328
376
|
/*
|
329
|
-
*
|
330
|
-
* Descriptor.each(&block)
|
377
|
+
* ruby-doc: Descriptor#each
|
331
378
|
*
|
332
379
|
* Iterates over fields in this message type, yielding to the block on each one.
|
380
|
+
*
|
381
|
+
* @yield [FieldDescriptor]
|
382
|
+
* @return [nil]
|
333
383
|
*/
|
334
384
|
static VALUE Descriptor_each(VALUE _self) {
|
335
385
|
Descriptor* self = ruby_to_Descriptor(_self);
|
@@ -344,11 +394,13 @@ static VALUE Descriptor_each(VALUE _self) {
|
|
344
394
|
}
|
345
395
|
|
346
396
|
/*
|
347
|
-
*
|
348
|
-
* Descriptor.lookup(name) => FieldDescriptor
|
397
|
+
* ruby-doc: Descriptor#lookup
|
349
398
|
*
|
350
399
|
* Returns the field descriptor for the field with the given name, if present,
|
351
400
|
* or nil if none.
|
401
|
+
*
|
402
|
+
* @param name [String]
|
403
|
+
* @return [FieldDescriptor]
|
352
404
|
*/
|
353
405
|
static VALUE Descriptor_lookup(VALUE _self, VALUE name) {
|
354
406
|
Descriptor* self = ruby_to_Descriptor(_self);
|
@@ -361,11 +413,13 @@ static VALUE Descriptor_lookup(VALUE _self, VALUE name) {
|
|
361
413
|
}
|
362
414
|
|
363
415
|
/*
|
364
|
-
*
|
365
|
-
* Descriptor.each_oneof(&block) => nil
|
416
|
+
* ruby-doc: Descriptor#each_oneof
|
366
417
|
*
|
367
418
|
* Invokes the given block for each oneof in this message type, passing the
|
368
|
-
* corresponding OneofDescriptor.
|
419
|
+
* corresponding {OneofDescriptor}.
|
420
|
+
*
|
421
|
+
* @yield [OneofDescriptor]
|
422
|
+
* @return [nil]
|
369
423
|
*/
|
370
424
|
static VALUE Descriptor_each_oneof(VALUE _self) {
|
371
425
|
Descriptor* self = ruby_to_Descriptor(_self);
|
@@ -380,11 +434,13 @@ static VALUE Descriptor_each_oneof(VALUE _self) {
|
|
380
434
|
}
|
381
435
|
|
382
436
|
/*
|
383
|
-
*
|
384
|
-
* Descriptor.lookup_oneof(name) => OneofDescriptor
|
437
|
+
* ruby-doc: Descriptor#lookup_oneof
|
385
438
|
*
|
386
439
|
* Returns the oneof descriptor for the oneof with the given name, if present,
|
387
440
|
* or nil if none.
|
441
|
+
*
|
442
|
+
* @param name [String]
|
443
|
+
* @return [OneofDescriptor]
|
388
444
|
*/
|
389
445
|
static VALUE Descriptor_lookup_oneof(VALUE _self, VALUE name) {
|
390
446
|
Descriptor* self = ruby_to_Descriptor(_self);
|
@@ -397,10 +453,11 @@ static VALUE Descriptor_lookup_oneof(VALUE _self, VALUE name) {
|
|
397
453
|
}
|
398
454
|
|
399
455
|
/*
|
400
|
-
*
|
401
|
-
* Descriptor.msgclass => message_klass
|
456
|
+
* ruby-doc: Descriptor#msgclass
|
402
457
|
*
|
403
458
|
* Returns the Ruby class created for this message type.
|
459
|
+
*
|
460
|
+
* @return [Class<Google::Protobuf::AbstractMessage>]
|
404
461
|
*/
|
405
462
|
static VALUE Descriptor_msgclass(VALUE _self) {
|
406
463
|
Descriptor* self = ruby_to_Descriptor(_self);
|
@@ -411,10 +468,13 @@ static VALUE Descriptor_msgclass(VALUE _self) {
|
|
411
468
|
}
|
412
469
|
|
413
470
|
/*
|
414
|
-
*
|
415
|
-
*
|
471
|
+
* ruby-doc: Descriptor#options
|
472
|
+
*
|
473
|
+
* Returns the
|
474
|
+
* {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L571
|
475
|
+
* MessageOptions} for this {Descriptor}.
|
416
476
|
*
|
417
|
-
*
|
477
|
+
* @return [MessageOptions]
|
418
478
|
*/
|
419
479
|
static VALUE Descriptor_options(VALUE _self) {
|
420
480
|
Descriptor* self = ruby_to_Descriptor(_self);
|
@@ -430,6 +490,30 @@ static VALUE Descriptor_options(VALUE _self) {
|
|
430
490
|
return message_options;
|
431
491
|
}
|
432
492
|
|
493
|
+
/*
|
494
|
+
* ruby-doc: Descriptor#to_proto
|
495
|
+
*
|
496
|
+
* Returns the
|
497
|
+
* {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L147
|
498
|
+
* DescriptorProto} of this {Descriptor}.
|
499
|
+
*
|
500
|
+
* @return [DescriptorProto]
|
501
|
+
*/
|
502
|
+
static VALUE Descriptor_to_proto(VALUE _self) {
|
503
|
+
Descriptor* self = ruby_to_Descriptor(_self);
|
504
|
+
upb_Arena* arena = upb_Arena_New();
|
505
|
+
google_protobuf_DescriptorProto* proto =
|
506
|
+
upb_MessageDef_ToProto(self->msgdef, arena);
|
507
|
+
size_t size;
|
508
|
+
const char* serialized =
|
509
|
+
google_protobuf_DescriptorProto_serialize(proto, arena, &size);
|
510
|
+
VALUE proto_class = rb_path2class("Google::Protobuf::DescriptorProto");
|
511
|
+
VALUE proto_rb =
|
512
|
+
Message_decode_bytes(size, serialized, 0, proto_class, false);
|
513
|
+
upb_Arena_Free(arena);
|
514
|
+
return proto_rb;
|
515
|
+
}
|
516
|
+
|
433
517
|
static void Descriptor_register(VALUE module) {
|
434
518
|
VALUE klass = rb_define_class_under(module, "Descriptor", rb_cObject);
|
435
519
|
rb_define_alloc_func(klass, Descriptor_alloc);
|
@@ -442,6 +526,7 @@ static void Descriptor_register(VALUE module) {
|
|
442
526
|
rb_define_method(klass, "name", Descriptor_name, 0);
|
443
527
|
rb_define_method(klass, "file_descriptor", Descriptor_file_descriptor, 0);
|
444
528
|
rb_define_method(klass, "options", Descriptor_options, 0);
|
529
|
+
rb_define_method(klass, "to_proto", Descriptor_to_proto, 0);
|
445
530
|
rb_include_module(klass, rb_mEnumerable);
|
446
531
|
rb_gc_register_address(&cDescriptor);
|
447
532
|
cDescriptor = klass;
|
@@ -485,11 +570,17 @@ static VALUE FileDescriptor_alloc(VALUE klass) {
|
|
485
570
|
return ret;
|
486
571
|
}
|
487
572
|
|
573
|
+
/**
|
574
|
+
* ruby-doc: FileDescriptor
|
575
|
+
*
|
576
|
+
* A FileDescriptor provides information about all Protobuf definitions in a
|
577
|
+
* particular file.
|
578
|
+
*/
|
579
|
+
|
488
580
|
/*
|
489
|
-
*
|
490
|
-
* FileDescriptor.new => file
|
581
|
+
* ruby-doc: FileDescriptor#initialize
|
491
582
|
*
|
492
|
-
* Returns a new file descriptor.
|
583
|
+
* Returns a new file descriptor. May
|
493
584
|
* to a builder.
|
494
585
|
*/
|
495
586
|
static VALUE FileDescriptor_initialize(VALUE _self, VALUE cookie,
|
@@ -508,10 +599,11 @@ static VALUE FileDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
508
599
|
}
|
509
600
|
|
510
601
|
/*
|
511
|
-
*
|
512
|
-
* FileDescriptor.name => name
|
602
|
+
* ruby-doc: FileDescriptor#name
|
513
603
|
*
|
514
604
|
* Returns the name of the file.
|
605
|
+
*
|
606
|
+
* @return [String]
|
515
607
|
*/
|
516
608
|
static VALUE FileDescriptor_name(VALUE _self) {
|
517
609
|
FileDescriptor* self = ruby_to_FileDescriptor(_self);
|
@@ -520,32 +612,13 @@ static VALUE FileDescriptor_name(VALUE _self) {
|
|
520
612
|
}
|
521
613
|
|
522
614
|
/*
|
523
|
-
*
|
524
|
-
* FileDescriptor.syntax => syntax
|
525
|
-
*
|
526
|
-
* Returns this file descriptors syntax.
|
615
|
+
* ruby-doc: FileDescriptor#options
|
527
616
|
*
|
528
|
-
*
|
529
|
-
*
|
530
|
-
|
531
|
-
static VALUE FileDescriptor_syntax(VALUE _self) {
|
532
|
-
FileDescriptor* self = ruby_to_FileDescriptor(_self);
|
533
|
-
|
534
|
-
switch (upb_FileDef_Syntax(self->filedef)) {
|
535
|
-
case kUpb_Syntax_Proto3:
|
536
|
-
return ID2SYM(rb_intern("proto3"));
|
537
|
-
case kUpb_Syntax_Proto2:
|
538
|
-
return ID2SYM(rb_intern("proto2"));
|
539
|
-
default:
|
540
|
-
return Qnil;
|
541
|
-
}
|
542
|
-
}
|
543
|
-
|
544
|
-
/*
|
545
|
-
* call-seq:
|
546
|
-
* FileDescriptor.options => options
|
617
|
+
* Returns the
|
618
|
+
* {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L442
|
619
|
+
* FileOptions} for this {FileDescriptor}.
|
547
620
|
*
|
548
|
-
*
|
621
|
+
* @return [FileOptions]
|
549
622
|
*/
|
550
623
|
static VALUE FileDescriptor_options(VALUE _self) {
|
551
624
|
FileDescriptor* self = ruby_to_FileDescriptor(_self);
|
@@ -559,13 +632,40 @@ static VALUE FileDescriptor_options(VALUE _self) {
|
|
559
632
|
return file_options;
|
560
633
|
}
|
561
634
|
|
635
|
+
/*
|
636
|
+
* ruby-doc: FileDescriptor#to_proto
|
637
|
+
*
|
638
|
+
* Returns the
|
639
|
+
* {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L104
|
640
|
+
* FileDescriptorProto} of this {FileDescriptor}.
|
641
|
+
*
|
642
|
+
* @return [FileDescriptorProto]
|
643
|
+
*/
|
644
|
+
static VALUE FileDescriptor_to_proto(VALUE _self) {
|
645
|
+
FileDescriptor* self = ruby_to_FileDescriptor(_self);
|
646
|
+
upb_Arena* arena = upb_Arena_New();
|
647
|
+
google_protobuf_FileDescriptorProto* file_proto =
|
648
|
+
upb_FileDef_ToProto(self->filedef, arena);
|
649
|
+
|
650
|
+
size_t size;
|
651
|
+
const char* serialized =
|
652
|
+
google_protobuf_FileDescriptorProto_serialize(file_proto, arena, &size);
|
653
|
+
|
654
|
+
VALUE file_proto_class =
|
655
|
+
rb_path2class("Google::Protobuf::FileDescriptorProto");
|
656
|
+
VALUE proto_rb =
|
657
|
+
Message_decode_bytes(size, serialized, 0, file_proto_class, false);
|
658
|
+
upb_Arena_Free(arena);
|
659
|
+
return proto_rb;
|
660
|
+
}
|
661
|
+
|
562
662
|
static void FileDescriptor_register(VALUE module) {
|
563
663
|
VALUE klass = rb_define_class_under(module, "FileDescriptor", rb_cObject);
|
564
664
|
rb_define_alloc_func(klass, FileDescriptor_alloc);
|
565
665
|
rb_define_method(klass, "initialize", FileDescriptor_initialize, 3);
|
566
666
|
rb_define_method(klass, "name", FileDescriptor_name, 0);
|
567
|
-
rb_define_method(klass, "syntax", FileDescriptor_syntax, 0);
|
568
667
|
rb_define_method(klass, "options", FileDescriptor_options, 0);
|
668
|
+
rb_define_method(klass, "to_proto", FileDescriptor_to_proto, 0);
|
569
669
|
rb_gc_register_address(&cFileDescriptor);
|
570
670
|
cFileDescriptor = klass;
|
571
671
|
}
|
@@ -600,9 +700,15 @@ static FieldDescriptor* ruby_to_FieldDescriptor(VALUE val) {
|
|
600
700
|
return ret;
|
601
701
|
}
|
602
702
|
|
703
|
+
/**
|
704
|
+
* ruby-doc: FieldDescriptor
|
705
|
+
*
|
706
|
+
* A FieldDescriptor provides information about the Protobuf definition of a
|
707
|
+
* field inside a {Descriptor}.
|
708
|
+
*/
|
709
|
+
|
603
710
|
/*
|
604
|
-
*
|
605
|
-
* FieldDescriptor.new => field
|
711
|
+
* ruby-doc: FieldDescriptor#initialize
|
606
712
|
*
|
607
713
|
* Returns a new field descriptor. Its name, type, etc. must be set before it is
|
608
714
|
* added to a message type.
|
@@ -636,10 +742,11 @@ static VALUE FieldDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
636
742
|
}
|
637
743
|
|
638
744
|
/*
|
639
|
-
*
|
640
|
-
* FieldDescriptor.name => name
|
745
|
+
* ruby-doc: FieldDescriptor#name
|
641
746
|
*
|
642
747
|
* Returns the name of this field.
|
748
|
+
*
|
749
|
+
* @return [String]
|
643
750
|
*/
|
644
751
|
static VALUE FieldDescriptor_name(VALUE _self) {
|
645
752
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
@@ -704,14 +811,15 @@ static VALUE descriptortype_to_ruby(upb_FieldType type) {
|
|
704
811
|
}
|
705
812
|
|
706
813
|
/*
|
707
|
-
*
|
708
|
-
* FieldDescriptor.type => type
|
814
|
+
* ruby-doc: FieldDescriptor#type
|
709
815
|
*
|
710
816
|
* Returns this field's type, as a Ruby symbol, or nil if not yet set.
|
711
817
|
*
|
712
818
|
* Valid field types are:
|
713
819
|
* :int32, :int64, :uint32, :uint64, :float, :double, :bool, :string,
|
714
820
|
* :bytes, :message.
|
821
|
+
*
|
822
|
+
* @return [Symbol]
|
715
823
|
*/
|
716
824
|
static VALUE FieldDescriptor__type(VALUE _self) {
|
717
825
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
@@ -719,15 +827,16 @@ static VALUE FieldDescriptor__type(VALUE _self) {
|
|
719
827
|
}
|
720
828
|
|
721
829
|
/*
|
722
|
-
*
|
723
|
-
* FieldDescriptor.default => default
|
830
|
+
* ruby-doc: FieldDescriptor#default
|
724
831
|
*
|
725
832
|
* Returns this field's default, as a Ruby object, or nil if not yet set.
|
833
|
+
*
|
834
|
+
* @return [Object,nil]
|
726
835
|
*/
|
727
836
|
static VALUE FieldDescriptor_default(VALUE _self) {
|
728
837
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
729
838
|
const upb_FieldDef* f = self->fielddef;
|
730
|
-
upb_MessageValue default_val =
|
839
|
+
upb_MessageValue default_val = upb_MessageValue_Zero();
|
731
840
|
if (upb_FieldDef_IsSubMessage(f)) {
|
732
841
|
return Qnil;
|
733
842
|
} else if (!upb_FieldDef_IsRepeated(f)) {
|
@@ -737,10 +846,57 @@ static VALUE FieldDescriptor_default(VALUE _self) {
|
|
737
846
|
}
|
738
847
|
|
739
848
|
/*
|
740
|
-
*
|
741
|
-
*
|
849
|
+
* ruby-doc: FieldDescriptor.has_presence?
|
850
|
+
*
|
851
|
+
* Returns whether this field tracks presence.
|
852
|
+
*
|
853
|
+
* @return [Boolean]
|
854
|
+
*/
|
855
|
+
static VALUE FieldDescriptor_has_presence(VALUE _self) {
|
856
|
+
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
857
|
+
return upb_FieldDef_HasPresence(self->fielddef) ? Qtrue : Qfalse;
|
858
|
+
}
|
859
|
+
|
860
|
+
/*
|
861
|
+
* ruby-doc: FieldDescriptor#required?
|
862
|
+
*
|
863
|
+
* Returns whether this is a required field.
|
864
|
+
*
|
865
|
+
* @return [Boolean]
|
866
|
+
*/
|
867
|
+
static VALUE FieldDescriptor_is_required(VALUE _self) {
|
868
|
+
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
869
|
+
return upb_FieldDef_IsRequired(self->fielddef) ? Qtrue : Qfalse;
|
870
|
+
}
|
871
|
+
|
872
|
+
/*
|
873
|
+
* ruby-doc: FieldDescriptor#repeated?
|
874
|
+
*
|
875
|
+
* Returns whether this is a repeated field.
|
876
|
+
* @return [Boolean]
|
877
|
+
*/
|
878
|
+
static VALUE FieldDescriptor_is_repeated(VALUE _self) {
|
879
|
+
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
880
|
+
return upb_FieldDef_IsRepeated(self->fielddef) ? Qtrue : Qfalse;
|
881
|
+
}
|
882
|
+
|
883
|
+
/*
|
884
|
+
* ruby-doc: FieldDescriptor#is_packed?
|
885
|
+
*
|
886
|
+
* Returns whether this is a repeated field that uses packed encoding.
|
887
|
+
* @return [Boolean]
|
888
|
+
*/
|
889
|
+
static VALUE FieldDescriptor_is_packed(VALUE _self) {
|
890
|
+
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
891
|
+
return upb_FieldDef_IsPacked(self->fielddef) ? Qtrue : Qfalse;
|
892
|
+
}
|
893
|
+
|
894
|
+
/*
|
895
|
+
* ruby-doc: FieldDescriptor#json_name
|
742
896
|
*
|
743
897
|
* Returns this field's json_name, as a Ruby string, or nil if not yet set.
|
898
|
+
*
|
899
|
+
* @return [String,nil]
|
744
900
|
*/
|
745
901
|
static VALUE FieldDescriptor_json_name(VALUE _self) {
|
746
902
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
@@ -750,13 +906,14 @@ static VALUE FieldDescriptor_json_name(VALUE _self) {
|
|
750
906
|
}
|
751
907
|
|
752
908
|
/*
|
753
|
-
*
|
754
|
-
* FieldDescriptor.label => label
|
909
|
+
* ruby-doc: FieldDescriptor#label
|
755
910
|
*
|
756
911
|
* Returns this field's label (i.e., plurality), as a Ruby symbol.
|
757
|
-
*
|
758
912
|
* Valid field labels are:
|
759
|
-
*
|
913
|
+
* :optional, :repeated
|
914
|
+
*
|
915
|
+
* @return [Symbol]
|
916
|
+
* @deprecated Use {#repeated?} or {#required?} instead.
|
760
917
|
*/
|
761
918
|
static VALUE FieldDescriptor_label(VALUE _self) {
|
762
919
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
@@ -776,10 +933,11 @@ static VALUE FieldDescriptor_label(VALUE _self) {
|
|
776
933
|
}
|
777
934
|
|
778
935
|
/*
|
779
|
-
*
|
780
|
-
* FieldDescriptor.number => number
|
936
|
+
* ruby-doc: FieldDescriptor#number
|
781
937
|
*
|
782
938
|
* Returns the tag number for this field.
|
939
|
+
*
|
940
|
+
* @return [Integer]
|
783
941
|
*/
|
784
942
|
static VALUE FieldDescriptor_number(VALUE _self) {
|
785
943
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
@@ -787,13 +945,14 @@ static VALUE FieldDescriptor_number(VALUE _self) {
|
|
787
945
|
}
|
788
946
|
|
789
947
|
/*
|
790
|
-
*
|
791
|
-
* FieldDescriptor.submsg_name => submsg_name
|
948
|
+
* ruby-doc: FieldDescriptor#submsg_name
|
792
949
|
*
|
793
950
|
* Returns the name of the message or enum type corresponding to this field, if
|
794
951
|
* it is a message or enum field (respectively), or nil otherwise. This type
|
795
952
|
* name will be resolved within the context of the pool to which the containing
|
796
953
|
* message type is added.
|
954
|
+
*
|
955
|
+
* @return [String,nil]
|
797
956
|
*/
|
798
957
|
static VALUE FieldDescriptor_submsg_name(VALUE _self) {
|
799
958
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
@@ -810,13 +969,14 @@ static VALUE FieldDescriptor_submsg_name(VALUE _self) {
|
|
810
969
|
}
|
811
970
|
|
812
971
|
/*
|
813
|
-
*
|
814
|
-
* FieldDescriptor.subtype => message_or_enum_descriptor
|
972
|
+
* ruby-doc: FieldDescriptor#subtype
|
815
973
|
*
|
816
974
|
* Returns the message or enum descriptor corresponding to this field's type if
|
817
975
|
* it is a message or enum field, respectively, or nil otherwise. Cannot be
|
818
976
|
* called *until* the containing message type is added to a pool (and thus
|
819
977
|
* resolved).
|
978
|
+
*
|
979
|
+
* @return [Descriptor,EnumDescriptor,nil]
|
820
980
|
*/
|
821
981
|
static VALUE FieldDescriptor_subtype(VALUE _self) {
|
822
982
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
@@ -833,11 +993,13 @@ static VALUE FieldDescriptor_subtype(VALUE _self) {
|
|
833
993
|
}
|
834
994
|
|
835
995
|
/*
|
836
|
-
*
|
837
|
-
* FieldDescriptor.get(message) => value
|
996
|
+
* ruby-doc: FieldDescriptor#get
|
838
997
|
*
|
839
998
|
* Returns the value set for this field on the given message. Raises an
|
840
999
|
* exception if message is of the wrong type.
|
1000
|
+
*
|
1001
|
+
* @param message [AbstractMessage]
|
1002
|
+
* @return [Object]
|
841
1003
|
*/
|
842
1004
|
static VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) {
|
843
1005
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
@@ -853,11 +1015,13 @@ static VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) {
|
|
853
1015
|
}
|
854
1016
|
|
855
1017
|
/*
|
856
|
-
*
|
857
|
-
* FieldDescriptor.has?(message) => boolean
|
1018
|
+
* ruby-doc: FieldDescriptor.has?
|
858
1019
|
*
|
859
1020
|
* Returns whether the value is set on the given message. Raises an
|
860
1021
|
* exception when calling for fields that do not have presence.
|
1022
|
+
*
|
1023
|
+
* @param message [AbstractMessage]
|
1024
|
+
* @return [Boolean]
|
861
1025
|
*/
|
862
1026
|
static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
|
863
1027
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
@@ -874,10 +1038,12 @@ static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
|
|
874
1038
|
}
|
875
1039
|
|
876
1040
|
/*
|
877
|
-
*
|
878
|
-
* FieldDescriptor.clear(message)
|
1041
|
+
* ruby-doc: FieldDescriptor#clear
|
879
1042
|
*
|
880
1043
|
* Clears the field from the message if it's set.
|
1044
|
+
*
|
1045
|
+
* @param message [AbstractMessage]
|
1046
|
+
* @return [nil]
|
881
1047
|
*/
|
882
1048
|
static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
|
883
1049
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
@@ -893,12 +1059,14 @@ static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
|
|
893
1059
|
}
|
894
1060
|
|
895
1061
|
/*
|
896
|
-
*
|
897
|
-
* FieldDescriptor.set(message, value)
|
1062
|
+
* ruby-doc: FieldDescriptor#set
|
898
1063
|
*
|
899
1064
|
* Sets the value corresponding to this field to the given value on the given
|
900
1065
|
* message. Raises an exception if message is of the wrong type. Performs the
|
901
1066
|
* ordinary type-checks for field setting.
|
1067
|
+
*
|
1068
|
+
* @param message [AbstractMessage]
|
1069
|
+
* @param value [Object]
|
902
1070
|
*/
|
903
1071
|
static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) {
|
904
1072
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
@@ -918,10 +1086,13 @@ static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) {
|
|
918
1086
|
}
|
919
1087
|
|
920
1088
|
/*
|
921
|
-
*
|
922
|
-
*
|
1089
|
+
* ruby-doc: FieldDescriptor#options
|
1090
|
+
*
|
1091
|
+
* Returns the
|
1092
|
+
* {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L656
|
1093
|
+
* FieldOptions} for this {FieldDescriptor}.
|
923
1094
|
*
|
924
|
-
*
|
1095
|
+
* @return [FieldOptions]
|
925
1096
|
*/
|
926
1097
|
static VALUE FieldDescriptor_options(VALUE _self) {
|
927
1098
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
@@ -936,6 +1107,30 @@ static VALUE FieldDescriptor_options(VALUE _self) {
|
|
936
1107
|
return field_options;
|
937
1108
|
}
|
938
1109
|
|
1110
|
+
/*
|
1111
|
+
* ruby-doc: FieldDescriptor#to_proto
|
1112
|
+
*
|
1113
|
+
* Returns the
|
1114
|
+
* {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L236
|
1115
|
+
* FieldDescriptorProto} of this {FieldDescriptor}.
|
1116
|
+
*
|
1117
|
+
* @return [FieldDescriptorProto]
|
1118
|
+
*/
|
1119
|
+
static VALUE FieldDescriptor_to_proto(VALUE _self) {
|
1120
|
+
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
1121
|
+
upb_Arena* arena = upb_Arena_New();
|
1122
|
+
google_protobuf_FieldDescriptorProto* proto =
|
1123
|
+
upb_FieldDef_ToProto(self->fielddef, arena);
|
1124
|
+
size_t size;
|
1125
|
+
const char* serialized =
|
1126
|
+
google_protobuf_FieldDescriptorProto_serialize(proto, arena, &size);
|
1127
|
+
VALUE proto_class = rb_path2class("Google::Protobuf::FieldDescriptorProto");
|
1128
|
+
VALUE proto_rb =
|
1129
|
+
Message_decode_bytes(size, serialized, 0, proto_class, false);
|
1130
|
+
upb_Arena_Free(arena);
|
1131
|
+
return proto_rb;
|
1132
|
+
}
|
1133
|
+
|
939
1134
|
static void FieldDescriptor_register(VALUE module) {
|
940
1135
|
VALUE klass = rb_define_class_under(module, "FieldDescriptor", rb_cObject);
|
941
1136
|
rb_define_alloc_func(klass, FieldDescriptor_alloc);
|
@@ -943,6 +1138,10 @@ static void FieldDescriptor_register(VALUE module) {
|
|
943
1138
|
rb_define_method(klass, "name", FieldDescriptor_name, 0);
|
944
1139
|
rb_define_method(klass, "type", FieldDescriptor__type, 0);
|
945
1140
|
rb_define_method(klass, "default", FieldDescriptor_default, 0);
|
1141
|
+
rb_define_method(klass, "has_presence?", FieldDescriptor_has_presence, 0);
|
1142
|
+
rb_define_method(klass, "required?", FieldDescriptor_is_required, 0);
|
1143
|
+
rb_define_method(klass, "repeated?", FieldDescriptor_is_repeated, 0);
|
1144
|
+
rb_define_method(klass, "is_packed?", FieldDescriptor_is_packed, 0);
|
946
1145
|
rb_define_method(klass, "json_name", FieldDescriptor_json_name, 0);
|
947
1146
|
rb_define_method(klass, "label", FieldDescriptor_label, 0);
|
948
1147
|
rb_define_method(klass, "number", FieldDescriptor_number, 0);
|
@@ -953,6 +1152,7 @@ static void FieldDescriptor_register(VALUE module) {
|
|
953
1152
|
rb_define_method(klass, "get", FieldDescriptor_get, 1);
|
954
1153
|
rb_define_method(klass, "set", FieldDescriptor_set, 2);
|
955
1154
|
rb_define_method(klass, "options", FieldDescriptor_options, 0);
|
1155
|
+
rb_define_method(klass, "to_proto", FieldDescriptor_to_proto, 0);
|
956
1156
|
rb_gc_register_address(&cFieldDescriptor);
|
957
1157
|
cFieldDescriptor = klass;
|
958
1158
|
}
|
@@ -987,9 +1187,15 @@ static OneofDescriptor* ruby_to_OneofDescriptor(VALUE val) {
|
|
987
1187
|
return ret;
|
988
1188
|
}
|
989
1189
|
|
1190
|
+
/**
|
1191
|
+
* ruby-doc: OneofDescriptor
|
1192
|
+
*
|
1193
|
+
* A OneofDescriptor provides information about the Protobuf definition of a
|
1194
|
+
* oneof inside a {Descriptor}.
|
1195
|
+
*/
|
1196
|
+
|
990
1197
|
/*
|
991
|
-
*
|
992
|
-
* OneofDescriptor.new => oneof_descriptor
|
1198
|
+
* ruby-doc: OneofDescriptor#initialize
|
993
1199
|
*
|
994
1200
|
* Creates a new, empty, oneof descriptor. The oneof may only be modified prior
|
995
1201
|
* to being added to a message descriptor which is subsequently added to a pool.
|
@@ -1024,10 +1230,11 @@ static VALUE OneofDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
1024
1230
|
}
|
1025
1231
|
|
1026
1232
|
/*
|
1027
|
-
*
|
1028
|
-
* OneofDescriptor.name => name
|
1233
|
+
* ruby-doc: OneofDescriptor#name
|
1029
1234
|
*
|
1030
1235
|
* Returns the name of this oneof.
|
1236
|
+
*
|
1237
|
+
* @return [String]
|
1031
1238
|
*/
|
1032
1239
|
static VALUE OneofDescriptor_name(VALUE _self) {
|
1033
1240
|
OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
|
@@ -1035,10 +1242,12 @@ static VALUE OneofDescriptor_name(VALUE _self) {
|
|
1035
1242
|
}
|
1036
1243
|
|
1037
1244
|
/*
|
1038
|
-
*
|
1039
|
-
* OneofDescriptor.each(&block) => nil
|
1245
|
+
* ruby-doc: OneofDescriptor#each
|
1040
1246
|
*
|
1041
1247
|
* Iterates through fields in this oneof, yielding to the block on each one.
|
1248
|
+
*
|
1249
|
+
* @yield [FieldDescriptor]
|
1250
|
+
* @return [nil]
|
1042
1251
|
*/
|
1043
1252
|
static VALUE OneofDescriptor_each(VALUE _self) {
|
1044
1253
|
OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
|
@@ -1053,10 +1262,13 @@ static VALUE OneofDescriptor_each(VALUE _self) {
|
|
1053
1262
|
}
|
1054
1263
|
|
1055
1264
|
/*
|
1056
|
-
*
|
1057
|
-
* OneofDescriptor.options => options
|
1265
|
+
* ruby-doc: OneofDescriptor#options
|
1058
1266
|
*
|
1059
|
-
* Returns the
|
1267
|
+
* Returns the
|
1268
|
+
* {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L824
|
1269
|
+
* OneofOptions} for this {OneofDescriptor}.
|
1270
|
+
*
|
1271
|
+
* @return [OneofOptions]
|
1060
1272
|
*/
|
1061
1273
|
static VALUE OneOfDescriptor_options(VALUE _self) {
|
1062
1274
|
OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
|
@@ -1071,6 +1283,30 @@ static VALUE OneOfDescriptor_options(VALUE _self) {
|
|
1071
1283
|
return oneof_options;
|
1072
1284
|
}
|
1073
1285
|
|
1286
|
+
/*
|
1287
|
+
* ruby-doc: OneofDescriptor#to_proto
|
1288
|
+
*
|
1289
|
+
* Returns the
|
1290
|
+
* {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L343
|
1291
|
+
* OneofDescriptorProto} of this {OneofDescriptor}.
|
1292
|
+
*
|
1293
|
+
* @return [OneofDescriptorProto]
|
1294
|
+
*/
|
1295
|
+
static VALUE OneOfDescriptor_to_proto(VALUE _self) {
|
1296
|
+
OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
|
1297
|
+
upb_Arena* arena = upb_Arena_New();
|
1298
|
+
google_protobuf_OneofDescriptorProto* proto =
|
1299
|
+
upb_OneofDef_ToProto(self->oneofdef, arena);
|
1300
|
+
size_t size;
|
1301
|
+
const char* serialized =
|
1302
|
+
google_protobuf_OneofDescriptorProto_serialize(proto, arena, &size);
|
1303
|
+
VALUE proto_class = rb_path2class("Google::Protobuf::OneofDescriptorProto");
|
1304
|
+
VALUE proto_rb =
|
1305
|
+
Message_decode_bytes(size, serialized, 0, proto_class, false);
|
1306
|
+
upb_Arena_Free(arena);
|
1307
|
+
return proto_rb;
|
1308
|
+
}
|
1309
|
+
|
1074
1310
|
static void OneofDescriptor_register(VALUE module) {
|
1075
1311
|
VALUE klass = rb_define_class_under(module, "OneofDescriptor", rb_cObject);
|
1076
1312
|
rb_define_alloc_func(klass, OneofDescriptor_alloc);
|
@@ -1078,6 +1314,7 @@ static void OneofDescriptor_register(VALUE module) {
|
|
1078
1314
|
rb_define_method(klass, "name", OneofDescriptor_name, 0);
|
1079
1315
|
rb_define_method(klass, "each", OneofDescriptor_each, 0);
|
1080
1316
|
rb_define_method(klass, "options", OneOfDescriptor_options, 0);
|
1317
|
+
rb_define_method(klass, "to_proto", OneOfDescriptor_to_proto, 0);
|
1081
1318
|
rb_include_module(klass, rb_mEnumerable);
|
1082
1319
|
rb_gc_register_address(&cOneofDescriptor);
|
1083
1320
|
cOneofDescriptor = klass;
|
@@ -1130,6 +1367,13 @@ const upb_EnumDef* EnumDescriptor_GetEnumDef(VALUE enum_desc_rb) {
|
|
1130
1367
|
return desc->enumdef;
|
1131
1368
|
}
|
1132
1369
|
|
1370
|
+
/**
|
1371
|
+
* ruby-doc: EnumDescriptor
|
1372
|
+
*
|
1373
|
+
* An EnumDescriptor provides information about the Protobuf definition of an
|
1374
|
+
* enum inside a {Descriptor}.
|
1375
|
+
*/
|
1376
|
+
|
1133
1377
|
/*
|
1134
1378
|
* call-seq:
|
1135
1379
|
* EnumDescriptor.new(c_only_cookie, ptr) => EnumDescriptor
|
@@ -1152,10 +1396,11 @@ static VALUE EnumDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
1152
1396
|
}
|
1153
1397
|
|
1154
1398
|
/*
|
1155
|
-
*
|
1156
|
-
* EnumDescriptor.file_descriptor
|
1399
|
+
* ruby-doc: EnumDescriptor#file_descriptor
|
1157
1400
|
*
|
1158
|
-
* Returns the FileDescriptor object this enum belongs to.
|
1401
|
+
* Returns the {FileDescriptor} object this enum belongs to.
|
1402
|
+
*
|
1403
|
+
* @return [FileDescriptor]
|
1159
1404
|
*/
|
1160
1405
|
static VALUE EnumDescriptor_file_descriptor(VALUE _self) {
|
1161
1406
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
@@ -1164,10 +1409,23 @@ static VALUE EnumDescriptor_file_descriptor(VALUE _self) {
|
|
1164
1409
|
}
|
1165
1410
|
|
1166
1411
|
/*
|
1167
|
-
*
|
1168
|
-
*
|
1412
|
+
* ruby-doc: EnumDescriptor#is_closed?
|
1413
|
+
*
|
1414
|
+
* Returns whether this enum is open or closed.
|
1415
|
+
*
|
1416
|
+
* @return [Boolean]
|
1417
|
+
*/
|
1418
|
+
static VALUE EnumDescriptor_is_closed(VALUE _self) {
|
1419
|
+
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
1420
|
+
return upb_EnumDef_IsClosed(self->enumdef) ? Qtrue : Qfalse;
|
1421
|
+
}
|
1422
|
+
|
1423
|
+
/*
|
1424
|
+
* ruby-doc: EnumDescriptor#name
|
1169
1425
|
*
|
1170
1426
|
* Returns the name of this enum type.
|
1427
|
+
*
|
1428
|
+
* @return [String]
|
1171
1429
|
*/
|
1172
1430
|
static VALUE EnumDescriptor_name(VALUE _self) {
|
1173
1431
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
@@ -1175,11 +1433,13 @@ static VALUE EnumDescriptor_name(VALUE _self) {
|
|
1175
1433
|
}
|
1176
1434
|
|
1177
1435
|
/*
|
1178
|
-
*
|
1179
|
-
* EnumDescriptor.lookup_name(name) => value
|
1436
|
+
* ruby-doc: EnumDescriptor#lookup_name
|
1180
1437
|
*
|
1181
1438
|
* Returns the numeric value corresponding to the given key name (as a Ruby
|
1182
1439
|
* symbol), or nil if none.
|
1440
|
+
*
|
1441
|
+
* @param name [Symbol]
|
1442
|
+
* @return [Integer,nil]
|
1183
1443
|
*/
|
1184
1444
|
static VALUE EnumDescriptor_lookup_name(VALUE _self, VALUE name) {
|
1185
1445
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
@@ -1194,11 +1454,13 @@ static VALUE EnumDescriptor_lookup_name(VALUE _self, VALUE name) {
|
|
1194
1454
|
}
|
1195
1455
|
|
1196
1456
|
/*
|
1197
|
-
*
|
1198
|
-
* EnumDescriptor.lookup_value(name) => value
|
1457
|
+
* ruby-doc: EnumDescriptor#lookup_value
|
1199
1458
|
*
|
1200
1459
|
* Returns the key name (as a Ruby symbol) corresponding to the integer value,
|
1201
1460
|
* or nil if none.
|
1461
|
+
*
|
1462
|
+
* @param name [Integer]
|
1463
|
+
* @return [Symbol,nil]
|
1202
1464
|
*/
|
1203
1465
|
static VALUE EnumDescriptor_lookup_value(VALUE _self, VALUE number) {
|
1204
1466
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
@@ -1213,11 +1475,13 @@ static VALUE EnumDescriptor_lookup_value(VALUE _self, VALUE number) {
|
|
1213
1475
|
}
|
1214
1476
|
|
1215
1477
|
/*
|
1216
|
-
*
|
1217
|
-
* EnumDescriptor.each(&block)
|
1478
|
+
* ruby-doc: EnumDescriptor#each
|
1218
1479
|
*
|
1219
1480
|
* Iterates over key => value mappings in this enum's definition, yielding to
|
1220
1481
|
* the block with (key, value) arguments for each one.
|
1482
|
+
*
|
1483
|
+
* @yield [Symbol, Integer]
|
1484
|
+
* @return [nil]
|
1221
1485
|
*/
|
1222
1486
|
static VALUE EnumDescriptor_each(VALUE _self) {
|
1223
1487
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
@@ -1234,10 +1498,11 @@ static VALUE EnumDescriptor_each(VALUE _self) {
|
|
1234
1498
|
}
|
1235
1499
|
|
1236
1500
|
/*
|
1237
|
-
*
|
1238
|
-
* EnumDescriptor.enummodule => module
|
1501
|
+
* ruby-doc: EnumDescriptor#enummodule
|
1239
1502
|
*
|
1240
1503
|
* Returns the Ruby module corresponding to this enum type.
|
1504
|
+
*
|
1505
|
+
* @return [Module]
|
1241
1506
|
*/
|
1242
1507
|
static VALUE EnumDescriptor_enummodule(VALUE _self) {
|
1243
1508
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
@@ -1248,10 +1513,13 @@ static VALUE EnumDescriptor_enummodule(VALUE _self) {
|
|
1248
1513
|
}
|
1249
1514
|
|
1250
1515
|
/*
|
1251
|
-
*
|
1252
|
-
*
|
1516
|
+
* ruby-doc: EnumDescriptor#options
|
1517
|
+
*
|
1518
|
+
* Returns the
|
1519
|
+
* {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L838
|
1520
|
+
* EnumOptions} for this {EnumDescriptor}.
|
1253
1521
|
*
|
1254
|
-
*
|
1522
|
+
* @return [EnumOptions]
|
1255
1523
|
*/
|
1256
1524
|
static VALUE EnumDescriptor_options(VALUE _self) {
|
1257
1525
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
@@ -1265,6 +1533,31 @@ static VALUE EnumDescriptor_options(VALUE _self) {
|
|
1265
1533
|
return enum_options;
|
1266
1534
|
}
|
1267
1535
|
|
1536
|
+
/*
|
1537
|
+
* ruby-doc: EnumDescriptor#to_proto
|
1538
|
+
*
|
1539
|
+
* Returns the
|
1540
|
+
* {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L349
|
1541
|
+
* EnumDescriptorProto} of this {EnumDescriptor}.
|
1542
|
+
* @return [EnumDescriptorProto]
|
1543
|
+
*/
|
1544
|
+
static VALUE EnumDescriptor_to_proto(VALUE _self) {
|
1545
|
+
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
1546
|
+
upb_Arena* arena = upb_Arena_New();
|
1547
|
+
google_protobuf_EnumDescriptorProto* proto =
|
1548
|
+
upb_EnumDef_ToProto(self->enumdef, arena);
|
1549
|
+
|
1550
|
+
size_t size;
|
1551
|
+
const char* serialized =
|
1552
|
+
google_protobuf_EnumDescriptorProto_serialize(proto, arena, &size);
|
1553
|
+
|
1554
|
+
VALUE proto_class = rb_path2class("Google::Protobuf::EnumDescriptorProto");
|
1555
|
+
VALUE proto_rb =
|
1556
|
+
Message_decode_bytes(size, serialized, 0, proto_class, false);
|
1557
|
+
upb_Arena_Free(arena);
|
1558
|
+
return proto_rb;
|
1559
|
+
}
|
1560
|
+
|
1268
1561
|
static void EnumDescriptor_register(VALUE module) {
|
1269
1562
|
VALUE klass = rb_define_class_under(module, "EnumDescriptor", rb_cObject);
|
1270
1563
|
rb_define_alloc_func(klass, EnumDescriptor_alloc);
|
@@ -1275,12 +1568,384 @@ static void EnumDescriptor_register(VALUE module) {
|
|
1275
1568
|
rb_define_method(klass, "each", EnumDescriptor_each, 0);
|
1276
1569
|
rb_define_method(klass, "enummodule", EnumDescriptor_enummodule, 0);
|
1277
1570
|
rb_define_method(klass, "file_descriptor", EnumDescriptor_file_descriptor, 0);
|
1571
|
+
rb_define_method(klass, "is_closed?", EnumDescriptor_is_closed, 0);
|
1278
1572
|
rb_define_method(klass, "options", EnumDescriptor_options, 0);
|
1573
|
+
rb_define_method(klass, "to_proto", EnumDescriptor_to_proto, 0);
|
1279
1574
|
rb_include_module(klass, rb_mEnumerable);
|
1280
1575
|
rb_gc_register_address(&cEnumDescriptor);
|
1281
1576
|
cEnumDescriptor = klass;
|
1282
1577
|
}
|
1283
1578
|
|
1579
|
+
// -----------------------------------------------------------------------------
|
1580
|
+
// ServiceDescriptor
|
1581
|
+
// -----------------------------------------------------------------------------
|
1582
|
+
|
1583
|
+
typedef struct {
|
1584
|
+
const upb_ServiceDef* servicedef;
|
1585
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
1586
|
+
// macro to update VALUE references, as to trigger write barriers.
|
1587
|
+
VALUE module; // begins as nil
|
1588
|
+
VALUE descriptor_pool; // Owns the upb_ServiceDef.
|
1589
|
+
} ServiceDescriptor;
|
1590
|
+
|
1591
|
+
static VALUE cServiceDescriptor = Qnil;
|
1592
|
+
|
1593
|
+
static void ServiceDescriptor_mark(void* _self) {
|
1594
|
+
ServiceDescriptor* self = _self;
|
1595
|
+
rb_gc_mark(self->module);
|
1596
|
+
rb_gc_mark(self->descriptor_pool);
|
1597
|
+
}
|
1598
|
+
|
1599
|
+
static const rb_data_type_t ServiceDescriptor_type = {
|
1600
|
+
"Google::Protobuf::ServicDescriptor",
|
1601
|
+
{ServiceDescriptor_mark, RUBY_DEFAULT_FREE, NULL},
|
1602
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
1603
|
+
};
|
1604
|
+
|
1605
|
+
static ServiceDescriptor* ruby_to_ServiceDescriptor(VALUE val) {
|
1606
|
+
ServiceDescriptor* ret;
|
1607
|
+
TypedData_Get_Struct(val, ServiceDescriptor, &ServiceDescriptor_type, ret);
|
1608
|
+
return ret;
|
1609
|
+
}
|
1610
|
+
|
1611
|
+
static VALUE ServiceDescriptor_alloc(VALUE klass) {
|
1612
|
+
ServiceDescriptor* self = ALLOC(ServiceDescriptor);
|
1613
|
+
VALUE ret = TypedData_Wrap_Struct(klass, &ServiceDescriptor_type, self);
|
1614
|
+
self->servicedef = NULL;
|
1615
|
+
self->module = Qnil;
|
1616
|
+
self->descriptor_pool = Qnil;
|
1617
|
+
return ret;
|
1618
|
+
}
|
1619
|
+
|
1620
|
+
/**
|
1621
|
+
* ruby-doc: ServiceDescriptor
|
1622
|
+
*
|
1623
|
+
* A ServiceDescriptor provides information about the Protobuf definition of an
|
1624
|
+
* RPC service.
|
1625
|
+
*/
|
1626
|
+
|
1627
|
+
/*
|
1628
|
+
* call-seq:
|
1629
|
+
* ServiceDescriptor.new(c_only_cookie, ptr) => ServiceDescriptor
|
1630
|
+
*
|
1631
|
+
* Creates a descriptor wrapper object. May only be called from C.
|
1632
|
+
*/
|
1633
|
+
static VALUE ServiceDescriptor_initialize(VALUE _self, VALUE cookie,
|
1634
|
+
VALUE descriptor_pool, VALUE ptr) {
|
1635
|
+
ServiceDescriptor* self = ruby_to_ServiceDescriptor(_self);
|
1636
|
+
|
1637
|
+
if (cookie != c_only_cookie) {
|
1638
|
+
rb_raise(rb_eRuntimeError,
|
1639
|
+
"Descriptor objects may not be created from Ruby.");
|
1640
|
+
}
|
1641
|
+
|
1642
|
+
RB_OBJ_WRITE(_self, &self->descriptor_pool, descriptor_pool);
|
1643
|
+
self->servicedef = (const upb_ServiceDef*)NUM2ULL(ptr);
|
1644
|
+
|
1645
|
+
return Qnil;
|
1646
|
+
}
|
1647
|
+
|
1648
|
+
/*
|
1649
|
+
* ruby-doc: ServiceDescriptor#name
|
1650
|
+
*
|
1651
|
+
* Returns the name of this service.
|
1652
|
+
*
|
1653
|
+
* @return [String]
|
1654
|
+
*/
|
1655
|
+
static VALUE ServiceDescriptor_name(VALUE _self) {
|
1656
|
+
ServiceDescriptor* self = ruby_to_ServiceDescriptor(_self);
|
1657
|
+
return rb_str_maybe_null(upb_ServiceDef_FullName(self->servicedef));
|
1658
|
+
}
|
1659
|
+
|
1660
|
+
/*
|
1661
|
+
* ruby-doc: ServiceDescriptor#file_descriptor
|
1662
|
+
*
|
1663
|
+
* Returns the {FileDescriptor} object this service belongs to.
|
1664
|
+
* @return [FileDescriptor]
|
1665
|
+
*/
|
1666
|
+
static VALUE ServiceDescriptor_file_descriptor(VALUE _self) {
|
1667
|
+
ServiceDescriptor* self = ruby_to_ServiceDescriptor(_self);
|
1668
|
+
return get_filedef_obj(self->descriptor_pool,
|
1669
|
+
upb_ServiceDef_File(self->servicedef));
|
1670
|
+
}
|
1671
|
+
|
1672
|
+
/*
|
1673
|
+
* ruby-doc: ServiceDescriptor#each
|
1674
|
+
*
|
1675
|
+
* Iterates over methods in this service, yielding to the block on each one.
|
1676
|
+
*
|
1677
|
+
* @yield [MethodDescriptor]
|
1678
|
+
* @return [nil]
|
1679
|
+
*/
|
1680
|
+
static VALUE ServiceDescriptor_each(VALUE _self) {
|
1681
|
+
ServiceDescriptor* self = ruby_to_ServiceDescriptor(_self);
|
1682
|
+
|
1683
|
+
int n = upb_ServiceDef_MethodCount(self->servicedef);
|
1684
|
+
for (int i = 0; i < n; i++) {
|
1685
|
+
const upb_MethodDef* method = upb_ServiceDef_Method(self->servicedef, i);
|
1686
|
+
VALUE obj = get_methoddef_obj(self->descriptor_pool, method);
|
1687
|
+
rb_yield(obj);
|
1688
|
+
}
|
1689
|
+
return Qnil;
|
1690
|
+
}
|
1691
|
+
|
1692
|
+
/*
|
1693
|
+
* ruby-doc: ServiceDescriptor#options
|
1694
|
+
*
|
1695
|
+
* Returns the
|
1696
|
+
* {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L901
|
1697
|
+
* ServiceOptions} for this {ServiceDescriptor}.
|
1698
|
+
*
|
1699
|
+
* @return [ServiceOptions]
|
1700
|
+
*/
|
1701
|
+
static VALUE ServiceDescriptor_options(VALUE _self) {
|
1702
|
+
ServiceDescriptor* self = ruby_to_ServiceDescriptor(_self);
|
1703
|
+
const google_protobuf_ServiceOptions* opts =
|
1704
|
+
upb_ServiceDef_Options(self->servicedef);
|
1705
|
+
upb_Arena* arena = upb_Arena_New();
|
1706
|
+
size_t size;
|
1707
|
+
char* serialized =
|
1708
|
+
google_protobuf_ServiceOptions_serialize(opts, arena, &size);
|
1709
|
+
VALUE service_options = decode_options(_self, "ServiceOptions", size,
|
1710
|
+
serialized, self->descriptor_pool);
|
1711
|
+
upb_Arena_Free(arena);
|
1712
|
+
return service_options;
|
1713
|
+
}
|
1714
|
+
|
1715
|
+
/*
|
1716
|
+
* ruby-doc: ServiceDescriptor#to_proto
|
1717
|
+
*
|
1718
|
+
* Returns the
|
1719
|
+
* {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L386
|
1720
|
+
* ServiceDescriptorProto} of this {ServiceDescriptor}.
|
1721
|
+
*
|
1722
|
+
* @return [ServiceDescriptorProto]
|
1723
|
+
*/
|
1724
|
+
static VALUE ServiceDescriptor_to_proto(VALUE _self) {
|
1725
|
+
ServiceDescriptor* self = ruby_to_ServiceDescriptor(_self);
|
1726
|
+
upb_Arena* arena = upb_Arena_New();
|
1727
|
+
google_protobuf_ServiceDescriptorProto* proto =
|
1728
|
+
upb_ServiceDef_ToProto(self->servicedef, arena);
|
1729
|
+
size_t size;
|
1730
|
+
const char* serialized =
|
1731
|
+
google_protobuf_ServiceDescriptorProto_serialize(proto, arena, &size);
|
1732
|
+
VALUE proto_class = rb_path2class("Google::Protobuf::ServiceDescriptorProto");
|
1733
|
+
VALUE proto_rb =
|
1734
|
+
Message_decode_bytes(size, serialized, 0, proto_class, false);
|
1735
|
+
upb_Arena_Free(arena);
|
1736
|
+
return proto_rb;
|
1737
|
+
}
|
1738
|
+
|
1739
|
+
static void ServiceDescriptor_register(VALUE module) {
|
1740
|
+
VALUE klass = rb_define_class_under(module, "ServiceDescriptor", rb_cObject);
|
1741
|
+
rb_define_alloc_func(klass, ServiceDescriptor_alloc);
|
1742
|
+
rb_define_method(klass, "initialize", ServiceDescriptor_initialize, 3);
|
1743
|
+
rb_define_method(klass, "name", ServiceDescriptor_name, 0);
|
1744
|
+
rb_define_method(klass, "each", ServiceDescriptor_each, 0);
|
1745
|
+
rb_define_method(klass, "file_descriptor", ServiceDescriptor_file_descriptor,
|
1746
|
+
0);
|
1747
|
+
rb_define_method(klass, "options", ServiceDescriptor_options, 0);
|
1748
|
+
rb_define_method(klass, "to_proto", ServiceDescriptor_to_proto, 0);
|
1749
|
+
rb_include_module(klass, rb_mEnumerable);
|
1750
|
+
rb_gc_register_address(&cServiceDescriptor);
|
1751
|
+
cServiceDescriptor = klass;
|
1752
|
+
}
|
1753
|
+
|
1754
|
+
// -----------------------------------------------------------------------------
|
1755
|
+
// MethodDescriptor
|
1756
|
+
// -----------------------------------------------------------------------------
|
1757
|
+
|
1758
|
+
typedef struct {
|
1759
|
+
const upb_MethodDef* methoddef;
|
1760
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
1761
|
+
// macro to update VALUE references, as to trigger write barriers.
|
1762
|
+
VALUE module; // begins as nil
|
1763
|
+
VALUE descriptor_pool; // Owns the upb_MethodDef.
|
1764
|
+
} MethodDescriptor;
|
1765
|
+
|
1766
|
+
static VALUE cMethodDescriptor = Qnil;
|
1767
|
+
|
1768
|
+
static void MethodDescriptor_mark(void* _self) {
|
1769
|
+
MethodDescriptor* self = _self;
|
1770
|
+
rb_gc_mark(self->module);
|
1771
|
+
rb_gc_mark(self->descriptor_pool);
|
1772
|
+
}
|
1773
|
+
|
1774
|
+
static const rb_data_type_t MethodDescriptor_type = {
|
1775
|
+
"Google::Protobuf::MethodDescriptor",
|
1776
|
+
{MethodDescriptor_mark, RUBY_DEFAULT_FREE, NULL},
|
1777
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
1778
|
+
};
|
1779
|
+
|
1780
|
+
static MethodDescriptor* ruby_to_MethodDescriptor(VALUE val) {
|
1781
|
+
MethodDescriptor* ret;
|
1782
|
+
TypedData_Get_Struct(val, MethodDescriptor, &MethodDescriptor_type, ret);
|
1783
|
+
return ret;
|
1784
|
+
}
|
1785
|
+
|
1786
|
+
static VALUE MethodDescriptor_alloc(VALUE klass) {
|
1787
|
+
MethodDescriptor* self = ALLOC(MethodDescriptor);
|
1788
|
+
VALUE ret = TypedData_Wrap_Struct(klass, &MethodDescriptor_type, self);
|
1789
|
+
self->methoddef = NULL;
|
1790
|
+
self->module = Qnil;
|
1791
|
+
self->descriptor_pool = Qnil;
|
1792
|
+
return ret;
|
1793
|
+
}
|
1794
|
+
|
1795
|
+
/**
|
1796
|
+
* ruby-doc: MethodDescriptor
|
1797
|
+
*
|
1798
|
+
* A MethodDescriptor provides information about the Protobuf definition of a
|
1799
|
+
* method inside an RPC service.
|
1800
|
+
*/
|
1801
|
+
|
1802
|
+
/*
|
1803
|
+
* call-seq:
|
1804
|
+
* MethodDescriptor.new(c_only_cookie, ptr) => MethodDescriptor
|
1805
|
+
*
|
1806
|
+
* Creates a descriptor wrapper object. May only be called from C.
|
1807
|
+
*/
|
1808
|
+
static VALUE MethodDescriptor_initialize(VALUE _self, VALUE cookie,
|
1809
|
+
VALUE descriptor_pool, VALUE ptr) {
|
1810
|
+
MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
|
1811
|
+
|
1812
|
+
if (cookie != c_only_cookie) {
|
1813
|
+
rb_raise(rb_eRuntimeError,
|
1814
|
+
"Descriptor objects may not be created from Ruby.");
|
1815
|
+
}
|
1816
|
+
|
1817
|
+
RB_OBJ_WRITE(_self, &self->descriptor_pool, descriptor_pool);
|
1818
|
+
self->methoddef = (const upb_MethodDef*)NUM2ULL(ptr);
|
1819
|
+
|
1820
|
+
return Qnil;
|
1821
|
+
}
|
1822
|
+
|
1823
|
+
/*
|
1824
|
+
* ruby-doc: MethodDescriptor#name
|
1825
|
+
*
|
1826
|
+
* Returns the name of this method
|
1827
|
+
*
|
1828
|
+
* @return [String]
|
1829
|
+
*/
|
1830
|
+
static VALUE MethodDescriptor_name(VALUE _self) {
|
1831
|
+
MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
|
1832
|
+
return rb_str_maybe_null(upb_MethodDef_Name(self->methoddef));
|
1833
|
+
}
|
1834
|
+
|
1835
|
+
/*
|
1836
|
+
* ruby-doc: MethodDescriptor#options
|
1837
|
+
*
|
1838
|
+
* Returns the
|
1839
|
+
* {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L927
|
1840
|
+
* MethodOptions} for this {MethodDescriptor}.
|
1841
|
+
*
|
1842
|
+
* @return [MethodOptions]
|
1843
|
+
*/
|
1844
|
+
static VALUE MethodDescriptor_options(VALUE _self) {
|
1845
|
+
MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
|
1846
|
+
const google_protobuf_MethodOptions* opts =
|
1847
|
+
upb_MethodDef_Options(self->methoddef);
|
1848
|
+
upb_Arena* arena = upb_Arena_New();
|
1849
|
+
size_t size;
|
1850
|
+
char* serialized =
|
1851
|
+
google_protobuf_MethodOptions_serialize(opts, arena, &size);
|
1852
|
+
VALUE method_options = decode_options(_self, "MethodOptions", size,
|
1853
|
+
serialized, self->descriptor_pool);
|
1854
|
+
upb_Arena_Free(arena);
|
1855
|
+
return method_options;
|
1856
|
+
}
|
1857
|
+
|
1858
|
+
/*
|
1859
|
+
* ruby-doc: MethodDescriptor#input_type
|
1860
|
+
*
|
1861
|
+
* Returns the {Descriptor} for the request message type of this method
|
1862
|
+
*
|
1863
|
+
* @return [Descriptor]
|
1864
|
+
*/
|
1865
|
+
static VALUE MethodDescriptor_input_type(VALUE _self) {
|
1866
|
+
MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
|
1867
|
+
const upb_MessageDef* type = upb_MethodDef_InputType(self->methoddef);
|
1868
|
+
return get_msgdef_obj(self->descriptor_pool, type);
|
1869
|
+
}
|
1870
|
+
|
1871
|
+
/*
|
1872
|
+
* ruby-doc: MethodDescriptor#output_type
|
1873
|
+
*
|
1874
|
+
* Returns the {Descriptor} for the response message type of this method
|
1875
|
+
*
|
1876
|
+
* @return [Descriptor]
|
1877
|
+
*/
|
1878
|
+
static VALUE MethodDescriptor_output_type(VALUE _self) {
|
1879
|
+
MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
|
1880
|
+
const upb_MessageDef* type = upb_MethodDef_OutputType(self->methoddef);
|
1881
|
+
return get_msgdef_obj(self->descriptor_pool, type);
|
1882
|
+
}
|
1883
|
+
|
1884
|
+
/*
|
1885
|
+
* ruby-doc: MethodDescriptor#client_streaming
|
1886
|
+
*
|
1887
|
+
* Returns whether or not this is a streaming request method
|
1888
|
+
*
|
1889
|
+
* @return [Boolean]
|
1890
|
+
*/
|
1891
|
+
static VALUE MethodDescriptor_client_streaming(VALUE _self) {
|
1892
|
+
MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
|
1893
|
+
return upb_MethodDef_ClientStreaming(self->methoddef) ? Qtrue : Qfalse;
|
1894
|
+
}
|
1895
|
+
|
1896
|
+
/*
|
1897
|
+
* ruby-doc: MethodDescriptor#to_proto
|
1898
|
+
*
|
1899
|
+
* Returns the
|
1900
|
+
* {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L394
|
1901
|
+
* MethodDescriptorProto} of this {MethodDescriptor}.
|
1902
|
+
*
|
1903
|
+
* @return [MethodDescriptorProto]
|
1904
|
+
*/
|
1905
|
+
static VALUE MethodDescriptor_to_proto(VALUE _self) {
|
1906
|
+
MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
|
1907
|
+
upb_Arena* arena = upb_Arena_New();
|
1908
|
+
google_protobuf_MethodDescriptorProto* proto =
|
1909
|
+
upb_MethodDef_ToProto(self->methoddef, arena);
|
1910
|
+
size_t size;
|
1911
|
+
const char* serialized =
|
1912
|
+
google_protobuf_MethodDescriptorProto_serialize(proto, arena, &size);
|
1913
|
+
VALUE proto_class = rb_path2class("Google::Protobuf::MethodDescriptorProto");
|
1914
|
+
VALUE proto_rb =
|
1915
|
+
Message_decode_bytes(size, serialized, 0, proto_class, false);
|
1916
|
+
upb_Arena_Free(arena);
|
1917
|
+
return proto_rb;
|
1918
|
+
}
|
1919
|
+
|
1920
|
+
/*
|
1921
|
+
* ruby-doc: MethodDescriptor#server_streaming
|
1922
|
+
*
|
1923
|
+
* Returns whether or not this is a streaming response method
|
1924
|
+
*
|
1925
|
+
* @return [Boolean]
|
1926
|
+
*/
|
1927
|
+
static VALUE MethodDescriptor_server_streaming(VALUE _self) {
|
1928
|
+
MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
|
1929
|
+
return upb_MethodDef_ServerStreaming(self->methoddef) ? Qtrue : Qfalse;
|
1930
|
+
}
|
1931
|
+
|
1932
|
+
static void MethodDescriptor_register(VALUE module) {
|
1933
|
+
VALUE klass = rb_define_class_under(module, "MethodDescriptor", rb_cObject);
|
1934
|
+
rb_define_alloc_func(klass, MethodDescriptor_alloc);
|
1935
|
+
rb_define_method(klass, "initialize", MethodDescriptor_initialize, 3);
|
1936
|
+
rb_define_method(klass, "name", MethodDescriptor_name, 0);
|
1937
|
+
rb_define_method(klass, "options", MethodDescriptor_options, 0);
|
1938
|
+
rb_define_method(klass, "input_type", MethodDescriptor_input_type, 0);
|
1939
|
+
rb_define_method(klass, "output_type", MethodDescriptor_output_type, 0);
|
1940
|
+
rb_define_method(klass, "client_streaming", MethodDescriptor_client_streaming,
|
1941
|
+
0);
|
1942
|
+
rb_define_method(klass, "server_streaming", MethodDescriptor_server_streaming,
|
1943
|
+
0);
|
1944
|
+
rb_define_method(klass, "to_proto", MethodDescriptor_to_proto, 0);
|
1945
|
+
rb_gc_register_address(&cMethodDescriptor);
|
1946
|
+
cMethodDescriptor = klass;
|
1947
|
+
}
|
1948
|
+
|
1284
1949
|
static VALUE get_def_obj(VALUE _descriptor_pool, const void* ptr, VALUE klass) {
|
1285
1950
|
DescriptorPool* descriptor_pool = ruby_to_DescriptorPool(_descriptor_pool);
|
1286
1951
|
VALUE key = ULL2NUM((intptr_t)ptr);
|
@@ -1322,6 +1987,16 @@ static VALUE get_oneofdef_obj(VALUE descriptor_pool, const upb_OneofDef* def) {
|
|
1322
1987
|
return get_def_obj(descriptor_pool, def, cOneofDescriptor);
|
1323
1988
|
}
|
1324
1989
|
|
1990
|
+
static VALUE get_servicedef_obj(VALUE descriptor_pool,
|
1991
|
+
const upb_ServiceDef* def) {
|
1992
|
+
return get_def_obj(descriptor_pool, def, cServiceDescriptor);
|
1993
|
+
}
|
1994
|
+
|
1995
|
+
static VALUE get_methoddef_obj(VALUE descriptor_pool,
|
1996
|
+
const upb_MethodDef* def) {
|
1997
|
+
return get_def_obj(descriptor_pool, def, cMethodDescriptor);
|
1998
|
+
}
|
1999
|
+
|
1325
2000
|
// -----------------------------------------------------------------------------
|
1326
2001
|
// Shared functions
|
1327
2002
|
// -----------------------------------------------------------------------------
|
@@ -1397,6 +2072,8 @@ void Defs_register(VALUE module) {
|
|
1397
2072
|
FieldDescriptor_register(module);
|
1398
2073
|
OneofDescriptor_register(module);
|
1399
2074
|
EnumDescriptor_register(module);
|
2075
|
+
ServiceDescriptor_register(module);
|
2076
|
+
MethodDescriptor_register(module);
|
1400
2077
|
|
1401
2078
|
rb_gc_register_address(&c_only_cookie);
|
1402
2079
|
c_only_cookie = rb_class_new_instance(0, NULL, rb_cObject);
|