google-protobuf 3.23.4 → 3.25.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of google-protobuf might be problematic. Click here for more details.

Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/ext/google/protobuf_c/Rakefile +3 -0
  3. data/ext/google/protobuf_c/convert.c +23 -70
  4. data/ext/google/protobuf_c/convert.h +3 -28
  5. data/ext/google/protobuf_c/defs.c +153 -40
  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 +56 -0
  9. data/ext/google/protobuf_c/map.c +27 -28
  10. data/ext/google/protobuf_c/map.h +6 -28
  11. data/ext/google/protobuf_c/message.c +70 -78
  12. data/ext/google/protobuf_c/message.h +10 -28
  13. data/ext/google/protobuf_c/protobuf.c +35 -174
  14. data/ext/google/protobuf_c/protobuf.h +24 -32
  15. data/ext/google/protobuf_c/repeated_field.c +28 -29
  16. data/ext/google/protobuf_c/repeated_field.h +6 -28
  17. data/ext/google/protobuf_c/ruby-upb.c +4451 -4011
  18. data/ext/google/protobuf_c/ruby-upb.h +5130 -3866
  19. data/ext/google/protobuf_c/shared_convert.c +64 -0
  20. data/ext/google/protobuf_c/shared_convert.h +26 -0
  21. data/ext/google/protobuf_c/shared_message.c +65 -0
  22. data/ext/google/protobuf_c/shared_message.h +25 -0
  23. data/ext/google/protobuf_c/wrap_memcpy.c +3 -26
  24. data/lib/google/protobuf/any_pb.rb +1 -1
  25. data/lib/google/protobuf/api_pb.rb +1 -1
  26. data/lib/google/protobuf/descriptor_pb.rb +13 -2
  27. data/lib/google/protobuf/duration_pb.rb +1 -1
  28. data/lib/google/protobuf/empty_pb.rb +1 -1
  29. data/lib/google/protobuf/ffi/descriptor.rb +165 -0
  30. data/lib/google/protobuf/ffi/descriptor_pool.rb +75 -0
  31. data/lib/google/protobuf/ffi/enum_descriptor.rb +171 -0
  32. data/lib/google/protobuf/ffi/ffi.rb +213 -0
  33. data/lib/google/protobuf/ffi/field_descriptor.rb +319 -0
  34. data/lib/google/protobuf/ffi/file_descriptor.rb +59 -0
  35. data/lib/google/protobuf/ffi/internal/arena.rb +66 -0
  36. data/lib/google/protobuf/ffi/internal/convert.rb +305 -0
  37. data/lib/google/protobuf/ffi/internal/pointer_helper.rb +35 -0
  38. data/lib/google/protobuf/ffi/internal/type_safety.rb +25 -0
  39. data/lib/google/protobuf/ffi/map.rb +407 -0
  40. data/lib/google/protobuf/ffi/message.rb +662 -0
  41. data/lib/google/protobuf/ffi/object_cache.rb +30 -0
  42. data/lib/google/protobuf/ffi/oneof_descriptor.rb +95 -0
  43. data/lib/google/protobuf/ffi/repeated_field.rb +383 -0
  44. data/lib/google/protobuf/field_mask_pb.rb +1 -1
  45. data/lib/google/protobuf/message_exts.rb +3 -26
  46. data/lib/google/protobuf/object_cache.rb +97 -0
  47. data/lib/google/protobuf/plugin_pb.rb +2 -2
  48. data/lib/google/protobuf/repeated_field.rb +3 -26
  49. data/lib/google/protobuf/source_context_pb.rb +1 -1
  50. data/lib/google/protobuf/struct_pb.rb +1 -1
  51. data/lib/google/protobuf/timestamp_pb.rb +1 -1
  52. data/lib/google/protobuf/type_pb.rb +1 -1
  53. data/lib/google/protobuf/well_known_types.rb +5 -34
  54. data/lib/google/protobuf/wrappers_pb.rb +1 -1
  55. data/lib/google/protobuf.rb +27 -45
  56. data/lib/google/protobuf_ffi.rb +50 -0
  57. data/lib/google/protobuf_native.rb +20 -0
  58. data/lib/google/tasks/ffi.rake +102 -0
  59. metadata +72 -4
