google-protobuf 3.24.4 → 3.25.6

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.
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 +27 -71
  4. data/ext/google/protobuf_c/convert.h +3 -26
  5. data/ext/google/protobuf_c/defs.c +145 -33
  6. data/ext/google/protobuf_c/defs.h +3 -26
  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 +25 -28
  10. data/ext/google/protobuf_c/map.h +6 -26
  11. data/ext/google/protobuf_c/message.c +73 -80
  12. data/ext/google/protobuf_c/message.h +10 -26
  13. data/ext/google/protobuf_c/protobuf.c +3 -26
  14. data/ext/google/protobuf_c/protobuf.h +3 -26
  15. data/ext/google/protobuf_c/repeated_field.c +23 -27
  16. data/ext/google/protobuf_c/repeated_field.h +6 -26
  17. data/ext/google/protobuf_c/ruby-upb.c +8419 -8202
  18. data/ext/google/protobuf_c/ruby-upb.h +4079 -3786
  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 +66 -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 +6 -3
  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 +3 -26
  47. data/lib/google/protobuf/plugin_pb.rb +1 -1
  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 +3 -26
  54. data/lib/google/protobuf/wrappers_pb.rb +1 -1
  55. data/lib/google/protobuf.rb +26 -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 +70 -3
@@ -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"
@@ -235,7 +212,7 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
235
212
  Map* self = ruby_to_Map(_self);
236
213
  Map* other = ruby_to_Map(hashmap);
237
214
  upb_Arena* arena = Arena_get(self->arena);
238
- upb_Message* self_msg = Map_GetMutable(_self);
215
+ upb_Map* self_map = Map_GetMutable(_self);
239
216
 
240
217
  Arena_fuse(other->arena, arena);
241
218
 
@@ -248,7 +225,7 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
248
225
  size_t iter = kUpb_Map_Begin;
249
226
  upb_MessageValue key, val;
250
227
  while (upb_Map_Next(other->map, &key, &val, &iter)) {
251
- upb_Map_Set(self_msg, key, val, arena);
228
+ upb_Map_Set(self_map, key, val, arena);
252
229
  }
