google-protobuf 3.25.5-x86-mingw32 → 4.26.0.rc.1-x86-mingw32
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 +7 -4
- data/ext/google/protobuf_c/defs.c +40 -27
- data/ext/google/protobuf_c/extconf.rb +1 -1
- data/ext/google/protobuf_c/map.c +9 -18
- data/ext/google/protobuf_c/map.h +1 -1
- data/ext/google/protobuf_c/message.c +38 -76
- data/ext/google/protobuf_c/message.h +1 -1
- data/ext/google/protobuf_c/repeated_field.c +6 -15
- data/ext/google/protobuf_c/repeated_field.h +1 -1
- data/ext/google/protobuf_c/ruby-upb.c +11791 -10801
- data/ext/google/protobuf_c/ruby-upb.h +5161 -4239
- data/ext/google/protobuf_c/shared_convert.c +5 -3
- data/ext/google/protobuf_c/shared_convert.h +2 -2
- data/ext/google/protobuf_c/shared_message.c +8 -6
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +467 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +9 -8
- 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/3.2/protobuf_c.so +0 -0
- data/lib/google/3.3/protobuf_c.so +0 -0
- data/lib/google/protobuf/any_pb.rb +1 -22
- data/lib/google/protobuf/api_pb.rb +1 -24
- data/lib/google/protobuf/descriptor_pb.rb +2 -23
- data/lib/google/protobuf/duration_pb.rb +1 -22
- data/lib/google/protobuf/empty_pb.rb +1 -22
- data/lib/google/protobuf/ffi/descriptor.rb +2 -3
- data/lib/google/protobuf/ffi/enum_descriptor.rb +1 -1
- data/lib/google/protobuf/ffi/ffi.rb +2 -0
- data/lib/google/protobuf/ffi/field_descriptor.rb +10 -1
- data/lib/google/protobuf/ffi/file_descriptor.rb +1 -13
- data/lib/google/protobuf/ffi/internal/convert.rb +7 -23
- data/lib/google/protobuf/ffi/map.rb +13 -11
- data/lib/google/protobuf/ffi/message.rb +10 -13
- data/lib/google/protobuf/ffi/oneof_descriptor.rb +1 -1
- data/lib/google/protobuf/ffi/repeated_field.rb +12 -10
- data/lib/google/protobuf/field_mask_pb.rb +1 -22
- data/lib/google/protobuf/plugin_pb.rb +2 -24
- data/lib/google/protobuf/repeated_field.rb +1 -2
- data/lib/google/protobuf/source_context_pb.rb +1 -22
- data/lib/google/protobuf/struct_pb.rb +1 -22
- data/lib/google/protobuf/timestamp_pb.rb +1 -22
- data/lib/google/protobuf/type_pb.rb +1 -24
- data/lib/google/protobuf/wrappers_pb.rb +1 -22
- data/lib/google/protobuf_ffi.rb +1 -2
- data/lib/google/protobuf_native.rb +0 -1
- data/lib/google/tasks/ffi.rake +1 -3
- metadata +9 -12
- data/ext/google/protobuf_c/third_party/utf8_range/naive.c +0 -92
- data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +0 -157
- data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +0 -170
- data/lib/google/protobuf/descriptor_dsl.rb +0 -465
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da03c30e5083d43f273f5ec65b4430645f9143a556989e54c882a31c4056ebbb
|
4
|
+
data.tar.gz: e8f19dc84193e13c0c25e6a7c68ab89cf5aa184dc7a2154d032e5e951177148b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b556ceaf73cffefef6ffc88cc127f4a570cc9b93d6e0a070bc2aad841ae044edf26cfb436afcc1b8559bc59d38ffc021739786ee51d6739ca7dd992643bf8619
|
7
|
+
data.tar.gz: 4a32ea79b8988356ce6a0acfc64432a69d831f2447b6e768bda101c8c79012101838c5088524b24ead2fcacfc148d9ad3821bc145b484c0d68f3dbdade7ea088
|
@@ -141,7 +141,7 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
|
|
141
141
|
VALUE utf8 = rb_enc_from_encoding(rb_utf8_encoding());
|
142
142
|
if (rb_obj_class(value) == rb_cSymbol) {
|
143
143
|
value = rb_funcall(value, rb_intern("to_s"), 0);
|
144
|
-
} else if (
|
144
|
+
} else if (!rb_obj_is_kind_of(value, rb_cString)) {
|
145
145
|
rb_raise(cTypeError,
|
146
146
|
"Invalid argument for string field '%s' (given %s).", name,
|
147
147
|
rb_class2name(CLASS_OF(value)));
|
@@ -208,7 +208,8 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
|
|
208
208
|
}
|
209
209
|
break;
|
210
210
|
default:
|
211
|
-
|
211
|
+
rb_raise(cTypeError,
|
212
|
+
"Convert_RubyToUpb(): Unexpected type %d", (int)type_info.type);
|
212
213
|
}
|
213
214
|
|
214
215
|
return ret;
|
@@ -296,7 +297,8 @@ bool Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2,
|
|
296
297
|
if (upb_Status_IsOk(&status)) {
|
297
298
|
return return_value;
|
298
299
|
} else {
|
299
|
-
rb_raise(rb_eRuntimeError,
|
300
|
+
rb_raise(rb_eRuntimeError, "Msgval_IsEqual(): %s",
|
301
|
+
upb_Status_ErrorMessage(&status));
|
300
302
|
}
|
301
303
|
}
|
302
304
|
|
@@ -309,6 +311,7 @@ uint64_t Msgval_GetHash(upb_MessageValue val, TypeInfo type_info,
|
|
309
311
|
if (upb_Status_IsOk(&status)) {
|
310
312
|
return return_value;
|
311
313
|
} else {
|
312
|
-
rb_raise(rb_eRuntimeError,
|
314
|
+
rb_raise(rb_eRuntimeError, "Msgval_GetHash(): %s",
|
315
|
+
upb_Status_ErrorMessage(&status));
|
313
316
|
}
|
314
317
|
}
|
@@ -489,7 +489,7 @@ static VALUE FileDescriptor_alloc(VALUE klass) {
|
|
489
489
|
* call-seq:
|
490
490
|
* FileDescriptor.new => file
|
491
491
|
*
|
492
|
-
* Returns a new file descriptor.
|
492
|
+
* Returns a new file descriptor. May
|
493
493
|
* to a builder.
|
494
494
|
*/
|
495
495
|
static VALUE FileDescriptor_initialize(VALUE _self, VALUE cookie,
|
@@ -519,28 +519,6 @@ static VALUE FileDescriptor_name(VALUE _self) {
|
|
519
519
|
return name == NULL ? Qnil : rb_str_new2(name);
|
520
520
|
}
|
521
521
|
|
522
|
-
/*
|
523
|
-
* call-seq:
|
524
|
-
* FileDescriptor.syntax => syntax
|
525
|
-
*
|
526
|
-
* Returns this file descriptors syntax.
|
527
|
-
*
|
528
|
-
* Valid syntax versions are:
|
529
|
-
* :proto2 or :proto3.
|
530
|
-
*/
|
531
|
-
static VALUE FileDescriptor_syntax(VALUE _self) {
|
532
|
-
FileDescriptor* self = ruby_to_FileDescriptor(_self);
|
533
|
-
|
534
|
-
switch (upb_FileDef_Syntax(self->filedef)) {
|
535
|
-
case kUpb_Syntax_Proto3:
|
536
|
-
return ID2SYM(rb_intern("proto3"));
|
537
|
-
case kUpb_Syntax_Proto2:
|
538
|
-
return ID2SYM(rb_intern("proto2"));
|
539
|
-
default:
|
540
|
-
return Qnil;
|
541
|
-
}
|
542
|
-
}
|
543
|
-
|
544
522
|
/*
|
545
523
|
* call-seq:
|
546
524
|
* FileDescriptor.options => options
|
@@ -564,7 +542,6 @@ static void FileDescriptor_register(VALUE module) {
|
|
564
542
|
rb_define_alloc_func(klass, FileDescriptor_alloc);
|
565
543
|
rb_define_method(klass, "initialize", FileDescriptor_initialize, 3);
|
566
544
|
rb_define_method(klass, "name", FileDescriptor_name, 0);
|
567
|
-
rb_define_method(klass, "syntax", FileDescriptor_syntax, 0);
|
568
545
|
rb_define_method(klass, "options", FileDescriptor_options, 0);
|
569
546
|
rb_gc_register_address(&cFileDescriptor);
|
570
547
|
cFileDescriptor = klass;
|
@@ -736,6 +713,28 @@ static VALUE FieldDescriptor_default(VALUE _self) {
|
|
736
713
|
return Convert_UpbToRuby(default_val, TypeInfo_get(self->fielddef), Qnil);
|
737
714
|
}
|
738
715
|
|
716
|
+
/*
|
717
|
+
* call-seq:
|
718
|
+
* FieldDescriptor.has_presence? => bool
|
719
|
+
*
|
720
|
+
* Returns whether this field tracks presence.
|
721
|
+
*/
|
722
|
+
static VALUE FieldDescriptor_has_presence(VALUE _self) {
|
723
|
+
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
724
|
+
return upb_FieldDef_HasPresence(self->fielddef) ? Qtrue : Qfalse;
|
725
|
+
}
|
726
|
+
|
727
|
+
/*
|
728
|
+
* call-seq:
|
729
|
+
* FieldDescriptor.is_packed? => bool
|
730
|
+
*
|
731
|
+
* Returns whether this is a repeated field that uses packed encoding.
|
732
|
+
*/
|
733
|
+
static VALUE FieldDescriptor_is_packed(VALUE _self) {
|
734
|
+
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
735
|
+
return upb_FieldDef_IsPacked(self->fielddef) ? Qtrue : Qfalse;
|
736
|
+
}
|
737
|
+
|
739
738
|
/*
|
740
739
|
* call-seq:
|
741
740
|
* FieldDescriptor.json_name => json_name
|
@@ -862,7 +861,7 @@ static VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) {
|
|
862
861
|
static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
|
863
862
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
864
863
|
const upb_MessageDef* m;
|
865
|
-
const
|
864
|
+
const upb_Message* msg = Message_Get(msg_rb, &m);
|
866
865
|
|
867
866
|
if (m != upb_FieldDef_ContainingType(self->fielddef)) {
|
868
867
|
rb_raise(cTypeError, "has method called on wrong message type");
|
@@ -882,7 +881,7 @@ static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
|
|
882
881
|
static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
|
883
882
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
884
883
|
const upb_MessageDef* m;
|
885
|
-
|
884
|
+
upb_Message* msg = Message_GetMutable(msg_rb, &m);
|
886
885
|
|
887
886
|
if (m != upb_FieldDef_ContainingType(self->fielddef)) {
|
888
887
|
rb_raise(cTypeError, "has method called on wrong message type");
|
@@ -903,7 +902,7 @@ static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
|
|
903
902
|
static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) {
|
904
903
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
905
904
|
const upb_MessageDef* m;
|
906
|
-
|
905
|
+
upb_Message* msg = Message_GetMutable(msg_rb, &m);
|
907
906
|
upb_Arena* arena = Arena_get(Message_GetArena(msg_rb));
|
908
907
|
upb_MessageValue msgval;
|
909
908
|
|
@@ -943,6 +942,8 @@ static void FieldDescriptor_register(VALUE module) {
|
|
943
942
|
rb_define_method(klass, "name", FieldDescriptor_name, 0);
|
944
943
|
rb_define_method(klass, "type", FieldDescriptor__type, 0);
|
945
944
|
rb_define_method(klass, "default", FieldDescriptor_default, 0);
|
945
|
+
rb_define_method(klass, "has_presence?", FieldDescriptor_has_presence, 0);
|
946
|
+
rb_define_method(klass, "is_packed?", FieldDescriptor_is_packed, 0);
|
946
947
|
rb_define_method(klass, "json_name", FieldDescriptor_json_name, 0);
|
947
948
|
rb_define_method(klass, "label", FieldDescriptor_label, 0);
|
948
949
|
rb_define_method(klass, "number", FieldDescriptor_number, 0);
|
@@ -1163,6 +1164,17 @@ static VALUE EnumDescriptor_file_descriptor(VALUE _self) {
|
|
1163
1164
|
upb_EnumDef_File(self->enumdef));
|
1164
1165
|
}
|
1165
1166
|
|
1167
|
+
/*
|
1168
|
+
* call-seq:
|
1169
|
+
* EnumDescriptor.is_closed? => bool
|
1170
|
+
*
|
1171
|
+
* Returns whether this enum is open or closed.
|
1172
|
+
*/
|
1173
|
+
static VALUE EnumDescriptor_is_closed(VALUE _self) {
|
1174
|
+
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
1175
|
+
return upb_EnumDef_IsClosed(self->enumdef) ? Qtrue : Qfalse;
|
1176
|
+
}
|
1177
|
+
|
1166
1178
|
/*
|
1167
1179
|
* call-seq:
|
1168
1180
|
* EnumDescriptor.name => name
|
@@ -1275,6 +1287,7 @@ static void EnumDescriptor_register(VALUE module) {
|
|
1275
1287
|
rb_define_method(klass, "each", EnumDescriptor_each, 0);
|
1276
1288
|
rb_define_method(klass, "enummodule", EnumDescriptor_enummodule, 0);
|
1277
1289
|
rb_define_method(klass, "file_descriptor", EnumDescriptor_file_descriptor, 0);
|
1290
|
+
rb_define_method(klass, "is_closed?", EnumDescriptor_is_closed, 0);
|
1278
1291
|
rb_define_method(klass, "options", EnumDescriptor_options, 0);
|
1279
1292
|
rb_include_module(klass, rb_mEnumerable);
|
1280
1293
|
rb_gc_register_address(&cEnumDescriptor);
|
@@ -22,7 +22,7 @@ $INCFLAGS += " -I$(srcdir)/third_party/utf8_range"
|
|
22
22
|
|
23
23
|
$srcs = ["protobuf.c", "convert.c", "defs.c", "message.c",
|
24
24
|
"repeated_field.c", "map.c", "ruby-upb.c", "wrap_memcpy.c",
|
25
|
-
"
|
25
|
+
"utf8_range.c", "shared_convert.c",
|
26
26
|
"shared_message.c"]
|
27
27
|
|
28
28
|
create_makefile(ext_name)
|
data/ext/google/protobuf_c/map.c
CHANGED
@@ -212,7 +212,7 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
|
|
212
212
|
Map* self = ruby_to_Map(_self);
|
213
213
|
Map* other = ruby_to_Map(hashmap);
|
214
214
|
upb_Arena* arena = Arena_get(self->arena);
|
215
|
-
|
215
|
+
upb_Map* self_map = Map_GetMutable(_self);
|
216
216
|
|
217
217
|
Arena_fuse(other->arena, arena);
|
218
218
|
|
@@ -225,7 +225,7 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
|
|
225
225
|
size_t iter = kUpb_Map_Begin;
|
226
226
|
upb_MessageValue key, val;
|
227
227
|
while (upb_Map_Next(other->map, &key, &val, &iter)) {
|
228
|
-
upb_Map_Set(
|
228
|
+
upb_Map_Set(self_map, key, val, arena);
|
229
229
|
}
|
230
230
|
} else {
|
231
231
|
rb_raise(rb_eArgError, "Unknown type merging into Map");
|
@@ -444,7 +444,7 @@ static VALUE Map_delete(VALUE _self, VALUE key) {
|
|
444
444
|
Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
|
445
445
|
upb_MessageValue val_upb;
|
446
446
|
|
447
|
-
if (upb_Map_Delete(
|
447
|
+
if (upb_Map_Delete(Map_GetMutable(_self), key_upb, &val_upb)) {
|
448
448
|
return Convert_UpbToRuby(val_upb, self->value_type_info, self->arena);
|
449
449
|
} else {
|
450
450
|
return Qnil;
|
@@ -563,22 +563,13 @@ VALUE Map_eq(VALUE _self, VALUE _other) {
|
|
563
563
|
* Freezes the message object. We have to intercept this so we can pin the
|
564
564
|
* Ruby object into memory so we don't forget it's frozen.
|
565
565
|
*/
|
566
|
-
|
566
|
+
VALUE Map_freeze(VALUE _self) {
|
567
567
|
Map* self = ruby_to_Map(_self);
|
568
|
-
if (!RB_OBJ_FROZEN(_self)) {
|
569
|
-
Arena_Pin(self->arena, _self);
|
570
|
-
RB_OBJ_FREEZE(_self);
|
571
|
-
}
|
572
|
-
return _self;
|
573
|
-
}
|
574
568
|
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
VALUE Map_internal_deep_freeze(VALUE _self) {
|
580
|
-
Map* self = ruby_to_Map(_self);
|
581
|
-
Map_freeze(_self);
|
569
|
+
if (RB_OBJ_FROZEN(_self)) return _self;
|
570
|
+
Arena_Pin(self->arena, _self);
|
571
|
+
RB_OBJ_FREEZE(_self);
|
572
|
+
|
582
573
|
if (self->value_type_info.type == kUpb_CType_Message) {
|
583
574
|
size_t iter = kUpb_Map_Begin;
|
584
575
|
upb_MessageValue key, val;
|
@@ -586,7 +577,7 @@ VALUE Map_internal_deep_freeze(VALUE _self) {
|
|
586
577
|
while (upb_Map_Next(self->map, &key, &val, &iter)) {
|
587
578
|
VALUE val_val =
|
588
579
|
Convert_UpbToRuby(val, self->value_type_info, self->arena);
|
589
|
-
|
580
|
+
Message_freeze(val_val);
|
590
581
|
}
|
591
582
|
}
|
592
583
|
return _self;
|
data/ext/google/protobuf_c/map.h
CHANGED
@@ -488,7 +488,8 @@ static int Map_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
|
|
488
488
|
k = Convert_RubyToUpb(key, "", map_init->key_type, NULL);
|
489
489
|
|
490
490
|
if (map_init->val_type.type == kUpb_CType_Message && TYPE(val) == T_HASH) {
|
491
|
-
upb_MiniTable* t =
|
491
|
+
const upb_MiniTable* t =
|
492
|
+
upb_MessageDef_MiniTable(map_init->val_type.def.msgdef);
|
492
493
|
upb_Message* msg = upb_Message_New(t, map_init->arena);
|
493
494
|
Message_InitFromValue(msg, map_init->val_type.def.msgdef, val,
|
494
495
|
map_init->arena);
|
@@ -519,7 +520,7 @@ static upb_MessageValue MessageValue_FromValue(VALUE val, TypeInfo info,
|
|
519
520
|
upb_Arena* arena) {
|
520
521
|
if (info.type == kUpb_CType_Message) {
|
521
522
|
upb_MessageValue msgval;
|
522
|
-
upb_MiniTable* t = upb_MessageDef_MiniTable(info.def.msgdef);
|
523
|
+
const upb_MiniTable* t = upb_MessageDef_MiniTable(info.def.msgdef);
|
523
524
|
upb_Message* msg = upb_Message_New(t, arena);
|
524
525
|
Message_InitFromValue(msg, info.def.msgdef, val, arena);
|
525
526
|
msgval.msg_val = msg;
|
@@ -635,7 +636,7 @@ static VALUE Message_initialize(int argc, VALUE* argv, VALUE _self) {
|
|
635
636
|
Message* self = ruby_to_Message(_self);
|
636
637
|
VALUE arena_rb = Arena_new();
|
637
638
|
upb_Arena* arena = Arena_get(arena_rb);
|
638
|
-
upb_MiniTable* t = upb_MessageDef_MiniTable(self->msgdef);
|
639
|
+
const upb_MiniTable* t = upb_MessageDef_MiniTable(self->msgdef);
|
639
640
|
upb_Message* msg = upb_Message_New(t, arena);
|
640
641
|
|
641
642
|
Message_InitPtr(_self, msg, arena_rb);
|
@@ -660,11 +661,8 @@ static VALUE Message_dup(VALUE _self) {
|
|
660
661
|
Message* self = ruby_to_Message(_self);
|
661
662
|
VALUE new_msg = rb_class_new_instance(0, NULL, CLASS_OF(_self));
|
662
663
|
Message* new_msg_self = ruby_to_Message(new_msg);
|
663
|
-
|
664
|
-
|
665
|
-
// TODO
|
666
|
-
// TODO
|
667
|
-
memcpy((upb_Message*)new_msg_self->msg, self->msg, size);
|
664
|
+
const upb_MiniTable* m = upb_MessageDef_MiniTable(self->msgdef);
|
665
|
+
upb_Message_ShallowCopy((upb_Message*)new_msg_self->msg, self->msg, m);
|
668
666
|
Arena_fuse(self->arena, Arena_get(new_msg_self->arena));
|
669
667
|
return new_msg;
|
670
668
|
}
|
@@ -678,7 +676,8 @@ bool Message_Equal(const upb_Message* m1, const upb_Message* m2,
|
|
678
676
|
if (upb_Status_IsOk(&status)) {
|
679
677
|
return return_value;
|
680
678
|
} else {
|
681
|
-
rb_raise(cParseError,
|
679
|
+
rb_raise(cParseError, "Message_Equal(): %s",
|
680
|
+
upb_Status_ErrorMessage(&status));
|
682
681
|
}
|
683
682
|
}
|
684
683
|
|
@@ -709,7 +708,8 @@ uint64_t Message_Hash(const upb_Message* msg, const upb_MessageDef* m,
|
|
709
708
|
if (upb_Status_IsOk(&status)) {
|
710
709
|
return return_value;
|
711
710
|
} else {
|
712
|
-
rb_raise(cParseError,
|
711
|
+
rb_raise(cParseError, "Message_Hash(): %s",
|
712
|
+
upb_Status_ErrorMessage(&status));
|
713
713
|
}
|
714
714
|
}
|
715
715
|
|
@@ -766,58 +766,34 @@ static VALUE Message_CreateHash(const upb_Message* msg,
|
|
766
766
|
if (!msg) return Qnil;
|
767
767
|
|
768
768
|
VALUE hash = rb_hash_new();
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
// This is unfortunate, we should key behaviors off field attributes (like
|
774
|
-
// whether a field has presence), not proto2 vs. proto3. We should see if we
|
775
|
-
// can change this without breaking users.
|
776
|
-
is_proto2 = upb_MessageDef_Syntax(m) == kUpb_Syntax_Proto2;
|
777
|
-
|
778
|
-
for (int i = 0; i < n; i++) {
|
779
|
-
const upb_FieldDef* field = upb_MessageDef_Field(m, i);
|
780
|
-
TypeInfo type_info = TypeInfo_get(field);
|
781
|
-
upb_MessageValue msgval;
|
782
|
-
VALUE msg_value;
|
783
|
-
VALUE msg_key;
|
784
|
-
|
785
|
-
if (!is_proto2 && upb_FieldDef_IsSubMessage(field) &&
|
786
|
-
!upb_FieldDef_IsRepeated(field) &&
|
787
|
-
!upb_Message_HasFieldByDef(msg, field)) {
|
788
|
-
// TODO: Legacy behavior, remove when we fix the is_proto2 differences.
|
789
|
-
msg_key = ID2SYM(rb_intern(upb_FieldDef_Name(field)));
|
790
|
-
rb_hash_aset(hash, msg_key, Qnil);
|
791
|
-
continue;
|
792
|
-
}
|
769
|
+
size_t iter = kUpb_Message_Begin;
|
770
|
+
const upb_DefPool* pool = upb_FileDef_Pool(upb_MessageDef_File(m));
|
771
|
+
const upb_FieldDef* field;
|
772
|
+
upb_MessageValue val;
|
793
773
|
|
794
|
-
|
795
|
-
if (
|
796
|
-
|
774
|
+
while (upb_Message_Next(msg, m, pool, &field, &val, &iter)) {
|
775
|
+
if (upb_FieldDef_IsExtension(field)) {
|
776
|
+
// TODO: allow extensions once we have decided what naming scheme the
|
777
|
+
// symbol should use. eg. :"[pkg.ext]"
|
797
778
|
continue;
|
798
779
|
}
|
799
780
|
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
// Proto2 omits empty map/repeated filds also.
|
781
|
+
TypeInfo type_info = TypeInfo_get(field);
|
782
|
+
VALUE msg_value;
|
804
783
|
|
805
784
|
if (upb_FieldDef_IsMap(field)) {
|
806
785
|
const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(field);
|
807
786
|
const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry_m, 1);
|
808
787
|
const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry_m, 2);
|
809
788
|
upb_CType key_type = upb_FieldDef_CType(key_f);
|
810
|
-
msg_value = Map_CreateHash(
|
789
|
+
msg_value = Map_CreateHash(val.map_val, key_type, TypeInfo_get(val_f));
|
811
790
|
} else if (upb_FieldDef_IsRepeated(field)) {
|
812
|
-
|
813
|
-
(!msgval.array_val || upb_Array_Size(msgval.array_val) == 0)) {
|
814
|
-
continue;
|
815
|
-
}
|
816
|
-
msg_value = RepeatedField_CreateArray(msgval.array_val, type_info);
|
791
|
+
msg_value = RepeatedField_CreateArray(val.array_val, type_info);
|
817
792
|
} else {
|
818
|
-
msg_value = Scalar_CreateHash(
|
793
|
+
msg_value = Scalar_CreateHash(val, type_info);
|
819
794
|
}
|
820
795
|
|
796
|
+
VALUE msg_key = ID2SYM(rb_intern(upb_FieldDef_Name(field)));
|
821
797
|
rb_hash_aset(hash, msg_key, msg_value);
|
822
798
|
}
|
823
799
|
|
@@ -850,22 +826,12 @@ static VALUE Message_to_h(VALUE _self) {
|
|
850
826
|
* Freezes the message object. We have to intercept this so we can pin the
|
851
827
|
* Ruby object into memory so we don't forget it's frozen.
|
852
828
|
*/
|
853
|
-
|
829
|
+
VALUE Message_freeze(VALUE _self) {
|
854
830
|
Message* self = ruby_to_Message(_self);
|
855
|
-
if (!RB_OBJ_FROZEN(_self)) {
|
856
|
-
Arena_Pin(self->arena, _self);
|
857
|
-
RB_OBJ_FREEZE(_self);
|
858
|
-
}
|
859
|
-
return _self;
|
860
|
-
}
|
861
831
|
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
*/
|
866
|
-
VALUE Message_internal_deep_freeze(VALUE _self) {
|
867
|
-
Message* self = ruby_to_Message(_self);
|
868
|
-
Message_freeze(_self);
|
832
|
+
if (RB_OBJ_FROZEN(_self)) return _self;
|
833
|
+
Arena_Pin(self->arena, _self);
|
834
|
+
RB_OBJ_FREEZE(_self);
|
869
835
|
|
870
836
|
int n = upb_MessageDef_FieldCount(self->msgdef);
|
871
837
|
for (int i = 0; i < n; i++) {
|
@@ -874,11 +840,11 @@ VALUE Message_internal_deep_freeze(VALUE _self) {
|
|
874
840
|
|
875
841
|
if (field != Qnil) {
|
876
842
|
if (upb_FieldDef_IsMap(f)) {
|
877
|
-
|
843
|
+
Map_freeze(field);
|
878
844
|
} else if (upb_FieldDef_IsRepeated(f)) {
|
879
|
-
|
845
|
+
RepeatedField_freeze(field);
|
880
846
|
} else if (upb_FieldDef_IsSubMessage(f)) {
|
881
|
-
|
847
|
+
Message_freeze(field);
|
882
848
|
}
|
883
849
|
}
|
884
850
|
}
|
@@ -987,7 +953,7 @@ VALUE Message_decode_bytes(int size, const char* bytes, int options,
|
|
987
953
|
rb_raise(cParseError, "Error occurred during parsing");
|
988
954
|
}
|
989
955
|
if (freeze) {
|
990
|
-
|
956
|
+
Message_freeze(msg_rb);
|
991
957
|
}
|
992
958
|
return msg_rb;
|
993
959
|
}
|
@@ -1009,9 +975,6 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
|
|
1009
975
|
int options = 0;
|
1010
976
|
upb_Status status;
|
1011
977
|
|
1012
|
-
// TODO: use this message's pool instead.
|
1013
|
-
const upb_DefPool* symtab = DescriptorPool_GetSymtab(generated_pool);
|
1014
|
-
|
1015
978
|
if (argc < 1 || argc > 2) {
|
1016
979
|
rb_raise(rb_eArgError, "Expected 1 or 2 arguments.");
|
1017
980
|
}
|
@@ -1045,8 +1008,9 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
|
|
1045
1008
|
}
|
1046
1009
|
|
1047
1010
|
upb_Status_Clear(&status);
|
1011
|
+
const upb_DefPool* pool = upb_FileDef_Pool(upb_MessageDef_File(msg->msgdef));
|
1048
1012
|
if (!upb_JsonDecode(RSTRING_PTR(data), RSTRING_LEN(data),
|
1049
|
-
(upb_Message*)msg->msg, msg->msgdef,
|
1013
|
+
(upb_Message*)msg->msg, msg->msgdef, pool, options,
|
1050
1014
|
Arena_get(msg->arena), &status)) {
|
1051
1015
|
rb_raise(cParseError, "Error occurred during parsing: %s",
|
1052
1016
|
upb_Status_ErrorMessage(&status));
|
@@ -1125,9 +1089,6 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
|
|
1125
1089
|
size_t size;
|
1126
1090
|
upb_Status status;
|
1127
1091
|
|
1128
|
-
// TODO: use this message's pool instead.
|
1129
|
-
const upb_DefPool* symtab = DescriptorPool_GetSymtab(generated_pool);
|
1130
|
-
|
1131
1092
|
if (argc < 1 || argc > 2) {
|
1132
1093
|
rb_raise(rb_eArgError, "Expected 1 or 2 arguments.");
|
1133
1094
|
}
|
@@ -1162,8 +1123,9 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
|
|
1162
1123
|
}
|
1163
1124
|
|
1164
1125
|
upb_Status_Clear(&status);
|
1165
|
-
|
1166
|
-
|
1126
|
+
const upb_DefPool* pool = upb_FileDef_Pool(upb_MessageDef_File(msg->msgdef));
|
1127
|
+
size = upb_JsonEncode(msg->msg, msg->msgdef, pool, options, buf, sizeof(buf),
|
1128
|
+
&status);
|
1167
1129
|
|
1168
1130
|
if (!upb_Status_IsOk(&status)) {
|
1169
1131
|
rb_raise(cParseError, "Error occurred during encoding: %s",
|
@@ -1173,7 +1135,7 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
|
|
1173
1135
|
VALUE ret;
|
1174
1136
|
if (size >= sizeof(buf)) {
|
1175
1137
|
char* buf2 = malloc(size + 1);
|
1176
|
-
upb_JsonEncode(msg->msg, msg->msgdef,
|
1138
|
+
upb_JsonEncode(msg->msg, msg->msgdef, pool, options, buf2, size + 1,
|
1177
1139
|
&status);
|
1178
1140
|
ret = rb_str_new(buf2, size);
|
1179
1141
|
free(buf2);
|
@@ -78,7 +78,7 @@ VALUE Message_decode_bytes(int size, const char* bytes, int options,
|
|
78
78
|
VALUE klass, bool freeze);
|
79
79
|
|
80
80
|
// Recursively freeze message
|
81
|
-
VALUE
|
81
|
+
VALUE Message_freeze(VALUE _self);
|
82
82
|
|
83
83
|
// Call at startup to register all types in this module.
|
84
84
|
void Message_register(VALUE protobuf);
|
@@ -478,29 +478,20 @@ VALUE RepeatedField_eq(VALUE _self, VALUE _other) {
|
|
478
478
|
* Freezes the repeated field. We have to intercept this so we can pin the Ruby
|
479
479
|
* object into memory so we don't forget it's frozen.
|
480
480
|
*/
|
481
|
-
|
481
|
+
VALUE RepeatedField_freeze(VALUE _self) {
|
482
482
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
483
|
-
if (!RB_OBJ_FROZEN(_self)) {
|
484
|
-
Arena_Pin(self->arena, _self);
|
485
|
-
RB_OBJ_FREEZE(_self);
|
486
|
-
}
|
487
|
-
return _self;
|
488
|
-
}
|
489
483
|
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
VALUE RepeatedField_internal_deep_freeze(VALUE _self) {
|
495
|
-
RepeatedField* self = ruby_to_RepeatedField(_self);
|
496
|
-
RepeatedField_freeze(_self);
|
484
|
+
if (RB_OBJ_FROZEN(_self)) return _self;
|
485
|
+
Arena_Pin(self->arena, _self);
|
486
|
+
RB_OBJ_FREEZE(_self);
|
487
|
+
|
497
488
|
if (self->type_info.type == kUpb_CType_Message) {
|
498
489
|
int size = upb_Array_Size(self->array);
|
499
490
|
int i;
|
500
491
|
for (i = 0; i < size; i++) {
|
501
492
|
upb_MessageValue msgval = upb_Array_Get(self->array, i);
|
502
493
|
VALUE val = Convert_UpbToRuby(msgval, self->type_info, self->arena);
|
503
|
-
|
494
|
+
Message_freeze(val);
|
504
495
|
}
|
505
496
|
}
|
506
497
|
return _self;
|
@@ -36,6 +36,6 @@ extern VALUE cRepeatedField;
|
|
36
36
|
void RepeatedField_register(VALUE module);
|
37
37
|
|
38
38
|
// Recursively freeze RepeatedField.
|
39
|
-
VALUE
|
39
|
+
VALUE RepeatedField_freeze(VALUE _self);
|
40
40
|
|
41
41
|
#endif // RUBY_PROTOBUF_REPEATED_FIELD_H_
|