google-protobuf 3.19.6-x86-linux → 3.20.0.rc.1-x86-linux
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.
Potentially problematic release.
This version of google-protobuf might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/ext/google/protobuf_c/convert.c +124 -111
- data/ext/google/protobuf_c/convert.h +12 -9
- data/ext/google/protobuf_c/defs.c +196 -201
- data/ext/google/protobuf_c/defs.h +19 -19
- data/ext/google/protobuf_c/extconf.rb +11 -3
- data/ext/google/protobuf_c/map.c +109 -101
- data/ext/google/protobuf_c/map.h +7 -8
- data/ext/google/protobuf_c/message.c +382 -303
- data/ext/google/protobuf_c/message.h +22 -19
- data/ext/google/protobuf_c/protobuf.c +57 -58
- data/ext/google/protobuf_c/protobuf.h +13 -10
- data/ext/google/protobuf_c/repeated_field.c +82 -84
- data/ext/google/protobuf_c/repeated_field.h +6 -6
- data/ext/google/protobuf_c/ruby-upb.c +4945 -3084
- data/ext/google/protobuf_c/ruby-upb.h +2285 -1701
- data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +21 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +395 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +9 -0
- data/ext/google/protobuf_c/wrap_memcpy.c +4 -3
- data/lib/google/2.5/protobuf_c.so +0 -0
- data/lib/google/2.6/protobuf_c.so +0 -0
- data/lib/google/2.7/protobuf_c.so +0 -0
- data/lib/google/3.0/protobuf_c.so +0 -0
- data/lib/google/protobuf/descriptor_dsl.rb +8 -1
- data/lib/google/protobuf/descriptor_pb.rb +3 -2
- data/lib/google/protobuf/message_exts.rb +2 -2
- data/lib/google/protobuf/well_known_types.rb +11 -6
- data/lib/google/protobuf.rb +4 -4
- data/tests/basic.rb +14 -0
- metadata +8 -5
@@ -41,11 +41,11 @@
|
|
41
41
|
// instances.
|
42
42
|
// -----------------------------------------------------------------------------
|
43
43
|
|
44
|
-
static VALUE get_msgdef_obj(VALUE descriptor_pool, const
|
45
|
-
static VALUE get_enumdef_obj(VALUE descriptor_pool, const
|
46
|
-
static VALUE get_fielddef_obj(VALUE descriptor_pool, const
|
47
|
-
static VALUE get_filedef_obj(VALUE descriptor_pool, const
|
48
|
-
static VALUE get_oneofdef_obj(VALUE descriptor_pool, const
|
44
|
+
static VALUE get_msgdef_obj(VALUE descriptor_pool, const upb_MessageDef* def);
|
45
|
+
static VALUE get_enumdef_obj(VALUE descriptor_pool, const upb_EnumDef* def);
|
46
|
+
static VALUE get_fielddef_obj(VALUE descriptor_pool, const upb_FieldDef* def);
|
47
|
+
static VALUE get_filedef_obj(VALUE descriptor_pool, const upb_FileDef* def);
|
48
|
+
static VALUE get_oneofdef_obj(VALUE descriptor_pool, const upb_OneofDef* def);
|
49
49
|
|
50
50
|
// A distinct object that is not accessible from Ruby. We use this as a
|
51
51
|
// constructor argument to enforce that certain objects cannot be created from
|
@@ -74,7 +74,7 @@ static VALUE rb_str_maybe_null(const char* s) {
|
|
74
74
|
|
75
75
|
typedef struct {
|
76
76
|
VALUE def_to_descriptor; // Hash table of def* -> Ruby descriptor.
|
77
|
-
|
77
|
+
upb_DefPool* symtab;
|
78
78
|
} DescriptorPool;
|
79
79
|
|
80
80
|
VALUE cDescriptorPool = Qnil;
|
@@ -90,14 +90,14 @@ static void DescriptorPool_mark(void* _self) {
|
|
90
90
|
|
91
91
|
static void DescriptorPool_free(void* _self) {
|
92
92
|
DescriptorPool* self = _self;
|
93
|
-
|
93
|
+
upb_DefPool_Free(self->symtab);
|
94
94
|
xfree(self);
|
95
95
|
}
|
96
96
|
|
97
97
|
static const rb_data_type_t DescriptorPool_type = {
|
98
|
-
|
99
|
-
|
100
|
-
|
98
|
+
"Google::Protobuf::DescriptorPool",
|
99
|
+
{DescriptorPool_mark, DescriptorPool_free, NULL},
|
100
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
101
101
|
};
|
102
102
|
|
103
103
|
static DescriptorPool* ruby_to_DescriptorPool(VALUE val) {
|
@@ -107,8 +107,8 @@ static DescriptorPool* ruby_to_DescriptorPool(VALUE val) {
|
|
107
107
|
}
|
108
108
|
|
109
109
|
// Exposed to other modules in defs.h.
|
110
|
-
const
|
111
|
-
DescriptorPool
|
110
|
+
const upb_DefPool* DescriptorPool_GetSymtab(VALUE desc_pool_rb) {
|
111
|
+
DescriptorPool* pool = ruby_to_DescriptorPool(desc_pool_rb);
|
112
112
|
return pool->symtab;
|
113
113
|
}
|
114
114
|
|
@@ -126,7 +126,7 @@ static VALUE DescriptorPool_alloc(VALUE klass) {
|
|
126
126
|
ret = TypedData_Wrap_Struct(klass, &DescriptorPool_type, self);
|
127
127
|
|
128
128
|
self->def_to_descriptor = rb_hash_new();
|
129
|
-
self->symtab =
|
129
|
+
self->symtab = upb_DefPool_New();
|
130
130
|
ObjectCache_Add(self->symtab, ret);
|
131
131
|
|
132
132
|
return ret;
|
@@ -143,7 +143,7 @@ VALUE DescriptorPool_add_serialized_file(VALUE _self,
|
|
143
143
|
DescriptorPool* self = ruby_to_DescriptorPool(_self);
|
144
144
|
Check_Type(serialized_file_proto, T_STRING);
|
145
145
|
VALUE arena_rb = Arena_new();
|
146
|
-
|
146
|
+
upb_Arena* arena = Arena_get(arena_rb);
|
147
147
|
google_protobuf_FileDescriptorProto* file_proto =
|
148
148
|
google_protobuf_FileDescriptorProto_parse(
|
149
149
|
RSTRING_PTR(serialized_file_proto),
|
@@ -151,13 +151,13 @@ VALUE DescriptorPool_add_serialized_file(VALUE _self,
|
|
151
151
|
if (!file_proto) {
|
152
152
|
rb_raise(rb_eArgError, "Unable to parse FileDescriptorProto");
|
153
153
|
}
|
154
|
-
|
155
|
-
|
156
|
-
const
|
157
|
-
|
154
|
+
upb_Status status;
|
155
|
+
upb_Status_Clear(&status);
|
156
|
+
const upb_FileDef* filedef =
|
157
|
+
upb_DefPool_AddFile(self->symtab, file_proto, &status);
|
158
158
|
if (!filedef) {
|
159
159
|
rb_raise(cTypeError, "Unable to build file to DescriptorPool: %s",
|
160
|
-
|
160
|
+
upb_Status_ErrorMessage(&status));
|
161
161
|
}
|
162
162
|
return get_filedef_obj(_self, filedef);
|
163
163
|
}
|
@@ -172,15 +172,15 @@ VALUE DescriptorPool_add_serialized_file(VALUE _self,
|
|
172
172
|
static VALUE DescriptorPool_lookup(VALUE _self, VALUE name) {
|
173
173
|
DescriptorPool* self = ruby_to_DescriptorPool(_self);
|
174
174
|
const char* name_str = get_str(name);
|
175
|
-
const
|
176
|
-
const
|
175
|
+
const upb_MessageDef* msgdef;
|
176
|
+
const upb_EnumDef* enumdef;
|
177
177
|
|
178
|
-
msgdef =
|
178
|
+
msgdef = upb_DefPool_FindMessageByName(self->symtab, name_str);
|
179
179
|
if (msgdef) {
|
180
180
|
return get_msgdef_obj(_self, msgdef);
|
181
181
|
}
|
182
182
|
|
183
|
-
enumdef =
|
183
|
+
enumdef = upb_DefPool_FindEnumByName(self->symtab, name_str);
|
184
184
|
if (enumdef) {
|
185
185
|
return get_enumdef_obj(_self, enumdef);
|
186
186
|
}
|
@@ -202,8 +202,7 @@ static VALUE DescriptorPool_generated_pool(VALUE _self) {
|
|
202
202
|
}
|
203
203
|
|
204
204
|
static void DescriptorPool_register(VALUE module) {
|
205
|
-
VALUE klass = rb_define_class_under(
|
206
|
-
module, "DescriptorPool", rb_cObject);
|
205
|
+
VALUE klass = rb_define_class_under(module, "DescriptorPool", rb_cObject);
|
207
206
|
rb_define_alloc_func(klass, DescriptorPool_alloc);
|
208
207
|
rb_define_method(klass, "add_serialized_file",
|
209
208
|
DescriptorPool_add_serialized_file, 1);
|
@@ -222,7 +221,7 @@ static void DescriptorPool_register(VALUE module) {
|
|
222
221
|
// -----------------------------------------------------------------------------
|
223
222
|
|
224
223
|
typedef struct {
|
225
|
-
const
|
224
|
+
const upb_MessageDef* msgdef;
|
226
225
|
VALUE klass;
|
227
226
|
VALUE descriptor_pool;
|
228
227
|
} Descriptor;
|
@@ -236,9 +235,9 @@ static void Descriptor_mark(void* _self) {
|
|
236
235
|
}
|
237
236
|
|
238
237
|
static const rb_data_type_t Descriptor_type = {
|
239
|
-
|
240
|
-
|
241
|
-
|
238
|
+
"Google::Protobuf::Descriptor",
|
239
|
+
{Descriptor_mark, RUBY_DEFAULT_FREE, NULL},
|
240
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
242
241
|
};
|
243
242
|
|
244
243
|
static Descriptor* ruby_to_Descriptor(VALUE val) {
|
@@ -281,7 +280,7 @@ static VALUE Descriptor_initialize(VALUE _self, VALUE cookie,
|
|
281
280
|
}
|
282
281
|
|
283
282
|
self->descriptor_pool = descriptor_pool;
|
284
|
-
self->msgdef = (const
|
283
|
+
self->msgdef = (const upb_MessageDef*)NUM2ULL(ptr);
|
285
284
|
|
286
285
|
return Qnil;
|
287
286
|
}
|
@@ -294,7 +293,8 @@ static VALUE Descriptor_initialize(VALUE _self, VALUE cookie,
|
|
294
293
|
*/
|
295
294
|
static VALUE Descriptor_file_descriptor(VALUE _self) {
|
296
295
|
Descriptor* self = ruby_to_Descriptor(_self);
|
297
|
-
return get_filedef_obj(self->descriptor_pool,
|
296
|
+
return get_filedef_obj(self->descriptor_pool,
|
297
|
+
upb_MessageDef_File(self->msgdef));
|
298
298
|
}
|
299
299
|
|
300
300
|
/*
|
@@ -306,7 +306,7 @@ static VALUE Descriptor_file_descriptor(VALUE _self) {
|
|
306
306
|
*/
|
307
307
|
static VALUE Descriptor_name(VALUE _self) {
|
308
308
|
Descriptor* self = ruby_to_Descriptor(_self);
|
309
|
-
return rb_str_maybe_null(
|
309
|
+
return rb_str_maybe_null(upb_MessageDef_FullName(self->msgdef));
|
310
310
|
}
|
311
311
|
|
312
312
|
/*
|
@@ -318,11 +318,9 @@ static VALUE Descriptor_name(VALUE _self) {
|
|
318
318
|
static VALUE Descriptor_each(VALUE _self) {
|
319
319
|
Descriptor* self = ruby_to_Descriptor(_self);
|
320
320
|
|
321
|
-
|
322
|
-
for (
|
323
|
-
|
324
|
-
upb_msg_field_next(&it)) {
|
325
|
-
const upb_fielddef* field = upb_msg_iter_field(&it);
|
321
|
+
int n = upb_MessageDef_FieldCount(self->msgdef);
|
322
|
+
for (int i = 0; i < n; i++) {
|
323
|
+
const upb_FieldDef* field = upb_MessageDef_Field(self->msgdef, i);
|
326
324
|
VALUE obj = get_fielddef_obj(self->descriptor_pool, field);
|
327
325
|
rb_yield(obj);
|
328
326
|
}
|
@@ -339,7 +337,7 @@ static VALUE Descriptor_each(VALUE _self) {
|
|
339
337
|
static VALUE Descriptor_lookup(VALUE _self, VALUE name) {
|
340
338
|
Descriptor* self = ruby_to_Descriptor(_self);
|
341
339
|
const char* s = get_str(name);
|
342
|
-
const
|
340
|
+
const upb_FieldDef* field = upb_MessageDef_FindFieldByName(self->msgdef, s);
|
343
341
|
if (field == NULL) {
|
344
342
|
return Qnil;
|
345
343
|
}
|
@@ -356,11 +354,9 @@ static VALUE Descriptor_lookup(VALUE _self, VALUE name) {
|
|
356
354
|
static VALUE Descriptor_each_oneof(VALUE _self) {
|
357
355
|
Descriptor* self = ruby_to_Descriptor(_self);
|
358
356
|
|
359
|
-
|
360
|
-
for (
|
361
|
-
|
362
|
-
upb_msg_oneof_next(&it)) {
|
363
|
-
const upb_oneofdef* oneof = upb_msg_iter_oneof(&it);
|
357
|
+
int n = upb_MessageDef_OneofCount(self->msgdef);
|
358
|
+
for (int i = 0; i < n; i++) {
|
359
|
+
const upb_OneofDef* oneof = upb_MessageDef_Oneof(self->msgdef, i);
|
364
360
|
VALUE obj = get_oneofdef_obj(self->descriptor_pool, oneof);
|
365
361
|
rb_yield(obj);
|
366
362
|
}
|
@@ -377,7 +373,7 @@ static VALUE Descriptor_each_oneof(VALUE _self) {
|
|
377
373
|
static VALUE Descriptor_lookup_oneof(VALUE _self, VALUE name) {
|
378
374
|
Descriptor* self = ruby_to_Descriptor(_self);
|
379
375
|
const char* s = get_str(name);
|
380
|
-
const
|
376
|
+
const upb_OneofDef* oneof = upb_MessageDef_FindOneofByName(self->msgdef, s);
|
381
377
|
if (oneof == NULL) {
|
382
378
|
return Qnil;
|
383
379
|
}
|
@@ -399,8 +395,7 @@ static VALUE Descriptor_msgclass(VALUE _self) {
|
|
399
395
|
}
|
400
396
|
|
401
397
|
static void Descriptor_register(VALUE module) {
|
402
|
-
VALUE klass = rb_define_class_under(
|
403
|
-
module, "Descriptor", rb_cObject);
|
398
|
+
VALUE klass = rb_define_class_under(module, "Descriptor", rb_cObject);
|
404
399
|
rb_define_alloc_func(klass, Descriptor_alloc);
|
405
400
|
rb_define_method(klass, "initialize", Descriptor_initialize, 3);
|
406
401
|
rb_define_method(klass, "each", Descriptor_each, 0);
|
@@ -420,8 +415,8 @@ static void Descriptor_register(VALUE module) {
|
|
420
415
|
// -----------------------------------------------------------------------------
|
421
416
|
|
422
417
|
typedef struct {
|
423
|
-
const
|
424
|
-
VALUE descriptor_pool; // Owns the
|
418
|
+
const upb_FileDef* filedef;
|
419
|
+
VALUE descriptor_pool; // Owns the upb_FileDef.
|
425
420
|
} FileDescriptor;
|
426
421
|
|
427
422
|
static VALUE cFileDescriptor = Qnil;
|
@@ -432,9 +427,9 @@ static void FileDescriptor_mark(void* _self) {
|
|
432
427
|
}
|
433
428
|
|
434
429
|
static const rb_data_type_t FileDescriptor_type = {
|
435
|
-
|
436
|
-
|
437
|
-
|
430
|
+
"Google::Protobuf::FileDescriptor",
|
431
|
+
{FileDescriptor_mark, RUBY_DEFAULT_FREE, NULL},
|
432
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
438
433
|
};
|
439
434
|
|
440
435
|
static FileDescriptor* ruby_to_FileDescriptor(VALUE val) {
|
@@ -459,7 +454,7 @@ static VALUE FileDescriptor_alloc(VALUE klass) {
|
|
459
454
|
* to a builder.
|
460
455
|
*/
|
461
456
|
static VALUE FileDescriptor_initialize(VALUE _self, VALUE cookie,
|
462
|
-
|
457
|
+
VALUE descriptor_pool, VALUE ptr) {
|
463
458
|
FileDescriptor* self = ruby_to_FileDescriptor(_self);
|
464
459
|
|
465
460
|
if (cookie != c_only_cookie) {
|
@@ -468,7 +463,7 @@ static VALUE FileDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
468
463
|
}
|
469
464
|
|
470
465
|
self->descriptor_pool = descriptor_pool;
|
471
|
-
self->filedef = (const
|
466
|
+
self->filedef = (const upb_FileDef*)NUM2ULL(ptr);
|
472
467
|
|
473
468
|
return Qnil;
|
474
469
|
}
|
@@ -481,7 +476,7 @@ static VALUE FileDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
481
476
|
*/
|
482
477
|
static VALUE FileDescriptor_name(VALUE _self) {
|
483
478
|
FileDescriptor* self = ruby_to_FileDescriptor(_self);
|
484
|
-
const char* name =
|
479
|
+
const char* name = upb_FileDef_Name(self->filedef);
|
485
480
|
return name == NULL ? Qnil : rb_str_new2(name);
|
486
481
|
}
|
487
482
|
|
@@ -497,16 +492,18 @@ static VALUE FileDescriptor_name(VALUE _self) {
|
|
497
492
|
static VALUE FileDescriptor_syntax(VALUE _self) {
|
498
493
|
FileDescriptor* self = ruby_to_FileDescriptor(_self);
|
499
494
|
|
500
|
-
switch (
|
501
|
-
case
|
502
|
-
|
503
|
-
|
495
|
+
switch (upb_FileDef_Syntax(self->filedef)) {
|
496
|
+
case kUpb_Syntax_Proto3:
|
497
|
+
return ID2SYM(rb_intern("proto3"));
|
498
|
+
case kUpb_Syntax_Proto2:
|
499
|
+
return ID2SYM(rb_intern("proto2"));
|
500
|
+
default:
|
501
|
+
return Qnil;
|
504
502
|
}
|
505
503
|
}
|
506
504
|
|
507
505
|
static void FileDescriptor_register(VALUE module) {
|
508
|
-
VALUE klass = rb_define_class_under(
|
509
|
-
module, "FileDescriptor", rb_cObject);
|
506
|
+
VALUE klass = rb_define_class_under(module, "FileDescriptor", rb_cObject);
|
510
507
|
rb_define_alloc_func(klass, FileDescriptor_alloc);
|
511
508
|
rb_define_method(klass, "initialize", FileDescriptor_initialize, 3);
|
512
509
|
rb_define_method(klass, "name", FileDescriptor_name, 0);
|
@@ -520,8 +517,8 @@ static void FileDescriptor_register(VALUE module) {
|
|
520
517
|
// -----------------------------------------------------------------------------
|
521
518
|
|
522
519
|
typedef struct {
|
523
|
-
const
|
524
|
-
VALUE descriptor_pool; // Owns the
|
520
|
+
const upb_FieldDef* fielddef;
|
521
|
+
VALUE descriptor_pool; // Owns the upb_FieldDef.
|
525
522
|
} FieldDescriptor;
|
526
523
|
|
527
524
|
static VALUE cFieldDescriptor = Qnil;
|
@@ -532,9 +529,9 @@ static void FieldDescriptor_mark(void* _self) {
|
|
532
529
|
}
|
533
530
|
|
534
531
|
static const rb_data_type_t FieldDescriptor_type = {
|
535
|
-
|
536
|
-
|
537
|
-
|
532
|
+
"Google::Protobuf::FieldDescriptor",
|
533
|
+
{FieldDescriptor_mark, RUBY_DEFAULT_FREE, NULL},
|
534
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
538
535
|
};
|
539
536
|
|
540
537
|
static FieldDescriptor* ruby_to_FieldDescriptor(VALUE val) {
|
@@ -573,7 +570,7 @@ static VALUE FieldDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
573
570
|
}
|
574
571
|
|
575
572
|
self->descriptor_pool = descriptor_pool;
|
576
|
-
self->fielddef = (const
|
573
|
+
self->fielddef = (const upb_FieldDef*)NUM2ULL(ptr);
|
577
574
|
|
578
575
|
return Qnil;
|
579
576
|
}
|
@@ -586,31 +583,31 @@ static VALUE FieldDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
586
583
|
*/
|
587
584
|
static VALUE FieldDescriptor_name(VALUE _self) {
|
588
585
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
589
|
-
return rb_str_maybe_null(
|
586
|
+
return rb_str_maybe_null(upb_FieldDef_Name(self->fielddef));
|
590
587
|
}
|
591
588
|
|
592
589
|
// Non-static, exposed to other .c files.
|
593
|
-
|
590
|
+
upb_CType ruby_to_fieldtype(VALUE type) {
|
594
591
|
if (TYPE(type) != T_SYMBOL) {
|
595
592
|
rb_raise(rb_eArgError, "Expected symbol for field type.");
|
596
593
|
}
|
597
594
|
|
598
|
-
#define CONVERT(upb, ruby)
|
599
|
-
if (SYM2ID(type) == rb_intern(
|
600
|
-
return
|
595
|
+
#define CONVERT(upb, ruby) \
|
596
|
+
if (SYM2ID(type) == rb_intern(#ruby)) { \
|
597
|
+
return kUpb_CType_##upb; \
|
601
598
|
}
|
602
599
|
|
603
|
-
CONVERT(
|
604
|
-
CONVERT(
|
605
|
-
CONVERT(
|
606
|
-
CONVERT(
|
607
|
-
CONVERT(
|
608
|
-
CONVERT(
|
609
|
-
CONVERT(
|
610
|
-
CONVERT(
|
611
|
-
CONVERT(
|
612
|
-
CONVERT(
|
613
|
-
CONVERT(
|
600
|
+
CONVERT(Float, float);
|
601
|
+
CONVERT(Double, double);
|
602
|
+
CONVERT(Bool, bool);
|
603
|
+
CONVERT(String, string);
|
604
|
+
CONVERT(Bytes, bytes);
|
605
|
+
CONVERT(Message, message);
|
606
|
+
CONVERT(Enum, enum);
|
607
|
+
CONVERT(Int32, int32);
|
608
|
+
CONVERT(Int64, int64);
|
609
|
+
CONVERT(UInt32, uint32);
|
610
|
+
CONVERT(UInt64, uint64);
|
614
611
|
|
615
612
|
#undef CONVERT
|
616
613
|
|
@@ -618,28 +615,29 @@ upb_fieldtype_t ruby_to_fieldtype(VALUE type) {
|
|
618
615
|
return 0;
|
619
616
|
}
|
620
617
|
|
621
|
-
static VALUE descriptortype_to_ruby(
|
618
|
+
static VALUE descriptortype_to_ruby(upb_FieldType type) {
|
622
619
|
switch (type) {
|
623
|
-
#define CONVERT(upb, ruby)
|
624
|
-
|
625
|
-
|
626
|
-
CONVERT(
|
627
|
-
CONVERT(
|
628
|
-
CONVERT(
|
629
|
-
CONVERT(
|
630
|
-
CONVERT(
|
631
|
-
CONVERT(
|
632
|
-
CONVERT(
|
633
|
-
CONVERT(
|
634
|
-
CONVERT(
|
635
|
-
CONVERT(
|
636
|
-
CONVERT(
|
637
|
-
CONVERT(
|
638
|
-
CONVERT(
|
639
|
-
CONVERT(
|
640
|
-
CONVERT(
|
641
|
-
CONVERT(
|
642
|
-
CONVERT(
|
620
|
+
#define CONVERT(upb, ruby) \
|
621
|
+
case kUpb_FieldType_##upb: \
|
622
|
+
return ID2SYM(rb_intern(#ruby));
|
623
|
+
CONVERT(Float, float);
|
624
|
+
CONVERT(Double, double);
|
625
|
+
CONVERT(Bool, bool);
|
626
|
+
CONVERT(String, string);
|
627
|
+
CONVERT(Bytes, bytes);
|
628
|
+
CONVERT(Message, message);
|
629
|
+
CONVERT(Group, group);
|
630
|
+
CONVERT(Enum, enum);
|
631
|
+
CONVERT(Int32, int32);
|
632
|
+
CONVERT(Int64, int64);
|
633
|
+
CONVERT(UInt32, uint32);
|
634
|
+
CONVERT(UInt64, uint64);
|
635
|
+
CONVERT(SInt32, sint32);
|
636
|
+
CONVERT(SInt64, sint64);
|
637
|
+
CONVERT(Fixed32, fixed32);
|
638
|
+
CONVERT(Fixed64, fixed64);
|
639
|
+
CONVERT(SFixed32, sfixed32);
|
640
|
+
CONVERT(SFixed64, sfixed64);
|
643
641
|
#undef CONVERT
|
644
642
|
}
|
645
643
|
return Qnil;
|
@@ -657,7 +655,7 @@ static VALUE descriptortype_to_ruby(upb_descriptortype_t type) {
|
|
657
655
|
*/
|
658
656
|
static VALUE FieldDescriptor__type(VALUE _self) {
|
659
657
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
660
|
-
return descriptortype_to_ruby(
|
658
|
+
return descriptortype_to_ruby(upb_FieldDef_Type(self->fielddef));
|
661
659
|
}
|
662
660
|
|
663
661
|
/*
|
@@ -668,17 +666,16 @@ static VALUE FieldDescriptor__type(VALUE _self) {
|
|
668
666
|
*/
|
669
667
|
static VALUE FieldDescriptor_default(VALUE _self) {
|
670
668
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
671
|
-
const
|
672
|
-
|
673
|
-
if (
|
669
|
+
const upb_FieldDef* f = self->fielddef;
|
670
|
+
upb_MessageValue default_val = {0};
|
671
|
+
if (upb_FieldDef_IsSubMessage(f)) {
|
674
672
|
return Qnil;
|
675
|
-
} else if (!
|
676
|
-
default_val =
|
673
|
+
} else if (!upb_FieldDef_IsRepeated(f)) {
|
674
|
+
default_val = upb_FieldDef_Default(f);
|
677
675
|
}
|
678
676
|
return Convert_UpbToRuby(default_val, TypeInfo_get(self->fielddef), Qnil);
|
679
677
|
}
|
680
678
|
|
681
|
-
|
682
679
|
/*
|
683
680
|
* call-seq:
|
684
681
|
* FieldDescriptor.json_name => json_name
|
@@ -687,8 +684,8 @@ static VALUE FieldDescriptor_default(VALUE _self) {
|
|
687
684
|
*/
|
688
685
|
static VALUE FieldDescriptor_json_name(VALUE _self) {
|
689
686
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
690
|
-
const
|
691
|
-
const char
|
687
|
+
const upb_FieldDef* f = self->fielddef;
|
688
|
+
const char* json_name = upb_FieldDef_JsonName(f);
|
692
689
|
return rb_str_new2(json_name);
|
693
690
|
}
|
694
691
|
|
@@ -703,13 +700,14 @@ static VALUE FieldDescriptor_json_name(VALUE _self) {
|
|
703
700
|
*/
|
704
701
|
static VALUE FieldDescriptor_label(VALUE _self) {
|
705
702
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
706
|
-
switch (
|
707
|
-
#define CONVERT(upb, ruby)
|
708
|
-
|
703
|
+
switch (upb_FieldDef_Label(self->fielddef)) {
|
704
|
+
#define CONVERT(upb, ruby) \
|
705
|
+
case kUpb_Label_##upb: \
|
706
|
+
return ID2SYM(rb_intern(#ruby));
|
709
707
|
|
710
|
-
CONVERT(
|
711
|
-
CONVERT(
|
712
|
-
CONVERT(
|
708
|
+
CONVERT(Optional, optional);
|
709
|
+
CONVERT(Required, required);
|
710
|
+
CONVERT(Repeated, repeated);
|
713
711
|
|
714
712
|
#undef CONVERT
|
715
713
|
}
|
@@ -725,7 +723,7 @@ static VALUE FieldDescriptor_label(VALUE _self) {
|
|
725
723
|
*/
|
726
724
|
static VALUE FieldDescriptor_number(VALUE _self) {
|
727
725
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
728
|
-
return INT2NUM(
|
726
|
+
return INT2NUM(upb_FieldDef_Number(self->fielddef));
|
729
727
|
}
|
730
728
|
|
731
729
|
/*
|
@@ -739,13 +737,13 @@ static VALUE FieldDescriptor_number(VALUE _self) {
|
|
739
737
|
*/
|
740
738
|
static VALUE FieldDescriptor_submsg_name(VALUE _self) {
|
741
739
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
742
|
-
switch (
|
743
|
-
case
|
740
|
+
switch (upb_FieldDef_CType(self->fielddef)) {
|
741
|
+
case kUpb_CType_Enum:
|
744
742
|
return rb_str_new2(
|
745
|
-
|
746
|
-
case
|
743
|
+
upb_EnumDef_FullName(upb_FieldDef_EnumSubDef(self->fielddef)));
|
744
|
+
case kUpb_CType_Message:
|
747
745
|
return rb_str_new2(
|
748
|
-
|
746
|
+
upb_MessageDef_FullName(upb_FieldDef_MessageSubDef(self->fielddef)));
|
749
747
|
default:
|
750
748
|
return Qnil;
|
751
749
|
}
|
@@ -762,13 +760,13 @@ static VALUE FieldDescriptor_submsg_name(VALUE _self) {
|
|
762
760
|
*/
|
763
761
|
static VALUE FieldDescriptor_subtype(VALUE _self) {
|
764
762
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
765
|
-
switch (
|
766
|
-
case
|
763
|
+
switch (upb_FieldDef_CType(self->fielddef)) {
|
764
|
+
case kUpb_CType_Enum:
|
767
765
|
return get_enumdef_obj(self->descriptor_pool,
|
768
|
-
|
769
|
-
case
|
766
|
+
upb_FieldDef_EnumSubDef(self->fielddef));
|
767
|
+
case kUpb_CType_Message:
|
770
768
|
return get_msgdef_obj(self->descriptor_pool,
|
771
|
-
|
769
|
+
upb_FieldDef_MessageSubDef(self->fielddef));
|
772
770
|
default:
|
773
771
|
return Qnil;
|
774
772
|
}
|
@@ -783,11 +781,11 @@ static VALUE FieldDescriptor_subtype(VALUE _self) {
|
|
783
781
|
*/
|
784
782
|
static VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) {
|
785
783
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
786
|
-
const
|
784
|
+
const upb_MessageDef* m;
|
787
785
|
|
788
786
|
Message_Get(msg_rb, &m);
|
789
787
|
|
790
|
-
if (m !=
|
788
|
+
if (m != upb_FieldDef_ContainingType(self->fielddef)) {
|
791
789
|
rb_raise(cTypeError, "get method called on wrong message type");
|
792
790
|
}
|
793
791
|
|
@@ -803,16 +801,16 @@ static VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) {
|
|
803
801
|
*/
|
804
802
|
static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
|
805
803
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
806
|
-
const
|
807
|
-
const
|
804
|
+
const upb_MessageDef* m;
|
805
|
+
const upb_MessageDef* msg = Message_Get(msg_rb, &m);
|
808
806
|
|
809
|
-
if (m !=
|
807
|
+
if (m != upb_FieldDef_ContainingType(self->fielddef)) {
|
810
808
|
rb_raise(cTypeError, "has method called on wrong message type");
|
811
|
-
} else if (!
|
809
|
+
} else if (!upb_FieldDef_HasPresence(self->fielddef)) {
|
812
810
|
rb_raise(rb_eArgError, "does not track presence");
|
813
811
|
}
|
814
812
|
|
815
|
-
return
|
813
|
+
return upb_Message_Has(msg, self->fielddef) ? Qtrue : Qfalse;
|
816
814
|
}
|
817
815
|
|
818
816
|
/*
|
@@ -823,14 +821,14 @@ static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
|
|
823
821
|
*/
|
824
822
|
static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
|
825
823
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
826
|
-
const
|
827
|
-
|
824
|
+
const upb_MessageDef* m;
|
825
|
+
upb_MessageDef* msg = Message_GetMutable(msg_rb, &m);
|
828
826
|
|
829
|
-
if (m !=
|
827
|
+
if (m != upb_FieldDef_ContainingType(self->fielddef)) {
|
830
828
|
rb_raise(cTypeError, "has method called on wrong message type");
|
831
829
|
}
|
832
830
|
|
833
|
-
|
831
|
+
upb_Message_ClearField(msg, self->fielddef);
|
834
832
|
return Qnil;
|
835
833
|
}
|
836
834
|
|
@@ -844,24 +842,23 @@ static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
|
|
844
842
|
*/
|
845
843
|
static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) {
|
846
844
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
847
|
-
const
|
848
|
-
|
849
|
-
|
850
|
-
|
845
|
+
const upb_MessageDef* m;
|
846
|
+
upb_MessageDef* msg = Message_GetMutable(msg_rb, &m);
|
847
|
+
upb_Arena* arena = Arena_get(Message_GetArena(msg_rb));
|
848
|
+
upb_MessageValue msgval;
|
851
849
|
|
852
|
-
if (m !=
|
850
|
+
if (m != upb_FieldDef_ContainingType(self->fielddef)) {
|
853
851
|
rb_raise(cTypeError, "set method called on wrong message type");
|
854
852
|
}
|
855
853
|
|
856
|
-
msgval = Convert_RubyToUpb(value,
|
854
|
+
msgval = Convert_RubyToUpb(value, upb_FieldDef_Name(self->fielddef),
|
857
855
|
TypeInfo_get(self->fielddef), arena);
|
858
|
-
|
856
|
+
upb_Message_Set(msg, self->fielddef, msgval, arena);
|
859
857
|
return Qnil;
|
860
858
|
}
|
861
859
|
|
862
860
|
static void FieldDescriptor_register(VALUE module) {
|
863
|
-
VALUE klass = rb_define_class_under(
|
864
|
-
module, "FieldDescriptor", rb_cObject);
|
861
|
+
VALUE klass = rb_define_class_under(module, "FieldDescriptor", rb_cObject);
|
865
862
|
rb_define_alloc_func(klass, FieldDescriptor_alloc);
|
866
863
|
rb_define_method(klass, "initialize", FieldDescriptor_initialize, 3);
|
867
864
|
rb_define_method(klass, "name", FieldDescriptor_name, 0);
|
@@ -885,8 +882,8 @@ static void FieldDescriptor_register(VALUE module) {
|
|
885
882
|
// -----------------------------------------------------------------------------
|
886
883
|
|
887
884
|
typedef struct {
|
888
|
-
const
|
889
|
-
VALUE descriptor_pool; // Owns the
|
885
|
+
const upb_OneofDef* oneofdef;
|
886
|
+
VALUE descriptor_pool; // Owns the upb_OneofDef.
|
890
887
|
} OneofDescriptor;
|
891
888
|
|
892
889
|
static VALUE cOneofDescriptor = Qnil;
|
@@ -930,7 +927,7 @@ static VALUE OneofDescriptor_alloc(VALUE klass) {
|
|
930
927
|
* Creates a descriptor wrapper object. May only be called from C.
|
931
928
|
*/
|
932
929
|
static VALUE OneofDescriptor_initialize(VALUE _self, VALUE cookie,
|
933
|
-
|
930
|
+
VALUE descriptor_pool, VALUE ptr) {
|
934
931
|
OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
|
935
932
|
|
936
933
|
if (cookie != c_only_cookie) {
|
@@ -939,7 +936,7 @@ static VALUE OneofDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
939
936
|
}
|
940
937
|
|
941
938
|
self->descriptor_pool = descriptor_pool;
|
942
|
-
self->oneofdef = (const
|
939
|
+
self->oneofdef = (const upb_OneofDef*)NUM2ULL(ptr);
|
943
940
|
|
944
941
|
return Qnil;
|
945
942
|
}
|
@@ -952,7 +949,7 @@ static VALUE OneofDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
952
949
|
*/
|
953
950
|
static VALUE OneofDescriptor_name(VALUE _self) {
|
954
951
|
OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
|
955
|
-
return rb_str_maybe_null(
|
952
|
+
return rb_str_maybe_null(upb_OneofDef_Name(self->oneofdef));
|
956
953
|
}
|
957
954
|
|
958
955
|
/*
|
@@ -963,11 +960,10 @@ static VALUE OneofDescriptor_name(VALUE _self) {
|
|
963
960
|
*/
|
964
961
|
static VALUE OneofDescriptor_each(VALUE _self) {
|
965
962
|
OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
const upb_fielddef* f = upb_oneof_iter_field(&it);
|
963
|
+
|
964
|
+
int n = upb_OneofDef_FieldCount(self->oneofdef);
|
965
|
+
for (int i = 0; i < n; i++) {
|
966
|
+
const upb_FieldDef* f = upb_OneofDef_Field(self->oneofdef, i);
|
971
967
|
VALUE obj = get_fielddef_obj(self->descriptor_pool, f);
|
972
968
|
rb_yield(obj);
|
973
969
|
}
|
@@ -975,8 +971,7 @@ static VALUE OneofDescriptor_each(VALUE _self) {
|
|
975
971
|
}
|
976
972
|
|
977
973
|
static void OneofDescriptor_register(VALUE module) {
|
978
|
-
VALUE klass = rb_define_class_under(
|
979
|
-
module, "OneofDescriptor", rb_cObject);
|
974
|
+
VALUE klass = rb_define_class_under(module, "OneofDescriptor", rb_cObject);
|
980
975
|
rb_define_alloc_func(klass, OneofDescriptor_alloc);
|
981
976
|
rb_define_method(klass, "initialize", OneofDescriptor_initialize, 3);
|
982
977
|
rb_define_method(klass, "name", OneofDescriptor_name, 0);
|
@@ -991,9 +986,9 @@ static void OneofDescriptor_register(VALUE module) {
|
|
991
986
|
// -----------------------------------------------------------------------------
|
992
987
|
|
993
988
|
typedef struct {
|
994
|
-
const
|
995
|
-
VALUE module;
|
996
|
-
VALUE descriptor_pool; // Owns the
|
989
|
+
const upb_EnumDef* enumdef;
|
990
|
+
VALUE module; // begins as nil
|
991
|
+
VALUE descriptor_pool; // Owns the upb_EnumDef.
|
997
992
|
} EnumDescriptor;
|
998
993
|
|
999
994
|
static VALUE cEnumDescriptor = Qnil;
|
@@ -1005,9 +1000,9 @@ static void EnumDescriptor_mark(void* _self) {
|
|
1005
1000
|
}
|
1006
1001
|
|
1007
1002
|
static const rb_data_type_t EnumDescriptor_type = {
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1003
|
+
"Google::Protobuf::EnumDescriptor",
|
1004
|
+
{EnumDescriptor_mark, RUBY_DEFAULT_FREE, NULL},
|
1005
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
1011
1006
|
};
|
1012
1007
|
|
1013
1008
|
static EnumDescriptor* ruby_to_EnumDescriptor(VALUE val) {
|
@@ -1026,8 +1021,8 @@ static VALUE EnumDescriptor_alloc(VALUE klass) {
|
|
1026
1021
|
}
|
1027
1022
|
|
1028
1023
|
// Exposed to other modules in defs.h.
|
1029
|
-
const
|
1030
|
-
EnumDescriptor
|
1024
|
+
const upb_EnumDef* EnumDescriptor_GetEnumDef(VALUE enum_desc_rb) {
|
1025
|
+
EnumDescriptor* desc = ruby_to_EnumDescriptor(enum_desc_rb);
|
1031
1026
|
return desc->enumdef;
|
1032
1027
|
}
|
1033
1028
|
|
@@ -1047,7 +1042,7 @@ static VALUE EnumDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
1047
1042
|
}
|
1048
1043
|
|
1049
1044
|
self->descriptor_pool = descriptor_pool;
|
1050
|
-
self->enumdef = (const
|
1045
|
+
self->enumdef = (const upb_EnumDef*)NUM2ULL(ptr);
|
1051
1046
|
|
1052
1047
|
return Qnil;
|
1053
1048
|
}
|
@@ -1061,7 +1056,7 @@ static VALUE EnumDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
1061
1056
|
static VALUE EnumDescriptor_file_descriptor(VALUE _self) {
|
1062
1057
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
1063
1058
|
return get_filedef_obj(self->descriptor_pool,
|
1064
|
-
|
1059
|
+
upb_EnumDef_File(self->enumdef));
|
1065
1060
|
}
|
1066
1061
|
|
1067
1062
|
/*
|
@@ -1072,7 +1067,7 @@ static VALUE EnumDescriptor_file_descriptor(VALUE _self) {
|
|
1072
1067
|
*/
|
1073
1068
|
static VALUE EnumDescriptor_name(VALUE _self) {
|
1074
1069
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
1075
|
-
return rb_str_maybe_null(
|
1070
|
+
return rb_str_maybe_null(upb_EnumDef_FullName(self->enumdef));
|
1076
1071
|
}
|
1077
1072
|
|
1078
1073
|
/*
|
@@ -1084,10 +1079,11 @@ static VALUE EnumDescriptor_name(VALUE _self) {
|
|
1084
1079
|
*/
|
1085
1080
|
static VALUE EnumDescriptor_lookup_name(VALUE _self, VALUE name) {
|
1086
1081
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
1087
|
-
const char* name_str= rb_id2name(SYM2ID(name));
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1082
|
+
const char* name_str = rb_id2name(SYM2ID(name));
|
1083
|
+
const upb_EnumValueDef *ev =
|
1084
|
+
upb_EnumDef_FindValueByName(self->enumdef, name_str);
|
1085
|
+
if (ev) {
|
1086
|
+
return INT2NUM(upb_EnumValueDef_Number(ev));
|
1091
1087
|
} else {
|
1092
1088
|
return Qnil;
|
1093
1089
|
}
|
@@ -1103,9 +1099,9 @@ static VALUE EnumDescriptor_lookup_name(VALUE _self, VALUE name) {
|
|
1103
1099
|
static VALUE EnumDescriptor_lookup_value(VALUE _self, VALUE number) {
|
1104
1100
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
1105
1101
|
int32_t val = NUM2INT(number);
|
1106
|
-
const
|
1107
|
-
if (
|
1108
|
-
return ID2SYM(rb_intern(
|
1102
|
+
const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNumber(self->enumdef, val);
|
1103
|
+
if (ev) {
|
1104
|
+
return ID2SYM(rb_intern(upb_EnumValueDef_Name(ev)));
|
1109
1105
|
} else {
|
1110
1106
|
return Qnil;
|
1111
1107
|
}
|
@@ -1121,12 +1117,11 @@ static VALUE EnumDescriptor_lookup_value(VALUE _self, VALUE number) {
|
|
1121
1117
|
static VALUE EnumDescriptor_each(VALUE _self) {
|
1122
1118
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
1123
1119
|
|
1124
|
-
|
1125
|
-
for (
|
1126
|
-
|
1127
|
-
|
1128
|
-
VALUE
|
1129
|
-
VALUE number = INT2NUM(upb_enum_iter_number(&it));
|
1120
|
+
int n = upb_EnumDef_ValueCount(self->enumdef);
|
1121
|
+
for (int i = 0; i < n; i++) {
|
1122
|
+
const upb_EnumValueDef* ev = upb_EnumDef_Value(self->enumdef, i);
|
1123
|
+
VALUE key = ID2SYM(rb_intern(upb_EnumValueDef_Name(ev)));
|
1124
|
+
VALUE number = INT2NUM(upb_EnumValueDef_Number(ev));
|
1130
1125
|
rb_yield_values(2, key, number);
|
1131
1126
|
}
|
1132
1127
|
|
@@ -1148,8 +1143,7 @@ static VALUE EnumDescriptor_enummodule(VALUE _self) {
|
|
1148
1143
|
}
|
1149
1144
|
|
1150
1145
|
static void EnumDescriptor_register(VALUE module) {
|
1151
|
-
VALUE klass = rb_define_class_under(
|
1152
|
-
module, "EnumDescriptor", rb_cObject);
|
1146
|
+
VALUE klass = rb_define_class_under(module, "EnumDescriptor", rb_cObject);
|
1153
1147
|
rb_define_alloc_func(klass, EnumDescriptor_alloc);
|
1154
1148
|
rb_define_method(klass, "initialize", EnumDescriptor_initialize, 3);
|
1155
1149
|
rb_define_method(klass, "name", EnumDescriptor_name, 0);
|
@@ -1176,7 +1170,7 @@ static VALUE get_def_obj(VALUE _descriptor_pool, const void* ptr, VALUE klass) {
|
|
1176
1170
|
|
1177
1171
|
if (def == Qnil) {
|
1178
1172
|
// Lazily create wrapper object.
|
1179
|
-
VALUE args[3] = {
|
1173
|
+
VALUE args[3] = {c_only_cookie, _descriptor_pool, key};
|
1180
1174
|
def = rb_class_new_instance(3, args, klass);
|
1181
1175
|
rb_hash_aset(descriptor_pool->def_to_descriptor, key, def);
|
1182
1176
|
}
|
@@ -1184,23 +1178,23 @@ static VALUE get_def_obj(VALUE _descriptor_pool, const void* ptr, VALUE klass) {
|
|
1184
1178
|
return def;
|
1185
1179
|
}
|
1186
1180
|
|
1187
|
-
static VALUE get_msgdef_obj(VALUE descriptor_pool, const
|
1181
|
+
static VALUE get_msgdef_obj(VALUE descriptor_pool, const upb_MessageDef* def) {
|
1188
1182
|
return get_def_obj(descriptor_pool, def, cDescriptor);
|
1189
1183
|
}
|
1190
1184
|
|
1191
|
-
static VALUE get_enumdef_obj(VALUE descriptor_pool, const
|
1185
|
+
static VALUE get_enumdef_obj(VALUE descriptor_pool, const upb_EnumDef* def) {
|
1192
1186
|
return get_def_obj(descriptor_pool, def, cEnumDescriptor);
|
1193
1187
|
}
|
1194
1188
|
|
1195
|
-
static VALUE get_fielddef_obj(VALUE descriptor_pool, const
|
1189
|
+
static VALUE get_fielddef_obj(VALUE descriptor_pool, const upb_FieldDef* def) {
|
1196
1190
|
return get_def_obj(descriptor_pool, def, cFieldDescriptor);
|
1197
1191
|
}
|
1198
1192
|
|
1199
|
-
static VALUE get_filedef_obj(VALUE descriptor_pool, const
|
1193
|
+
static VALUE get_filedef_obj(VALUE descriptor_pool, const upb_FileDef* def) {
|
1200
1194
|
return get_def_obj(descriptor_pool, def, cFileDescriptor);
|
1201
1195
|
}
|
1202
1196
|
|
1203
|
-
static VALUE get_oneofdef_obj(VALUE descriptor_pool, const
|
1197
|
+
static VALUE get_oneofdef_obj(VALUE descriptor_pool, const upb_OneofDef* def) {
|
1204
1198
|
return get_def_obj(descriptor_pool, def, cOneofDescriptor);
|
1205
1199
|
}
|
1206
1200
|
|
@@ -1210,8 +1204,8 @@ static VALUE get_oneofdef_obj(VALUE descriptor_pool, const upb_oneofdef* def) {
|
|
1210
1204
|
|
1211
1205
|
// Functions exposed to other modules in defs.h.
|
1212
1206
|
|
1213
|
-
VALUE Descriptor_DefToClass(const
|
1214
|
-
const
|
1207
|
+
VALUE Descriptor_DefToClass(const upb_MessageDef* m) {
|
1208
|
+
const upb_DefPool* symtab = upb_FileDef_Pool(upb_MessageDef_File(m));
|
1215
1209
|
VALUE pool = ObjectCache_Get(symtab);
|
1216
1210
|
PBRUBY_ASSERT(pool != Qnil);
|
1217
1211
|
VALUE desc_rb = get_msgdef_obj(pool, m);
|
@@ -1219,15 +1213,16 @@ VALUE Descriptor_DefToClass(const upb_msgdef *m) {
|
|
1219
1213
|
return desc->klass;
|
1220
1214
|
}
|
1221
1215
|
|
1222
|
-
const
|
1216
|
+
const upb_MessageDef* Descriptor_GetMsgDef(VALUE desc_rb) {
|
1223
1217
|
const Descriptor* desc = ruby_to_Descriptor(desc_rb);
|
1224
1218
|
return desc->msgdef;
|
1225
1219
|
}
|
1226
1220
|
|
1227
|
-
VALUE TypeInfo_InitArg(int argc, VALUE
|
1221
|
+
VALUE TypeInfo_InitArg(int argc, VALUE* argv, int skip_arg) {
|
1228
1222
|
if (argc > skip_arg) {
|
1229
1223
|
if (argc > 1 + skip_arg) {
|
1230
|
-
rb_raise(rb_eArgError, "Expected a maximum of %d arguments.",
|
1224
|
+
rb_raise(rb_eArgError, "Expected a maximum of %d arguments.",
|
1225
|
+
skip_arg + 1);
|
1231
1226
|
}
|
1232
1227
|
return argv[skip_arg];
|
1233
1228
|
} else {
|
@@ -1239,7 +1234,7 @@ TypeInfo TypeInfo_FromClass(int argc, VALUE* argv, int skip_arg,
|
|
1239
1234
|
VALUE* type_class, VALUE* init_arg) {
|
1240
1235
|
TypeInfo ret = {ruby_to_fieldtype(argv[skip_arg])};
|
1241
1236
|
|
1242
|
-
if (ret.type ==
|
1237
|
+
if (ret.type == kUpb_CType_Message || ret.type == kUpb_CType_Enum) {
|
1243
1238
|
*init_arg = TypeInfo_InitArg(argc, argv, skip_arg + 2);
|
1244
1239
|
|
1245
1240
|
if (argc < 2 + skip_arg) {
|
@@ -1257,11 +1252,11 @@ TypeInfo TypeInfo_FromClass(int argc, VALUE* argv, int skip_arg,
|
|
1257
1252
|
"class or enum as returned by the DescriptorPool.");
|
1258
1253
|
}
|
1259
1254
|
|
1260
|
-
if (ret.type ==
|
1255
|
+
if (ret.type == kUpb_CType_Message) {
|
1261
1256
|
ret.def.msgdef = ruby_to_Descriptor(desc)->msgdef;
|
1262
1257
|
Message_CheckClass(klass);
|
1263
1258
|
} else {
|
1264
|
-
PBRUBY_ASSERT(ret.type ==
|
1259
|
+
PBRUBY_ASSERT(ret.type == kUpb_CType_Enum);
|
1265
1260
|
ret.def.enumdef = ruby_to_EnumDescriptor(desc)->enumdef;
|
1266
1261
|
}
|
1267
1262
|
} else {
|