253
230
  } else {
254
231
  rb_raise(rb_eArgError, "Unknown type merging into Map");
@@ -595,6 +572,26 @@ static VALUE Map_freeze(VALUE _self) {
595
572
  return _self;
596
573
  }
597
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
+
598
595
  /*
599
596
  * call-seq:
600
597
  * Map.hash => hash_value
@@ -1,32 +1,9 @@
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_
@@ -61,4 +38,7 @@ extern VALUE cMap;
61
38
  // Call at startup to register all types in this module.
62
39
  void Map_register(VALUE module);
63
40
 
41
+ // Recursively freeze map
42
+ VALUE Map_internal_deep_freeze(VALUE _self);
43
+
64
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;
@@ -510,7 +488,8 @@ static int Map_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
510
488
  k = Convert_RubyToUpb(key, "", map_init->key_type, NULL);
511
489
 
512
490
  if (map_init->val_type.type == kUpb_CType_Message && TYPE(val) == T_HASH) {
513
- upb_MiniTable* t = upb_MessageDef_MiniTable(map_init->val_type.def.msgdef);
491
+ const upb_MiniTable* t =
492
+ upb_MessageDef_MiniTable(map_init->val_type.def.msgdef);
514
493
  upb_Message* msg = upb_Message_New(t, map_init->arena);
515
494
  Message_InitFromValue(msg, map_init->val_type.def.msgdef, val,
516
495
  map_init->arena);
@@ -541,7 +520,7 @@ static upb_MessageValue MessageValue_FromValue(VALUE val, TypeInfo info,
541
520
  upb_Arena* arena) {
542
521
  if (info.type == kUpb_CType_Message) {
543
522
  upb_MessageValue msgval;
544
- upb_MiniTable* t = upb_MessageDef_MiniTable(info.def.msgdef);
523
+ const upb_MiniTable* t = upb_MessageDef_MiniTable(info.def.msgdef);
545
524
  upb_Message* msg = upb_Message_New(t, arena);
546
525
  Message_InitFromValue(msg, info.def.msgdef, val, arena);
547
526
  msgval.msg_val = msg;
@@ -657,7 +636,7 @@ static VALUE Message_initialize(int argc, VALUE* argv, VALUE _self) {
657
636
  Message* self = ruby_to_Message(_self);
658
637
  VALUE arena_rb = Arena_new();
659
638
  upb_Arena* arena = Arena_get(arena_rb);
660
- upb_MiniTable* t = upb_MessageDef_MiniTable(self->msgdef);
639
+ const upb_MiniTable* t = upb_MessageDef_MiniTable(self->msgdef);
661
640
  upb_Message* msg = upb_Message_New(t, arena);
662
641
 
663
642
  Message_InitPtr(_self, msg, arena_rb);
@@ -684,8 +663,8 @@ static VALUE Message_dup(VALUE _self) {
684
663
  Message* new_msg_self = ruby_to_Message(new_msg);
685
664
  size_t size = upb_MessageDef_MiniTable(self->msgdef)->size;
686
665
 
687
- // TODO(copy unknown fields?)
688
- // TODO(use official upb msg copy function)
666
+ // TODO
667
+ // TODO
689
668
  memcpy((upb_Message*)new_msg_self->msg, self->msg, size);
690
669
  Arena_fuse(self->arena, Arena_get(new_msg_self->arena));
691
670
  return new_msg;
@@ -694,29 +673,14 @@ static VALUE Message_dup(VALUE _self) {
694
673
  // Support function for Message_eq, and also used by other #eq functions.
695
674
  bool Message_Equal(const upb_Message* m1, const upb_Message* m2,
696
675
  const upb_MessageDef* m) {
697
- if (m1 == m2) return true;
698
-
699
- size_t size1, size2;
700
- int encode_opts =
701
- kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic;
702
- upb_Arena* arena_tmp = upb_Arena_New();
703
- const upb_MiniTable* layout = upb_MessageDef_MiniTable(m);
704
-
705
- // Compare deterministically serialized payloads with no unknown fields.
706
- char* data1;
707
- char* data2;
708
- upb_EncodeStatus status1 =
709
- upb_Encode(m1, layout, encode_opts, arena_tmp, &data1, &size1);
710
- upb_EncodeStatus status2 =
711
- upb_Encode(m2, layout, encode_opts, arena_tmp, &data2, &size2);
712
-
713
- if (status1 == kUpb_EncodeStatus_Ok && status2 == kUpb_EncodeStatus_Ok) {
714
- bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0);
715
- upb_Arena_Free(arena_tmp);
716
- return ret;
676
+ upb_Status status;
677
+ upb_Status_Clear(&status);
678
+ bool return_value = shared_Message_Equal(m1, m2, m, &status);
679
+ if (upb_Status_IsOk(&status)) {
680
+ return return_value;
717
681
  } else {
718
- upb_Arena_Free(arena_tmp);
719
- rb_raise(cParseError, "Error comparing messages");
682
+ rb_raise(cParseError, "Message_Equal(): %s",
683
+ upb_Status_ErrorMessage(&status));
720
684
  }
721
685
  }
722
686
 
@@ -741,23 +705,14 @@ static VALUE Message_eq(VALUE _self, VALUE _other) {
741
705
 
742
706
  uint64_t Message_Hash(const upb_Message* msg, const upb_MessageDef* m,
743
707
  uint64_t seed) {
744
- upb_Arena* arena = upb_Arena_New();
745
- char* data;
746
- size_t size;
747
-
748
- // Hash a deterministically serialized payloads with no unknown fields.
749
- upb_EncodeStatus status = upb_Encode(
750
- msg, upb_MessageDef_MiniTable(m),
751
- kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic, arena,
752
- &data, &size);
753
-
754
- if (status == kUpb_EncodeStatus_Ok) {
755
- uint64_t ret = _upb_Hash(data, size, seed);
756
- upb_Arena_Free(arena);
757
- return ret;
708
+ upb_Status status;
709
+ upb_Status_Clear(&status);
710
+ uint64_t return_value = shared_Message_Hash(msg, m, seed, &status);
711
+ if (upb_Status_IsOk(&status)) {
712
+ return return_value;
758
713
  } else {
759
- upb_Arena_Free(arena);
760
- rb_raise(cParseError, "Error calculating hash");
714
+ rb_raise(cParseError, "Message_Hash(): %s",
715
+ upb_Status_ErrorMessage(&status));
761
716
  }
762
717
  }
763
718
 
@@ -907,6 +862,32 @@ static VALUE Message_freeze(VALUE _self) {
907
862
  return _self;
908
863
  }
909
864
 
865
+ /*
866
+ * Deep freezes the message object recursively.
867
+ * Internal use only.
868
+ */
869
+ VALUE Message_internal_deep_freeze(VALUE _self) {
870
+ Message* self = ruby_to_Message(_self);
871
+ Message_freeze(_self);
872
+
873
+ int n = upb_MessageDef_FieldCount(self->msgdef);
874
+ for (int i = 0; i < n; i++) {
875
+ const upb_FieldDef* f = upb_MessageDef_Field(self->msgdef, i);
876
+ VALUE field = Message_getfield(_self, f);
877
+
878
+ if (field != Qnil) {
879
+ if (upb_FieldDef_IsMap(f)) {
880
+ Map_internal_deep_freeze(field);
881
+ } else if (upb_FieldDef_IsRepeated(f)) {
882
+ RepeatedField_internal_deep_freeze(field);
883
+ } else if (upb_FieldDef_IsSubMessage(f)) {
884
+ Message_internal_deep_freeze(field);
885
+ }
886
+ }
887
+ }
888
+ return _self;
889
+ }
890
+
910
891
  /*
911
892
  * call-seq:
912
893
  * Message.[](index) => value
@@ -959,7 +940,7 @@ static VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value) {
959
940
  * MessageClass.decode(data, options) => message
960
941
  *
961
942
  * Decodes the given data (as a string containing bytes in protocol buffers wire
962
- * format) under the interpretration given by this message class's definition
943
+ * format) under the interpretation given by this message class's definition
963
944
  * and returns a message object with the corresponding field values.
964
945
  * @param options [Hash] options for the decoder
965
946
  * recursion_limit: set to maximum decoding depth for message (default is 64)
@@ -990,18 +971,27 @@ static VALUE Message_decode(int argc, VALUE* argv, VALUE klass) {
990
971
  rb_raise(rb_eArgError, "Expected string for binary protobuf data.");
991
972
  }
992
973
 
974
+ return Message_decode_bytes(RSTRING_LEN(data), RSTRING_PTR(data), options,
975
+ klass, /*freeze*/ false);
976
+ }
977
+
978
+ VALUE Message_decode_bytes(int size, const char* bytes, int options,
979
+ VALUE klass, bool freeze) {
993
980
  VALUE msg_rb = initialize_rb_class_with_no_args(klass);
994
981
  Message* msg = ruby_to_Message(msg_rb);
995
982
 
996
- upb_DecodeStatus status =
997
- upb_Decode(RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg,
998
- upb_MessageDef_MiniTable(msg->msgdef), NULL, options,
999
- Arena_get(msg->arena));
1000
-
983
+ const upb_FileDef* file = upb_MessageDef_File(msg->msgdef);
984
+ const upb_ExtensionRegistry* extreg =
985
+ upb_DefPool_ExtensionRegistry(upb_FileDef_Pool(file));
986
+ upb_DecodeStatus status = upb_Decode(bytes, size, (upb_Message*)msg->msg,
987
+ upb_MessageDef_MiniTable(msg->msgdef),
988
+ extreg, options, Arena_get(msg->arena));
1001
989
  if (status != kUpb_DecodeStatus_Ok) {
1002
990
  rb_raise(cParseError, "Error occurred during parsing");
1003
991
  }
1004
-
992
+ if (freeze) {
993
+ Message_internal_deep_freeze(msg_rb);
994
+ }
1005
995
  return msg_rb;
1006
996
  }
