google-protobuf 3.23.3 → 4.27.1

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.

Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/ext/google/protobuf_c/Rakefile +3 -0
  3. data/ext/google/protobuf_c/convert.c +28 -72
  4. data/ext/google/protobuf_c/convert.h +3 -28
  5. data/ext/google/protobuf_c/defs.c +512 -60
  6. data/ext/google/protobuf_c/defs.h +3 -28
  7. data/ext/google/protobuf_c/extconf.rb +2 -1
  8. data/ext/google/protobuf_c/glue.c +72 -0
  9. data/ext/google/protobuf_c/map.c +28 -36
  10. data/ext/google/protobuf_c/map.h +6 -28
  11. data/ext/google/protobuf_c/message.c +88 -143
  12. data/ext/google/protobuf_c/message.h +10 -32
  13. data/ext/google/protobuf_c/protobuf.c +49 -175
  14. data/ext/google/protobuf_c/protobuf.h +24 -32
  15. data/ext/google/protobuf_c/repeated_field.c +23 -33
  16. data/ext/google/protobuf_c/repeated_field.h +6 -28
  17. data/ext/google/protobuf_c/ruby-upb.c +13046 -10690
  18. data/ext/google/protobuf_c/ruby-upb.h +8405 -5836
  19. data/ext/google/protobuf_c/shared_convert.c +69 -0
  20. data/ext/google/protobuf_c/shared_convert.h +26 -0
  21. data/ext/google/protobuf_c/shared_message.c +37 -0
  22. data/ext/google/protobuf_c/shared_message.h +21 -0
  23. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +467 -0
  24. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +9 -8
  25. data/ext/google/protobuf_c/wrap_memcpy.c +3 -26
  26. data/lib/google/protobuf/any_pb.rb +1 -22
  27. data/lib/google/protobuf/api_pb.rb +1 -24
  28. data/lib/google/protobuf/descriptor_pb.rb +14 -23
  29. data/lib/google/protobuf/duration_pb.rb +1 -22
  30. data/lib/google/protobuf/empty_pb.rb +1 -22
  31. data/lib/google/protobuf/ffi/descriptor.rb +166 -0
  32. data/lib/google/protobuf/ffi/descriptor_pool.rb +77 -0
  33. data/lib/google/protobuf/ffi/enum_descriptor.rb +173 -0
  34. data/lib/google/protobuf/ffi/ffi.rb +210 -0
  35. data/lib/google/protobuf/ffi/field_descriptor.rb +330 -0
  36. data/lib/google/protobuf/ffi/file_descriptor.rb +49 -0
  37. data/lib/google/protobuf/ffi/internal/arena.rb +66 -0
  38. data/lib/google/protobuf/ffi/internal/convert.rb +289 -0
  39. data/lib/google/protobuf/ffi/internal/pointer_helper.rb +35 -0
  40. data/lib/google/protobuf/ffi/internal/type_safety.rb +25 -0
  41. data/lib/google/protobuf/ffi/map.rb +409 -0
  42. data/lib/google/protobuf/ffi/message.rb +659 -0
  43. data/lib/google/protobuf/ffi/method_descriptor.rb +114 -0
  44. data/lib/google/protobuf/ffi/object_cache.rb +30 -0
  45. data/lib/google/protobuf/ffi/oneof_descriptor.rb +97 -0
  46. data/lib/google/protobuf/ffi/repeated_field.rb +385 -0
  47. data/lib/google/protobuf/ffi/service_descriptor.rb +107 -0
  48. data/lib/google/protobuf/field_mask_pb.rb +1 -22
  49. data/lib/google/protobuf/internal/object_cache.rb +99 -0
  50. data/lib/google/protobuf/message_exts.rb +3 -26
  51. data/lib/google/protobuf/plugin_pb.rb +2 -24
  52. data/lib/google/protobuf/repeated_field.rb +7 -31
  53. data/lib/google/protobuf/source_context_pb.rb +1 -22
  54. data/lib/google/protobuf/struct_pb.rb +1 -22
  55. data/lib/google/protobuf/timestamp_pb.rb +1 -22
  56. data/lib/google/protobuf/type_pb.rb +1 -24
  57. data/lib/google/protobuf/well_known_types.rb +5 -34
  58. data/lib/google/protobuf/wrappers_pb.rb +1 -22
  59. data/lib/google/protobuf.rb +27 -45
  60. data/lib/google/protobuf_ffi.rb +51 -0
  61. data/lib/google/protobuf_native.rb +19 -0
  62. data/lib/google/tasks/ffi.rake +100 -0
  63. metadata +89 -8
  64. data/ext/google/protobuf_c/third_party/utf8_range/naive.c +0 -92
  65. data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +0 -157
  66. data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +0 -170
  67. data/lib/google/protobuf/descriptor_dsl.rb +0 -465
