google-protobuf 3.25.7 → 4.34.0
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 +806 -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 +11504 -7961
- data/ext/google/protobuf_c/ruby-upb.h +11760 -6934
- 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 +9 -1
- data/lib/google/protobuf/ffi/enum_descriptor.rb +13 -1
- data/lib/google/protobuf/ffi/ffi.rb +8 -8
- 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 +189 -68
- 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 +38 -30
- 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
|
*/
|
|
@@ -106,14 +114,22 @@ static VALUE DescriptorPool_alloc(VALUE klass) {
|
|
|
106
114
|
|
|
107
115
|
RB_OBJ_WRITE(ret, &self->def_to_descriptor, rb_hash_new());
|
|
108
116
|
self->symtab = upb_DefPool_New();
|
|
117
|
+
|
|
118
|
+
// Ruby treats all enums as open.
|
|
119
|
+
upb_DefPool_DisableClosedEnumChecking(self->symtab);
|
|
120
|
+
|
|
109
121
|
return ObjectCache_TryAdd(self->symtab, ret);
|
|
110
122
|
}
|
|
111
123
|
|
|
112
124
|
/*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
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.
|
|
115
130
|
*
|
|
116
|
-
*
|
|
131
|
+
* @param serialized_file_proto [String]
|
|
132
|
+
* @return [FileDescriptor]
|
|
117
133
|
*/
|
|
118
134
|
VALUE DescriptorPool_add_serialized_file(VALUE _self,
|
|
119
135
|
VALUE serialized_file_proto) {
|
|
@@ -141,11 +157,14 @@ VALUE DescriptorPool_add_serialized_file(VALUE _self,
|
|
|
141
157
|
}
|
|
142
158
|
|
|
143
159
|
/*
|
|
144
|
-
*
|
|
145
|
-
* DescriptorPool.lookup(name) => descriptor
|
|
160
|
+
* ruby-doc: DescriptorPool#lookup
|
|
146
161
|
*
|
|
147
|
-
* Finds a Descriptor, EnumDescriptor
|
|
148
|
-
* or
|
|
162
|
+
* Finds a {Descriptor}, {EnumDescriptor},
|
|
163
|
+
* {FieldDescriptor} or {ServiceDescriptor} by
|
|
164
|
+
* name and returns it, or nil if none exists with the given name.
|
|
165
|
+
*
|
|
166
|
+
* @param name [String]
|
|
167
|
+
* @return [Descriptor,EnumDescriptor,FieldDescriptor,ServiceDescriptor]
|
|
149
168
|
*/
|
|
150
169
|
static VALUE DescriptorPool_lookup(VALUE _self, VALUE name) {
|
|
151
170
|
DescriptorPool* self = ruby_to_DescriptorPool(_self);
|
|
@@ -153,6 +172,8 @@ static VALUE DescriptorPool_lookup(VALUE _self, VALUE name) {
|
|
|
153
172
|
const upb_MessageDef* msgdef;
|
|
154
173
|
const upb_EnumDef* enumdef;
|
|
155
174
|
const upb_FieldDef* fielddef;
|
|
175
|
+
const upb_ServiceDef* servicedef;
|
|
176
|
+
const upb_FileDef* filedef;
|
|
156
177
|
|
|
157
178
|
msgdef = upb_DefPool_FindMessageByName(self->symtab, name_str);
|
|
158
179
|
if (msgdef) {
|
|
@@ -169,17 +190,28 @@ static VALUE DescriptorPool_lookup(VALUE _self, VALUE name) {
|
|
|
169
190
|
return get_enumdef_obj(_self, enumdef);
|
|
170
191
|
}
|
|
171
192
|
|
|
193
|
+
servicedef = upb_DefPool_FindServiceByName(self->symtab, name_str);
|
|
194
|
+
if (servicedef) {
|
|
195
|
+
return get_servicedef_obj(_self, servicedef);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
filedef = upb_DefPool_FindFileByName(self->symtab, name_str);
|
|
199
|
+
if (filedef) {
|
|
200
|
+
return get_filedef_obj(_self, filedef);
|
|
201
|
+
}
|
|
202
|
+
|
|
172
203
|
return Qnil;
|
|
173
204
|
}
|
|
174
205
|
|
|
175
206
|
/*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
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.
|
|
178
213
|
*
|
|
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.
|
|
214
|
+
* @return [DescriptorPool]
|
|
183
215
|
*/
|
|
184
216
|
static VALUE DescriptorPool_generated_pool(VALUE _self) {
|
|
185
217
|
return generated_pool;
|
|
@@ -257,14 +289,32 @@ static VALUE decode_options(VALUE self, const char* option_type, int size,
|
|
|
257
289
|
VALUE desc_rb = get_msgdef_obj(descriptor_pool, msgdef);
|
|
258
290
|
const Descriptor* desc = ruby_to_Descriptor(desc_rb);
|
|
259
291
|
|
|
260
|
-
options_rb = Message_decode_bytes(size, bytes, 0, desc->klass,
|
|
292
|
+
options_rb = Message_decode_bytes(size, bytes, 0, desc->klass, false);
|
|
293
|
+
|
|
294
|
+
// Strip features from the options proto to keep it internal.
|
|
295
|
+
const upb_MessageDef* decoded_desc = NULL;
|
|
296
|
+
upb_Message* options = Message_GetMutable(options_rb, &decoded_desc);
|
|
297
|
+
PBRUBY_ASSERT(options != NULL);
|
|
298
|
+
PBRUBY_ASSERT(decoded_desc == msgdef);
|
|
299
|
+
const upb_FieldDef* field =
|
|
300
|
+
upb_MessageDef_FindFieldByName(decoded_desc, "features");
|
|
301
|
+
PBRUBY_ASSERT(field != NULL);
|
|
302
|
+
upb_Message_ClearFieldByDef(options, field);
|
|
303
|
+
|
|
304
|
+
Message_freeze(options_rb);
|
|
305
|
+
|
|
261
306
|
rb_ivar_set(self, options_instancevar_interned, options_rb);
|
|
262
307
|
return options_rb;
|
|
263
308
|
}
|
|
264
309
|
|
|
265
310
|
/*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
311
|
+
* ruby-doc: Descriptor
|
|
312
|
+
*
|
|
313
|
+
* A Descriptor provides information about a given Protobuf definition.
|
|
314
|
+
*/
|
|
315
|
+
|
|
316
|
+
/*
|
|
317
|
+
* ruby-doc: Descriptor.initialize
|
|
268
318
|
*
|
|
269
319
|
* Creates a new, empty, message type descriptor. At a minimum, its name must be
|
|
270
320
|
* set before it is added to a pool. It cannot be used to create messages until
|
|
@@ -302,10 +352,11 @@ static VALUE Descriptor_initialize(VALUE _self, VALUE cookie,
|
|
|
302
352
|
}
|
|
303
353
|
|
|
304
354
|
/*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
355
|
+
* ruby-doc: Descriptor#file_descriptor
|
|
356
|
+
*
|
|
357
|
+
* Returns the {FileDescriptor} object this message belongs to.
|
|
307
358
|
*
|
|
308
|
-
*
|
|
359
|
+
* @return [FileDescriptor]
|
|
309
360
|
*/
|
|
310
361
|
static VALUE Descriptor_file_descriptor(VALUE _self) {
|
|
311
362
|
Descriptor* self = ruby_to_Descriptor(_self);
|
|
@@ -314,11 +365,12 @@ static VALUE Descriptor_file_descriptor(VALUE _self) {
|
|
|
314
365
|
}
|
|
315
366
|
|
|
316
367
|
/*
|
|
317
|
-
*
|
|
318
|
-
* Descriptor.name => name
|
|
368
|
+
* ruby-doc: Descriptor#name
|
|
319
369
|
*
|
|
320
370
|
* Returns the name of this message type as a fully-qualified string (e.g.,
|
|
321
371
|
* My.Package.MessageType).
|
|
372
|
+
*
|
|
373
|
+
* @return [String]
|
|
322
374
|
*/
|
|
323
375
|
static VALUE Descriptor_name(VALUE _self) {
|
|
324
376
|
Descriptor* self = ruby_to_Descriptor(_self);
|
|
@@ -326,10 +378,12 @@ static VALUE Descriptor_name(VALUE _self) {
|
|
|
326
378
|
}
|
|
327
379
|
|
|
328
380
|
/*
|
|
329
|
-
*
|
|
330
|
-
* Descriptor.each(&block)
|
|
381
|
+
* ruby-doc: Descriptor#each
|
|
331
382
|
*
|
|
332
383
|
* Iterates over fields in this message type, yielding to the block on each one.
|
|
384
|
+
*
|
|
385
|
+
* @yield [FieldDescriptor]
|
|
386
|
+
* @return [nil]
|
|
333
387
|
*/
|
|
334
388
|
static VALUE Descriptor_each(VALUE _self) {
|
|
335
389
|
Descriptor* self = ruby_to_Descriptor(_self);
|
|
@@ -344,11 +398,13 @@ static VALUE Descriptor_each(VALUE _self) {
|
|
|
344
398
|
}
|
|
345
399
|
|
|
346
400
|
/*
|
|
347
|
-
*
|
|
348
|
-
* Descriptor.lookup(name) => FieldDescriptor
|
|
401
|
+
* ruby-doc: Descriptor#lookup
|
|
349
402
|
*
|
|
350
403
|
* Returns the field descriptor for the field with the given name, if present,
|
|
351
404
|
* or nil if none.
|
|
405
|
+
*
|
|
406
|
+
* @param name [String]
|
|
407
|
+
* @return [FieldDescriptor]
|
|
352
408
|
*/
|
|
353
409
|
static VALUE Descriptor_lookup(VALUE _self, VALUE name) {
|
|
354
410
|
Descriptor* self = ruby_to_Descriptor(_self);
|
|
@@ -361,11 +417,13 @@ static VALUE Descriptor_lookup(VALUE _self, VALUE name) {
|
|
|
361
417
|
}
|
|
362
418
|
|
|
363
419
|
/*
|
|
364
|
-
*
|
|
365
|
-
* Descriptor.each_oneof(&block) => nil
|
|
420
|
+
* ruby-doc: Descriptor#each_oneof
|
|
366
421
|
*
|
|
367
422
|
* Invokes the given block for each oneof in this message type, passing the
|
|
368
|
-
* corresponding OneofDescriptor.
|
|
423
|
+
* corresponding {OneofDescriptor}.
|
|
424
|
+
*
|
|
425
|
+
* @yield [OneofDescriptor]
|
|
426
|
+
* @return [nil]
|
|
369
427
|
*/
|
|
370
428
|
static VALUE Descriptor_each_oneof(VALUE _self) {
|
|
371
429
|
Descriptor* self = ruby_to_Descriptor(_self);
|
|
@@ -380,11 +438,13 @@ static VALUE Descriptor_each_oneof(VALUE _self) {
|
|
|
380
438
|
}
|
|
381
439
|
|
|
382
440
|
/*
|
|
383
|
-
*
|
|
384
|
-
* Descriptor.lookup_oneof(name) => OneofDescriptor
|
|
441
|
+
* ruby-doc: Descriptor#lookup_oneof
|
|
385
442
|
*
|
|
386
443
|
* Returns the oneof descriptor for the oneof with the given name, if present,
|
|
387
444
|
* or nil if none.
|
|
445
|
+
*
|
|
446
|
+
* @param name [String]
|
|
447
|
+
* @return [OneofDescriptor]
|
|
388
448
|
*/
|
|
389
449
|
static VALUE Descriptor_lookup_oneof(VALUE _self, VALUE name) {
|
|
390
450
|
Descriptor* self = ruby_to_Descriptor(_self);
|
|
@@ -397,10 +457,11 @@ static VALUE Descriptor_lookup_oneof(VALUE _self, VALUE name) {
|
|
|
397
457
|
}
|
|
398
458
|
|
|
399
459
|
/*
|
|
400
|
-
*
|
|
401
|
-
* Descriptor.msgclass => message_klass
|
|
460
|
+
* ruby-doc: Descriptor#msgclass
|
|
402
461
|
*
|
|
403
462
|
* Returns the Ruby class created for this message type.
|
|
463
|
+
*
|
|
464
|
+
* @return [Class<Google::Protobuf::AbstractMessage>]
|
|
404
465
|
*/
|
|
405
466
|
static VALUE Descriptor_msgclass(VALUE _self) {
|
|
406
467
|
Descriptor* self = ruby_to_Descriptor(_self);
|
|
@@ -411,10 +472,13 @@ static VALUE Descriptor_msgclass(VALUE _self) {
|
|
|
411
472
|
}
|
|
412
473
|
|
|
413
474
|
/*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
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}.
|
|
416
480
|
*
|
|
417
|
-
*
|
|
481
|
+
* @return [MessageOptions]
|
|
418
482
|
*/
|
|
419
483
|
static VALUE Descriptor_options(VALUE _self) {
|
|
420
484
|
Descriptor* self = ruby_to_Descriptor(_self);
|
|
@@ -430,6 +494,30 @@ static VALUE Descriptor_options(VALUE _self) {
|
|
|
430
494
|
return message_options;
|
|
431
495
|
}
|
|
432
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
|
+
|
|
433
521
|
static void Descriptor_register(VALUE module) {
|
|
434
522
|
VALUE klass = rb_define_class_under(module, "Descriptor", rb_cObject);
|
|
435
523
|
rb_define_alloc_func(klass, Descriptor_alloc);
|
|
@@ -442,6 +530,7 @@ static void Descriptor_register(VALUE module) {
|
|
|
442
530
|
rb_define_method(klass, "name", Descriptor_name, 0);
|
|
443
531
|
rb_define_method(klass, "file_descriptor", Descriptor_file_descriptor, 0);
|
|
444
532
|
rb_define_method(klass, "options", Descriptor_options, 0);
|
|
533
|
+
rb_define_method(klass, "to_proto", Descriptor_to_proto, 0);
|
|
445
534
|
rb_include_module(klass, rb_mEnumerable);
|
|
446
535
|
rb_gc_register_address(&cDescriptor);
|
|
447
536
|
cDescriptor = klass;
|
|
@@ -485,11 +574,17 @@ static VALUE FileDescriptor_alloc(VALUE klass) {
|
|
|
485
574
|
return ret;
|
|
486
575
|
}
|
|
487
576
|
|
|
577
|
+
/**
|
|
578
|
+
* ruby-doc: FileDescriptor
|
|
579
|
+
*
|
|
580
|
+
* A FileDescriptor provides information about all Protobuf definitions in a
|
|
581
|
+
* particular file.
|
|
582
|
+
*/
|
|
583
|
+
|
|
488
584
|
/*
|
|
489
|
-
*
|
|
490
|
-
* FileDescriptor.new => file
|
|
585
|
+
* ruby-doc: FileDescriptor#initialize
|
|
491
586
|
*
|
|
492
|
-
* Returns a new file descriptor.
|
|
587
|
+
* Returns a new file descriptor. May
|
|
493
588
|
* to a builder.
|
|
494
589
|
*/
|
|
495
590
|
static VALUE FileDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
@@ -508,10 +603,11 @@ static VALUE FileDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
|
508
603
|
}
|
|
509
604
|
|
|
510
605
|
/*
|
|
511
|
-
*
|
|
512
|
-
* FileDescriptor.name => name
|
|
606
|
+
* ruby-doc: FileDescriptor#name
|
|
513
607
|
*
|
|
514
608
|
* Returns the name of the file.
|
|
609
|
+
*
|
|
610
|
+
* @return [String]
|
|
515
611
|
*/
|
|
516
612
|
static VALUE FileDescriptor_name(VALUE _self) {
|
|
517
613
|
FileDescriptor* self = ruby_to_FileDescriptor(_self);
|
|
@@ -520,32 +616,13 @@ static VALUE FileDescriptor_name(VALUE _self) {
|
|
|
520
616
|
}
|
|
521
617
|
|
|
522
618
|
/*
|
|
523
|
-
*
|
|
524
|
-
* FileDescriptor.syntax => syntax
|
|
525
|
-
*
|
|
526
|
-
* Returns this file descriptors syntax.
|
|
619
|
+
* ruby-doc: FileDescriptor#options
|
|
527
620
|
*
|
|
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
|
|
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
|
-
*
|
|
625
|
+
* @return [FileOptions]
|
|
549
626
|
*/
|
|
550
627
|
static VALUE FileDescriptor_options(VALUE _self) {
|
|
551
628
|
FileDescriptor* self = ruby_to_FileDescriptor(_self);
|
|
@@ -559,13 +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
|
-
rb_define_method(klass, "syntax", FileDescriptor_syntax, 0);
|
|
568
671
|
rb_define_method(klass, "options", FileDescriptor_options, 0);
|
|
672
|
+
rb_define_method(klass, "to_proto", FileDescriptor_to_proto, 0);
|
|
569
673
|
rb_gc_register_address(&cFileDescriptor);
|
|
570
674
|
cFileDescriptor = klass;
|
|
571
675
|
}
|
|
@@ -600,9 +704,15 @@ static FieldDescriptor* ruby_to_FieldDescriptor(VALUE val) {
|
|
|
600
704
|
return ret;
|
|
601
705
|
}
|
|
602
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
|
+
|
|
603
714
|
/*
|
|
604
|
-
*
|
|
605
|
-
* FieldDescriptor.new => field
|
|
715
|
+
* ruby-doc: FieldDescriptor#initialize
|
|
606
716
|
*
|
|
607
717
|
* Returns a new field descriptor. Its name, type, etc. must be set before it is
|
|
608
718
|
* added to a message type.
|
|
@@ -636,10 +746,11 @@ static VALUE FieldDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
|
636
746
|
}
|
|
637
747
|
|
|
638
748
|
/*
|
|
639
|
-
*
|
|
640
|
-
* FieldDescriptor.name => name
|
|
749
|
+
* ruby-doc: FieldDescriptor#name
|
|
641
750
|
*
|
|
642
751
|
* Returns the name of this field.
|
|
752
|
+
*
|
|
753
|
+
* @return [String]
|
|
643
754
|
*/
|
|
644
755
|
static VALUE FieldDescriptor_name(VALUE _self) {
|
|
645
756
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
|
@@ -704,14 +815,15 @@ static VALUE descriptortype_to_ruby(upb_FieldType type) {
|
|
|
704
815
|
}
|
|
705
816
|
|
|
706
817
|
/*
|
|
707
|
-
*
|
|
708
|
-
* FieldDescriptor.type => type
|
|
818
|
+
* ruby-doc: FieldDescriptor#type
|
|
709
819
|
*
|
|
710
820
|
* Returns this field's type, as a Ruby symbol, or nil if not yet set.
|
|
711
821
|
*
|
|
712
822
|
* Valid field types are:
|
|
713
823
|
* :int32, :int64, :uint32, :uint64, :float, :double, :bool, :string,
|
|
714
824
|
* :bytes, :message.
|
|
825
|
+
*
|
|
826
|
+
* @return [Symbol]
|
|
715
827
|
*/
|
|
716
828
|
static VALUE FieldDescriptor__type(VALUE _self) {
|
|
717
829
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
|
@@ -719,15 +831,16 @@ static VALUE FieldDescriptor__type(VALUE _self) {
|
|
|
719
831
|
}
|
|
720
832
|
|
|
721
833
|
/*
|
|
722
|
-
*
|
|
723
|
-
* FieldDescriptor.default => default
|
|
834
|
+
* ruby-doc: FieldDescriptor#default
|
|
724
835
|
*
|
|
725
836
|
* Returns this field's default, as a Ruby object, or nil if not yet set.
|
|
837
|
+
*
|
|
838
|
+
* @return [Object,nil]
|
|
726
839
|
*/
|
|
727
840
|
static VALUE FieldDescriptor_default(VALUE _self) {
|
|
728
841
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
|
729
842
|
const upb_FieldDef* f = self->fielddef;
|
|
730
|
-
upb_MessageValue default_val =
|
|
843
|
+
upb_MessageValue default_val = upb_MessageValue_Zero();
|
|
731
844
|
if (upb_FieldDef_IsSubMessage(f)) {
|
|
732
845
|
return Qnil;
|
|
733
846
|
} else if (!upb_FieldDef_IsRepeated(f)) {
|
|
@@ -737,10 +850,57 @@ static VALUE FieldDescriptor_default(VALUE _self) {
|
|
|
737
850
|
}
|
|
738
851
|
|
|
739
852
|
/*
|
|
740
|
-
*
|
|
741
|
-
*
|
|
853
|
+
* ruby-doc: FieldDescriptor.has_presence?
|
|
854
|
+
*
|
|
855
|
+
* Returns whether this field tracks presence.
|
|
856
|
+
*
|
|
857
|
+
* @return [Boolean]
|
|
858
|
+
*/
|
|
859
|
+
static VALUE FieldDescriptor_has_presence(VALUE _self) {
|
|
860
|
+
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
|
861
|
+
return upb_FieldDef_HasPresence(self->fielddef) ? Qtrue : Qfalse;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
/*
|
|
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?
|
|
889
|
+
*
|
|
890
|
+
* Returns whether this is a repeated field that uses packed encoding.
|
|
891
|
+
* @return [Boolean]
|
|
892
|
+
*/
|
|
893
|
+
static VALUE FieldDescriptor_is_packed(VALUE _self) {
|
|
894
|
+
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
|
895
|
+
return upb_FieldDef_IsPacked(self->fielddef) ? Qtrue : Qfalse;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
/*
|
|
899
|
+
* ruby-doc: FieldDescriptor#json_name
|
|
742
900
|
*
|
|
743
901
|
* Returns this field's json_name, as a Ruby string, or nil if not yet set.
|
|
902
|
+
*
|
|
903
|
+
* @return [String,nil]
|
|
744
904
|
*/
|
|
745
905
|
static VALUE FieldDescriptor_json_name(VALUE _self) {
|
|
746
906
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
|
@@ -750,13 +910,14 @@ static VALUE FieldDescriptor_json_name(VALUE _self) {
|
|
|
750
910
|
}
|
|
751
911
|
|
|
752
912
|
/*
|
|
753
|
-
*
|
|
754
|
-
* FieldDescriptor.label => label
|
|
913
|
+
* ruby-doc: FieldDescriptor#label
|
|
755
914
|
*
|
|
756
915
|
* Returns this field's label (i.e., plurality), as a Ruby symbol.
|
|
757
|
-
*
|
|
758
916
|
* Valid field labels are:
|
|
759
|
-
*
|
|
917
|
+
* :optional, :repeated
|
|
918
|
+
*
|
|
919
|
+
* @return [Symbol]
|
|
920
|
+
* @deprecated Use {#repeated?} or {#required?} instead.
|
|
760
921
|
*/
|
|
761
922
|
static VALUE FieldDescriptor_label(VALUE _self) {
|
|
762
923
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
|
@@ -776,10 +937,11 @@ static VALUE FieldDescriptor_label(VALUE _self) {
|
|
|
776
937
|
}
|
|
777
938
|
|
|
778
939
|
/*
|
|
779
|
-
*
|
|
780
|
-
* FieldDescriptor.number => number
|
|
940
|
+
* ruby-doc: FieldDescriptor#number
|
|
781
941
|
*
|
|
782
942
|
* Returns the tag number for this field.
|
|
943
|
+
*
|
|
944
|
+
* @return [Integer]
|
|
783
945
|
*/
|
|
784
946
|
static VALUE FieldDescriptor_number(VALUE _self) {
|
|
785
947
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
|
@@ -787,13 +949,14 @@ static VALUE FieldDescriptor_number(VALUE _self) {
|
|
|
787
949
|
}
|
|
788
950
|
|
|
789
951
|
/*
|
|
790
|
-
*
|
|
791
|
-
* FieldDescriptor.submsg_name => submsg_name
|
|
952
|
+
* ruby-doc: FieldDescriptor#submsg_name
|
|
792
953
|
*
|
|
793
954
|
* Returns the name of the message or enum type corresponding to this field, if
|
|
794
955
|
* it is a message or enum field (respectively), or nil otherwise. This type
|
|
795
956
|
* name will be resolved within the context of the pool to which the containing
|
|
796
957
|
* message type is added.
|
|
958
|
+
*
|
|
959
|
+
* @return [String,nil]
|
|
797
960
|
*/
|
|
798
961
|
static VALUE FieldDescriptor_submsg_name(VALUE _self) {
|
|
799
962
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
|
@@ -810,13 +973,14 @@ static VALUE FieldDescriptor_submsg_name(VALUE _self) {
|
|
|
810
973
|
}
|
|
811
974
|
|
|
812
975
|
/*
|
|
813
|
-
*
|
|
814
|
-
* FieldDescriptor.subtype => message_or_enum_descriptor
|
|
976
|
+
* ruby-doc: FieldDescriptor#subtype
|
|
815
977
|
*
|
|
816
978
|
* Returns the message or enum descriptor corresponding to this field's type if
|
|
817
979
|
* it is a message or enum field, respectively, or nil otherwise. Cannot be
|
|
818
980
|
* called *until* the containing message type is added to a pool (and thus
|
|
819
981
|
* resolved).
|
|
982
|
+
*
|
|
983
|
+
* @return [Descriptor,EnumDescriptor,nil]
|
|
820
984
|
*/
|
|
821
985
|
static VALUE FieldDescriptor_subtype(VALUE _self) {
|
|
822
986
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
|
@@ -833,11 +997,13 @@ static VALUE FieldDescriptor_subtype(VALUE _self) {
|
|
|
833
997
|
}
|
|
834
998
|
|
|
835
999
|
/*
|
|
836
|
-
*
|
|
837
|
-
* FieldDescriptor.get(message) => value
|
|
1000
|
+
* ruby-doc: FieldDescriptor#get
|
|
838
1001
|
*
|
|
839
1002
|
* Returns the value set for this field on the given message. Raises an
|
|
840
1003
|
* exception if message is of the wrong type.
|
|
1004
|
+
*
|
|
1005
|
+
* @param message [AbstractMessage]
|
|
1006
|
+
* @return [Object]
|
|
841
1007
|
*/
|
|
842
1008
|
static VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) {
|
|
843
1009
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
|
@@ -853,11 +1019,13 @@ static VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) {
|
|
|
853
1019
|
}
|
|
854
1020
|
|
|
855
1021
|
/*
|
|
856
|
-
*
|
|
857
|
-
* FieldDescriptor.has?(message) => boolean
|
|
1022
|
+
* ruby-doc: FieldDescriptor.has?
|
|
858
1023
|
*
|
|
859
1024
|
* Returns whether the value is set on the given message. Raises an
|
|
860
1025
|
* exception when calling for fields that do not have presence.
|
|
1026
|
+
*
|
|
1027
|
+
* @param message [AbstractMessage]
|
|
1028
|
+
* @return [Boolean]
|
|
861
1029
|
*/
|
|
862
1030
|
static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
|
|
863
1031
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
|
@@ -874,10 +1042,12 @@ static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
|
|
|
874
1042
|
}
|
|
875
1043
|
|
|
876
1044
|
/*
|
|
877
|
-
*
|
|
878
|
-
* FieldDescriptor.clear(message)
|
|
1045
|
+
* ruby-doc: FieldDescriptor#clear
|
|
879
1046
|
*
|
|
880
1047
|
* Clears the field from the message if it's set.
|
|
1048
|
+
*
|
|
1049
|
+
* @param message [AbstractMessage]
|
|
1050
|
+
* @return [nil]
|
|
881
1051
|
*/
|
|
882
1052
|
static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
|
|
883
1053
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
|
@@ -893,12 +1063,14 @@ static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
|
|
|
893
1063
|
}
|
|
894
1064
|
|
|
895
1065
|
/*
|
|
896
|
-
*
|
|
897
|
-
* FieldDescriptor.set(message, value)
|
|
1066
|
+
* ruby-doc: FieldDescriptor#set
|
|
898
1067
|
*
|
|
899
1068
|
* Sets the value corresponding to this field to the given value on the given
|
|
900
1069
|
* message. Raises an exception if message is of the wrong type. Performs the
|
|
901
1070
|
* ordinary type-checks for field setting.
|
|
1071
|
+
*
|
|
1072
|
+
* @param message [AbstractMessage]
|
|
1073
|
+
* @param value [Object]
|
|
902
1074
|
*/
|
|
903
1075
|
static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) {
|
|
904
1076
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
|
@@ -918,10 +1090,13 @@ static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) {
|
|
|
918
1090
|
}
|
|
919
1091
|
|
|
920
1092
|
/*
|
|
921
|
-
*
|
|
922
|
-
*
|
|
1093
|
+
* ruby-doc: FieldDescriptor#options
|
|
1094
|
+
*
|
|
1095
|
+
* Returns the
|
|
1096
|
+
* {https://github.com/protocolbuffers/protobuf/blob/v30.2/src/google/protobuf/descriptor.proto#L656
|
|
1097
|
+
* FieldOptions} for this {FieldDescriptor}.
|
|
923
1098
|
*
|
|
924
|
-
*
|
|
1099
|
+
* @return [FieldOptions]
|
|
925
1100
|
*/
|
|
926
1101
|
static VALUE FieldDescriptor_options(VALUE _self) {
|
|
927
1102
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
|
@@ -936,6 +1111,30 @@ static VALUE FieldDescriptor_options(VALUE _self) {
|
|
|
936
1111
|
return field_options;
|
|
937
1112
|
}
|
|
938
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
|
+
|
|
939
1138
|
static void FieldDescriptor_register(VALUE module) {
|
|
940
1139
|
VALUE klass = rb_define_class_under(module, "FieldDescriptor", rb_cObject);
|
|
941
1140
|
rb_define_alloc_func(klass, FieldDescriptor_alloc);
|
|
@@ -943,6 +1142,10 @@ static void FieldDescriptor_register(VALUE module) {
|
|
|
943
1142
|
rb_define_method(klass, "name", FieldDescriptor_name, 0);
|
|
944
1143
|
rb_define_method(klass, "type", FieldDescriptor__type, 0);
|
|
945
1144
|
rb_define_method(klass, "default", FieldDescriptor_default, 0);
|
|
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);
|
|
1148
|
+
rb_define_method(klass, "is_packed?", FieldDescriptor_is_packed, 0);
|
|
946
1149
|
rb_define_method(klass, "json_name", FieldDescriptor_json_name, 0);
|
|
947
1150
|
rb_define_method(klass, "label", FieldDescriptor_label, 0);
|
|
948
1151
|
rb_define_method(klass, "number", FieldDescriptor_number, 0);
|
|
@@ -953,6 +1156,7 @@ static void FieldDescriptor_register(VALUE module) {
|
|
|
953
1156
|
rb_define_method(klass, "get", FieldDescriptor_get, 1);
|
|
954
1157
|
rb_define_method(klass, "set", FieldDescriptor_set, 2);
|
|
955
1158
|
rb_define_method(klass, "options", FieldDescriptor_options, 0);
|
|
1159
|
+
rb_define_method(klass, "to_proto", FieldDescriptor_to_proto, 0);
|
|
956
1160
|
rb_gc_register_address(&cFieldDescriptor);
|
|
957
1161
|
cFieldDescriptor = klass;
|
|
958
1162
|
}
|
|
@@ -987,9 +1191,15 @@ static OneofDescriptor* ruby_to_OneofDescriptor(VALUE val) {
|
|
|
987
1191
|
return ret;
|
|
988
1192
|
}
|
|
989
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
|
+
|
|
990
1201
|
/*
|
|
991
|
-
*
|
|
992
|
-
* OneofDescriptor.new => oneof_descriptor
|
|
1202
|
+
* ruby-doc: OneofDescriptor#initialize
|
|
993
1203
|
*
|
|
994
1204
|
* Creates a new, empty, oneof descriptor. The oneof may only be modified prior
|
|
995
1205
|
* to being added to a message descriptor which is subsequently added to a pool.
|
|
@@ -1024,10 +1234,11 @@ static VALUE OneofDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
|
1024
1234
|
}
|
|
1025
1235
|
|
|
1026
1236
|
/*
|
|
1027
|
-
*
|
|
1028
|
-
* OneofDescriptor.name => name
|
|
1237
|
+
* ruby-doc: OneofDescriptor#name
|
|
1029
1238
|
*
|
|
1030
1239
|
* Returns the name of this oneof.
|
|
1240
|
+
*
|
|
1241
|
+
* @return [String]
|
|
1031
1242
|
*/
|
|
1032
1243
|
static VALUE OneofDescriptor_name(VALUE _self) {
|
|
1033
1244
|
OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
|
|
@@ -1035,10 +1246,12 @@ static VALUE OneofDescriptor_name(VALUE _self) {
|
|
|
1035
1246
|
}
|
|
1036
1247
|
|
|
1037
1248
|
/*
|
|
1038
|
-
*
|
|
1039
|
-
* OneofDescriptor.each(&block) => nil
|
|
1249
|
+
* ruby-doc: OneofDescriptor#each
|
|
1040
1250
|
*
|
|
1041
1251
|
* Iterates through fields in this oneof, yielding to the block on each one.
|
|
1252
|
+
*
|
|
1253
|
+
* @yield [FieldDescriptor]
|
|
1254
|
+
* @return [nil]
|
|
1042
1255
|
*/
|
|
1043
1256
|
static VALUE OneofDescriptor_each(VALUE _self) {
|
|
1044
1257
|
OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
|
|
@@ -1053,10 +1266,13 @@ static VALUE OneofDescriptor_each(VALUE _self) {
|
|
|
1053
1266
|
}
|
|
1054
1267
|
|
|
1055
1268
|
/*
|
|
1056
|
-
*
|
|
1057
|
-
*
|
|
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}.
|
|
1058
1274
|
*
|
|
1059
|
-
*
|
|
1275
|
+
* @return [OneofOptions]
|
|
1060
1276
|
*/
|
|
1061
1277
|
static VALUE OneOfDescriptor_options(VALUE _self) {
|
|
1062
1278
|
OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
|
|
@@ -1071,6 +1287,30 @@ static VALUE OneOfDescriptor_options(VALUE _self) {
|
|
|
1071
1287
|
return oneof_options;
|
|
1072
1288
|
}
|
|
1073
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
|
+
|
|
1074
1314
|
static void OneofDescriptor_register(VALUE module) {
|
|
1075
1315
|
VALUE klass = rb_define_class_under(module, "OneofDescriptor", rb_cObject);
|
|
1076
1316
|
rb_define_alloc_func(klass, OneofDescriptor_alloc);
|
|
@@ -1078,6 +1318,7 @@ static void OneofDescriptor_register(VALUE module) {
|
|
|
1078
1318
|
rb_define_method(klass, "name", OneofDescriptor_name, 0);
|
|
1079
1319
|
rb_define_method(klass, "each", OneofDescriptor_each, 0);
|
|
1080
1320
|
rb_define_method(klass, "options", OneOfDescriptor_options, 0);
|
|
1321
|
+
rb_define_method(klass, "to_proto", OneOfDescriptor_to_proto, 0);
|
|
1081
1322
|
rb_include_module(klass, rb_mEnumerable);
|
|
1082
1323
|
rb_gc_register_address(&cOneofDescriptor);
|
|
1083
1324
|
cOneofDescriptor = klass;
|
|
@@ -1130,6 +1371,13 @@ const upb_EnumDef* EnumDescriptor_GetEnumDef(VALUE enum_desc_rb) {
|
|
|
1130
1371
|
return desc->enumdef;
|
|
1131
1372
|
}
|
|
1132
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
|
+
|
|
1133
1381
|
/*
|
|
1134
1382
|
* call-seq:
|
|
1135
1383
|
* EnumDescriptor.new(c_only_cookie, ptr) => EnumDescriptor
|
|
@@ -1152,10 +1400,11 @@ static VALUE EnumDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
|
1152
1400
|
}
|
|
1153
1401
|
|
|
1154
1402
|
/*
|
|
1155
|
-
*
|
|
1156
|
-
*
|
|
1403
|
+
* ruby-doc: EnumDescriptor#file_descriptor
|
|
1404
|
+
*
|
|
1405
|
+
* Returns the {FileDescriptor} object this enum belongs to.
|
|
1157
1406
|
*
|
|
1158
|
-
*
|
|
1407
|
+
* @return [FileDescriptor]
|
|
1159
1408
|
*/
|
|
1160
1409
|
static VALUE EnumDescriptor_file_descriptor(VALUE _self) {
|
|
1161
1410
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
|
@@ -1164,10 +1413,23 @@ static VALUE EnumDescriptor_file_descriptor(VALUE _self) {
|
|
|
1164
1413
|
}
|
|
1165
1414
|
|
|
1166
1415
|
/*
|
|
1167
|
-
*
|
|
1168
|
-
*
|
|
1416
|
+
* ruby-doc: EnumDescriptor#is_closed?
|
|
1417
|
+
*
|
|
1418
|
+
* Returns whether this enum is open or closed.
|
|
1419
|
+
*
|
|
1420
|
+
* @return [Boolean]
|
|
1421
|
+
*/
|
|
1422
|
+
static VALUE EnumDescriptor_is_closed(VALUE _self) {
|
|
1423
|
+
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
|
1424
|
+
return upb_EnumDef_IsClosed(self->enumdef) ? Qtrue : Qfalse;
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
/*
|
|
1428
|
+
* ruby-doc: EnumDescriptor#name
|
|
1169
1429
|
*
|
|
1170
1430
|
* Returns the name of this enum type.
|
|
1431
|
+
*
|
|
1432
|
+
* @return [String]
|
|
1171
1433
|
*/
|
|
1172
1434
|
static VALUE EnumDescriptor_name(VALUE _self) {
|
|
1173
1435
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
|
@@ -1175,11 +1437,13 @@ static VALUE EnumDescriptor_name(VALUE _self) {
|
|
|
1175
1437
|
}
|
|
1176
1438
|
|
|
1177
1439
|
/*
|
|
1178
|
-
*
|
|
1179
|
-
* EnumDescriptor.lookup_name(name) => value
|
|
1440
|
+
* ruby-doc: EnumDescriptor#lookup_name
|
|
1180
1441
|
*
|
|
1181
1442
|
* Returns the numeric value corresponding to the given key name (as a Ruby
|
|
1182
1443
|
* symbol), or nil if none.
|
|
1444
|
+
*
|
|
1445
|
+
* @param name [Symbol]
|
|
1446
|
+
* @return [Integer,nil]
|
|
1183
1447
|
*/
|
|
1184
1448
|
static VALUE EnumDescriptor_lookup_name(VALUE _self, VALUE name) {
|
|
1185
1449
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
|
@@ -1194,11 +1458,13 @@ static VALUE EnumDescriptor_lookup_name(VALUE _self, VALUE name) {
|
|
|
1194
1458
|
}
|
|
1195
1459
|
|
|
1196
1460
|
/*
|
|
1197
|
-
*
|
|
1198
|
-
* EnumDescriptor.lookup_value(name) => value
|
|
1461
|
+
* ruby-doc: EnumDescriptor#lookup_value
|
|
1199
1462
|
*
|
|
1200
1463
|
* Returns the key name (as a Ruby symbol) corresponding to the integer value,
|
|
1201
1464
|
* or nil if none.
|
|
1465
|
+
*
|
|
1466
|
+
* @param name [Integer]
|
|
1467
|
+
* @return [Symbol,nil]
|
|
1202
1468
|
*/
|
|
1203
1469
|
static VALUE EnumDescriptor_lookup_value(VALUE _self, VALUE number) {
|
|
1204
1470
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
|
@@ -1213,11 +1479,13 @@ static VALUE EnumDescriptor_lookup_value(VALUE _self, VALUE number) {
|
|
|
1213
1479
|
}
|
|
1214
1480
|
|
|
1215
1481
|
/*
|
|
1216
|
-
*
|
|
1217
|
-
* EnumDescriptor.each(&block)
|
|
1482
|
+
* ruby-doc: EnumDescriptor#each
|
|
1218
1483
|
*
|
|
1219
1484
|
* Iterates over key => value mappings in this enum's definition, yielding to
|
|
1220
1485
|
* the block with (key, value) arguments for each one.
|
|
1486
|
+
*
|
|
1487
|
+
* @yield [Symbol, Integer]
|
|
1488
|
+
* @return [nil]
|
|
1221
1489
|
*/
|
|
1222
1490
|
static VALUE EnumDescriptor_each(VALUE _self) {
|
|
1223
1491
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
|
@@ -1234,10 +1502,11 @@ static VALUE EnumDescriptor_each(VALUE _self) {
|
|
|
1234
1502
|
}
|
|
1235
1503
|
|
|
1236
1504
|
/*
|
|
1237
|
-
*
|
|
1238
|
-
* EnumDescriptor.enummodule => module
|
|
1505
|
+
* ruby-doc: EnumDescriptor#enummodule
|
|
1239
1506
|
*
|
|
1240
1507
|
* Returns the Ruby module corresponding to this enum type.
|
|
1508
|
+
*
|
|
1509
|
+
* @return [Module]
|
|
1241
1510
|
*/
|
|
1242
1511
|
static VALUE EnumDescriptor_enummodule(VALUE _self) {
|
|
1243
1512
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
|
@@ -1248,10 +1517,13 @@ static VALUE EnumDescriptor_enummodule(VALUE _self) {
|
|
|
1248
1517
|
}
|
|
1249
1518
|
|
|
1250
1519
|
/*
|
|
1251
|
-
*
|
|
1252
|
-
*
|
|
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}.
|
|
1253
1525
|
*
|
|
1254
|
-
*
|
|
1526
|
+
* @return [EnumOptions]
|
|
1255
1527
|
*/
|
|
1256
1528
|
static VALUE EnumDescriptor_options(VALUE _self) {
|
|
1257
1529
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
|
@@ -1265,6 +1537,31 @@ static VALUE EnumDescriptor_options(VALUE _self) {
|
|
|
1265
1537
|
return enum_options;
|
|
1266
1538
|
}
|
|
1267
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
|
+
|
|
1268
1565
|
static void EnumDescriptor_register(VALUE module) {
|
|
1269
1566
|
VALUE klass = rb_define_class_under(module, "EnumDescriptor", rb_cObject);
|
|
1270
1567
|
rb_define_alloc_func(klass, EnumDescriptor_alloc);
|
|
@@ -1275,12 +1572,384 @@ static void EnumDescriptor_register(VALUE module) {
|
|
|
1275
1572
|
rb_define_method(klass, "each", EnumDescriptor_each, 0);
|
|
1276
1573
|
rb_define_method(klass, "enummodule", EnumDescriptor_enummodule, 0);
|
|
1277
1574
|
rb_define_method(klass, "file_descriptor", EnumDescriptor_file_descriptor, 0);
|
|
1575
|
+
rb_define_method(klass, "is_closed?", EnumDescriptor_is_closed, 0);
|
|
1278
1576
|
rb_define_method(klass, "options", EnumDescriptor_options, 0);
|
|
1577
|
+
rb_define_method(klass, "to_proto", EnumDescriptor_to_proto, 0);
|
|
1279
1578
|
rb_include_module(klass, rb_mEnumerable);
|
|
1280
1579
|
rb_gc_register_address(&cEnumDescriptor);
|
|
1281
1580
|
cEnumDescriptor = klass;
|
|
1282
1581
|
}
|
|
1283
1582
|
|
|
1583
|
+
// -----------------------------------------------------------------------------
|
|
1584
|
+
// ServiceDescriptor
|
|
1585
|
+
// -----------------------------------------------------------------------------
|
|
1586
|
+
|
|
1587
|
+
typedef struct {
|
|
1588
|
+
const upb_ServiceDef* servicedef;
|
|
1589
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
|
1590
|
+
// macro to update VALUE references, as to trigger write barriers.
|
|
1591
|
+
VALUE module; // begins as nil
|
|
1592
|
+
VALUE descriptor_pool; // Owns the upb_ServiceDef.
|
|
1593
|
+
} ServiceDescriptor;
|
|
1594
|
+
|
|
1595
|
+
static VALUE cServiceDescriptor = Qnil;
|
|
1596
|
+
|
|
1597
|
+
static void ServiceDescriptor_mark(void* _self) {
|
|
1598
|
+
ServiceDescriptor* self = _self;
|
|
1599
|
+
rb_gc_mark(self->module);
|
|
1600
|
+
rb_gc_mark(self->descriptor_pool);
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
static const rb_data_type_t ServiceDescriptor_type = {
|
|
1604
|
+
"Google::Protobuf::ServicDescriptor",
|
|
1605
|
+
{ServiceDescriptor_mark, RUBY_DEFAULT_FREE, NULL},
|
|
1606
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
|
1607
|
+
};
|
|
1608
|
+
|
|
1609
|
+
static ServiceDescriptor* ruby_to_ServiceDescriptor(VALUE val) {
|
|
1610
|
+
ServiceDescriptor* ret;
|
|
1611
|
+
TypedData_Get_Struct(val, ServiceDescriptor, &ServiceDescriptor_type, ret);
|
|
1612
|
+
return ret;
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
static VALUE ServiceDescriptor_alloc(VALUE klass) {
|
|
1616
|
+
ServiceDescriptor* self = ALLOC(ServiceDescriptor);
|
|
1617
|
+
VALUE ret = TypedData_Wrap_Struct(klass, &ServiceDescriptor_type, self);
|
|
1618
|
+
self->servicedef = NULL;
|
|
1619
|
+
self->module = Qnil;
|
|
1620
|
+
self->descriptor_pool = Qnil;
|
|
1621
|
+
return ret;
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
/**
|
|
1625
|
+
* ruby-doc: ServiceDescriptor
|
|
1626
|
+
*
|
|
1627
|
+
* A ServiceDescriptor provides information about the Protobuf definition of an
|
|
1628
|
+
* RPC service.
|
|
1629
|
+
*/
|
|
1630
|
+
|
|
1631
|
+
/*
|
|
1632
|
+
* call-seq:
|
|
1633
|
+
* ServiceDescriptor.new(c_only_cookie, ptr) => ServiceDescriptor
|
|
1634
|
+
*
|
|
1635
|
+
* Creates a descriptor wrapper object. May only be called from C.
|
|
1636
|
+
*/
|
|
1637
|
+
static VALUE ServiceDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
1638
|
+
VALUE descriptor_pool, VALUE ptr) {
|
|
1639
|
+
ServiceDescriptor* self = ruby_to_ServiceDescriptor(_self);
|
|
1640
|
+
|
|
1641
|
+
if (cookie != c_only_cookie) {
|
|
1642
|
+
rb_raise(rb_eRuntimeError,
|
|
1643
|
+
"Descriptor objects may not be created from Ruby.");
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
RB_OBJ_WRITE(_self, &self->descriptor_pool, descriptor_pool);
|
|
1647
|
+
self->servicedef = (const upb_ServiceDef*)NUM2ULL(ptr);
|
|
1648
|
+
|
|
1649
|
+
return Qnil;
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
/*
|
|
1653
|
+
* ruby-doc: ServiceDescriptor#name
|
|
1654
|
+
*
|
|
1655
|
+
* Returns the name of this service.
|
|
1656
|
+
*
|
|
1657
|
+
* @return [String]
|
|
1658
|
+
*/
|
|
1659
|
+
static VALUE ServiceDescriptor_name(VALUE _self) {
|
|
1660
|
+
ServiceDescriptor* self = ruby_to_ServiceDescriptor(_self);
|
|
1661
|
+
return rb_str_maybe_null(upb_ServiceDef_FullName(self->servicedef));
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
/*
|
|
1665
|
+
* ruby-doc: ServiceDescriptor#file_descriptor
|
|
1666
|
+
*
|
|
1667
|
+
* Returns the {FileDescriptor} object this service belongs to.
|
|
1668
|
+
* @return [FileDescriptor]
|
|
1669
|
+
*/
|
|
1670
|
+
static VALUE ServiceDescriptor_file_descriptor(VALUE _self) {
|
|
1671
|
+
ServiceDescriptor* self = ruby_to_ServiceDescriptor(_self);
|
|
1672
|
+
return get_filedef_obj(self->descriptor_pool,
|
|
1673
|
+
upb_ServiceDef_File(self->servicedef));
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
/*
|
|
1677
|
+
* ruby-doc: ServiceDescriptor#each
|
|
1678
|
+
*
|
|
1679
|
+
* Iterates over methods in this service, yielding to the block on each one.
|
|
1680
|
+
*
|
|
1681
|
+
* @yield [MethodDescriptor]
|
|
1682
|
+
* @return [nil]
|
|
1683
|
+
*/
|
|
1684
|
+
static VALUE ServiceDescriptor_each(VALUE _self) {
|
|
1685
|
+
ServiceDescriptor* self = ruby_to_ServiceDescriptor(_self);
|
|
1686
|
+
|
|
1687
|
+
int n = upb_ServiceDef_MethodCount(self->servicedef);
|
|
1688
|
+
for (int i = 0; i < n; i++) {
|
|
1689
|
+
const upb_MethodDef* method = upb_ServiceDef_Method(self->servicedef, i);
|
|
1690
|
+
VALUE obj = get_methoddef_obj(self->descriptor_pool, method);
|
|
1691
|
+
rb_yield(obj);
|
|
1692
|
+
}
|
|
1693
|
+
return Qnil;
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
/*
|
|
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}.
|
|
1702
|
+
*
|
|
1703
|
+
* @return [ServiceOptions]
|
|
1704
|
+
*/
|
|
1705
|
+
static VALUE ServiceDescriptor_options(VALUE _self) {
|
|
1706
|
+
ServiceDescriptor* self = ruby_to_ServiceDescriptor(_self);
|
|
1707
|
+
const google_protobuf_ServiceOptions* opts =
|
|
1708
|
+
upb_ServiceDef_Options(self->servicedef);
|
|
1709
|
+
upb_Arena* arena = upb_Arena_New();
|
|
1710
|
+
size_t size;
|
|
1711
|
+
char* serialized =
|
|
1712
|
+
google_protobuf_ServiceOptions_serialize(opts, arena, &size);
|
|
1713
|
+
VALUE service_options = decode_options(_self, "ServiceOptions", size,
|
|
1714
|
+
serialized, self->descriptor_pool);
|
|
1715
|
+
upb_Arena_Free(arena);
|
|
1716
|
+
return service_options;
|
|
1717
|
+
}
|
|
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
|
+
|
|
1743
|
+
static void ServiceDescriptor_register(VALUE module) {
|
|
1744
|
+
VALUE klass = rb_define_class_under(module, "ServiceDescriptor", rb_cObject);
|
|
1745
|
+
rb_define_alloc_func(klass, ServiceDescriptor_alloc);
|
|
1746
|
+
rb_define_method(klass, "initialize", ServiceDescriptor_initialize, 3);
|
|
1747
|
+
rb_define_method(klass, "name", ServiceDescriptor_name, 0);
|
|
1748
|
+
rb_define_method(klass, "each", ServiceDescriptor_each, 0);
|
|
1749
|
+
rb_define_method(klass, "file_descriptor", ServiceDescriptor_file_descriptor,
|
|
1750
|
+
0);
|
|
1751
|
+
rb_define_method(klass, "options", ServiceDescriptor_options, 0);
|
|
1752
|
+
rb_define_method(klass, "to_proto", ServiceDescriptor_to_proto, 0);
|
|
1753
|
+
rb_include_module(klass, rb_mEnumerable);
|
|
1754
|
+
rb_gc_register_address(&cServiceDescriptor);
|
|
1755
|
+
cServiceDescriptor = klass;
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
// -----------------------------------------------------------------------------
|
|
1759
|
+
// MethodDescriptor
|
|
1760
|
+
// -----------------------------------------------------------------------------
|
|
1761
|
+
|
|
1762
|
+
typedef struct {
|
|
1763
|
+
const upb_MethodDef* methoddef;
|
|
1764
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
|
1765
|
+
// macro to update VALUE references, as to trigger write barriers.
|
|
1766
|
+
VALUE module; // begins as nil
|
|
1767
|
+
VALUE descriptor_pool; // Owns the upb_MethodDef.
|
|
1768
|
+
} MethodDescriptor;
|
|
1769
|
+
|
|
1770
|
+
static VALUE cMethodDescriptor = Qnil;
|
|
1771
|
+
|
|
1772
|
+
static void MethodDescriptor_mark(void* _self) {
|
|
1773
|
+
MethodDescriptor* self = _self;
|
|
1774
|
+
rb_gc_mark(self->module);
|
|
1775
|
+
rb_gc_mark(self->descriptor_pool);
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1778
|
+
static const rb_data_type_t MethodDescriptor_type = {
|
|
1779
|
+
"Google::Protobuf::MethodDescriptor",
|
|
1780
|
+
{MethodDescriptor_mark, RUBY_DEFAULT_FREE, NULL},
|
|
1781
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
|
1782
|
+
};
|
|
1783
|
+
|
|
1784
|
+
static MethodDescriptor* ruby_to_MethodDescriptor(VALUE val) {
|
|
1785
|
+
MethodDescriptor* ret;
|
|
1786
|
+
TypedData_Get_Struct(val, MethodDescriptor, &MethodDescriptor_type, ret);
|
|
1787
|
+
return ret;
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
static VALUE MethodDescriptor_alloc(VALUE klass) {
|
|
1791
|
+
MethodDescriptor* self = ALLOC(MethodDescriptor);
|
|
1792
|
+
VALUE ret = TypedData_Wrap_Struct(klass, &MethodDescriptor_type, self);
|
|
1793
|
+
self->methoddef = NULL;
|
|
1794
|
+
self->module = Qnil;
|
|
1795
|
+
self->descriptor_pool = Qnil;
|
|
1796
|
+
return ret;
|
|
1797
|
+
}
|
|
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
|
+
|
|
1806
|
+
/*
|
|
1807
|
+
* call-seq:
|
|
1808
|
+
* MethodDescriptor.new(c_only_cookie, ptr) => MethodDescriptor
|
|
1809
|
+
*
|
|
1810
|
+
* Creates a descriptor wrapper object. May only be called from C.
|
|
1811
|
+
*/
|
|
1812
|
+
static VALUE MethodDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
1813
|
+
VALUE descriptor_pool, VALUE ptr) {
|
|
1814
|
+
MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
|
|
1815
|
+
|
|
1816
|
+
if (cookie != c_only_cookie) {
|
|
1817
|
+
rb_raise(rb_eRuntimeError,
|
|
1818
|
+
"Descriptor objects may not be created from Ruby.");
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
RB_OBJ_WRITE(_self, &self->descriptor_pool, descriptor_pool);
|
|
1822
|
+
self->methoddef = (const upb_MethodDef*)NUM2ULL(ptr);
|
|
1823
|
+
|
|
1824
|
+
return Qnil;
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
/*
|
|
1828
|
+
* ruby-doc: MethodDescriptor#name
|
|
1829
|
+
*
|
|
1830
|
+
* Returns the name of this method
|
|
1831
|
+
*
|
|
1832
|
+
* @return [String]
|
|
1833
|
+
*/
|
|
1834
|
+
static VALUE MethodDescriptor_name(VALUE _self) {
|
|
1835
|
+
MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
|
|
1836
|
+
return rb_str_maybe_null(upb_MethodDef_Name(self->methoddef));
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
/*
|
|
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}.
|
|
1845
|
+
*
|
|
1846
|
+
* @return [MethodOptions]
|
|
1847
|
+
*/
|
|
1848
|
+
static VALUE MethodDescriptor_options(VALUE _self) {
|
|
1849
|
+
MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
|
|
1850
|
+
const google_protobuf_MethodOptions* opts =
|
|
1851
|
+
upb_MethodDef_Options(self->methoddef);
|
|
1852
|
+
upb_Arena* arena = upb_Arena_New();
|
|
1853
|
+
size_t size;
|
|
1854
|
+
char* serialized =
|
|
1855
|
+
google_protobuf_MethodOptions_serialize(opts, arena, &size);
|
|
1856
|
+
VALUE method_options = decode_options(_self, "MethodOptions", size,
|
|
1857
|
+
serialized, self->descriptor_pool);
|
|
1858
|
+
upb_Arena_Free(arena);
|
|
1859
|
+
return method_options;
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1862
|
+
/*
|
|
1863
|
+
* ruby-doc: MethodDescriptor#input_type
|
|
1864
|
+
*
|
|
1865
|
+
* Returns the {Descriptor} for the request message type of this method
|
|
1866
|
+
*
|
|
1867
|
+
* @return [Descriptor]
|
|
1868
|
+
*/
|
|
1869
|
+
static VALUE MethodDescriptor_input_type(VALUE _self) {
|
|
1870
|
+
MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
|
|
1871
|
+
const upb_MessageDef* type = upb_MethodDef_InputType(self->methoddef);
|
|
1872
|
+
return get_msgdef_obj(self->descriptor_pool, type);
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
/*
|
|
1876
|
+
* ruby-doc: MethodDescriptor#output_type
|
|
1877
|
+
*
|
|
1878
|
+
* Returns the {Descriptor} for the response message type of this method
|
|
1879
|
+
*
|
|
1880
|
+
* @return [Descriptor]
|
|
1881
|
+
*/
|
|
1882
|
+
static VALUE MethodDescriptor_output_type(VALUE _self) {
|
|
1883
|
+
MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
|
|
1884
|
+
const upb_MessageDef* type = upb_MethodDef_OutputType(self->methoddef);
|
|
1885
|
+
return get_msgdef_obj(self->descriptor_pool, type);
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
/*
|
|
1889
|
+
* ruby-doc: MethodDescriptor#client_streaming
|
|
1890
|
+
*
|
|
1891
|
+
* Returns whether or not this is a streaming request method
|
|
1892
|
+
*
|
|
1893
|
+
* @return [Boolean]
|
|
1894
|
+
*/
|
|
1895
|
+
static VALUE MethodDescriptor_client_streaming(VALUE _self) {
|
|
1896
|
+
MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
|
|
1897
|
+
return upb_MethodDef_ClientStreaming(self->methoddef) ? Qtrue : Qfalse;
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1900
|
+
/*
|
|
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
|
|
1926
|
+
*
|
|
1927
|
+
* Returns whether or not this is a streaming response method
|
|
1928
|
+
*
|
|
1929
|
+
* @return [Boolean]
|
|
1930
|
+
*/
|
|
1931
|
+
static VALUE MethodDescriptor_server_streaming(VALUE _self) {
|
|
1932
|
+
MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
|
|
1933
|
+
return upb_MethodDef_ServerStreaming(self->methoddef) ? Qtrue : Qfalse;
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
static void MethodDescriptor_register(VALUE module) {
|
|
1937
|
+
VALUE klass = rb_define_class_under(module, "MethodDescriptor", rb_cObject);
|
|
1938
|
+
rb_define_alloc_func(klass, MethodDescriptor_alloc);
|
|
1939
|
+
rb_define_method(klass, "initialize", MethodDescriptor_initialize, 3);
|
|
1940
|
+
rb_define_method(klass, "name", MethodDescriptor_name, 0);
|
|
1941
|
+
rb_define_method(klass, "options", MethodDescriptor_options, 0);
|
|
1942
|
+
rb_define_method(klass, "input_type", MethodDescriptor_input_type, 0);
|
|
1943
|
+
rb_define_method(klass, "output_type", MethodDescriptor_output_type, 0);
|
|
1944
|
+
rb_define_method(klass, "client_streaming", MethodDescriptor_client_streaming,
|
|
1945
|
+
0);
|
|
1946
|
+
rb_define_method(klass, "server_streaming", MethodDescriptor_server_streaming,
|
|
1947
|
+
0);
|
|
1948
|
+
rb_define_method(klass, "to_proto", MethodDescriptor_to_proto, 0);
|
|
1949
|
+
rb_gc_register_address(&cMethodDescriptor);
|
|
1950
|
+
cMethodDescriptor = klass;
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1284
1953
|
static VALUE get_def_obj(VALUE _descriptor_pool, const void* ptr, VALUE klass) {
|
|
1285
1954
|
DescriptorPool* descriptor_pool = ruby_to_DescriptorPool(_descriptor_pool);
|
|
1286
1955
|
VALUE key = ULL2NUM((intptr_t)ptr);
|
|
@@ -1322,6 +1991,16 @@ static VALUE get_oneofdef_obj(VALUE descriptor_pool, const upb_OneofDef* def) {
|
|
|
1322
1991
|
return get_def_obj(descriptor_pool, def, cOneofDescriptor);
|
|
1323
1992
|
}
|
|
1324
1993
|
|
|
1994
|
+
static VALUE get_servicedef_obj(VALUE descriptor_pool,
|
|
1995
|
+
const upb_ServiceDef* def) {
|
|
1996
|
+
return get_def_obj(descriptor_pool, def, cServiceDescriptor);
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
static VALUE get_methoddef_obj(VALUE descriptor_pool,
|
|
2000
|
+
const upb_MethodDef* def) {
|
|
2001
|
+
return get_def_obj(descriptor_pool, def, cMethodDescriptor);
|
|
2002
|
+
}
|
|
2003
|
+
|
|
1325
2004
|
// -----------------------------------------------------------------------------
|
|
1326
2005
|
// Shared functions
|
|
1327
2006
|
// -----------------------------------------------------------------------------
|
|
@@ -1397,6 +2076,8 @@ void Defs_register(VALUE module) {
|
|
|
1397
2076
|
FieldDescriptor_register(module);
|
|
1398
2077
|
OneofDescriptor_register(module);
|
|
1399
2078
|
EnumDescriptor_register(module);
|
|
2079
|
+
ServiceDescriptor_register(module);
|
|
2080
|
+
MethodDescriptor_register(module);
|
|
1400
2081
|
|
|
1401
2082
|
rb_gc_register_address(&c_only_cookie);
|
|
1402
2083
|
c_only_cookie = rb_class_new_instance(0, NULL, rb_cObject);
|