google-protobuf 3.21.12-x86_64-linux → 3.22.0.rc.2-x86_64-linux

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.

Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/ext/google/protobuf_c/convert.c +0 -0
  3. data/ext/google/protobuf_c/convert.h +0 -0
  4. data/ext/google/protobuf_c/defs.c +3 -3
  5. data/ext/google/protobuf_c/defs.h +0 -0
  6. data/ext/google/protobuf_c/extconf.rb +2 -2
  7. data/ext/google/protobuf_c/map.c +27 -42
  8. data/ext/google/protobuf_c/map.h +0 -0
  9. data/ext/google/protobuf_c/message.c +112 -86
  10. data/ext/google/protobuf_c/message.h +0 -0
  11. data/ext/google/protobuf_c/protobuf.c +0 -0
  12. data/ext/google/protobuf_c/protobuf.h +0 -0
  13. data/ext/google/protobuf_c/repeated_field.c +0 -0
  14. data/ext/google/protobuf_c/repeated_field.h +0 -0
  15. data/ext/google/protobuf_c/ruby-upb.c +11144 -9889
  16. data/ext/google/protobuf_c/ruby-upb.h +9285 -4982
  17. data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +1 -0
  18. data/ext/google/protobuf_c/third_party/utf8_range/naive.c +0 -0
  19. data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +1 -1
  20. data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +0 -0
  21. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +13 -1
  22. data/ext/google/protobuf_c/wrap_memcpy.c +0 -0
  23. data/lib/google/2.6/protobuf_c.so +0 -0
  24. data/lib/google/2.7/protobuf_c.so +0 -0
  25. data/lib/google/3.0/protobuf_c.so +0 -0
  26. data/lib/google/3.1/protobuf_c.so +0 -0
  27. data/lib/google/3.2/protobuf_c.so +0 -0
  28. data/lib/google/protobuf/any_pb.rb +0 -0
  29. data/lib/google/protobuf/api_pb.rb +0 -0
  30. data/lib/google/protobuf/descriptor_dsl.rb +0 -0
  31. data/lib/google/protobuf/descriptor_pb.rb +41 -12
  32. data/lib/google/protobuf/duration_pb.rb +0 -0
  33. data/lib/google/protobuf/empty_pb.rb +0 -0
  34. data/lib/google/protobuf/field_mask_pb.rb +0 -0
  35. data/lib/google/protobuf/message_exts.rb +5 -0
  36. data/lib/google/protobuf/plugin_pb.rb +50 -0
  37. data/lib/google/protobuf/repeated_field.rb +0 -0
  38. data/lib/google/protobuf/source_context_pb.rb +0 -0
  39. data/lib/google/protobuf/struct_pb.rb +0 -0
  40. data/lib/google/protobuf/timestamp_pb.rb +0 -0
  41. data/lib/google/protobuf/type_pb.rb +0 -0
  42. data/lib/google/protobuf/wrappers_pb.rb +0 -0
  43. data/lib/google/protobuf.rb +0 -0
  44. metadata +14 -19
  45. data/lib/google/2.5/protobuf_c.so +0 -0
  46. data/tests/basic.rb +0 -739
  47. data/tests/generated_code_test.rb +0 -23
  48. 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) && !upb_Message_Has(msg, 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 = upb_Message_Get(msg, field);
160
+ upb_MessageValue msgval = upb_Message_GetFieldByDef(msg, field);
159
161
 
160
162
  StringBuilder_Printf(b, "%s: ", upb_FieldDef_Name(field));
161
163
 
@@ -278,7 +280,8 @@ static VALUE Message_oneof_accessor(VALUE _self, const upb_OneofDef* o,
278
280
  return oneof_field == NULL ? Qfalse : Qtrue;
279
281
  case METHOD_CLEAR:
280
282
  if (oneof_field != NULL) {
281
- upb_Message_ClearField(Message_GetMutable(_self, NULL), oneof_field);
283
+ upb_Message_ClearFieldByDef(Message_GetMutable(_self, NULL),
284
+ oneof_field);
282
285
  }
283
286
  return Qnil;
284
287
  case METHOD_GETTER:
@@ -301,13 +304,13 @@ static void Message_setfield(upb_Message* msg, const upb_FieldDef* f, VALUE val,
301
304
  } else {
302
305
  if (val == Qnil &&
303
306
  (upb_FieldDef_IsSubMessage(f) || upb_FieldDef_RealContainingOneof(f))) {
304
- upb_Message_ClearField(msg, f);
307
+ upb_Message_ClearFieldByDef(msg, f);
305
308
  return;
306
309
  }
307
310
  msgval =
308
311
  Convert_RubyToUpb(val, upb_FieldDef_Name(f), TypeInfo_get(f), arena);
309
312
  }
310
- upb_Message_Set(msg, f, msgval, arena);
313
+ upb_Message_SetFieldByDef(msg, f, msgval, arena);
311
314
  }
312
315
 
313
316
  VALUE Message_getfield(VALUE _self, const upb_FieldDef* f) {
@@ -329,12 +332,12 @@ VALUE Message_getfield(VALUE _self, const upb_FieldDef* f) {
329
332
  upb_Array* arr = upb_Message_Mutable(msg, f, arena).array;
330
333
  return RepeatedField_GetRubyWrapper(arr, TypeInfo_get(f), self->arena);
331
334
  } else if (upb_FieldDef_IsSubMessage(f)) {
332
- if (!upb_Message_Has(self->msg, f)) return Qnil;
335
+ if (!upb_Message_HasFieldByDef(self->msg, f)) return Qnil;
333
336
  upb_Message* submsg = upb_Message_Mutable(msg, f, arena).msg;
334
337
  const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f);
335
338
  return Message_GetRubyWrapper(submsg, m, self->arena);
336
339
  } else {
337
- upb_MessageValue msgval = upb_Message_Get(self->msg, f);
340
+ upb_MessageValue msgval = upb_Message_GetFieldByDef(self->msg, f);
338
341
  return Convert_UpbToRuby(msgval, TypeInfo_get(f), self->arena);
339
342
  }
340
343
  }
