google-protobuf 3.19.4 → 3.23.3
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 +215 -209
- data/ext/google/protobuf_c/defs.h +19 -19
- data/ext/google/protobuf_c/extconf.rb +12 -5
- data/ext/google/protobuf_c/map.c +102 -109
- data/ext/google/protobuf_c/map.h +7 -8
- data/ext/google/protobuf_c/message.c +446 -341
- data/ext/google/protobuf_c/message.h +22 -19
- data/ext/google/protobuf_c/protobuf.c +71 -59
- 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 +11651 -6848
- data/ext/google/protobuf_c/ruby-upb.h +10715 -3639
- data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +22 -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 +21 -0
- data/ext/google/protobuf_c/wrap_memcpy.c +4 -3
- data/lib/google/protobuf/any_pb.rb +24 -5
- data/lib/google/protobuf/api_pb.rb +26 -23
- data/lib/google/protobuf/descriptor_dsl.rb +8 -1
- data/lib/google/protobuf/descriptor_pb.rb +32 -225
- data/lib/google/protobuf/duration_pb.rb +24 -5
- data/lib/google/protobuf/empty_pb.rb +24 -3
- data/lib/google/protobuf/field_mask_pb.rb +24 -4
- data/lib/google/protobuf/message_exts.rb +7 -2
- data/lib/google/protobuf/plugin_pb.rb +47 -0
- data/lib/google/protobuf/repeated_field.rb +15 -2
- data/lib/google/protobuf/source_context_pb.rb +24 -4
- data/lib/google/protobuf/struct_pb.rb +24 -20
- data/lib/google/protobuf/timestamp_pb.rb +24 -5
- data/lib/google/protobuf/type_pb.rb +26 -68
- data/lib/google/protobuf/well_known_types.rb +11 -6
- data/lib/google/protobuf/wrappers_pb.rb +24 -28
- data/lib/google/protobuf.rb +4 -4
- metadata +13 -13
- data/tests/basic.rb +0 -648
- data/tests/generated_code_test.rb +0 -23
- data/tests/stress.rb +0 -38
@@ -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,9 @@ static void DescriptorPool_register(VALUE module) {
|
|
222
222
|
// -----------------------------------------------------------------------------
|
223
223
|
|
224
224
|
typedef struct {
|
225
|
-
const
|
225
|
+
const upb_MessageDef* msgdef;
|
226
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
227
|
+
// macro to update VALUE references, as to trigger write barriers.
|
226
228
|
VALUE klass;
|
227
229
|
VALUE descriptor_pool;
|
228
230
|
} Descriptor;
|
@@ -236,9 +238,9 @@ static void Descriptor_mark(void* _self) {
|
|
236
238
|
}
|
237
239
|
|
238
240
|
static const rb_data_type_t Descriptor_type = {
|
239
|
-
|
240
|
-
|
241
|
-
|
241
|
+
"Google::Protobuf::Descriptor",
|
242
|
+
{Descriptor_mark, RUBY_DEFAULT_FREE, NULL},
|
243
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
242
244
|
};
|
243
245
|
|
244
246
|
static Descriptor* ruby_to_Descriptor(VALUE val) {
|
@@ -280,8 +282,8 @@ static VALUE Descriptor_initialize(VALUE _self, VALUE cookie,
|
|
280
282
|
"Descriptor objects may not be created from Ruby.");
|
281
283
|
}
|
282
284
|
|
283
|
-
self->descriptor_pool
|
284
|
-
self->msgdef = (const
|
285
|
+
RB_OBJ_WRITE(_self, &self->descriptor_pool, descriptor_pool);
|
286
|
+
self->msgdef = (const upb_MessageDef*)NUM2ULL(ptr);
|
285
287
|
|
286
288
|
return Qnil;
|
287
289
|
}
|
@@ -294,7 +296,8 @@ static VALUE Descriptor_initialize(VALUE _self, VALUE cookie,
|
|
294
296
|
*/
|
295
297
|
static VALUE Descriptor_file_descriptor(VALUE _self) {
|
296
298
|
Descriptor* self = ruby_to_Descriptor(_self);
|
297
|
-
return get_filedef_obj(self->descriptor_pool,
|
299
|
+
return get_filedef_obj(self->descriptor_pool,
|
300
|
+
upb_MessageDef_File(self->msgdef));
|
298
301
|
}
|
299
302
|
|
300
303
|
/*
|
@@ -306,7 +309,7 @@ static VALUE Descriptor_file_descriptor(VALUE _self) {
|
|
306
309
|
*/
|
307
310
|
static VALUE Descriptor_name(VALUE _self) {
|
308
311
|
Descriptor* self = ruby_to_Descriptor(_self);
|
309
|
-
return rb_str_maybe_null(
|
312
|
+
return rb_str_maybe_null(upb_MessageDef_FullName(self->msgdef));
|
310
313
|
}
|
311
314
|
|
312
315
|
/*
|
@@ -318,11 +321,9 @@ static VALUE Descriptor_name(VALUE _self) {
|
|
318
321
|
static VALUE Descriptor_each(VALUE _self) {
|
319
322
|
Descriptor* self = ruby_to_Descriptor(_self);
|
320
323
|
|
321
|
-
|
322
|
-
for (
|
323
|
-
|
324
|
-
upb_msg_field_next(&it)) {
|
325
|
-
const upb_fielddef* field = upb_msg_iter_field(&it);
|
324
|
+
int n = upb_MessageDef_FieldCount(self->msgdef);
|
325
|
+
for (int i = 0; i < n; i++) {
|
326
|
+
const upb_FieldDef* field = upb_MessageDef_Field(self->msgdef, i);
|
326
327
|
VALUE obj = get_fielddef_obj(self->descriptor_pool, field);
|
327
328
|
rb_yield(obj);
|
328
329
|
}
|
@@ -339,7 +340,7 @@ static VALUE Descriptor_each(VALUE _self) {
|
|
339
340
|
static VALUE Descriptor_lookup(VALUE _self, VALUE name) {
|
340
341
|
Descriptor* self = ruby_to_Descriptor(_self);
|
341
342
|
const char* s = get_str(name);
|
342
|
-
const
|
343
|
+
const upb_FieldDef* field = upb_MessageDef_FindFieldByName(self->msgdef, s);
|
343
344
|
if (field == NULL) {
|
344
345
|
return Qnil;
|
345
346
|
}
|
@@ -356,11 +357,9 @@ static VALUE Descriptor_lookup(VALUE _self, VALUE name) {
|
|
356
357
|
static VALUE Descriptor_each_oneof(VALUE _self) {
|
357
358
|
Descriptor* self = ruby_to_Descriptor(_self);
|
358
359
|
|
359
|
-
|
360
|
-
for (
|
361
|
-
|
362
|
-
upb_msg_oneof_next(&it)) {
|
363
|
-
const upb_oneofdef* oneof = upb_msg_iter_oneof(&it);
|
360
|
+
int n = upb_MessageDef_OneofCount(self->msgdef);
|
361
|
+
for (int i = 0; i < n; i++) {
|
362
|
+
const upb_OneofDef* oneof = upb_MessageDef_Oneof(self->msgdef, i);
|
364
363
|
VALUE obj = get_oneofdef_obj(self->descriptor_pool, oneof);
|
365
364
|
rb_yield(obj);
|
366
365
|
}
|
@@ -377,7 +376,7 @@ static VALUE Descriptor_each_oneof(VALUE _self) {
|
|
377
376
|
static VALUE Descriptor_lookup_oneof(VALUE _self, VALUE name) {
|
378
377
|
Descriptor* self = ruby_to_Descriptor(_self);
|
379
378
|
const char* s = get_str(name);
|
380
|
-
const
|
379
|
+
const upb_OneofDef* oneof = upb_MessageDef_FindOneofByName(self->msgdef, s);
|
381
380
|
if (oneof == NULL) {
|
382
381
|
return Qnil;
|
383
382
|
}
|
@@ -393,14 +392,13 @@ static VALUE Descriptor_lookup_oneof(VALUE _self, VALUE name) {
|
|
393
392
|
static VALUE Descriptor_msgclass(VALUE _self) {
|
394
393
|
Descriptor* self = ruby_to_Descriptor(_self);
|
395
394
|
if (self->klass == Qnil) {
|
396
|
-
self->klass
|
395
|
+
RB_OBJ_WRITE(_self, &self->klass, build_class_from_descriptor(_self));
|
397
396
|
}
|
398
397
|
return self->klass;
|
399
398
|
}
|
400
399
|
|
401
400
|
static void Descriptor_register(VALUE module) {
|
402
|
-
VALUE klass = rb_define_class_under(
|
403
|
-
module, "Descriptor", rb_cObject);
|
401
|
+
VALUE klass = rb_define_class_under(module, "Descriptor", rb_cObject);
|
404
402
|
rb_define_alloc_func(klass, Descriptor_alloc);
|
405
403
|
rb_define_method(klass, "initialize", Descriptor_initialize, 3);
|
406
404
|
rb_define_method(klass, "each", Descriptor_each, 0);
|
@@ -420,8 +418,10 @@ static void Descriptor_register(VALUE module) {
|
|
420
418
|
// -----------------------------------------------------------------------------
|
421
419
|
|
422
420
|
typedef struct {
|
423
|
-
const
|
424
|
-
|
421
|
+
const upb_FileDef* filedef;
|
422
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
423
|
+
// macro to update VALUE references, as to trigger write barriers.
|
424
|
+
VALUE descriptor_pool; // Owns the upb_FileDef.
|
425
425
|
} FileDescriptor;
|
426
426
|
|
427
427
|
static VALUE cFileDescriptor = Qnil;
|
@@ -432,9 +432,9 @@ static void FileDescriptor_mark(void* _self) {
|
|
432
432
|
}
|
433
433
|
|
434
434
|
static const rb_data_type_t FileDescriptor_type = {
|
435
|
-
|
436
|
-
|
437
|
-
|
435
|
+
"Google::Protobuf::FileDescriptor",
|
436
|
+
{FileDescriptor_mark, RUBY_DEFAULT_FREE, NULL},
|
437
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
438
438
|
};
|
439
439
|
|
440
440
|
static FileDescriptor* ruby_to_FileDescriptor(VALUE val) {
|
@@ -459,7 +459,7 @@ static VALUE FileDescriptor_alloc(VALUE klass) {
|
|
459
459
|
* to a builder.
|
460
460
|
*/
|
461
461
|
static VALUE FileDescriptor_initialize(VALUE _self, VALUE cookie,
|
462
|
-
|
462
|
+
VALUE descriptor_pool, VALUE ptr) {
|
463
463
|
FileDescriptor* self = ruby_to_FileDescriptor(_self);
|
464
464
|
|
465
465
|
if (cookie != c_only_cookie) {
|
@@ -467,8 +467,8 @@ static VALUE FileDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
467
467
|
"Descriptor objects may not be created from Ruby.");
|
468
468
|
}
|
469
469
|
|
470
|
-
self->descriptor_pool
|
471
|
-
self->filedef = (const
|
470
|
+
RB_OBJ_WRITE(_self, &self->descriptor_pool, descriptor_pool);
|
471
|
+
self->filedef = (const upb_FileDef*)NUM2ULL(ptr);
|
472
472
|
|
473
473
|
return Qnil;
|
474
474
|
}
|
@@ -481,7 +481,7 @@ static VALUE FileDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
481
481
|
*/
|
482
482
|
static VALUE FileDescriptor_name(VALUE _self) {
|
483
483
|
FileDescriptor* self = ruby_to_FileDescriptor(_self);
|
484
|
-
const char* name =
|
484
|
+
const char* name = upb_FileDef_Name(self->filedef);
|
485
485
|
return name == NULL ? Qnil : rb_str_new2(name);
|
486
486
|
}
|
487
487
|
|
@@ -497,16 +497,18 @@ static VALUE FileDescriptor_name(VALUE _self) {
|
|
497
497
|
static VALUE FileDescriptor_syntax(VALUE _self) {
|
498
498
|
FileDescriptor* self = ruby_to_FileDescriptor(_self);
|
499
499
|
|
500
|
-
switch (
|
501
|
-
case
|
502
|
-
|
503
|
-
|
500
|
+
switch (upb_FileDef_Syntax(self->filedef)) {
|
501
|
+
case kUpb_Syntax_Proto3:
|
502
|
+
return ID2SYM(rb_intern("proto3"));
|
503
|
+
case kUpb_Syntax_Proto2:
|
504
|
+
return ID2SYM(rb_intern("proto2"));
|
505
|
+
default:
|
506
|
+
return Qnil;
|
504
507
|
}
|
505
508
|
}
|
506
509
|
|
507
510
|
static void FileDescriptor_register(VALUE module) {
|
508
|
-
VALUE klass = rb_define_class_under(
|
509
|
-
module, "FileDescriptor", rb_cObject);
|
511
|
+
VALUE klass = rb_define_class_under(module, "FileDescriptor", rb_cObject);
|
510
512
|
rb_define_alloc_func(klass, FileDescriptor_alloc);
|
511
513
|
rb_define_method(klass, "initialize", FileDescriptor_initialize, 3);
|
512
514
|
rb_define_method(klass, "name", FileDescriptor_name, 0);
|
@@ -520,8 +522,10 @@ static void FileDescriptor_register(VALUE module) {
|
|
520
522
|
// -----------------------------------------------------------------------------
|
521
523
|
|
522
524
|
typedef struct {
|
523
|
-
const
|
524
|
-
|
525
|
+
const upb_FieldDef* fielddef;
|
526
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
527
|
+
// macro to update VALUE references, as to trigger write barriers.
|
528
|
+
VALUE descriptor_pool; // Owns the upb_FieldDef.
|
525
529
|
} FieldDescriptor;
|
526
530
|
|
527
531
|
static VALUE cFieldDescriptor = Qnil;
|
@@ -532,9 +536,9 @@ static void FieldDescriptor_mark(void* _self) {
|
|
532
536
|
}
|
533
537
|
|
534
538
|
static const rb_data_type_t FieldDescriptor_type = {
|
535
|
-
|
536
|
-
|
537
|
-
|
539
|
+
"Google::Protobuf::FieldDescriptor",
|
540
|
+
{FieldDescriptor_mark, RUBY_DEFAULT_FREE, NULL},
|
541
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
538
542
|
};
|
539
543
|
|
540
544
|
static FieldDescriptor* ruby_to_FieldDescriptor(VALUE val) {
|
@@ -572,8 +576,8 @@ static VALUE FieldDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
572
576
|
"Descriptor objects may not be created from Ruby.");
|
573
577
|
}
|
574
578
|
|
575
|
-
self->descriptor_pool
|
576
|
-
self->fielddef = (const
|
579
|
+
RB_OBJ_WRITE(_self, &self->descriptor_pool, descriptor_pool);
|
580
|
+
self->fielddef = (const upb_FieldDef*)NUM2ULL(ptr);
|
577
581
|
|
578
582
|
return Qnil;
|
579
583
|
}
|
@@ -586,31 +590,31 @@ static VALUE FieldDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
586
590
|
*/
|
587
591
|
static VALUE FieldDescriptor_name(VALUE _self) {
|
588
592
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
589
|
-
return rb_str_maybe_null(
|
593
|
+
return rb_str_maybe_null(upb_FieldDef_Name(self->fielddef));
|
590
594
|
}
|
591
595
|
|
592
596
|
// Non-static, exposed to other .c files.
|
593
|
-
|
597
|
+
upb_CType ruby_to_fieldtype(VALUE type) {
|
594
598
|
if (TYPE(type) != T_SYMBOL) {
|
595
599
|
rb_raise(rb_eArgError, "Expected symbol for field type.");
|
596
600
|
}
|
597
601
|
|
598
|
-
#define CONVERT(upb, ruby)
|
599
|
-
if (SYM2ID(type) == rb_intern(
|
600
|
-
return
|
602
|
+
#define CONVERT(upb, ruby) \
|
603
|
+
if (SYM2ID(type) == rb_intern(#ruby)) { \
|
604
|
+
return kUpb_CType_##upb; \
|
601
605
|
}
|
602
606
|
|
603
|
-
CONVERT(
|
604
|
-
CONVERT(
|
605
|
-
CONVERT(
|
606
|
-
CONVERT(
|
607
|
-
CONVERT(
|
608
|
-
CONVERT(
|
609
|
-
CONVERT(
|
610
|
-
CONVERT(
|
611
|
-
CONVERT(
|
612
|
-
CONVERT(
|
613
|
-
CONVERT(
|
607
|
+
CONVERT(Float, float);
|
608
|
+
CONVERT(Double, double);
|
609
|
+
CONVERT(Bool, bool);
|
610
|
+
CONVERT(String, string);
|
611
|
+
CONVERT(Bytes, bytes);
|
612
|
+
CONVERT(Message, message);
|
613
|
+
CONVERT(Enum, enum);
|
614
|
+
CONVERT(Int32, int32);
|
615
|
+
CONVERT(Int64, int64);
|
616
|
+
CONVERT(UInt32, uint32);
|
617
|
+
CONVERT(UInt64, uint64);
|
614
618
|
|
615
619
|
#undef CONVERT
|
616
620
|
|
@@ -618,28 +622,29 @@ upb_fieldtype_t ruby_to_fieldtype(VALUE type) {
|
|
618
622
|
return 0;
|
619
623
|
}
|
620
624
|
|
621
|
-
static VALUE descriptortype_to_ruby(
|
625
|
+
static VALUE descriptortype_to_ruby(upb_FieldType type) {
|
622
626
|
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(
|
627
|
+
#define CONVERT(upb, ruby) \
|
628
|
+
case kUpb_FieldType_##upb: \
|
629
|
+
return ID2SYM(rb_intern(#ruby));
|
630
|
+
CONVERT(Float, float);
|
631
|
+
CONVERT(Double, double);
|
632
|
+
CONVERT(Bool, bool);
|
633
|
+
CONVERT(String, string);
|
634
|
+
CONVERT(Bytes, bytes);
|
635
|
+
CONVERT(Message, message);
|
636
|
+
CONVERT(Group, group);
|
637
|
+
CONVERT(Enum, enum);
|
638
|
+
CONVERT(Int32, int32);
|
639
|
+
CONVERT(Int64, int64);
|
640
|
+
CONVERT(UInt32, uint32);
|
641
|
+
CONVERT(UInt64, uint64);
|
642
|
+
CONVERT(SInt32, sint32);
|
643
|
+
CONVERT(SInt64, sint64);
|
644
|
+
CONVERT(Fixed32, fixed32);
|
645
|
+
CONVERT(Fixed64, fixed64);
|
646
|
+
CONVERT(SFixed32, sfixed32);
|
647
|
+
CONVERT(SFixed64, sfixed64);
|
643
648
|
#undef CONVERT
|
644
649
|
}
|
645
650
|
return Qnil;
|
@@ -657,7 +662,7 @@ static VALUE descriptortype_to_ruby(upb_descriptortype_t type) {
|
|
657
662
|
*/
|
658
663
|
static VALUE FieldDescriptor__type(VALUE _self) {
|
659
664
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
660
|
-
return descriptortype_to_ruby(
|
665
|
+
return descriptortype_to_ruby(upb_FieldDef_Type(self->fielddef));
|
661
666
|
}
|
662
667
|
|
663
668
|
/*
|
@@ -668,17 +673,16 @@ static VALUE FieldDescriptor__type(VALUE _self) {
|
|
668
673
|
*/
|
669
674
|
static VALUE FieldDescriptor_default(VALUE _self) {
|
670
675
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
671
|
-
const
|
672
|
-
|
673
|
-
if (
|
676
|
+
const upb_FieldDef* f = self->fielddef;
|
677
|
+
upb_MessageValue default_val = {0};
|
678
|
+
if (upb_FieldDef_IsSubMessage(f)) {
|
674
679
|
return Qnil;
|
675
|
-
} else if (!
|
676
|
-
default_val =
|
680
|
+
} else if (!upb_FieldDef_IsRepeated(f)) {
|
681
|
+
default_val = upb_FieldDef_Default(f);
|
677
682
|
}
|
678
683
|
return Convert_UpbToRuby(default_val, TypeInfo_get(self->fielddef), Qnil);
|
679
684
|
}
|
680
685
|
|
681
|
-
|
682
686
|
/*
|
683
687
|
* call-seq:
|
684
688
|
* FieldDescriptor.json_name => json_name
|
@@ -687,8 +691,8 @@ static VALUE FieldDescriptor_default(VALUE _self) {
|
|
687
691
|
*/
|
688
692
|
static VALUE FieldDescriptor_json_name(VALUE _self) {
|
689
693
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
690
|
-
const
|
691
|
-
const char
|
694
|
+
const upb_FieldDef* f = self->fielddef;
|
695
|
+
const char* json_name = upb_FieldDef_JsonName(f);
|
692
696
|
return rb_str_new2(json_name);
|
693
697
|
}
|
694
698
|
|
@@ -703,13 +707,14 @@ static VALUE FieldDescriptor_json_name(VALUE _self) {
|
|
703
707
|
*/
|
704
708
|
static VALUE FieldDescriptor_label(VALUE _self) {
|
705
709
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
706
|
-
switch (
|
707
|
-
#define CONVERT(upb, ruby)
|
708
|
-
|
710
|
+
switch (upb_FieldDef_Label(self->fielddef)) {
|
711
|
+
#define CONVERT(upb, ruby) \
|
712
|
+
case kUpb_Label_##upb: \
|
713
|
+
return ID2SYM(rb_intern(#ruby));
|
709
714
|
|
710
|
-
CONVERT(
|
711
|
-
CONVERT(
|
712
|
-
CONVERT(
|
715
|
+
CONVERT(Optional, optional);
|
716
|
+
CONVERT(Required, required);
|
717
|
+
CONVERT(Repeated, repeated);
|
713
718
|
|
714
719
|
#undef CONVERT
|
715
720
|
}
|
@@ -725,7 +730,7 @@ static VALUE FieldDescriptor_label(VALUE _self) {
|
|
725
730
|
*/
|
726
731
|
static VALUE FieldDescriptor_number(VALUE _self) {
|
727
732
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
728
|
-
return INT2NUM(
|
733
|
+
return INT2NUM(upb_FieldDef_Number(self->fielddef));
|
729
734
|
}
|
730
735
|
|
731
736
|
/*
|
@@ -739,13 +744,13 @@ static VALUE FieldDescriptor_number(VALUE _self) {
|
|
739
744
|
*/
|
740
745
|
static VALUE FieldDescriptor_submsg_name(VALUE _self) {
|
741
746
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
742
|
-
switch (
|
743
|
-
case
|
747
|
+
switch (upb_FieldDef_CType(self->fielddef)) {
|
748
|
+
case kUpb_CType_Enum:
|
744
749
|
return rb_str_new2(
|
745
|
-
|
746
|
-
case
|
750
|
+
upb_EnumDef_FullName(upb_FieldDef_EnumSubDef(self->fielddef)));
|
751
|
+
case kUpb_CType_Message:
|
747
752
|
return rb_str_new2(
|
748
|
-
|
753
|
+
upb_MessageDef_FullName(upb_FieldDef_MessageSubDef(self->fielddef)));
|
749
754
|
default:
|
750
755
|
return Qnil;
|
751
756
|
}
|
@@ -762,13 +767,13 @@ static VALUE FieldDescriptor_submsg_name(VALUE _self) {
|
|
762
767
|
*/
|
763
768
|
static VALUE FieldDescriptor_subtype(VALUE _self) {
|
764
769
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
765
|
-
switch (
|
766
|
-
case
|
770
|
+
switch (upb_FieldDef_CType(self->fielddef)) {
|
771
|
+
case kUpb_CType_Enum:
|
767
772
|
return get_enumdef_obj(self->descriptor_pool,
|
768
|
-
|
769
|
-
case
|
773
|
+
upb_FieldDef_EnumSubDef(self->fielddef));
|
774
|
+
case kUpb_CType_Message:
|
770
775
|
return get_msgdef_obj(self->descriptor_pool,
|
771
|
-
|
776
|
+
upb_FieldDef_MessageSubDef(self->fielddef));
|
772
777
|
default:
|
773
778
|
return Qnil;
|
774
779
|
}
|
@@ -783,11 +788,11 @@ static VALUE FieldDescriptor_subtype(VALUE _self) {
|
|
783
788
|
*/
|
784
789
|
static VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) {
|
785
790
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
786
|
-
const
|
791
|
+
const upb_MessageDef* m;
|
787
792
|
|
788
793
|
Message_Get(msg_rb, &m);
|
789
794
|
|
790
|
-
if (m !=
|
795
|
+
if (m != upb_FieldDef_ContainingType(self->fielddef)) {
|
791
796
|
rb_raise(cTypeError, "get method called on wrong message type");
|
792
797
|
}
|
793
798
|
|
@@ -803,16 +808,16 @@ static VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) {
|
|
803
808
|
*/
|
804
809
|
static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
|
805
810
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
806
|
-
const
|
807
|
-
const
|
811
|
+
const upb_MessageDef* m;
|
812
|
+
const upb_MessageDef* msg = Message_Get(msg_rb, &m);
|
808
813
|
|
809
|
-
if (m !=
|
814
|
+
if (m != upb_FieldDef_ContainingType(self->fielddef)) {
|
810
815
|
rb_raise(cTypeError, "has method called on wrong message type");
|
811
|
-
} else if (!
|
816
|
+
} else if (!upb_FieldDef_HasPresence(self->fielddef)) {
|
812
817
|
rb_raise(rb_eArgError, "does not track presence");
|
813
818
|
}
|
814
819
|
|
815
|
-
return
|
820
|
+
return upb_Message_HasFieldByDef(msg, self->fielddef) ? Qtrue : Qfalse;
|
816
821
|
}
|
817
822
|
|
818
823
|
/*
|
@@ -823,14 +828,14 @@ static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
|
|
823
828
|
*/
|
824
829
|
static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
|
825
830
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
826
|
-
const
|
827
|
-
|
831
|
+
const upb_MessageDef* m;
|
832
|
+
upb_MessageDef* msg = Message_GetMutable(msg_rb, &m);
|
828
833
|
|
829
|
-
if (m !=
|
834
|
+
if (m != upb_FieldDef_ContainingType(self->fielddef)) {
|
830
835
|
rb_raise(cTypeError, "has method called on wrong message type");
|
831
836
|
}
|
832
837
|
|
833
|
-
|
838
|
+
upb_Message_ClearFieldByDef(msg, self->fielddef);
|
834
839
|
return Qnil;
|
835
840
|
}
|
836
841
|
|
@@ -844,24 +849,23 @@ static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
|
|
844
849
|
*/
|
845
850
|
static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) {
|
846
851
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
847
|
-
const
|
848
|
-
|
849
|
-
|
850
|
-
|
852
|
+
const upb_MessageDef* m;
|
853
|
+
upb_MessageDef* msg = Message_GetMutable(msg_rb, &m);
|
854
|
+
upb_Arena* arena = Arena_get(Message_GetArena(msg_rb));
|
855
|
+
upb_MessageValue msgval;
|
851
856
|
|
852
|
-
if (m !=
|
857
|
+
if (m != upb_FieldDef_ContainingType(self->fielddef)) {
|
853
858
|
rb_raise(cTypeError, "set method called on wrong message type");
|
854
859
|
}
|
855
860
|
|
856
|
-
msgval = Convert_RubyToUpb(value,
|
861
|
+
msgval = Convert_RubyToUpb(value, upb_FieldDef_Name(self->fielddef),
|
857
862
|
TypeInfo_get(self->fielddef), arena);
|
858
|
-
|
863
|
+
upb_Message_SetFieldByDef(msg, self->fielddef, msgval, arena);
|
859
864
|
return Qnil;
|
860
865
|
}
|
861
866
|
|
862
867
|
static void FieldDescriptor_register(VALUE module) {
|
863
|
-
VALUE klass = rb_define_class_under(
|
864
|
-
module, "FieldDescriptor", rb_cObject);
|
868
|
+
VALUE klass = rb_define_class_under(module, "FieldDescriptor", rb_cObject);
|
865
869
|
rb_define_alloc_func(klass, FieldDescriptor_alloc);
|
866
870
|
rb_define_method(klass, "initialize", FieldDescriptor_initialize, 3);
|
867
871
|
rb_define_method(klass, "name", FieldDescriptor_name, 0);
|
@@ -885,8 +889,10 @@ static void FieldDescriptor_register(VALUE module) {
|
|
885
889
|
// -----------------------------------------------------------------------------
|
886
890
|
|
887
891
|
typedef struct {
|
888
|
-
const
|
889
|
-
|
892
|
+
const upb_OneofDef* oneofdef;
|
893
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
894
|
+
// macro to update VALUE references, as to trigger write barriers.
|
895
|
+
VALUE descriptor_pool; // Owns the upb_OneofDef.
|
890
896
|
} OneofDescriptor;
|
891
897
|
|
892
898
|
static VALUE cOneofDescriptor = Qnil;
|
@@ -899,7 +905,7 @@ static void OneofDescriptor_mark(void* _self) {
|
|
899
905
|
static const rb_data_type_t OneofDescriptor_type = {
|
900
906
|
"Google::Protobuf::OneofDescriptor",
|
901
907
|
{OneofDescriptor_mark, RUBY_DEFAULT_FREE, NULL},
|
902
|
-
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
908
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
903
909
|
};
|
904
910
|
|
905
911
|
static OneofDescriptor* ruby_to_OneofDescriptor(VALUE val) {
|
@@ -930,7 +936,7 @@ static VALUE OneofDescriptor_alloc(VALUE klass) {
|
|
930
936
|
* Creates a descriptor wrapper object. May only be called from C.
|
931
937
|
*/
|
932
938
|
static VALUE OneofDescriptor_initialize(VALUE _self, VALUE cookie,
|
933
|
-
|
939
|
+
VALUE descriptor_pool, VALUE ptr) {
|
934
940
|
OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
|
935
941
|
|
936
942
|
if (cookie != c_only_cookie) {
|
@@ -938,8 +944,8 @@ static VALUE OneofDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
938
944
|
"Descriptor objects may not be created from Ruby.");
|
939
945
|
}
|
940
946
|
|
941
|
-
self->descriptor_pool
|
942
|
-
self->oneofdef = (const
|
947
|
+
RB_OBJ_WRITE(_self, &self->descriptor_pool, descriptor_pool);
|
948
|
+
self->oneofdef = (const upb_OneofDef*)NUM2ULL(ptr);
|
943
949
|
|
944
950
|
return Qnil;
|
945
951
|
}
|
@@ -952,7 +958,7 @@ static VALUE OneofDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
952
958
|
*/
|
953
959
|
static VALUE OneofDescriptor_name(VALUE _self) {
|
954
960
|
OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
|
955
|
-
return rb_str_maybe_null(
|
961
|
+
return rb_str_maybe_null(upb_OneofDef_Name(self->oneofdef));
|
956
962
|
}
|
957
963
|
|
958
964
|
/*
|
@@ -963,11 +969,10 @@ static VALUE OneofDescriptor_name(VALUE _self) {
|
|
963
969
|
*/
|
964
970
|
static VALUE OneofDescriptor_each(VALUE _self) {
|
965
971
|
OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
const upb_fielddef* f = upb_oneof_iter_field(&it);
|
972
|
+
|
973
|
+
int n = upb_OneofDef_FieldCount(self->oneofdef);
|
974
|
+
for (int i = 0; i < n; i++) {
|
975
|
+
const upb_FieldDef* f = upb_OneofDef_Field(self->oneofdef, i);
|
971
976
|
VALUE obj = get_fielddef_obj(self->descriptor_pool, f);
|
972
977
|
rb_yield(obj);
|
973
978
|
}
|
@@ -975,8 +980,7 @@ static VALUE OneofDescriptor_each(VALUE _self) {
|
|
975
980
|
}
|
976
981
|
|
977
982
|
static void OneofDescriptor_register(VALUE module) {
|
978
|
-
VALUE klass = rb_define_class_under(
|
979
|
-
module, "OneofDescriptor", rb_cObject);
|
983
|
+
VALUE klass = rb_define_class_under(module, "OneofDescriptor", rb_cObject);
|
980
984
|
rb_define_alloc_func(klass, OneofDescriptor_alloc);
|
981
985
|
rb_define_method(klass, "initialize", OneofDescriptor_initialize, 3);
|
982
986
|
rb_define_method(klass, "name", OneofDescriptor_name, 0);
|
@@ -991,9 +995,11 @@ static void OneofDescriptor_register(VALUE module) {
|
|
991
995
|
// -----------------------------------------------------------------------------
|
992
996
|
|
993
997
|
typedef struct {
|
994
|
-
const
|
995
|
-
|
996
|
-
VALUE
|
998
|
+
const upb_EnumDef* enumdef;
|
999
|
+
// IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE()
|
1000
|
+
// macro to update VALUE references, as to trigger write barriers.
|
1001
|
+
VALUE module; // begins as nil
|
1002
|
+
VALUE descriptor_pool; // Owns the upb_EnumDef.
|
997
1003
|
} EnumDescriptor;
|
998
1004
|
|
999
1005
|
static VALUE cEnumDescriptor = Qnil;
|
@@ -1005,9 +1011,9 @@ static void EnumDescriptor_mark(void* _self) {
|
|
1005
1011
|
}
|
1006
1012
|
|
1007
1013
|
static const rb_data_type_t EnumDescriptor_type = {
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1014
|
+
"Google::Protobuf::EnumDescriptor",
|
1015
|
+
{EnumDescriptor_mark, RUBY_DEFAULT_FREE, NULL},
|
1016
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
1011
1017
|
};
|
1012
1018
|
|
1013
1019
|
static EnumDescriptor* ruby_to_EnumDescriptor(VALUE val) {
|
@@ -1026,8 +1032,8 @@ static VALUE EnumDescriptor_alloc(VALUE klass) {
|
|
1026
1032
|
}
|
1027
1033
|
|
1028
1034
|
// Exposed to other modules in defs.h.
|
1029
|
-
const
|
1030
|
-
EnumDescriptor
|
1035
|
+
const upb_EnumDef* EnumDescriptor_GetEnumDef(VALUE enum_desc_rb) {
|
1036
|
+
EnumDescriptor* desc = ruby_to_EnumDescriptor(enum_desc_rb);
|
1031
1037
|
return desc->enumdef;
|
1032
1038
|
}
|
1033
1039
|
|
@@ -1046,8 +1052,8 @@ static VALUE EnumDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
1046
1052
|
"Descriptor objects may not be created from Ruby.");
|
1047
1053
|
}
|
1048
1054
|
|
1049
|
-
self->descriptor_pool
|
1050
|
-
self->enumdef = (const
|
1055
|
+
RB_OBJ_WRITE(_self, &self->descriptor_pool, descriptor_pool);
|
1056
|
+
self->enumdef = (const upb_EnumDef*)NUM2ULL(ptr);
|
1051
1057
|
|
1052
1058
|
return Qnil;
|
1053
1059
|
}
|
@@ -1061,7 +1067,7 @@ static VALUE EnumDescriptor_initialize(VALUE _self, VALUE cookie,
|
|
1061
1067
|
static VALUE EnumDescriptor_file_descriptor(VALUE _self) {
|
1062
1068
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
1063
1069
|
return get_filedef_obj(self->descriptor_pool,
|
1064
|
-
|
1070
|
+
upb_EnumDef_File(self->enumdef));
|
1065
1071
|
}
|
1066
1072
|
|
1067
1073
|
/*
|
@@ -1072,7 +1078,7 @@ static VALUE EnumDescriptor_file_descriptor(VALUE _self) {
|
|
1072
1078
|
*/
|
1073
1079
|
static VALUE EnumDescriptor_name(VALUE _self) {
|
1074
1080
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
1075
|
-
return rb_str_maybe_null(
|
1081
|
+
return rb_str_maybe_null(upb_EnumDef_FullName(self->enumdef));
|
1076
1082
|
}
|
1077
1083
|
|
1078
1084
|
/*
|
@@ -1084,10 +1090,11 @@ static VALUE EnumDescriptor_name(VALUE _self) {
|
|
1084
1090
|
*/
|
1085
1091
|
static VALUE EnumDescriptor_lookup_name(VALUE _self, VALUE name) {
|
1086
1092
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
1087
|
-
const char* name_str= rb_id2name(SYM2ID(name));
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1093
|
+
const char* name_str = rb_id2name(SYM2ID(name));
|
1094
|
+
const upb_EnumValueDef *ev =
|
1095
|
+
upb_EnumDef_FindValueByName(self->enumdef, name_str);
|
1096
|
+
if (ev) {
|
1097
|
+
return INT2NUM(upb_EnumValueDef_Number(ev));
|
1091
1098
|
} else {
|
1092
1099
|
return Qnil;
|
1093
1100
|
}
|
@@ -1103,9 +1110,9 @@ static VALUE EnumDescriptor_lookup_name(VALUE _self, VALUE name) {
|
|
1103
1110
|
static VALUE EnumDescriptor_lookup_value(VALUE _self, VALUE number) {
|
1104
1111
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
1105
1112
|
int32_t val = NUM2INT(number);
|
1106
|
-
const
|
1107
|
-
if (
|
1108
|
-
return ID2SYM(rb_intern(
|
1113
|
+
const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNumber(self->enumdef, val);
|
1114
|
+
if (ev) {
|
1115
|
+
return ID2SYM(rb_intern(upb_EnumValueDef_Name(ev)));
|
1109
1116
|
} else {
|
1110
1117
|
return Qnil;
|
1111
1118
|
}
|
@@ -1121,12 +1128,11 @@ static VALUE EnumDescriptor_lookup_value(VALUE _self, VALUE number) {
|
|
1121
1128
|
static VALUE EnumDescriptor_each(VALUE _self) {
|
1122
1129
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
1123
1130
|
|
1124
|
-
|
1125
|
-
for (
|
1126
|
-
|
1127
|
-
|
1128
|
-
VALUE
|
1129
|
-
VALUE number = INT2NUM(upb_enum_iter_number(&it));
|
1131
|
+
int n = upb_EnumDef_ValueCount(self->enumdef);
|
1132
|
+
for (int i = 0; i < n; i++) {
|
1133
|
+
const upb_EnumValueDef* ev = upb_EnumDef_Value(self->enumdef, i);
|
1134
|
+
VALUE key = ID2SYM(rb_intern(upb_EnumValueDef_Name(ev)));
|
1135
|
+
VALUE number = INT2NUM(upb_EnumValueDef_Number(ev));
|
1130
1136
|
rb_yield_values(2, key, number);
|
1131
1137
|
}
|
1132
1138
|
|
@@ -1142,14 +1148,13 @@ static VALUE EnumDescriptor_each(VALUE _self) {
|
|
1142
1148
|
static VALUE EnumDescriptor_enummodule(VALUE _self) {
|
1143
1149
|
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
1144
1150
|
if (self->module == Qnil) {
|
1145
|
-
self->module
|
1151
|
+
RB_OBJ_WRITE(_self, &self->module, build_module_from_enumdesc(_self));
|
1146
1152
|
}
|
1147
1153
|
return self->module;
|
1148
1154
|
}
|
1149
1155
|
|
1150
1156
|
static void EnumDescriptor_register(VALUE module) {
|
1151
|
-
VALUE klass = rb_define_class_under(
|
1152
|
-
module, "EnumDescriptor", rb_cObject);
|
1157
|
+
VALUE klass = rb_define_class_under(module, "EnumDescriptor", rb_cObject);
|
1153
1158
|
rb_define_alloc_func(klass, EnumDescriptor_alloc);
|
1154
1159
|
rb_define_method(klass, "initialize", EnumDescriptor_initialize, 3);
|
1155
1160
|
rb_define_method(klass, "name", EnumDescriptor_name, 0);
|
@@ -1176,7 +1181,7 @@ static VALUE get_def_obj(VALUE _descriptor_pool, const void* ptr, VALUE klass) {
|
|
1176
1181
|
|
1177
1182
|
if (def == Qnil) {
|
1178
1183
|
// Lazily create wrapper object.
|
1179
|
-
VALUE args[3] = {
|
1184
|
+
VALUE args[3] = {c_only_cookie, _descriptor_pool, key};
|
1180
1185
|
def = rb_class_new_instance(3, args, klass);
|
1181
1186
|
rb_hash_aset(descriptor_pool->def_to_descriptor, key, def);
|
1182
1187
|
}
|
@@ -1184,23 +1189,23 @@ static VALUE get_def_obj(VALUE _descriptor_pool, const void* ptr, VALUE klass) {
|
|
1184
1189
|
return def;
|
1185
1190
|
}
|
1186
1191
|
|
1187
|
-
static VALUE get_msgdef_obj(VALUE descriptor_pool, const
|
1192
|
+
static VALUE get_msgdef_obj(VALUE descriptor_pool, const upb_MessageDef* def) {
|
1188
1193
|
return get_def_obj(descriptor_pool, def, cDescriptor);
|
1189
1194
|
}
|
1190
1195
|
|
1191
|
-
static VALUE get_enumdef_obj(VALUE descriptor_pool, const
|
1196
|
+
static VALUE get_enumdef_obj(VALUE descriptor_pool, const upb_EnumDef* def) {
|
1192
1197
|
return get_def_obj(descriptor_pool, def, cEnumDescriptor);
|
1193
1198
|
}
|
1194
1199
|
|
1195
|
-
static VALUE get_fielddef_obj(VALUE descriptor_pool, const
|
1200
|
+
static VALUE get_fielddef_obj(VALUE descriptor_pool, const upb_FieldDef* def) {
|
1196
1201
|
return get_def_obj(descriptor_pool, def, cFieldDescriptor);
|
1197
1202
|
}
|
1198
1203
|
|
1199
|
-
static VALUE get_filedef_obj(VALUE descriptor_pool, const
|
1204
|
+
static VALUE get_filedef_obj(VALUE descriptor_pool, const upb_FileDef* def) {
|
1200
1205
|
return get_def_obj(descriptor_pool, def, cFileDescriptor);
|
1201
1206
|
}
|
1202
1207
|
|
1203
|
-
static VALUE get_oneofdef_obj(VALUE descriptor_pool, const
|
1208
|
+
static VALUE get_oneofdef_obj(VALUE descriptor_pool, const upb_OneofDef* def) {
|
1204
1209
|
return get_def_obj(descriptor_pool, def, cOneofDescriptor);
|
1205
1210
|
}
|
1206
1211
|
|
@@ -1210,8 +1215,8 @@ static VALUE get_oneofdef_obj(VALUE descriptor_pool, const upb_oneofdef* def) {
|
|
1210
1215
|
|
1211
1216
|
// Functions exposed to other modules in defs.h.
|
1212
1217
|
|
1213
|
-
VALUE Descriptor_DefToClass(const
|
1214
|
-
const
|
1218
|
+
VALUE Descriptor_DefToClass(const upb_MessageDef* m) {
|
1219
|
+
const upb_DefPool* symtab = upb_FileDef_Pool(upb_MessageDef_File(m));
|
1215
1220
|
VALUE pool = ObjectCache_Get(symtab);
|
1216
1221
|
PBRUBY_ASSERT(pool != Qnil);
|
1217
1222
|
VALUE desc_rb = get_msgdef_obj(pool, m);
|
@@ -1219,15 +1224,16 @@ VALUE Descriptor_DefToClass(const upb_msgdef *m) {
|
|
1219
1224
|
return desc->klass;
|
1220
1225
|
}
|
1221
1226
|
|
1222
|
-
const
|
1227
|
+
const upb_MessageDef* Descriptor_GetMsgDef(VALUE desc_rb) {
|
1223
1228
|
const Descriptor* desc = ruby_to_Descriptor(desc_rb);
|
1224
1229
|
return desc->msgdef;
|
1225
1230
|
}
|
1226
1231
|
|
1227
|
-
VALUE TypeInfo_InitArg(int argc, VALUE
|
1232
|
+
VALUE TypeInfo_InitArg(int argc, VALUE* argv, int skip_arg) {
|
1228
1233
|
if (argc > skip_arg) {
|
1229
1234
|
if (argc > 1 + skip_arg) {
|
1230
|
-
rb_raise(rb_eArgError, "Expected a maximum of %d arguments.",
|
1235
|
+
rb_raise(rb_eArgError, "Expected a maximum of %d arguments.",
|
1236
|
+
skip_arg + 1);
|
1231
1237
|
}
|
1232
1238
|
return argv[skip_arg];
|
1233
1239
|
} else {
|
@@ -1239,7 +1245,7 @@ TypeInfo TypeInfo_FromClass(int argc, VALUE* argv, int skip_arg,
|
|
1239
1245
|
VALUE* type_class, VALUE* init_arg) {
|
1240
1246
|
TypeInfo ret = {ruby_to_fieldtype(argv[skip_arg])};
|
1241
1247
|
|
1242
|
-
if (ret.type ==
|
1248
|
+
if (ret.type == kUpb_CType_Message || ret.type == kUpb_CType_Enum) {
|
1243
1249
|
*init_arg = TypeInfo_InitArg(argc, argv, skip_arg + 2);
|
1244
1250
|
|
1245
1251
|
if (argc < 2 + skip_arg) {
|
@@ -1257,11 +1263,11 @@ TypeInfo TypeInfo_FromClass(int argc, VALUE* argv, int skip_arg,
|
|
1257
1263
|
"class or enum as returned by the DescriptorPool.");
|
1258
1264
|
}
|
1259
1265
|
|
1260
|
-
if (ret.type ==
|
1266
|
+
if (ret.type == kUpb_CType_Message) {
|
1261
1267
|
ret.def.msgdef = ruby_to_Descriptor(desc)->msgdef;
|
1262
1268
|
Message_CheckClass(klass);
|
1263
1269
|
} else {
|
1264
|
-
PBRUBY_ASSERT(ret.type ==
|
1270
|
+
PBRUBY_ASSERT(ret.type == kUpb_CType_Enum);
|
1265
1271
|
ret.def.enumdef = ruby_to_EnumDescriptor(desc)->enumdef;
|
1266
1272
|
}
|
1267
1273
|
} else {
|