@@ -1,32 +1,9 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2014 Google Inc. All rights reserved.
3
- // https://developers.google.com/protocol-buffers/
4
3
  //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  #include "message.h"
32
9
 
@@ -35,6 +12,7 @@
35
12
  #include "map.h"
36
13
  #include "protobuf.h"
37
14
  #include "repeated_field.h"
15
+ #include "shared_message.h"
38
16
 
39
17
  static VALUE cParseError = Qnil;
40
18
  static VALUE cAbstractMessage = Qnil;
@@ -66,9 +44,11 @@ static void Message_mark(void* _self) {
66
44
  rb_gc_mark(self->arena);
67
45
  }
68
46
 
47
+ static size_t Message_memsize(const void* _self) { return sizeof(Message); }
48
+
69
49
  static rb_data_type_t Message_type = {
70
50
  "Google::Protobuf::Message",
71
- {Message_mark, RUBY_DEFAULT_FREE, NULL},
51
+ {Message_mark, RUBY_DEFAULT_FREE, Message_memsize},
72
52
  .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
73
53
  };
74
54
 
@@ -108,7 +88,9 @@ void Message_InitPtr(VALUE self_, upb_Message* msg, VALUE arena) {
108
88
  Message* self = ruby_to_Message(self_);
109
89
  self->msg = msg;
110
90
  RB_OBJ_WRITE(self_, &self->arena, arena);
111
- ObjectCache_Add(msg, self_);
91
+ VALUE stored = ObjectCache_TryAdd(msg, self_);
92
+ (void)stored;
93
+ PBRUBY_ASSERT(stored == self_);
112
94
  }
113
95
 
