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