1007
997
 
@@ -1022,7 +1012,7 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
1022
1012
  int options = 0;
1023
1013
  upb_Status status;
1024
1014
 
1025
- // TODO(haberman): use this message's pool instead.
1015
+ // TODO: use this message's pool instead.
1026
1016
  const upb_DefPool* symtab = DescriptorPool_GetSymtab(generated_pool);
1027
1017
 
1028
1018
  if (argc < 1 || argc > 2) {
@@ -1045,7 +1035,7 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
1045
1035
  rb_raise(rb_eArgError, "Expected string for JSON data.");
1046
1036
  }
1047
1037
 
1048
- // TODO(cfallin): Check and respect string encoding. If not UTF-8, we need to
1038
+ // TODO: Check and respect string encoding. If not UTF-8, we need to
1049
1039
  // convert, because string handlers pass data directly to message string
1050
1040
  // fields.
1051
1041
 
@@ -1138,7 +1128,7 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
1138
1128
  size_t size;
1139
1129
  upb_Status status;
1140
1130
 
1141
- // TODO(haberman): use this message's pool instead.
1131
+ // TODO: use this message's pool instead.
1142
1132
  const upb_DefPool* symtab = DescriptorPool_GetSymtab(generated_pool);
1143
1133
 
1144
1134
  if (argc < 1 || argc > 2) {
@@ -1319,9 +1309,12 @@ upb_Message* Message_deep_copy(const upb_Message* msg, const upb_MessageDef* m,
1319
1309
  upb_Message* new_msg = upb_Message_New(layout, arena);
1320
1310
  char* data;
1321
1311
 
1312
+ const upb_FileDef* file = upb_MessageDef_File(m);
1313
+ const upb_ExtensionRegistry* extreg =
1314
+ upb_DefPool_ExtensionRegistry(upb_FileDef_Pool(file));
1322
1315
  if (upb_Encode(msg, layout, 0, tmp_arena, &data, &size) !=
1323
1316
  kUpb_EncodeStatus_Ok ||
1324
- upb_Decode(data, size, new_msg, layout, NULL, 0, arena) !=
1317
+ upb_Decode(data, size, new_msg, layout, extreg, 0, arena) !=
1325
1318
  kUpb_DecodeStatus_Ok) {
1326
1319
  upb_Arena_Free(tmp_arena);
1327
1320
  rb_raise(cParseError, "Error occurred copying proto");
@@ -1,32 +1,9 @@
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_
@@ -96,6 +73,13 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc);
96
73
  // module.
97
74
  VALUE MessageOrEnum_GetDescriptor(VALUE klass);
98
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
+
99
83
  // Call at startup to register all types in this module.
100
84
  void Message_register(VALUE protobuf);
101
85
 
@@ -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 "protobuf.h"
32
9
 
@@ -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
  #ifndef __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__
32
9
  #define __GOOGLE_PROTOBUF_RUBY_PROTOBUF_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 "repeated_field.h"
32
9
 
@@ -286,7 +263,7 @@ static VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val) {
286
263
  memset(&fill, 0, sizeof(fill));
287
264
  for (int i = size; i < index; i++) {
288
265
  // Fill default values.
289
- // TODO(haberman): should this happen at the upb level?
266
+ // TODO: should this happen at the upb level?
290
267
  upb_Array_Set(array, i, fill);
291
268
  }
292
269
  }
@@ -510,6 +487,25 @@ static VALUE RepeatedField_freeze(VALUE _self) {
510
487
  return _self;
511
488
  }
512
489
 
490
+ /*
491
+ * Deep freezes the repeated field and values recursively.
492
+ * Internal use only.
493
+ */
494
+ VALUE RepeatedField_internal_deep_freeze(VALUE _self) {
495
+ RepeatedField* self = ruby_to_RepeatedField(_self);
496
+ RepeatedField_freeze(_self);
497
+ if (self->type_info.type == kUpb_CType_Message) {
498
+ int size = upb_Array_Size(self->array);
499
+ int i;
500
+ for (i = 0; i < size; i++) {
501
+ upb_MessageValue msgval = upb_Array_Get(self->array, i);
502
+ VALUE val = Convert_UpbToRuby(msgval, self->type_info, self->arena);
503
+ Message_internal_deep_freeze(val);
504
+ }
505
+ }
506
+ return _self;
507
+ }
508
+
513
509
  /*
514
510
  * call-seq:
515
511
  * RepeatedField.hash => hash_value
@@ -1,32 +1,9 @@
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_REPEATED_FIELD_H_
32
9
  #define RUBY_PROTOBUF_REPEATED_FIELD_H_
@@ -58,4 +35,7 @@ extern VALUE cRepeatedField;
58
35
  // Call at startup to register all types in this module.
59
36
  void RepeatedField_register(VALUE module);
60
37
 
38
+ // Recursively freeze RepeatedField.
39
+ VALUE RepeatedField_internal_deep_freeze(VALUE _self);
40
+
61
41
  #endif // RUBY_PROTOBUF_REPEATED_FIELD_H_