google-protobuf 3.21.12-x86-mingw32 → 3.22.0.rc.3-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
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 +0 -0
- data/ext/google/protobuf_c/convert.h +0 -0
- data/ext/google/protobuf_c/defs.c +3 -3
- data/ext/google/protobuf_c/defs.h +0 -0
- data/ext/google/protobuf_c/extconf.rb +2 -3
- data/ext/google/protobuf_c/map.c +27 -42
- data/ext/google/protobuf_c/map.h +0 -0
- data/ext/google/protobuf_c/message.c +116 -99
- data/ext/google/protobuf_c/message.h +0 -0
- data/ext/google/protobuf_c/protobuf.c +0 -0
- data/ext/google/protobuf_c/protobuf.h +0 -0
- data/ext/google/protobuf_c/repeated_field.c +0 -0
- data/ext/google/protobuf_c/repeated_field.h +0 -0
- data/ext/google/protobuf_c/ruby-upb.c +10546 -9149
- data/ext/google/protobuf_c/ruby-upb.h +7608 -3276
- data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +1 -0
- data/ext/google/protobuf_c/third_party/utf8_range/naive.c +0 -0
- data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +1 -1
- data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +0 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +13 -1
- data/ext/google/protobuf_c/wrap_memcpy.c +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/3.2/protobuf_c.so +0 -0
- data/lib/google/protobuf/any_pb.rb +0 -0
- data/lib/google/protobuf/api_pb.rb +0 -0
- data/lib/google/protobuf/descriptor_dsl.rb +0 -0
- data/lib/google/protobuf/descriptor_pb.rb +41 -12
- data/lib/google/protobuf/duration_pb.rb +0 -0
- data/lib/google/protobuf/empty_pb.rb +0 -0
- data/lib/google/protobuf/field_mask_pb.rb +0 -0
- data/lib/google/protobuf/message_exts.rb +5 -0
- data/lib/google/protobuf/plugin_pb.rb +50 -0
- data/lib/google/protobuf/repeated_field.rb +0 -0
- data/lib/google/protobuf/source_context_pb.rb +0 -0
- data/lib/google/protobuf/struct_pb.rb +0 -0
- data/lib/google/protobuf/timestamp_pb.rb +0 -0
- data/lib/google/protobuf/type_pb.rb +0 -0
- data/lib/google/protobuf/wrappers_pb.rb +0 -0
- data/lib/google/protobuf.rb +0 -0
- metadata +14 -19
- data/lib/google/2.5/protobuf_c.so +0 -0
- data/tests/basic.rb +0 -739
- data/tests/generated_code_test.rb +0 -23
- data/tests/stress.rb +0 -38
@@ -37,6 +37,7 @@
|
|
37
37
|
#include "repeated_field.h"
|
38
38
|
|
39
39
|
static VALUE cParseError = Qnil;
|
40
|
+
static VALUE cAbstractMessage = Qnil;
|
40
41
|
static ID descriptor_instancevar_interned;
|
41
42
|
|
42
43
|
static VALUE initialize_rb_class_with_no_args(VALUE klass) {
|
@@ -145,7 +146,8 @@ void Message_PrintMessage(StringBuilder* b, const upb_Message* msg,
|
|
145
146
|
for (int i = 0; i < n; i++) {
|
146
147
|
const upb_FieldDef* field = upb_MessageDef_Field(m, i);
|
147
148
|
|
148
|
-
if (upb_FieldDef_HasPresence(field) &&
|
149
|
+
if (upb_FieldDef_HasPresence(field) &&
|
150
|
+
!upb_Message_HasFieldByDef(msg, field)) {
|
149
151
|
continue;
|
150
152
|
}
|
151
153
|
|
@@ -155,7 +157,7 @@ void Message_PrintMessage(StringBuilder* b, const upb_Message* msg,
|
|
155
157
|
first = false;
|
156
158
|
}
|
157
159
|
|
158
|
-
upb_MessageValue msgval =
|
160
|
+
upb_MessageValue msgval = upb_Message_GetFieldByDef(msg, field);
|
159
161
|
|
160
162
|
StringBuilder_Printf(b, "%s: ", upb_FieldDef_Name(field));
|
161
163
|
|
@@ -241,15 +243,6 @@ static int extract_method_call(VALUE method_name, Message* self,
|
|
241
243
|
if (Match(m, name, f, o, "clear_", "")) return METHOD_CLEAR;
|
242
244
|
if (Match(m, name, f, o, "has_", "?") &&
|
243
245
|
(*o || (*f && upb_FieldDef_HasPresence(*f)))) {
|
244
|
-
// Disallow oneof hazzers for proto3.
|
245
|
-
// TODO(haberman): remove this test when we are enabling oneof hazzers for
|
246
|
-
// proto3.
|
247
|
-
if (*f && !upb_FieldDef_IsSubMessage(*f) &&
|
248
|
-
upb_FieldDef_RealContainingOneof(*f) &&
|
249
|
-
upb_MessageDef_Syntax(upb_FieldDef_ContainingType(*f)) !=
|
250
|
-
kUpb_Syntax_Proto2) {
|
251
|
-
return METHOD_UNKNOWN;
|
252
|
-
}
|
253
246
|
return METHOD_PRESENCE;
|
254
247
|
}
|
255
248
|
if (Match(m, name, f, o, "", "_as_value") && *f &&
|
@@ -278,7 +271,8 @@ static VALUE Message_oneof_accessor(VALUE _self, const upb_OneofDef* o,
|
|
278
271
|
return oneof_field == NULL ? Qfalse : Qtrue;
|
279
272
|
case METHOD_CLEAR:
|
280
273
|
if (oneof_field != NULL) {
|
281
|
-
|
274
|
+
upb_Message_ClearFieldByDef(Message_GetMutable(_self, NULL),
|
275
|
+
oneof_field);
|
282
276
|
}
|
283
277
|
return Qnil;
|
284
278
|
case METHOD_GETTER:
|
@@ -301,13 +295,13 @@ static void Message_setfield(upb_Message* msg, const upb_FieldDef* f, VALUE val,
|
|
301
295
|
} else {
|
302
296
|
if (val == Qnil &&
|
303
297
|
(upb_FieldDef_IsSubMessage(f) || upb_FieldDef_RealContainingOneof(f))) {
|
304
|
-
|
298
|
+
upb_Message_ClearFieldByDef(msg, f);
|
305
299
|
return;
|
306
300
|
}
|
307
301
|
msgval =
|
308
302
|
Convert_RubyToUpb(val, upb_FieldDef_Name(f), TypeInfo_get(f), arena);
|
309
303
|
}
|
310
|
-
|
304
|
+
upb_Message_SetFieldByDef(msg, f, msgval, arena);
|
311
305
|
}
|
312
306
|
|
313
307
|
VALUE Message_getfield(VALUE _self, const upb_FieldDef* f) {
|
@@ -329,12 +323,12 @@ VALUE Message_getfield(VALUE _self, const upb_FieldDef* f) {
|
|
329
323
|
upb_Array* arr = upb_Message_Mutable(msg, f, arena).array;
|
330
324
|
return RepeatedField_GetRubyWrapper(arr, TypeInfo_get(f), self->arena);
|
331
325
|
} else if (upb_FieldDef_IsSubMessage(f)) {
|
332
|
-
if (!
|
326
|
+
if (!upb_Message_HasFieldByDef(self->msg, f)) return Qnil;
|
333
327
|
upb_Message* submsg = upb_Message_Mutable(msg, f, arena).msg;
|
334
328
|
const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f);
|
335
329
|
return Message_GetRubyWrapper(submsg, m, self->arena);
|
336
330
|
} else {
|
337
|
-
upb_MessageValue msgval =
|
331
|
+
upb_MessageValue msgval = upb_Message_GetFieldByDef(self->msg, f);
|
338
332
|
return Convert_UpbToRuby(msgval, TypeInfo_get(f), self->arena);
|
339
333
|
}
|
340
334
|
}
|
@@ -348,23 +342,24 @@ static VALUE Message_field_accessor(VALUE _self, const upb_FieldDef* f,
|
|
348
342
|
Message_setfield(Message_GetMutable(_self, NULL), f, argv[1], arena);
|
349
343
|
return Qnil;
|
350
344
|
case METHOD_CLEAR:
|
351
|
-
|
345
|
+
upb_Message_ClearFieldByDef(Message_GetMutable(_self, NULL), f);
|
352
346
|
return Qnil;
|
353
347
|
case METHOD_PRESENCE:
|
354
348
|
if (!upb_FieldDef_HasPresence(f)) {
|
355
349
|
rb_raise(rb_eRuntimeError, "Field does not have presence.");
|
356
350
|
}
|
357
|
-
return
|
351
|
+
return upb_Message_HasFieldByDef(Message_Get(_self, NULL), f);
|
358
352
|
case METHOD_WRAPPER_GETTER: {
|
359
353
|
Message* self = ruby_to_Message(_self);
|
360
|
-
if (
|
354
|
+
if (upb_Message_HasFieldByDef(self->msg, f)) {
|
361
355
|
PBRUBY_ASSERT(upb_FieldDef_IsSubMessage(f) &&
|
362
356
|
!upb_FieldDef_IsRepeated(f));
|
363
|
-
upb_MessageValue wrapper =
|
357
|
+
upb_MessageValue wrapper = upb_Message_GetFieldByDef(self->msg, f);
|
364
358
|
const upb_MessageDef* wrapper_m = upb_FieldDef_MessageSubDef(f);
|
365
359
|
const upb_FieldDef* value_f =
|
366
360
|
upb_MessageDef_FindFieldByNumber(wrapper_m, 1);
|
367
|
-
upb_MessageValue value =
|
361
|
+
upb_MessageValue value =
|
362
|
+
upb_Message_GetFieldByDef(wrapper.msg_val, value_f);
|
368
363
|
return Convert_UpbToRuby(value, TypeInfo_get(value_f), self->arena);
|
369
364
|
} else {
|
370
365
|
return Qnil;
|
@@ -373,19 +368,20 @@ static VALUE Message_field_accessor(VALUE _self, const upb_FieldDef* f,
|
|
373
368
|
case METHOD_WRAPPER_SETTER: {
|
374
369
|
upb_Message* msg = Message_GetMutable(_self, NULL);
|
375
370
|
if (argv[1] == Qnil) {
|
376
|
-
|
371
|
+
upb_Message_ClearFieldByDef(msg, f);
|
377
372
|
} else {
|
378
373
|
const upb_FieldDef* val_f =
|
379
374
|
upb_MessageDef_FindFieldByNumber(upb_FieldDef_MessageSubDef(f), 1);
|
380
375
|
upb_MessageValue msgval = Convert_RubyToUpb(
|
381
376
|
argv[1], upb_FieldDef_Name(f), TypeInfo_get(val_f), arena);
|
382
377
|
upb_Message* wrapper = upb_Message_Mutable(msg, f, arena).msg;
|
383
|
-
|
378
|
+
upb_Message_SetFieldByDef(wrapper, val_f, msgval, arena);
|
384
379
|
}
|
385
380
|
return Qnil;
|
386
381
|
}
|
387
382
|
case METHOD_ENUM_GETTER: {
|
388
|
-
upb_MessageValue msgval =
|
383
|
+
upb_MessageValue msgval =
|
384
|
+
upb_Message_GetFieldByDef(Message_Get(_self, NULL), f);
|
389
385
|
|
390
386
|
if (upb_FieldDef_Label(f) == kUpb_Label_Repeated) {
|
391
387
|
// Map repeated fields to a new type with ints
|
@@ -510,8 +506,8 @@ static int Map_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
|
|
510
506
|
k = Convert_RubyToUpb(key, "", map_init->key_type, NULL);
|
511
507
|
|
512
508
|
if (map_init->val_type.type == kUpb_CType_Message && TYPE(val) == T_HASH) {
|
513
|
-
|
514
|
-
|
509
|
+
upb_MiniTable* t = upb_MessageDef_MiniTable(map_init->val_type.def.msgdef);
|
510
|
+
upb_Message* msg = upb_Message_New(t, map_init->arena);
|
515
511
|
Message_InitFromValue(msg, map_init->val_type.def.msgdef, val,
|
516
512
|
map_init->arena);
|
517
513
|
v.msg_val = msg;
|
@@ -541,7 +537,8 @@ static upb_MessageValue MessageValue_FromValue(VALUE val, TypeInfo info,
|
|
541
537
|
upb_Arena* arena) {
|
542
538
|
if (info.type == kUpb_CType_Message) {
|
543
539
|
upb_MessageValue msgval;
|
544
|
-
|
540
|
+
upb_MiniTable* t = upb_MessageDef_MiniTable(info.def.msgdef);
|
541
|
+
upb_Message* msg = upb_Message_New(t, arena);
|
545
542
|
Message_InitFromValue(msg, info.def.msgdef, val, arena);
|
546
543
|
msgval.msg_val = msg;
|
547
544
|
return msgval;
|
@@ -593,7 +590,7 @@ static void Message_InitFieldFromValue(upb_Message* msg, const upb_FieldDef* f,
|
|
593
590
|
} else {
|
594
591
|
upb_MessageValue msgval =
|
595
592
|
Convert_RubyToUpb(val, upb_FieldDef_Name(f), TypeInfo_get(f), arena);
|
596
|
-
|
593
|
+
upb_Message_SetFieldByDef(msg, f, msgval, arena);
|
597
594
|
}
|
598
595
|
}
|
599
596
|
|
@@ -656,7 +653,8 @@ static VALUE Message_initialize(int argc, VALUE* argv, VALUE _self) {
|
|
656
653
|
Message* self = ruby_to_Message(_self);
|
657
654
|
VALUE arena_rb = Arena_new();
|
658
655
|
upb_Arena* arena = Arena_get(arena_rb);
|
659
|
-
|
656
|
+
upb_MiniTable* t = upb_MessageDef_MiniTable(self->msgdef);
|
657
|
+
upb_Message* msg = upb_Message_New(t, arena);
|
660
658
|
|
661
659
|
Message_InitPtr(_self, msg, arena_rb);
|
662
660
|
|
@@ -695,15 +693,20 @@ bool Message_Equal(const upb_Message* m1, const upb_Message* m2,
|
|
695
693
|
if (m1 == m2) return true;
|
696
694
|
|
697
695
|
size_t size1, size2;
|
698
|
-
int encode_opts =
|
696
|
+
int encode_opts =
|
697
|
+
kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic;
|
699
698
|
upb_Arena* arena_tmp = upb_Arena_New();
|
700
699
|
const upb_MiniTable* layout = upb_MessageDef_MiniTable(m);
|
701
700
|
|
702
701
|
// Compare deterministically serialized payloads with no unknown fields.
|
703
|
-
char* data1
|
704
|
-
char* data2
|
705
|
-
|
706
|
-
|
702
|
+
char* data1;
|
703
|
+
char* data2;
|
704
|
+
upb_EncodeStatus status1 =
|
705
|
+
upb_Encode(m1, layout, encode_opts, arena_tmp, &data1, &size1);
|
706
|
+
upb_EncodeStatus status2 =
|
707
|
+
upb_Encode(m2, layout, encode_opts, arena_tmp, &data2, &size2);
|
708
|
+
|
709
|
+
if (status1 == kUpb_EncodeStatus_Ok && status2 == kUpb_EncodeStatus_Ok) {
|
707
710
|
bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0);
|
708
711
|
upb_Arena_Free(arena_tmp);
|
709
712
|
return ret;
|
@@ -735,15 +738,16 @@ static VALUE Message_eq(VALUE _self, VALUE _other) {
|
|
735
738
|
uint64_t Message_Hash(const upb_Message* msg, const upb_MessageDef* m,
|
736
739
|
uint64_t seed) {
|
737
740
|
upb_Arena* arena = upb_Arena_New();
|
738
|
-
|
741
|
+
char* data;
|
739
742
|
size_t size;
|
740
743
|
|
741
744
|
// Hash a deterministically serialized payloads with no unknown fields.
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
+
upb_EncodeStatus status = upb_Encode(
|
746
|
+
msg, upb_MessageDef_MiniTable(m),
|
747
|
+
kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic, arena,
|
748
|
+
&data, &size);
|
745
749
|
|
746
|
-
if (
|
750
|
+
if (status == kUpb_EncodeStatus_Ok) {
|
747
751
|
uint64_t ret = _upb_Hash(data, size, seed);
|
748
752
|
upb_Arena_Free(arena);
|
749
753
|
return ret;
|
@@ -823,7 +827,8 @@ static VALUE Message_CreateHash(const upb_Message* msg,
|
|
823
827
|
VALUE msg_key;
|
824
828
|
|
825
829
|
if (!is_proto2 && upb_FieldDef_IsSubMessage(field) &&
|
826
|
-
!upb_FieldDef_IsRepeated(field) &&
|
830
|
+
!upb_FieldDef_IsRepeated(field) &&
|
831
|
+
!upb_Message_HasFieldByDef(msg, field)) {
|
827
832
|
// TODO: Legacy behavior, remove when we fix the is_proto2 differences.
|
828
833
|
msg_key = ID2SYM(rb_intern(upb_FieldDef_Name(field)));
|
829
834
|
rb_hash_aset(hash, msg_key, Qnil);
|
@@ -832,12 +837,12 @@ static VALUE Message_CreateHash(const upb_Message* msg,
|
|
832
837
|
|
833
838
|
// Do not include fields that are not present (oneof or optional fields).
|
834
839
|
if (is_proto2 && upb_FieldDef_HasPresence(field) &&
|
835
|
-
!
|
840
|
+
!upb_Message_HasFieldByDef(msg, field)) {
|
836
841
|
continue;
|
837
842
|
}
|
838
843
|
|
839
844
|
msg_key = ID2SYM(rb_intern(upb_FieldDef_Name(field)));
|
840
|
-
msgval =
|
845
|
+
msgval = upb_Message_GetFieldByDef(msg, field);
|
841
846
|
|
842
847
|
// Proto2 omits empty map/repeated filds also.
|
843
848
|
|
@@ -940,7 +945,7 @@ static VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value) {
|
|
940
945
|
}
|
941
946
|
|
942
947
|
val = Convert_RubyToUpb(value, upb_FieldDef_Name(f), TypeInfo_get(f), arena);
|
943
|
-
|
948
|
+
upb_Message_SetFieldByDef(Message_GetMutable(_self, NULL), f, val, arena);
|
944
949
|
|
945
950
|
return Qnil;
|
946
951
|
}
|
@@ -969,7 +974,8 @@ static VALUE Message_decode(int argc, VALUE* argv, VALUE klass) {
|
|
969
974
|
rb_raise(rb_eArgError, "Expected hash arguments.");
|
970
975
|
}
|
971
976
|
|
972
|
-
VALUE depth =
|
977
|
+
VALUE depth =
|
978
|
+
rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit")));
|
973
979
|
|
974
980
|
if (depth != Qnil && TYPE(depth) == T_FIXNUM) {
|
975
981
|
options |= UPB_DECODE_MAXDEPTH(FIX2INT(depth));
|
@@ -983,9 +989,10 @@ static VALUE Message_decode(int argc, VALUE* argv, VALUE klass) {
|
|
983
989
|
VALUE msg_rb = initialize_rb_class_with_no_args(klass);
|
984
990
|
Message* msg = ruby_to_Message(msg_rb);
|
985
991
|
|
986
|
-
upb_DecodeStatus status =
|
987
|
-
RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg,
|
988
|
-
|
992
|
+
upb_DecodeStatus status =
|
993
|
+
upb_Decode(RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg,
|
994
|
+
upb_MessageDef_MiniTable(msg->msgdef), NULL, options,
|
995
|
+
Arena_get(msg->arena));
|
989
996
|
|
990
997
|
if (status != kUpb_DecodeStatus_Ok) {
|
991
998
|
rb_raise(cParseError, "Error occurred during parsing");
|
@@ -1069,7 +1076,7 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
|
|
1069
1076
|
static VALUE Message_encode(int argc, VALUE* argv, VALUE klass) {
|
1070
1077
|
Message* msg = ruby_to_Message(argv[0]);
|
1071
1078
|
int options = 0;
|
1072
|
-
|
1079
|
+
char* data;
|
1073
1080
|
size_t size;
|
1074
1081
|
|
1075
1082
|
if (CLASS_OF(argv[0]) != klass) {
|
@@ -1085,19 +1092,21 @@ static VALUE Message_encode(int argc, VALUE* argv, VALUE klass) {
|
|
1085
1092
|
if (TYPE(hash_args) != T_HASH) {
|
1086
1093
|
rb_raise(rb_eArgError, "Expected hash arguments.");
|
1087
1094
|
}
|
1088
|
-
VALUE depth =
|
1095
|
+
VALUE depth =
|
1096
|
+
rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit")));
|
1089
1097
|
|
1090
1098
|
if (depth != Qnil && TYPE(depth) == T_FIXNUM) {
|
1091
1099
|
options |= UPB_DECODE_MAXDEPTH(FIX2INT(depth));
|
1092
1100
|
}
|
1093
1101
|
}
|
1094
1102
|
|
1095
|
-
upb_Arena
|
1103
|
+
upb_Arena* arena = upb_Arena_New();
|
1096
1104
|
|
1097
|
-
|
1098
|
-
|
1105
|
+
upb_EncodeStatus status =
|
1106
|
+
upb_Encode(msg->msg, upb_MessageDef_MiniTable(msg->msgdef), options,
|
1107
|
+
arena, &data, &size);
|
1099
1108
|
|
1100
|
-
if (
|
1109
|
+
if (status == kUpb_EncodeStatus_Ok) {
|
1101
1110
|
VALUE ret = rb_str_new(data, size);
|
1102
1111
|
rb_enc_associate(ret, rb_ascii8bit_encoding());
|
1103
1112
|
upb_Arena_Free(arena);
|
@@ -1135,7 +1144,8 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
|
|
1135
1144
|
if (argc == 2) {
|
1136
1145
|
VALUE hash_args = argv[1];
|
1137
1146
|
if (TYPE(hash_args) != T_HASH) {
|
1138
|
-
if (RTEST(rb_funcall(hash_args, rb_intern("respond_to?"), 1,
|
1147
|
+
if (RTEST(rb_funcall(hash_args, rb_intern("respond_to?"), 1,
|
1148
|
+
rb_str_new2("to_h")))) {
|
1139
1149
|
hash_args = rb_funcall(hash_args, rb_intern("to_h"), 0);
|
1140
1150
|
} else {
|
1141
1151
|
rb_raise(rb_eArgError, "Expected hash arguments.");
|
@@ -1201,36 +1211,8 @@ VALUE build_class_from_descriptor(VALUE descriptor) {
|
|
1201
1211
|
klass = rb_define_class_id(
|
1202
1212
|
// Docs say this parameter is ignored. User will assign return value to
|
1203
1213
|
// their own toplevel constant class name.
|
1204
|
-
rb_intern("Message"),
|
1214
|
+
rb_intern("Message"), cAbstractMessage);
|
1205
1215
|
rb_ivar_set(klass, descriptor_instancevar_interned, descriptor);
|
1206
|
-
rb_define_alloc_func(klass, Message_alloc);
|
1207
|
-
rb_require("google/protobuf/message_exts");
|
1208
|
-
rb_include_module(klass, rb_eval_string("::Google::Protobuf::MessageExts"));
|
1209
|
-
rb_extend_object(
|
1210
|
-
klass, rb_eval_string("::Google::Protobuf::MessageExts::ClassMethods"));
|
1211
|
-
|
1212
|
-
rb_define_method(klass, "method_missing", Message_method_missing, -1);
|
1213
|
-
rb_define_method(klass, "respond_to_missing?", Message_respond_to_missing,
|
1214
|
-
-1);
|
1215
|
-
rb_define_method(klass, "initialize", Message_initialize, -1);
|
1216
|
-
rb_define_method(klass, "dup", Message_dup, 0);
|
1217
|
-
// Also define #clone so that we don't inherit Object#clone.
|
1218
|
-
rb_define_method(klass, "clone", Message_dup, 0);
|
1219
|
-
rb_define_method(klass, "==", Message_eq, 1);
|
1220
|
-
rb_define_method(klass, "eql?", Message_eq, 1);
|
1221
|
-
rb_define_method(klass, "freeze", Message_freeze, 0);
|
1222
|
-
rb_define_method(klass, "hash", Message_hash, 0);
|
1223
|
-
rb_define_method(klass, "to_h", Message_to_h, 0);
|
1224
|
-
rb_define_method(klass, "inspect", Message_inspect, 0);
|
1225
|
-
rb_define_method(klass, "to_s", Message_inspect, 0);
|
1226
|
-
rb_define_method(klass, "[]", Message_index, 1);
|
1227
|
-
rb_define_method(klass, "[]=", Message_index_set, 2);
|
1228
|
-
rb_define_singleton_method(klass, "decode", Message_decode, -1);
|
1229
|
-
rb_define_singleton_method(klass, "encode", Message_encode, -1);
|
1230
|
-
rb_define_singleton_method(klass, "decode_json", Message_decode_json, -1);
|
1231
|
-
rb_define_singleton_method(klass, "encode_json", Message_encode_json, -1);
|
1232
|
-
rb_define_singleton_method(klass, "descriptor", Message_descriptor, 0);
|
1233
|
-
|
1234
1216
|
return klass;
|
1235
1217
|
}
|
1236
1218
|
|
@@ -1296,12 +1278,12 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) {
|
|
1296
1278
|
int32_t value = upb_EnumValueDef_Number(ev);
|
1297
1279
|
if (name[0] < 'A' || name[0] > 'Z') {
|
1298
1280
|
if (name[0] >= 'a' && name[0] <= 'z') {
|
1299
|
-
name[0] -= 32;
|
1281
|
+
name[0] -= 32; // auto capitalize
|
1300
1282
|
} else {
|
1301
1283
|
rb_warn(
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1284
|
+
"Enum value '%s' does not start with an uppercase letter "
|
1285
|
+
"as is required for Ruby constants.",
|
1286
|
+
name);
|
1305
1287
|
}
|
1306
1288
|
}
|
1307
1289
|
rb_define_const(mod, name, INT2NUM(value));
|
@@ -1316,7 +1298,7 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) {
|
|
1316
1298
|
return mod;
|
1317
1299
|
}
|
1318
1300
|
|
1319
|
-
// Internal
|
1301
|
+
// Internal to the library; used by Google::Protobuf.deep_copy.
|
1320
1302
|
upb_Message* Message_deep_copy(const upb_Message* msg, const upb_MessageDef* m,
|
1321
1303
|
upb_Arena* arena) {
|
1322
1304
|
// Serialize and parse.
|
@@ -1324,11 +1306,13 @@ upb_Message* Message_deep_copy(const upb_Message* msg, const upb_MessageDef* m,
|
|
1324
1306
|
const upb_MiniTable* layout = upb_MessageDef_MiniTable(m);
|
1325
1307
|
size_t size;
|
1326
1308
|
|
1327
|
-
|
1328
|
-
|
1309
|
+
upb_Message* new_msg = upb_Message_New(layout, arena);
|
1310
|
+
char* data;
|
1329
1311
|
|
1330
|
-
if (
|
1331
|
-
|
1312
|
+
if (upb_Encode(msg, layout, 0, tmp_arena, &data, &size) !=
|
1313
|
+
kUpb_EncodeStatus_Ok ||
|
1314
|
+
upb_Decode(data, size, new_msg, layout, NULL, 0, arena) !=
|
1315
|
+
kUpb_DecodeStatus_Ok) {
|
1332
1316
|
upb_Arena_Free(tmp_arena);
|
1333
1317
|
rb_raise(cParseError, "Error occurred copying proto");
|
1334
1318
|
}
|
@@ -1355,7 +1339,8 @@ const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m,
|
|
1355
1339
|
switch (upb_MessageDef_WellKnownType(m)) {
|
1356
1340
|
case kUpb_WellKnown_Timestamp: {
|
1357
1341
|
// Time -> Google::Protobuf::Timestamp
|
1358
|
-
|
1342
|
+
const upb_MiniTable* t = upb_MessageDef_MiniTable(m);
|
1343
|
+
upb_Message* msg = upb_Message_New(t, arena);
|
1359
1344
|
upb_MessageValue sec, nsec;
|
1360
1345
|
struct timespec time;
|
1361
1346
|
const upb_FieldDef* sec_f = upb_MessageDef_FindFieldByNumber(m, 1);
|
@@ -1366,13 +1351,14 @@ const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m,
|
|
1366
1351
|
time = rb_time_timespec(value);
|
1367
1352
|
sec.int64_val = time.tv_sec;
|
1368
1353
|
nsec.int32_val = time.tv_nsec;
|
1369
|
-
|
1370
|
-
|
1354
|
+
upb_Message_SetFieldByDef(msg, sec_f, sec, arena);
|
1355
|
+
upb_Message_SetFieldByDef(msg, nsec_f, nsec, arena);
|
1371
1356
|
return msg;
|
1372
1357
|
}
|
1373
1358
|
case kUpb_WellKnown_Duration: {
|
1374
1359
|
// Numeric -> Google::Protobuf::Duration
|
1375
|
-
|
1360
|
+
const upb_MiniTable* t = upb_MessageDef_MiniTable(m);
|
1361
|
+
upb_Message* msg = upb_Message_New(t, arena);
|
1376
1362
|
upb_MessageValue sec, nsec;
|
1377
1363
|
const upb_FieldDef* sec_f = upb_MessageDef_FindFieldByNumber(m, 1);
|
1378
1364
|
const upb_FieldDef* nsec_f = upb_MessageDef_FindFieldByNumber(m, 2);
|
@@ -1381,8 +1367,8 @@ const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m,
|
|
1381
1367
|
|
1382
1368
|
sec.int64_val = NUM2LL(value);
|
1383
1369
|
nsec.int32_val = round((NUM2DBL(value) - NUM2LL(value)) * 1000000000);
|
1384
|
-
|
1385
|
-
|
1370
|
+
upb_Message_SetFieldByDef(msg, sec_f, sec, arena);
|
1371
|
+
upb_Message_SetFieldByDef(msg, nsec_f, nsec, arena);
|
1386
1372
|
return msg;
|
1387
1373
|
}
|
1388
1374
|
default:
|
@@ -1399,11 +1385,42 @@ const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m,
|
|
1399
1385
|
return self->msg;
|
1400
1386
|
}
|
1401
1387
|
|
1388
|
+
static void Message_define_class(VALUE klass) {
|
1389
|
+
rb_define_alloc_func(klass, Message_alloc);
|
1390
|
+
|
1391
|
+
rb_require("google/protobuf/message_exts");
|
1392
|
+
rb_define_method(klass, "method_missing", Message_method_missing, -1);
|
1393
|
+
rb_define_method(klass, "respond_to_missing?", Message_respond_to_missing,
|
1394
|
+
-1);
|
1395
|
+
rb_define_method(klass, "initialize", Message_initialize, -1);
|
1396
|
+
rb_define_method(klass, "dup", Message_dup, 0);
|
1397
|
+
// Also define #clone so that we don't inherit Object#clone.
|
1398
|
+
rb_define_method(klass, "clone", Message_dup, 0);
|
1399
|
+
rb_define_method(klass, "==", Message_eq, 1);
|
1400
|
+
rb_define_method(klass, "eql?", Message_eq, 1);
|
1401
|
+
rb_define_method(klass, "freeze", Message_freeze, 0);
|
1402
|
+
rb_define_method(klass, "hash", Message_hash, 0);
|
1403
|
+
rb_define_method(klass, "to_h", Message_to_h, 0);
|
1404
|
+
rb_define_method(klass, "inspect", Message_inspect, 0);
|
1405
|
+
rb_define_method(klass, "to_s", Message_inspect, 0);
|
1406
|
+
rb_define_method(klass, "[]", Message_index, 1);
|
1407
|
+
rb_define_method(klass, "[]=", Message_index_set, 2);
|
1408
|
+
rb_define_singleton_method(klass, "decode", Message_decode, -1);
|
1409
|
+
rb_define_singleton_method(klass, "encode", Message_encode, -1);
|
1410
|
+
rb_define_singleton_method(klass, "decode_json", Message_decode_json, -1);
|
1411
|
+
rb_define_singleton_method(klass, "encode_json", Message_encode_json, -1);
|
1412
|
+
rb_define_singleton_method(klass, "descriptor", Message_descriptor, 0);
|
1413
|
+
}
|
1414
|
+
|
1402
1415
|
void Message_register(VALUE protobuf) {
|
1403
1416
|
cParseError = rb_const_get(protobuf, rb_intern("ParseError"));
|
1417
|
+
cAbstractMessage =
|
1418
|
+
rb_define_class_under(protobuf, "AbstractMessage", rb_cObject);
|
1419
|
+
Message_define_class(cAbstractMessage);
|
1420
|
+
rb_gc_register_address(&cAbstractMessage);
|
1404
1421
|
|
1405
1422
|
// Ruby-interned string: "descriptor". We use this identifier to store an
|
1406
1423
|
// instance variable on message classes we create in order to link them back
|
1407
1424
|
// to their descriptors.
|
1408
|
-
descriptor_instancevar_interned = rb_intern("descriptor");
|
1425
|
+
descriptor_instancevar_interned = rb_intern("@descriptor");
|
1409
1426
|
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|