114
96
  VALUE Message_GetArena(VALUE msg_rb) {
@@ -508,7 +490,8 @@ static int Map_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
508
490
  k = Convert_RubyToUpb(key, "", map_init->key_type, NULL);
509
491
 
510
492
  if (map_init->val_type.type == kUpb_CType_Message && TYPE(val) == T_HASH) {
511
- upb_MiniTable* t = upb_MessageDef_MiniTable(map_init->val_type.def.msgdef);
493
+ const upb_MiniTable* t =
494
+ upb_MessageDef_MiniTable(map_init->val_type.def.msgdef);
512
495
  upb_Message* msg = upb_Message_New(t, map_init->arena);
513
496
  Message_InitFromValue(msg, map_init->val_type.def.msgdef, val,
514
497
  map_init->arena);
@@ -539,7 +522,7 @@ static upb_MessageValue MessageValue_FromValue(VALUE val, TypeInfo info,
539
522
  upb_Arena* arena) {
540
523
  if (info.type == kUpb_CType_Message) {
541
524
  upb_MessageValue msgval;
542
- upb_MiniTable* t = upb_MessageDef_MiniTable(info.def.msgdef);
525
+ const upb_MiniTable* t = upb_MessageDef_MiniTable(info.def.msgdef);
543
526
  upb_Message* msg = upb_Message_New(t, arena);
544
527
  Message_InitFromValue(msg, info.def.msgdef, val, arena);
545
528
  msgval.msg_val = msg;
@@ -655,7 +638,7 @@ static VALUE Message_initialize(int argc, VALUE* argv, VALUE _self) {
655
638
  Message* self = ruby_to_Message(_self);
656
639
  VALUE arena_rb = Arena_new();
657
640
  upb_Arena* arena = Arena_get(arena_rb);
658
- upb_MiniTable* t = upb_MessageDef_MiniTable(self->msgdef);
641
+ const upb_MiniTable* t = upb_MessageDef_MiniTable(self->msgdef);
659
642
  upb_Message* msg = upb_Message_New(t, arena);
660
643
 
661
644
  Message_InitPtr(_self, msg, arena_rb);
@@ -680,44 +663,12 @@ static VALUE Message_dup(VALUE _self) {
680
663
  Message* self = ruby_to_Message(_self);
681
664
  VALUE new_msg = rb_class_new_instance(0, NULL, CLASS_OF(_self));
682
665
  Message* new_msg_self = ruby_to_Message(new_msg);
683
- size_t size = upb_MessageDef_MiniTable(self->msgdef)->size;
684
-
685
- // TODO(copy unknown fields?)
686
- // TODO(use official upb msg copy function)
687
- memcpy((upb_Message*)new_msg_self->msg, self->msg, size);
666
+ const upb_MiniTable* m = upb_MessageDef_MiniTable(self->msgdef);
667
+ upb_Message_ShallowCopy((upb_Message*)new_msg_self->msg, self->msg, m);
688
668
  Arena_fuse(self->arena, Arena_get(new_msg_self->arena));
689
669
  return new_msg;
690
670
  }
691
671
 
692
- // Support function for Message_eq, and also used by other #eq functions.
693
- bool Message_Equal(const upb_Message* m1, const upb_Message* m2,
694
- const upb_MessageDef* m) {
695
- if (m1 == m2) return true;
696
-
697
- size_t size1, size2;
698
- int encode_opts =
699
- kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic;
700
- upb_Arena* arena_tmp = upb_Arena_New();
701
- const upb_MiniTable* layout = upb_MessageDef_MiniTable(m);
702
-
703
- // Compare deterministically serialized payloads with no unknown fields.
704
- char* data1;
705
- char* data2;
706
- upb_EncodeStatus status1 =
707
- upb_Encode(m1, layout, encode_opts, arena_tmp, &data1, &size1);
708
- upb_EncodeStatus status2 =
709
- upb_Encode(m2, layout, encode_opts, arena_tmp, &data2, &size2);
710
-
711
- if (status1 == kUpb_EncodeStatus_Ok && status2 == kUpb_EncodeStatus_Ok) {
712
- bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0);
713
- upb_Arena_Free(arena_tmp);
714
- return ret;
715
- } else {
716
- upb_Arena_Free(arena_tmp);
717
- rb_raise(cParseError, "Error comparing messages");
718
- }
719
- }
720
-
721
672
  /*
722
673
  * call-seq:
723
674
  * Message.==(other) => boolean
@@ -734,28 +685,22 @@ static VALUE Message_eq(VALUE _self, VALUE _other) {
734
685
  Message* other = ruby_to_Message(_other);
735
686
  assert(self->msgdef == other->msgdef);
736
687
 
737
- return Message_Equal(self->msg, other->msg, self->msgdef) ? Qtrue : Qfalse;
688
+ const upb_MiniTable* m = upb_MessageDef_MiniTable(self->msgdef);
689
+ const int options = 0;
690
+ return upb_Message_IsEqual(self->msg, other->msg, m, options) ? Qtrue
691
+ : Qfalse;
738
692
  }
739
693
 
740
694
  uint64_t Message_Hash(const upb_Message* msg, const upb_MessageDef* m,
741
695
  uint64_t seed) {
742
- upb_Arena* arena = upb_Arena_New();
743
- char* data;
744
- size_t size;
745
-
746
- // Hash a deterministically serialized payloads with no unknown fields.
747
- upb_EncodeStatus status = upb_Encode(
748
- msg, upb_MessageDef_MiniTable(m),
749
- kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic, arena,
750
- &data, &size);
751
-
752
- if (status == kUpb_EncodeStatus_Ok) {
753
- uint64_t ret = _upb_Hash(data, size, seed);
754
- upb_Arena_Free(arena);
755
- return ret;
696
+ upb_Status status;
697
+ upb_Status_Clear(&status);
698
+ uint64_t return_value = shared_Message_Hash(msg, m, seed, &status);
699
+ if (upb_Status_IsOk(&status)) {
700
+ return return_value;
756
701
  } else {
757
- upb_Arena_Free(arena);
758
- rb_raise(cParseError, "Error calculating hash");
702
+ rb_raise(cParseError, "Message_Hash(): %s",
703
+ upb_Status_ErrorMessage(&status));
759
704
  }
760
705
  }
761
706
 
@@ -812,58 +757,34 @@ static VALUE Message_CreateHash(const upb_Message* msg,
812
757
  if (!msg) return Qnil;
813
758
 
814
759
  VALUE hash = rb_hash_new();
815
- int n = upb_MessageDef_FieldCount(m);
816
- bool is_proto2;
817
-
818
- // We currently have a few behaviors that are specific to proto2.
819
- // This is unfortunate, we should key behaviors off field attributes (like
820
- // whether a field has presence), not proto2 vs. proto3. We should see if we
821
- // can change this without breaking users.
822
- is_proto2 = upb_MessageDef_Syntax(m) == kUpb_Syntax_Proto2;
823
-
824
- for (int i = 0; i < n; i++) {
825
- const upb_FieldDef* field = upb_MessageDef_Field(m, i);
826
- TypeInfo type_info = TypeInfo_get(field);
827
- upb_MessageValue msgval;
828
- VALUE msg_value;
829
- VALUE msg_key;
830
-
831
- if (!is_proto2 && upb_FieldDef_IsSubMessage(field) &&
832
- !upb_FieldDef_IsRepeated(field) &&
833
- !upb_Message_HasFieldByDef(msg, field)) {
834
- // TODO: Legacy behavior, remove when we fix the is_proto2 differences.
835
- msg_key = ID2SYM(rb_intern(upb_FieldDef_Name(field)));
836
- rb_hash_aset(hash, msg_key, Qnil);
837
- continue;
838
- }
760
+ size_t iter = kUpb_Message_Begin;
761
+ const upb_DefPool* pool = upb_FileDef_Pool(upb_MessageDef_File(m));
762
+ const upb_FieldDef* field;
763
+ upb_MessageValue val;
839
764
 
840
- // Do not include fields that are not present (oneof or optional fields).
841
- if (is_proto2 && upb_FieldDef_HasPresence(field) &&
842
- !upb_Message_HasFieldByDef(msg, field)) {
765
+ while (upb_Message_Next(msg, m, pool, &field, &val, &iter)) {
766
+ if (upb_FieldDef_IsExtension(field)) {
767
+ // TODO: allow extensions once we have decided what naming scheme the
768
+ // symbol should use. eg. :"[pkg.ext]"
843
769
  continue;
844
770
  }
845
771
 
846
- msg_key = ID2SYM(rb_intern(upb_FieldDef_Name(field)));
847
- msgval = upb_Message_GetFieldByDef(msg, field);
848
-
849
- // Proto2 omits empty map/repeated filds also.
772
+ TypeInfo type_info = TypeInfo_get(field);
773
+ VALUE msg_value;
850
774
 
851
775
  if (upb_FieldDef_IsMap(field)) {
852
776
  const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(field);
853
777
  const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry_m, 1);
854
778
  const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry_m, 2);
855
779
  upb_CType key_type = upb_FieldDef_CType(key_f);
856
- msg_value = Map_CreateHash(msgval.map_val, key_type, TypeInfo_get(val_f));
780
+ msg_value = Map_CreateHash(val.map_val, key_type, TypeInfo_get(val_f));
857
781
  } else if (upb_FieldDef_IsRepeated(field)) {
858
- if (is_proto2 &&
859
- (!msgval.array_val || upb_Array_Size(msgval.array_val) == 0)) {
860
- continue;
861
- }
862
- msg_value = RepeatedField_CreateArray(msgval.array_val, type_info);
782
+ msg_value = RepeatedField_CreateArray(val.array_val, type_info);
863
783
  } else {
864
- msg_value = Scalar_CreateHash(msgval, type_info);
784
+ msg_value = Scalar_CreateHash(val, type_info);
865
785
  }
866
786
 
787
+ VALUE msg_key = ID2SYM(rb_intern(upb_FieldDef_Name(field)));
867
788
  rb_hash_aset(hash, msg_key, msg_value);
868
789
  }
869
790
 
@@ -896,11 +817,27 @@ static VALUE Message_to_h(VALUE _self) {
896
817
  * Freezes the message object. We have to intercept this so we can pin the
897
818
  * Ruby object into memory so we don't forget it's frozen.
898
819
  */
899
- static VALUE Message_freeze(VALUE _self) {
820
+ VALUE Message_freeze(VALUE _self) {
900
821
  Message* self = ruby_to_Message(_self);
901
- if (!RB_OBJ_FROZEN(_self)) {
902
- Arena_Pin(self->arena, _self);
903
- RB_OBJ_FREEZE(_self);
822
+
823
+ if (RB_OBJ_FROZEN(_self)) return _self;
824
+ Arena_Pin(self->arena, _self);
825
+ RB_OBJ_FREEZE(_self);
826
+
827
+ int n = upb_MessageDef_FieldCount(self->msgdef);
828
+ for (int i = 0; i < n; i++) {
829
+ const upb_FieldDef* f = upb_MessageDef_Field(self->msgdef, i);
830
+ VALUE field = Message_getfield(_self, f);
831
+
832
+ if (field != Qnil) {
833
+ if (upb_FieldDef_IsMap(f)) {
834
+ Map_freeze(field);
835
+ } else if (upb_FieldDef_IsRepeated(f)) {
836
+ RepeatedField_freeze(field);
837
+ } else if (upb_FieldDef_IsSubMessage(f)) {
838
+ Message_freeze(field);
839
+ }
840
+ }
904
841
  }
905
842
  return _self;
906
843
  }
@@ -957,7 +894,7 @@ static VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value) {
957
894
  * MessageClass.decode(data, options) => message
958
895
  *
959
896
  * Decodes the given data (as a string containing bytes in protocol buffers wire
960
- * format) under the interpretration given by this message class's definition
897
+ * format) under the interpretation given by this message class's definition
961
898
  * and returns a message object with the corresponding field values.
962
899
  * @param options [Hash] options for the decoder
963
900
  * recursion_limit: set to maximum decoding depth for message (default is 64)
@@ -988,18 +925,27 @@ static VALUE Message_decode(int argc, VALUE* argv, VALUE klass) {
988
925
  rb_raise(rb_eArgError, "Expected string for binary protobuf data.");
989
926
  }
990
927
 
928
+ return Message_decode_bytes(RSTRING_LEN(data), RSTRING_PTR(data), options,
929
+ klass, /*freeze*/ false);
930
+ }
931
+
932
+ VALUE Message_decode_bytes(int size, const char* bytes, int options,
933
+ VALUE klass, bool freeze) {
991
934
  VALUE msg_rb = initialize_rb_class_with_no_args(klass);
992
935
  Message* msg = ruby_to_Message(msg_rb);
993
936
 
994
- upb_DecodeStatus status =
995
- upb_Decode(RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg,
996
- upb_MessageDef_MiniTable(msg->msgdef), NULL, options,
997
- Arena_get(msg->arena));
998
-
937
+ const upb_FileDef* file = upb_MessageDef_File(msg->msgdef);
938
+ const upb_ExtensionRegistry* extreg =
939
+ upb_DefPool_ExtensionRegistry(upb_FileDef_Pool(file));
940
+ upb_DecodeStatus status = upb_Decode(bytes, size, (upb_Message*)msg->msg,
941
+ upb_MessageDef_MiniTable(msg->msgdef),
942
+ extreg, options, Arena_get(msg->arena));
999
943
  if (status != kUpb_DecodeStatus_Ok) {
1000
944
  rb_raise(cParseError, "Error occurred during parsing");
1001
945
  }
1002
-
946
+ if (freeze) {
947
+ Message_freeze(msg_rb);
948
+ }
1003
949
  return msg_rb;
1004
950
  }
1005
951
 
@@ -1020,9 +966,6 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
1020
966
  int options = 0;
1021
967
  upb_Status status;
1022
968
 
1023
- // TODO(haberman): use this message's pool instead.
1024
- const upb_DefPool* symtab = DescriptorPool_GetSymtab(generated_pool);
1025
-
1026
969
  if (argc < 1 || argc > 2) {
1027
970
  rb_raise(rb_eArgError, "Expected 1 or 2 arguments.");
1028
971
  }
@@ -1043,7 +986,7 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
1043
986
  rb_raise(rb_eArgError, "Expected string for JSON data.");
1044
987
  }
1045
988
 
1046
- // TODO(cfallin): Check and respect string encoding. If not UTF-8, we need to
989
+ // TODO: Check and respect string encoding. If not UTF-8, we need to
1047
990
  // convert, because string handlers pass data directly to message string
1048
991
  // fields.
1049
992
 
@@ -1056,8 +999,9 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
1056
999
  }
1057
1000
 
1058
1001
  upb_Status_Clear(&status);
1002
+ const upb_DefPool* pool = upb_FileDef_Pool(upb_MessageDef_File(msg->msgdef));
1059
1003
  if (!upb_JsonDecode(RSTRING_PTR(data), RSTRING_LEN(data),
1060
- (upb_Message*)msg->msg, msg->msgdef, symtab, options,
1004
+ (upb_Message*)msg->msg, msg->msgdef, pool, options,
1061
1005
  Arena_get(msg->arena), &status)) {
1062
1006
  rb_raise(cParseError, "Error occurred during parsing: %s",
1063
1007
  upb_Status_ErrorMessage(&status));
@@ -1136,9 +1080,6 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
1136
1080
  size_t size;
1137
1081
  upb_Status status;
1138
1082
 
1139
- // TODO(haberman): use this message's pool instead.
1140
- const upb_DefPool* symtab = DescriptorPool_GetSymtab(generated_pool);
1141
-
1142
1083
  if (argc < 1 || argc > 2) {
1143
1084
  rb_raise(rb_eArgError, "Expected 1 or 2 arguments.");
1144
1085
  }
@@ -1173,8 +1114,9 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
1173
1114
  }
1174
1115
 
1175
1116
  upb_Status_Clear(&status);
1176
- size = upb_JsonEncode(msg->msg, msg->msgdef, symtab, options, buf,
1177
- sizeof(buf), &status);
1117
+ const upb_DefPool* pool = upb_FileDef_Pool(upb_MessageDef_File(msg->msgdef));
1118
+ size = upb_JsonEncode(msg->msg, msg->msgdef, pool, options, buf, sizeof(buf),
1119
+ &status);
1178
1120
 
1179
1121
  if (!upb_Status_IsOk(&status)) {
1180
1122
  rb_raise(cParseError, "Error occurred during encoding: %s",
@@ -1184,7 +1126,7 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
1184
1126
  VALUE ret;
1185
1127
  if (size >= sizeof(buf)) {
1186
1128
  char* buf2 = malloc(size + 1);
1187
- upb_JsonEncode(msg->msg, msg->msgdef, symtab, options, buf2, size + 1,
1129
+ upb_JsonEncode(msg->msg, msg->msgdef, pool, options, buf2, size + 1,
1188
1130
  &status);
1189
1131
  ret = rb_str_new(buf2, size);
1190
1132
  free(buf2);
@@ -1317,9 +1259,12 @@ upb_Message* Message_deep_copy(const upb_Message* msg, const upb_MessageDef* m,
1317
1259
  upb_Message* new_msg = upb_Message_New(layout, arena);
1318
1260
  char* data;
1319
1261
 
1262
+ const upb_FileDef* file = upb_MessageDef_File(m);
1263
+ const upb_ExtensionRegistry* extreg =
1264
+ upb_DefPool_ExtensionRegistry(upb_FileDef_Pool(file));
1320
1265
  if (upb_Encode(msg, layout, 0, tmp_arena, &data, &size) !=
1321
1266
  kUpb_EncodeStatus_Ok ||
1322
- upb_Decode(data, size, new_msg, layout, NULL, 0, arena) !=
1267
+ upb_Decode(data, size, new_msg, layout, extreg, 0, arena) !=
1323
1268
  kUpb_DecodeStatus_Ok) {
1324
1269
  upb_Arena_Free(tmp_arena);
1325
1270
  rb_raise(cParseError, "Error occurred copying proto");
@@ -1,38 +1,13 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2008 Google Inc. All rights reserved.
3
- // https://developers.google.com/protocol-buffers/
4
3
  //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  #ifndef RUBY_PROTOBUF_MESSAGE_H_
32
9
  #define RUBY_PROTOBUF_MESSAGE_H_
33
10
 
34
- #include <ruby/ruby.h>
35
-
36
11
  #include "protobuf.h"
37
12
  #include "ruby-upb.h"
38
13
 
@@ -79,10 +54,6 @@ uint64_t Message_Hash(const upb_Message* msg, const upb_MessageDef* m,
79
54
  upb_Message* Message_deep_copy(const upb_Message* msg, const upb_MessageDef* m,
80
55
  upb_Arena* arena);
81
56
 
82
- // Returns true if these two messages are equal.
83
- bool Message_Equal(const upb_Message* m1, const upb_Message* m2,
84
- const upb_MessageDef* m);
85
-
86
57
  // Checks that this Ruby object is a message, and raises an exception if not.
87
58
  void Message_CheckClass(VALUE klass);
88
59
 
@@ -98,6 +69,13 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc);
98
69
  // module.
99
70
  VALUE MessageOrEnum_GetDescriptor(VALUE klass);
100
71
 
72
+ // Decodes a Message from a byte sequence.
73
+ VALUE Message_decode_bytes(int size, const char* bytes, int options,
74
+ VALUE klass, bool freeze);
75
+
76
+ // Recursively freeze message
77
+ VALUE Message_freeze(VALUE _self);
78
+
101
79
  // Call at startup to register all types in this module.
102
80
  void Message_register(VALUE protobuf);
103
81