@@ -348,23 +351,24 @@ static VALUE Message_field_accessor(VALUE _self, const upb_FieldDef* f,
348
351
  Message_setfield(Message_GetMutable(_self, NULL), f, argv[1], arena);
349
352
  return Qnil;
350
353
  case METHOD_CLEAR:
351
- upb_Message_ClearField(Message_GetMutable(_self, NULL), f);
354
+ upb_Message_ClearFieldByDef(Message_GetMutable(_self, NULL), f);
352
355
  return Qnil;
353
356
  case METHOD_PRESENCE:
354
357
  if (!upb_FieldDef_HasPresence(f)) {
355
358
  rb_raise(rb_eRuntimeError, "Field does not have presence.");
356
359
  }
357
- return upb_Message_Has(Message_Get(_self, NULL), f);
360
+ return upb_Message_HasFieldByDef(Message_Get(_self, NULL), f);
358
361
  case METHOD_WRAPPER_GETTER: {
359
362
  Message* self = ruby_to_Message(_self);
360
- if (upb_Message_Has(self->msg, f)) {
363
+ if (upb_Message_HasFieldByDef(self->msg, f)) {
361
364
  PBRUBY_ASSERT(upb_FieldDef_IsSubMessage(f) &&
362
365
  !upb_FieldDef_IsRepeated(f));
363
- upb_MessageValue wrapper = upb_Message_Get(self->msg, f);
366
+ upb_MessageValue wrapper = upb_Message_GetFieldByDef(self->msg, f);
364
367
  const upb_MessageDef* wrapper_m = upb_FieldDef_MessageSubDef(f);
365
368
  const upb_FieldDef* value_f =
366
369
  upb_MessageDef_FindFieldByNumber(wrapper_m, 1);
367
- upb_MessageValue value = upb_Message_Get(wrapper.msg_val, value_f);
370
+ upb_MessageValue value =
371
+ upb_Message_GetFieldByDef(wrapper.msg_val, value_f);
368
372
  return Convert_UpbToRuby(value, TypeInfo_get(value_f), self->arena);
369
373
  } else {
370
374
  return Qnil;
@@ -373,19 +377,20 @@ static VALUE Message_field_accessor(VALUE _self, const upb_FieldDef* f,
373
377
  case METHOD_WRAPPER_SETTER: {
374
378
  upb_Message* msg = Message_GetMutable(_self, NULL);
375
379
  if (argv[1] == Qnil) {
376
- upb_Message_ClearField(msg, f);
380
+ upb_Message_ClearFieldByDef(msg, f);
377
381
  } else {
378
382
  const upb_FieldDef* val_f =
379
383
  upb_MessageDef_FindFieldByNumber(upb_FieldDef_MessageSubDef(f), 1);
380
384
  upb_MessageValue msgval = Convert_RubyToUpb(
381
385
  argv[1], upb_FieldDef_Name(f), TypeInfo_get(val_f), arena);
382
386
  upb_Message* wrapper = upb_Message_Mutable(msg, f, arena).msg;
383
- upb_Message_Set(wrapper, val_f, msgval, arena);
387
+ upb_Message_SetFieldByDef(wrapper, val_f, msgval, arena);
384
388
  }
385
389
  return Qnil;
386
390
  }
387
391
  case METHOD_ENUM_GETTER: {
388
- upb_MessageValue msgval = upb_Message_Get(Message_Get(_self, NULL), f);
392
+ upb_MessageValue msgval =
393
+ upb_Message_GetFieldByDef(Message_Get(_self, NULL), f);
389
394
 
390
395
  if (upb_FieldDef_Label(f) == kUpb_Label_Repeated) {
391
396
  // Map repeated fields to a new type with ints
@@ -510,8 +515,8 @@ static int Map_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
510
515
  k = Convert_RubyToUpb(key, "", map_init->key_type, NULL);
511
516
 
512
517
  if (map_init->val_type.type == kUpb_CType_Message && TYPE(val) == T_HASH) {
513
- upb_Message* msg =
514
- upb_Message_New(map_init->val_type.def.msgdef, map_init->arena);
518
+ upb_MiniTable* t = upb_MessageDef_MiniTable(map_init->val_type.def.msgdef);
519
+ upb_Message* msg = upb_Message_New(t, map_init->arena);
515
520
  Message_InitFromValue(msg, map_init->val_type.def.msgdef, val,
516
521
  map_init->arena);
517
522
  v.msg_val = msg;
@@ -541,7 +546,8 @@ static upb_MessageValue MessageValue_FromValue(VALUE val, TypeInfo info,
541
546
  upb_Arena* arena) {
542
547
  if (info.type == kUpb_CType_Message) {
543
548
  upb_MessageValue msgval;
544
- upb_Message* msg = upb_Message_New(info.def.msgdef, arena);
549
+ upb_MiniTable* t = upb_MessageDef_MiniTable(info.def.msgdef);
550
+ upb_Message* msg = upb_Message_New(t, arena);
545
551
  Message_InitFromValue(msg, info.def.msgdef, val, arena);
546
552
  msgval.msg_val = msg;
547
553
  return msgval;
@@ -593,7 +599,7 @@ static void Message_InitFieldFromValue(upb_Message* msg, const upb_FieldDef* f,
593
599
  } else {
594
600
  upb_MessageValue msgval =
595
601
  Convert_RubyToUpb(val, upb_FieldDef_Name(f), TypeInfo_get(f), arena);
596
- upb_Message_Set(msg, f, msgval, arena);
602
+ upb_Message_SetFieldByDef(msg, f, msgval, arena);
597
603
  }
598
604
  }
599
605
 
@@ -656,7 +662,8 @@ static VALUE Message_initialize(int argc, VALUE* argv, VALUE _self) {
656
662
  Message* self = ruby_to_Message(_self);
657
663
  VALUE arena_rb = Arena_new();
658
664
  upb_Arena* arena = Arena_get(arena_rb);
659
- upb_Message* msg = upb_Message_New(self->msgdef, arena);
665
+ upb_MiniTable* t = upb_MessageDef_MiniTable(self->msgdef);
666
+ upb_Message* msg = upb_Message_New(t, arena);
660
667
 
661
668
  Message_InitPtr(_self, msg, arena_rb);
662
669
 
@@ -695,15 +702,20 @@ bool Message_Equal(const upb_Message* m1, const upb_Message* m2,
695
702
  if (m1 == m2) return true;
696
703
 
697
704
  size_t size1, size2;
698
- int encode_opts = kUpb_Encode_SkipUnknown | kUpb_Encode_Deterministic;
705
+ int encode_opts =
706
+ kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic;
699
707
  upb_Arena* arena_tmp = upb_Arena_New();
700
708
  const upb_MiniTable* layout = upb_MessageDef_MiniTable(m);
701
709
 
702
710
  // Compare deterministically serialized payloads with no unknown fields.
703
- char* data1 = upb_Encode(m1, layout, encode_opts, arena_tmp, &size1);
704
- char* data2 = upb_Encode(m2, layout, encode_opts, arena_tmp, &size2);
705
-
706
- if (data1 && data2) {
711
+ char* data1;
712
+ char* data2;
713
+ upb_EncodeStatus status1 =
714
+ upb_Encode(m1, layout, encode_opts, arena_tmp, &data1, &size1);
715
+ upb_EncodeStatus status2 =
716
+ upb_Encode(m2, layout, encode_opts, arena_tmp, &data2, &size2);
717
+
718
+ if (status1 == kUpb_EncodeStatus_Ok && status2 == kUpb_EncodeStatus_Ok) {
707
719
  bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0);
708
720
  upb_Arena_Free(arena_tmp);
709
721
  return ret;
@@ -735,15 +747,16 @@ static VALUE Message_eq(VALUE _self, VALUE _other) {
735
747
  uint64_t Message_Hash(const upb_Message* msg, const upb_MessageDef* m,
736
748
  uint64_t seed) {
737
749
  upb_Arena* arena = upb_Arena_New();
738
- const char* data;
750
+ char* data;
739
751
  size_t size;
740
752
 
741
753
  // Hash a deterministically serialized payloads with no unknown fields.
742
- data = upb_Encode(msg, upb_MessageDef_MiniTable(m),
743
- kUpb_Encode_SkipUnknown | kUpb_Encode_Deterministic, arena,
744
- &size);
754
+ upb_EncodeStatus status = upb_Encode(
755
+ msg, upb_MessageDef_MiniTable(m),
756
+ kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic, arena,
757
+ &data, &size);
745
758
 
746
- if (data) {
759
+ if (status == kUpb_EncodeStatus_Ok) {
747
760
  uint64_t ret = _upb_Hash(data, size, seed);
748
761
  upb_Arena_Free(arena);
749
762
  return ret;
@@ -823,7 +836,8 @@ static VALUE Message_CreateHash(const upb_Message* msg,
823
836
  VALUE msg_key;
824
837
 
825
838
  if (!is_proto2 && upb_FieldDef_IsSubMessage(field) &&
826
- !upb_FieldDef_IsRepeated(field) && !upb_Message_Has(msg, field)) {
839
+ !upb_FieldDef_IsRepeated(field) &&
840
+ !upb_Message_HasFieldByDef(msg, field)) {
827
841
  // TODO: Legacy behavior, remove when we fix the is_proto2 differences.
828
842
  msg_key = ID2SYM(rb_intern(upb_FieldDef_Name(field)));
829
843
  rb_hash_aset(hash, msg_key, Qnil);
@@ -832,12 +846,12 @@ static VALUE Message_CreateHash(const upb_Message* msg,
832
846
 
833
847
  // Do not include fields that are not present (oneof or optional fields).
834
848
  if (is_proto2 && upb_FieldDef_HasPresence(field) &&
835
- !upb_Message_Has(msg, field)) {
849
+ !upb_Message_HasFieldByDef(msg, field)) {
836
850
  continue;
837
851
  }
838
852
 
839
853
  msg_key = ID2SYM(rb_intern(upb_FieldDef_Name(field)));
840
- msgval = upb_Message_Get(msg, field);
854
+ msgval = upb_Message_GetFieldByDef(msg, field);
841
855
 
842
856
  // Proto2 omits empty map/repeated filds also.
843
857
 
@@ -940,7 +954,7 @@ static VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value) {
940
954
  }
941
955
 
942
956
  val = Convert_RubyToUpb(value, upb_FieldDef_Name(f), TypeInfo_get(f), arena);
943
- upb_Message_Set(Message_GetMutable(_self, NULL), f, val, arena);
957
+ upb_Message_SetFieldByDef(Message_GetMutable(_self, NULL), f, val, arena);
944
958
 
945
959
  return Qnil;
946
960
  }
@@ -969,7 +983,8 @@ static VALUE Message_decode(int argc, VALUE* argv, VALUE klass) {
969
983
  rb_raise(rb_eArgError, "Expected hash arguments.");
970
984
  }
971
985
 
972
- VALUE depth = rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit")));
986
+ VALUE depth =
987
+ rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit")));
973
988
 
974
989
  if (depth != Qnil && TYPE(depth) == T_FIXNUM) {
975
990
  options |= UPB_DECODE_MAXDEPTH(FIX2INT(depth));
@@ -983,9 +998,10 @@ static VALUE Message_decode(int argc, VALUE* argv, VALUE klass) {
983
998
  VALUE msg_rb = initialize_rb_class_with_no_args(klass);
984
999
  Message* msg = ruby_to_Message(msg_rb);
985
1000
 
986
- upb_DecodeStatus status = upb_Decode(
987
- RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg,
988
- upb_MessageDef_MiniTable(msg->msgdef), NULL, options, Arena_get(msg->arena));
1001
+ upb_DecodeStatus status =
1002
+ upb_Decode(RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg,
1003
+ upb_MessageDef_MiniTable(msg->msgdef), NULL, options,
1004
+ Arena_get(msg->arena));
989
1005
 
990
1006
  if (status != kUpb_DecodeStatus_Ok) {
991
1007
  rb_raise(cParseError, "Error occurred during parsing");
@@ -1069,7 +1085,7 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
1069
1085
  static VALUE Message_encode(int argc, VALUE* argv, VALUE klass) {
1070
1086
  Message* msg = ruby_to_Message(argv[0]);
1071
1087
  int options = 0;
1072
- const char* data;
1088
+ char* data;
1073
1089
  size_t size;
1074
1090
 
1075
1091
  if (CLASS_OF(argv[0]) != klass) {
@@ -1085,19 +1101,21 @@ static VALUE Message_encode(int argc, VALUE* argv, VALUE klass) {
1085
1101
  if (TYPE(hash_args) != T_HASH) {
1086
1102
  rb_raise(rb_eArgError, "Expected hash arguments.");
1087
1103
  }
1088
- VALUE depth = rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit")));
1104
+ VALUE depth =
1105
+ rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit")));
1089
1106
 
1090
1107
  if (depth != Qnil && TYPE(depth) == T_FIXNUM) {
1091
1108
  options |= UPB_DECODE_MAXDEPTH(FIX2INT(depth));
1092
1109
  }
1093
1110
  }
1094
1111
 
1095
- upb_Arena *arena = upb_Arena_New();
1112
+ upb_Arena* arena = upb_Arena_New();
1096
1113
 
1097
- data = upb_Encode(msg->msg, upb_MessageDef_MiniTable(msg->msgdef),
1098
- options, arena, &size);
1114
+ upb_EncodeStatus status =
1115
+ upb_Encode(msg->msg, upb_MessageDef_MiniTable(msg->msgdef), options,
1116
+ arena, &data, &size);
1099
1117
 
1100
- if (data) {
1118
+ if (status == kUpb_EncodeStatus_Ok) {
1101
1119
  VALUE ret = rb_str_new(data, size);
1102
1120
  rb_enc_associate(ret, rb_ascii8bit_encoding());
1103
1121
  upb_Arena_Free(arena);
@@ -1135,7 +1153,8 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
1135
1153
  if (argc == 2) {
1136
1154
  VALUE hash_args = argv[1];
1137
1155
  if (TYPE(hash_args) != T_HASH) {
1138
- if (RTEST(rb_funcall(hash_args, rb_intern("respond_to?"), 1, rb_str_new2("to_h")))) {
1156
+ if (RTEST(rb_funcall(hash_args, rb_intern("respond_to?"), 1,
1157
+ rb_str_new2("to_h")))) {
1139
1158
  hash_args = rb_funcall(hash_args, rb_intern("to_h"), 0);
1140
1159
  } else {
1141
1160
  rb_raise(rb_eArgError, "Expected hash arguments.");
@@ -1201,36 +1220,8 @@ VALUE build_class_from_descriptor(VALUE descriptor) {
1201
1220
  klass = rb_define_class_id(
1202
1221
  // Docs say this parameter is ignored. User will assign return value to
1203
1222
  // their own toplevel constant class name.
1204
- rb_intern("Message"), rb_cObject);
1223
+ rb_intern("Message"), cAbstractMessage);
1205
1224
  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
1225
  return klass;
1235
1226
  }
1236
1227
 
@@ -1316,7 +1307,7 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) {
1316
1307
  return mod;
1317
1308
  }
1318
1309
 
1319
- // Internal only; used by Google::Protobuf.deep_copy.
1310
+ // Internal to the library; used by Google::Protobuf.deep_copy.
1320
1311
  upb_Message* Message_deep_copy(const upb_Message* msg, const upb_MessageDef* m,
1321
1312
  upb_Arena* arena) {
1322
1313
  // Serialize and parse.
@@ -1324,11 +1315,13 @@ upb_Message* Message_deep_copy(const upb_Message* msg, const upb_MessageDef* m,
1324
1315
  const upb_MiniTable* layout = upb_MessageDef_MiniTable(m);
1325
1316
  size_t size;
1326
1317
 
1327
- char* data = upb_Encode(msg, layout, 0, tmp_arena, &size);
1328
- upb_Message* new_msg = upb_Message_New(m, arena);
1318
+ upb_Message* new_msg = upb_Message_New(layout, arena);
1319
+ char* data;
1329
1320
 
1330
- if (!data || upb_Decode(data, size, new_msg, layout, NULL, 0, arena) !=
1331
- kUpb_DecodeStatus_Ok) {
1321
+ if (upb_Encode(msg, layout, 0, tmp_arena, &data, &size) !=
1322
+ kUpb_EncodeStatus_Ok ||
1323
+ upb_Decode(data, size, new_msg, layout, NULL, 0, arena) !=
1324
+ kUpb_DecodeStatus_Ok) {
1332
1325
  upb_Arena_Free(tmp_arena);
1333
1326
  rb_raise(cParseError, "Error occurred copying proto");
1334
1327
  }
@@ -1355,7 +1348,8 @@ const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m,
1355
1348
  switch (upb_MessageDef_WellKnownType(m)) {
1356
1349
  case kUpb_WellKnown_Timestamp: {
1357
1350
  // Time -> Google::Protobuf::Timestamp
1358
- upb_Message* msg = upb_Message_New(m, arena);
1351
+ const upb_MiniTable* t = upb_MessageDef_MiniTable(m);
1352
+ upb_Message* msg = upb_Message_New(t, arena);
1359
1353
  upb_MessageValue sec, nsec;
1360
1354
  struct timespec time;
1361
1355
  const upb_FieldDef* sec_f = upb_MessageDef_FindFieldByNumber(m, 1);
@@ -1366,13 +1360,14 @@ const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m,
1366
1360
  time = rb_time_timespec(value);
1367
1361
  sec.int64_val = time.tv_sec;
1368
1362
  nsec.int32_val = time.tv_nsec;
1369
- upb_Message_Set(msg, sec_f, sec, arena);
1370
- upb_Message_Set(msg, nsec_f, nsec, arena);
1363
+ upb_Message_SetFieldByDef(msg, sec_f, sec, arena);
1364
+ upb_Message_SetFieldByDef(msg, nsec_f, nsec, arena);
1371
1365
  return msg;
1372
1366
  }
1373
1367
  case kUpb_WellKnown_Duration: {
1374
1368
  // Numeric -> Google::Protobuf::Duration
1375
- upb_Message* msg = upb_Message_New(m, arena);
1369
+ const upb_MiniTable* t = upb_MessageDef_MiniTable(m);
1370
+ upb_Message* msg = upb_Message_New(t, arena);
1376
1371
  upb_MessageValue sec, nsec;
1377
1372
  const upb_FieldDef* sec_f = upb_MessageDef_FindFieldByNumber(m, 1);
1378
1373
  const upb_FieldDef* nsec_f = upb_MessageDef_FindFieldByNumber(m, 2);
@@ -1381,8 +1376,8 @@ const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m,
1381
1376
 
1382
1377
  sec.int64_val = NUM2LL(value);
1383
1378
  nsec.int32_val = round((NUM2DBL(value) - NUM2LL(value)) * 1000000000);
1384
- upb_Message_Set(msg, sec_f, sec, arena);
1385
- upb_Message_Set(msg, nsec_f, nsec, arena);
1379
+ upb_Message_SetFieldByDef(msg, sec_f, sec, arena);
1380
+ upb_Message_SetFieldByDef(msg, nsec_f, nsec, arena);
1386
1381
  return msg;
1387
1382
  }
1388
1383
  default:
@@ -1399,11 +1394,42 @@ const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m,
1399
1394
  return self->msg;
1400
1395
  }
1401
1396
 
1397
+ static void Message_define_class(VALUE klass) {
1398
+ rb_define_alloc_func(klass, Message_alloc);
1399
+
1400
+ rb_require("google/protobuf/message_exts");
1401
+ rb_define_method(klass, "method_missing", Message_method_missing, -1);
1402
+ rb_define_method(klass, "respond_to_missing?", Message_respond_to_missing,
1403
+ -1);
1404
+ rb_define_method(klass, "initialize", Message_initialize, -1);
1405
+ rb_define_method(klass, "dup", Message_dup, 0);
1406
+ // Also define #clone so that we don't inherit Object#clone.
1407
+ rb_define_method(klass, "clone", Message_dup, 0);
1408
+ rb_define_method(klass, "==", Message_eq, 1);
1409
+ rb_define_method(klass, "eql?", Message_eq, 1);
1410
+ rb_define_method(klass, "freeze", Message_freeze, 0);
1411
+ rb_define_method(klass, "hash", Message_hash, 0);
1412
+ rb_define_method(klass, "to_h", Message_to_h, 0);
1413
+ rb_define_method(klass, "inspect", Message_inspect, 0);
1414
+ rb_define_method(klass, "to_s", Message_inspect, 0);
1415
+ rb_define_method(klass, "[]", Message_index, 1);
1416
+ rb_define_method(klass, "[]=", Message_index_set, 2);
1417
+ rb_define_singleton_method(klass, "decode", Message_decode, -1);
1418
+ rb_define_singleton_method(klass, "encode", Message_encode, -1);
1419
+ rb_define_singleton_method(klass, "decode_json", Message_decode_json, -1);
1420
+ rb_define_singleton_method(klass, "encode_json", Message_encode_json, -1);
1421
+ rb_define_singleton_method(klass, "descriptor", Message_descriptor, 0);
1422
+ }
1423
+
1402
1424
  void Message_register(VALUE protobuf) {
1403
1425
  cParseError = rb_const_get(protobuf, rb_intern("ParseError"));
1426
+ cAbstractMessage =
1427
+ rb_define_class_under(protobuf, "AbstractMessage", rb_cObject);
1428
+ Message_define_class(cAbstractMessage);
1429
+ rb_gc_register_address(&cAbstractMessage);
1404
1430
 
1405
1431
  // Ruby-interned string: "descriptor". We use this identifier to store an
1406
1432
  // instance variable on message classes we create in order to link them back
1407
1433
  // to their descriptors.
1408
- descriptor_instancevar_interned = rb_intern("descriptor");
1434
+ descriptor_instancevar_interned = rb_intern("@descriptor");
1409
1435
  }
File without changes
File without changes
File without changes
File without changes
File without changes