@@ -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 "convert.h"
32
9
  #include "defs.h"
@@ -93,7 +70,6 @@ VALUE Map_GetRubyWrapper(upb_Map* map, upb_CType key_type, TypeInfo value_type,
93
70
  if (val == Qnil) {
94
71
  val = Map_alloc(cMap);
95
72
  Map* self;
96
- ObjectCache_Add(map, val);
97
73
  TypedData_Get_Struct(val, Map, &Map_type, self);
98
74
  self->map = map;
99
75
  self->arena = arena;
@@ -103,6 +79,7 @@ VALUE Map_GetRubyWrapper(upb_Map* map, upb_CType key_type, TypeInfo value_type,
103
79
  const upb_MessageDef* val_m = self->value_type_info.def.msgdef;
104
80
  self->value_type_class = Descriptor_DefToClass(val_m);
105
81
  }
82
+ return ObjectCache_TryAdd(map, val);
106
83
  }
107
84
 
108
85
  return val;
@@ -319,7 +296,9 @@ static VALUE Map_init(int argc, VALUE* argv, VALUE _self) {
319
296
 
320
297
  self->map = upb_Map_New(Arena_get(self->arena), self->key_type,
321
298
  self->value_type_info.type);
322
- ObjectCache_Add(self->map, _self);
299
+ VALUE stored = ObjectCache_TryAdd(self->map, _self);
300
+ (void)stored;
301
+ PBRUBY_ASSERT(stored == _self);
323
302
 
324
303
  if (init_arg != Qnil) {
325
304
  Map_merge_into_self(_self, init_arg);
@@ -593,6 +572,26 @@ static VALUE Map_freeze(VALUE _self) {
593
572
  return _self;
594
573
  }
595
574
 
575
+ /*
576
+ * Deep freezes the map and values recursively.
577
+ * Internal use only.
578
+ */
579
+ VALUE Map_internal_deep_freeze(VALUE _self) {
580
+ Map* self = ruby_to_Map(_self);
581
+ Map_freeze(_self);
582
+ if (self->value_type_info.type == kUpb_CType_Message) {
583
+ size_t iter = kUpb_Map_Begin;
584
+ upb_MessageValue key, val;
585
+
586
+ while (upb_Map_Next(self->map, &key, &val, &iter)) {
587
+ VALUE val_val =
588
+ Convert_UpbToRuby(val, self->value_type_info, self->arena);
589
+ Message_internal_deep_freeze(val_val);
590
+ }
591
+ }
592
+ return _self;
593
+ }
594
+
596
595
  /*
597
596
  * call-seq:
598
597
  * Map.hash => hash_value
@@ -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_MAP_H_
32
9
  #define RUBY_PROTOBUF_MAP_H_
33
10
 
34
- #include <ruby/ruby.h>
35
-
36
11
  #include "protobuf.h"
37
12
  #include "ruby-upb.h"
38
13
 
@@ -63,4 +38,7 @@ extern VALUE cMap;
63
38
  // Call at startup to register all types in this module.
64
39
  void Map_register(VALUE module);
65
40
 
41
+ // Recursively freeze map
42
+ VALUE Map_internal_deep_freeze(VALUE _self);
43
+
66
44
  #endif // RUBY_PROTOBUF_MAP_H_
@@ -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;
@@ -108,7 +86,9 @@ void Message_InitPtr(VALUE self_, upb_Message* msg, VALUE arena) {
108
86
  Message* self = ruby_to_Message(self_);
109
87
  self->msg = msg;
110
88
  RB_OBJ_WRITE(self_, &self->arena, arena);
111
- ObjectCache_Add(msg, self_);
89
+ VALUE stored = ObjectCache_TryAdd(msg, self_);
90
+ (void)stored;
91
+ PBRUBY_ASSERT(stored == self_);
112
92
  }
113
93
 
114
94
  VALUE Message_GetArena(VALUE msg_rb) {
@@ -682,8 +662,8 @@ static VALUE Message_dup(VALUE _self) {
682
662
  Message* new_msg_self = ruby_to_Message(new_msg);
683
663
  size_t size = upb_MessageDef_MiniTable(self->msgdef)->size;
684
664
 
685
- // TODO(copy unknown fields?)
686
- // TODO(use official upb msg copy function)
665
+ // TODO
666
+ // TODO
687
667
  memcpy((upb_Message*)new_msg_self->msg, self->msg, size);
688
668
  Arena_fuse(self->arena, Arena_get(new_msg_self->arena));
689
669
  return new_msg;
@@ -692,29 +672,13 @@ static VALUE Message_dup(VALUE _self) {
692
672
  // Support function for Message_eq, and also used by other #eq functions.
693
673
  bool Message_Equal(const upb_Message* m1, const upb_Message* m2,
694
674
  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;
675
+ upb_Status status;
676
+ upb_Status_Clear(&status);
677
+ bool return_value = shared_Message_Equal(m1, m2, m, &status);
678
+ if (upb_Status_IsOk(&status)) {
679
+ return return_value;
715
680
  } else {
716
- upb_Arena_Free(arena_tmp);
717
- rb_raise(cParseError, "Error comparing messages");
681
+ rb_raise(cParseError, upb_Status_ErrorMessage(&status));
718
682
  }
719
683
  }
720
684
 
@@ -739,23 +703,13 @@ static VALUE Message_eq(VALUE _self, VALUE _other) {
739
703
 
740
704
  uint64_t Message_Hash(const upb_Message* msg, const upb_MessageDef* m,
741
705
  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;
706
+ upb_Status status;
707
+ upb_Status_Clear(&status);
708
+ uint64_t return_value = shared_Message_Hash(msg, m, seed, &status);
709
+ if (upb_Status_IsOk(&status)) {
710
+ return return_value;
756
711
  } else {
757
- upb_Arena_Free(arena);
758
- rb_raise(cParseError, "Error calculating hash");
712
+ rb_raise(cParseError, upb_Status_ErrorMessage(&status));
759
713
  }
760
714
  }
761
715
 
@@ -905,6 +859,32 @@ static VALUE Message_freeze(VALUE _self) {
905
859
  return _self;
906
860
  }
907
861
 
862
+ /*
863
+ * Deep freezes the message object recursively.
864
+ * Internal use only.
865
+ */
866
+ VALUE Message_internal_deep_freeze(VALUE _self) {
867
+ Message* self = ruby_to_Message(_self);
868
+ Message_freeze(_self);
869
+
870
+ int n = upb_MessageDef_FieldCount(self->msgdef);
871
+ for (int i = 0; i < n; i++) {
872
+ const upb_FieldDef* f = upb_MessageDef_Field(self->msgdef, i);
873
+ VALUE field = Message_getfield(_self, f);
874
+
875
+ if (field != Qnil) {
876
+ if (upb_FieldDef_IsMap(f)) {
877
+ Map_internal_deep_freeze(field);
878
+ } else if (upb_FieldDef_IsRepeated(f)) {
879
+ RepeatedField_internal_deep_freeze(field);
880
+ } else if (upb_FieldDef_IsSubMessage(f)) {
881
+ Message_internal_deep_freeze(field);
882
+ }
883
+ }
884
+ }
885
+ return _self;
886
+ }
887
+
908
888
  /*
909
889
  * call-seq:
910
890
  * Message.[](index) => value
@@ -957,7 +937,7 @@ static VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value) {
957
937
  * MessageClass.decode(data, options) => message
958
938
  *
959
939
  * 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
940
+ * format) under the interpretation given by this message class's definition
961
941
  * and returns a message object with the corresponding field values.
962
942
  * @param options [Hash] options for the decoder
963
943
  * recursion_limit: set to maximum decoding depth for message (default is 64)
@@ -988,18 +968,27 @@ static VALUE Message_decode(int argc, VALUE* argv, VALUE klass) {
988
968
  rb_raise(rb_eArgError, "Expected string for binary protobuf data.");
989
969
  }
990
970
 
971
+ return Message_decode_bytes(RSTRING_LEN(data), RSTRING_PTR(data), options,
972
+ klass, /*freeze*/ false);
973
+ }
974
+
975
+ VALUE Message_decode_bytes(int size, const char* bytes, int options,
976
+ VALUE klass, bool freeze) {
991
977
  VALUE msg_rb = initialize_rb_class_with_no_args(klass);
992
978
  Message* msg = ruby_to_Message(msg_rb);
993
979
 
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
-
980
+ const upb_FileDef* file = upb_MessageDef_File(msg->msgdef);
981
+ const upb_ExtensionRegistry* extreg =
982
+ upb_DefPool_ExtensionRegistry(upb_FileDef_Pool(file));
983
+ upb_DecodeStatus status = upb_Decode(bytes, size, (upb_Message*)msg->msg,
984
+ upb_MessageDef_MiniTable(msg->msgdef),
985
+ extreg, options, Arena_get(msg->arena));
999
986
  if (status != kUpb_DecodeStatus_Ok) {
1000
987
  rb_raise(cParseError, "Error occurred during parsing");
1001
988
  }
1002
-
989
+ if (freeze) {
990
+ Message_internal_deep_freeze(msg_rb);
991
+ }
1003
992
  return msg_rb;
1004
993
  }
1005
994
 
@@ -1020,7 +1009,7 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
1020
1009
  int options = 0;
1021
1010
  upb_Status status;
1022
1011
 
1023
- // TODO(haberman): use this message's pool instead.
1012
+ // TODO: use this message's pool instead.
1024
1013
  const upb_DefPool* symtab = DescriptorPool_GetSymtab(generated_pool);
1025
1014
 
1026
1015
  if (argc < 1 || argc > 2) {
@@ -1043,7 +1032,7 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
1043
1032
  rb_raise(rb_eArgError, "Expected string for JSON data.");
1044
1033
  }
1045
1034
 
1046
- // TODO(cfallin): Check and respect string encoding. If not UTF-8, we need to
1035
+ // TODO: Check and respect string encoding. If not UTF-8, we need to
1047
1036
  // convert, because string handlers pass data directly to message string
1048
1037
  // fields.
1049
1038
 
@@ -1136,7 +1125,7 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
1136
1125
  size_t size;
1137
1126
  upb_Status status;
1138
1127
 
1139
- // TODO(haberman): use this message's pool instead.
1128
+ // TODO: use this message's pool instead.
1140
1129
  const upb_DefPool* symtab = DescriptorPool_GetSymtab(generated_pool);
1141
1130
 
1142
1131
  if (argc < 1 || argc > 2) {
@@ -1317,9 +1306,12 @@ upb_Message* Message_deep_copy(const upb_Message* msg, const upb_MessageDef* m,
1317
1306
  upb_Message* new_msg = upb_Message_New(layout, arena);
1318
1307
  char* data;
1319
1308
 
1309
+ const upb_FileDef* file = upb_MessageDef_File(m);
1310
+ const upb_ExtensionRegistry* extreg =
1311
+ upb_DefPool_ExtensionRegistry(upb_FileDef_Pool(file));
1320
1312
  if (upb_Encode(msg, layout, 0, tmp_arena, &data, &size) !=
1321
1313
  kUpb_EncodeStatus_Ok ||
1322
- upb_Decode(data, size, new_msg, layout, NULL, 0, arena) !=
1314
+ upb_Decode(data, size, new_msg, layout, extreg, 0, arena) !=
1323
1315
  kUpb_DecodeStatus_Ok) {
1324
1316
  upb_Arena_Free(tmp_arena);
1325
1317
  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
 
@@ -98,6 +73,13 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc);
98
73
  // module.
99
74
  VALUE MessageOrEnum_GetDescriptor(VALUE klass);
100
75
 
76
+ // Decodes a Message from a byte sequence.
77
+ VALUE Message_decode_bytes(int size, const char* bytes, int options,
78
+ VALUE klass, bool freeze);
79
+
80
+ // Recursively freeze message
81
+ VALUE Message_internal_deep_freeze(VALUE _self);
82
+
101
83
  // Call at startup to register all types in this module.
102
84
  void Message_register(VALUE protobuf);
103
85