google-protobuf 4.29.3 → 4.33.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.
- checksums.yaml +4 -4
- data/ext/google/protobuf_c/convert.c +3 -10
- data/ext/google/protobuf_c/defs.c +469 -130
- data/ext/google/protobuf_c/extconf.rb +20 -10
- data/ext/google/protobuf_c/glue.c +63 -0
- data/ext/google/protobuf_c/map.c +76 -39
- data/ext/google/protobuf_c/message.c +96 -62
- data/ext/google/protobuf_c/protobuf.c +3 -2
- data/ext/google/protobuf_c/protobuf.h +0 -8
- data/ext/google/protobuf_c/repeated_field.c +75 -38
- data/ext/google/protobuf_c/ruby-upb.c +14055 -13540
- data/ext/google/protobuf_c/ruby-upb.h +4343 -2827
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +21 -281
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_neon.inc +117 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_sse.inc +272 -0
- data/lib/google/protobuf/any_pb.rb +1 -1
- data/lib/google/protobuf/api_pb.rb +2 -2
- data/lib/google/protobuf/descriptor_pb.rb +6 -2
- data/lib/google/protobuf/duration_pb.rb +1 -1
- data/lib/google/protobuf/empty_pb.rb +1 -1
- data/lib/google/protobuf/ffi/descriptor.rb +10 -0
- data/lib/google/protobuf/ffi/descriptor_pool.rb +3 -1
- data/lib/google/protobuf/ffi/enum_descriptor.rb +10 -0
- data/lib/google/protobuf/ffi/ffi.rb +0 -1
- data/lib/google/protobuf/ffi/field_descriptor.rb +16 -0
- data/lib/google/protobuf/ffi/file_descriptor.rb +36 -0
- data/lib/google/protobuf/ffi/internal/convert.rb +1 -5
- data/lib/google/protobuf/ffi/internal/pointer_helper.rb +2 -1
- data/lib/google/protobuf/ffi/map.rb +2 -2
- data/lib/google/protobuf/ffi/message.rb +2 -4
- data/lib/google/protobuf/ffi/method_descriptor.rb +11 -1
- data/lib/google/protobuf/ffi/oneof_descriptor.rb +10 -0
- data/lib/google/protobuf/ffi/service_descriptor.rb +11 -1
- data/lib/google/protobuf/field_mask_pb.rb +1 -1
- data/lib/google/protobuf/message_exts.rb +4 -0
- data/lib/google/protobuf/plugin_pb.rb +1 -1
- data/lib/google/protobuf/source_context_pb.rb +1 -1
- data/lib/google/protobuf/struct_pb.rb +1 -1
- data/lib/google/protobuf/timestamp_pb.rb +1 -1
- data/lib/google/protobuf/type_pb.rb +1 -1
- data/lib/google/protobuf/wrappers_pb.rb +1 -1
- data/lib/google/protobuf_ffi.rb +3 -2
- data/lib/google/tasks/ffi.rake +1 -1
- metadata +23 -22
- data/ext/google/protobuf_c/wrap_memcpy.c +0 -29
|
@@ -362,7 +362,8 @@ static VALUE Message_field_accessor(VALUE _self, const upb_FieldDef* f,
|
|
|
362
362
|
if (!upb_FieldDef_HasPresence(f)) {
|
|
363
363
|
rb_raise(rb_eRuntimeError, "Field does not have presence.");
|
|
364
364
|
}
|
|
365
|
-
return upb_Message_HasFieldByDef(Message_Get(_self, NULL), f)
|
|
365
|
+
return upb_Message_HasFieldByDef(Message_Get(_self, NULL), f) ? Qtrue
|
|
366
|
+
: Qfalse;
|
|
366
367
|
case METHOD_WRAPPER_GETTER: {
|
|
367
368
|
Message* self = ruby_to_Message(_self);
|
|
368
369
|
if (upb_Message_HasFieldByDef(self->msg, f)) {
|
|
@@ -397,7 +398,7 @@ static VALUE Message_field_accessor(VALUE _self, const upb_FieldDef* f,
|
|
|
397
398
|
upb_MessageValue msgval =
|
|
398
399
|
upb_Message_GetFieldByDef(Message_Get(_self, NULL), f);
|
|
399
400
|
|
|
400
|
-
if (
|
|
401
|
+
if (upb_FieldDef_IsRepeated(f)) {
|
|
401
402
|
// Map repeated fields to a new type with ints
|
|
402
403
|
VALUE arr = rb_ary_new();
|
|
403
404
|
size_t i, n = upb_Array_Size(msgval.array_val);
|
|
@@ -419,11 +420,10 @@ static VALUE Message_field_accessor(VALUE _self, const upb_FieldDef* f,
|
|
|
419
420
|
}
|
|
420
421
|
|
|
421
422
|
/*
|
|
422
|
-
*
|
|
423
|
-
* Message.method_missing(*args)
|
|
423
|
+
* ruby-doc: AbstractMessage
|
|
424
424
|
*
|
|
425
|
-
*
|
|
426
|
-
*
|
|
425
|
+
* The {AbstractMessage} class is the parent class for all Protobuf messages,
|
|
426
|
+
* and is generated from C code.
|
|
427
427
|
*
|
|
428
428
|
* For any field whose name does not conflict with a built-in method, an
|
|
429
429
|
* accessor is provided with the same name as the field, and a setter is
|
|
@@ -591,7 +591,7 @@ static void Message_InitFieldFromValue(upb_Message* msg, const upb_FieldDef* f,
|
|
|
591
591
|
if (upb_FieldDef_IsMap(f)) {
|
|
592
592
|
upb_Map* map = upb_Message_Mutable(msg, f, arena).map;
|
|
593
593
|
Map_InitFromValue(map, f, val, arena);
|
|
594
|
-
} else if (
|
|
594
|
+
} else if (upb_FieldDef_IsRepeated(f)) {
|
|
595
595
|
upb_Array* arr = upb_Message_Mutable(msg, f, arena).array;
|
|
596
596
|
RepeatedField_InitFromValue(arr, f, val, arena);
|
|
597
597
|
} else if (upb_FieldDef_IsSubMessage(f)) {
|
|
@@ -652,16 +652,12 @@ void Message_InitFromValue(upb_Message* msg, const upb_MessageDef* m, VALUE val,
|
|
|
652
652
|
}
|
|
653
653
|
|
|
654
654
|
/*
|
|
655
|
-
*
|
|
656
|
-
* Message.new(kwargs) => new_message
|
|
655
|
+
* ruby-doc: AbstractMessage#initialize
|
|
657
656
|
*
|
|
658
657
|
* Creates a new instance of the given message class. Keyword arguments may be
|
|
659
658
|
* provided with keywords corresponding to field names.
|
|
660
659
|
*
|
|
661
|
-
*
|
|
662
|
-
* type exist, as provided by the #msgclass method on Descriptors after they
|
|
663
|
-
* have been added to a pool. The method definitions described here on the
|
|
664
|
-
* Message class are provided on each concrete message class.
|
|
660
|
+
* @param kwargs the list of field keys and values.
|
|
665
661
|
*/
|
|
666
662
|
static VALUE Message_initialize(int argc, VALUE* argv, VALUE _self) {
|
|
667
663
|
Message* self = ruby_to_Message(_self);
|
|
@@ -683,10 +679,11 @@ static VALUE Message_initialize(int argc, VALUE* argv, VALUE _self) {
|
|
|
683
679
|
}
|
|
684
680
|
|
|
685
681
|
/*
|
|
686
|
-
*
|
|
687
|
-
* Message.dup => new_message
|
|
682
|
+
* ruby-doc: AbstractMessage#dup
|
|
688
683
|
*
|
|
689
684
|
* Performs a shallow copy of this message and returns the new copy.
|
|
685
|
+
*
|
|
686
|
+
* @return [AbstractMessage]
|
|
690
687
|
*/
|
|
691
688
|
static VALUE Message_dup(VALUE _self) {
|
|
692
689
|
Message* self = ruby_to_Message(_self);
|
|
@@ -699,13 +696,15 @@ static VALUE Message_dup(VALUE _self) {
|
|
|
699
696
|
}
|
|
700
697
|
|
|
701
698
|
/*
|
|
702
|
-
*
|
|
703
|
-
* Message.==(other) => boolean
|
|
699
|
+
* ruby-doc: AbstractMessage#==
|
|
704
700
|
*
|
|
705
701
|
* Performs a deep comparison of this message with another. Messages are equal
|
|
706
702
|
* if they have the same type and if each field is equal according to the :==
|
|
707
703
|
* method's semantics (a more efficient comparison may actually be done if the
|
|
708
704
|
* field is of a primitive type).
|
|
705
|
+
*
|
|
706
|
+
* @param other [AbstractMessage]
|
|
707
|
+
* @return [Boolean]
|
|
709
708
|
*/
|
|
710
709
|
static VALUE Message_eq(VALUE _self, VALUE _other) {
|
|
711
710
|
if (CLASS_OF(_self) != CLASS_OF(_other)) return Qfalse;
|
|
@@ -734,10 +733,11 @@ uint64_t Message_Hash(const upb_Message* msg, const upb_MessageDef* m,
|
|
|
734
733
|
}
|
|
735
734
|
|
|
736
735
|
/*
|
|
737
|
-
*
|
|
738
|
-
* Message.hash => hash_value
|
|
736
|
+
* ruby-doc: AbstractMessage#hash
|
|
739
737
|
*
|
|
740
738
|
* Returns a hash value that represents this message's field values.
|
|
739
|
+
*
|
|
740
|
+
* @return [Integer]
|
|
741
741
|
*/
|
|
742
742
|
static VALUE Message_hash(VALUE _self) {
|
|
743
743
|
Message* self = ruby_to_Message(_self);
|
|
@@ -748,12 +748,13 @@ static VALUE Message_hash(VALUE _self) {
|
|
|
748
748
|
}
|
|
749
749
|
|
|
750
750
|
/*
|
|
751
|
-
*
|
|
752
|
-
* Message.inspect => string
|
|
751
|
+
* ruby-doc: AbstractMessage#inspect
|
|
753
752
|
*
|
|
754
753
|
* Returns a human-readable string representing this message. It will be
|
|
755
754
|
* formatted as "<MessageType: field1: value1, field2: value2, ...>". Each
|
|
756
755
|
* field's value is represented according to its own #inspect method.
|
|
756
|
+
*
|
|
757
|
+
* @return [String]
|
|
757
758
|
*/
|
|
758
759
|
static VALUE Message_inspect(VALUE _self) {
|
|
759
760
|
Message* self = ruby_to_Message(_self);
|
|
@@ -829,10 +830,11 @@ VALUE Scalar_CreateHash(upb_MessageValue msgval, TypeInfo type_info) {
|
|
|
829
830
|
}
|
|
830
831
|
|
|
831
832
|
/*
|
|
832
|
-
*
|
|
833
|
-
* Message.to_h => {}
|
|
833
|
+
* ruby-doc: AbstractMessage#to_h
|
|
834
834
|
*
|
|
835
835
|
* Returns the message as a Ruby Hash object, with keys as symbols.
|
|
836
|
+
*
|
|
837
|
+
* @return [Hash]
|
|
836
838
|
*/
|
|
837
839
|
static VALUE Message_to_h(VALUE _self) {
|
|
838
840
|
Message* self = ruby_to_Message(_self);
|
|
@@ -840,12 +842,13 @@ static VALUE Message_to_h(VALUE _self) {
|
|
|
840
842
|
}
|
|
841
843
|
|
|
842
844
|
/*
|
|
843
|
-
*
|
|
844
|
-
* Message.frozen? => bool
|
|
845
|
+
* ruby-doc: AbstractMessage#frozen?
|
|
845
846
|
*
|
|
846
847
|
* Returns true if the message is frozen in either Ruby or the underlying
|
|
847
848
|
* representation. Freezes the Ruby message object if it is not already frozen
|
|
848
849
|
* in Ruby but it is frozen in the underlying representation.
|
|
850
|
+
*
|
|
851
|
+
* @return [Boolean]
|
|
849
852
|
*/
|
|
850
853
|
VALUE Message_frozen(VALUE _self) {
|
|
851
854
|
Message* self = ruby_to_Message(_self);
|
|
@@ -860,11 +863,12 @@ VALUE Message_frozen(VALUE _self) {
|
|
|
860
863
|
}
|
|
861
864
|
|
|
862
865
|
/*
|
|
863
|
-
*
|
|
864
|
-
* Message.freeze => self
|
|
866
|
+
* ruby-doc: AbstractMessage#freeze
|
|
865
867
|
*
|
|
866
868
|
* Freezes the message object. We have to intercept this so we can freeze the
|
|
867
869
|
* underlying representation, not just the Ruby wrapper.
|
|
870
|
+
*
|
|
871
|
+
* @return [self]
|
|
868
872
|
*/
|
|
869
873
|
VALUE Message_freeze(VALUE _self) {
|
|
870
874
|
Message* self = ruby_to_Message(_self);
|
|
@@ -881,11 +885,13 @@ VALUE Message_freeze(VALUE _self) {
|
|
|
881
885
|
}
|
|
882
886
|
|
|
883
887
|
/*
|
|
884
|
-
*
|
|
885
|
-
* Message.[](index) => value
|
|
888
|
+
* ruby-doc: AbstractMessage#[]
|
|
886
889
|
*
|
|
887
890
|
* Accesses a field's value by field name. The provided field name should be a
|
|
888
891
|
* string.
|
|
892
|
+
*
|
|
893
|
+
* @param index [Integer]
|
|
894
|
+
* @return [Object]
|
|
889
895
|
*/
|
|
890
896
|
static VALUE Message_index(VALUE _self, VALUE field_name) {
|
|
891
897
|
Message* self = ruby_to_Message(_self);
|
|
@@ -902,11 +908,14 @@ static VALUE Message_index(VALUE _self, VALUE field_name) {
|
|
|
902
908
|
}
|
|
903
909
|
|
|
904
910
|
/*
|
|
905
|
-
*
|
|
906
|
-
* Message.[]=(index, value)
|
|
911
|
+
* ruby-doc: AbstractMessage#[]=
|
|
907
912
|
*
|
|
908
913
|
* Sets a field's value by field name. The provided field name should be a
|
|
909
914
|
* string.
|
|
915
|
+
*
|
|
916
|
+
* @param index [Integer]
|
|
917
|
+
* @param value [Object]
|
|
918
|
+
* @return [nil]
|
|
910
919
|
*/
|
|
911
920
|
static VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value) {
|
|
912
921
|
Message* self = ruby_to_Message(_self);
|
|
@@ -928,14 +937,16 @@ static VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value) {
|
|
|
928
937
|
}
|
|
929
938
|
|
|
930
939
|
/*
|
|
931
|
-
*
|
|
932
|
-
* MessageClass.decode(data, options) => message
|
|
940
|
+
* ruby-doc: AbstractMessage.decode
|
|
933
941
|
*
|
|
934
942
|
* Decodes the given data (as a string containing bytes in protocol buffers wire
|
|
935
943
|
* format) under the interpretation given by this message class's definition
|
|
936
944
|
* and returns a message object with the corresponding field values.
|
|
937
|
-
* @param
|
|
938
|
-
*
|
|
945
|
+
* @param data [String]
|
|
946
|
+
* @param options [Hash]
|
|
947
|
+
* @option recursion_limit [Integer] set to maximum decoding depth for message
|
|
948
|
+
* (default is 64)
|
|
949
|
+
* @return [AbstractMessage]
|
|
939
950
|
*/
|
|
940
951
|
static VALUE Message_decode(int argc, VALUE* argv, VALUE klass) {
|
|
941
952
|
VALUE data = argv[0];
|
|
@@ -988,16 +999,17 @@ VALUE Message_decode_bytes(int size, const char* bytes, int options,
|
|
|
988
999
|
}
|
|
989
1000
|
|
|
990
1001
|
/*
|
|
991
|
-
*
|
|
992
|
-
* MessageClass.decode_json(data, options = {}) => message
|
|
1002
|
+
* ruby-doc: AbstractMessage.decode_json
|
|
993
1003
|
*
|
|
994
1004
|
* Decodes the given data (as a string containing bytes in protocol buffers wire
|
|
995
1005
|
* format) under the interpretration given by this message class's definition
|
|
996
1006
|
* and returns a message object with the corresponding field values.
|
|
997
1007
|
*
|
|
998
|
-
*
|
|
999
|
-
*
|
|
1000
|
-
*
|
|
1008
|
+
* @param data [String]
|
|
1009
|
+
* @param options [Hash]
|
|
1010
|
+
* @option ignore_unknown_fields [Boolean] set true to ignore unknown fields
|
|
1011
|
+
* (default is to raise an error)
|
|
1012
|
+
* @return [AbstractMessage]
|
|
1001
1013
|
*/
|
|
1002
1014
|
static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
|
|
1003
1015
|
VALUE data = argv[0];
|
|
@@ -1046,9 +1058,6 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
|
|
|
1046
1058
|
switch (result) {
|
|
1047
1059
|
case kUpb_JsonDecodeResult_Ok:
|
|
1048
1060
|
break;
|
|
1049
|
-
case kUpb_JsonDecodeResult_OkWithEmptyStringNumerics:
|
|
1050
|
-
rb_warn("%s", upb_Status_ErrorMessage(&status));
|
|
1051
|
-
break;
|
|
1052
1061
|
case kUpb_JsonDecodeResult_Error:
|
|
1053
1062
|
rb_raise(cParseError, "Error occurred during parsing: %s",
|
|
1054
1063
|
upb_Status_ErrorMessage(&status));
|
|
@@ -1059,13 +1068,16 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
|
|
|
1059
1068
|
}
|
|
1060
1069
|
|
|
1061
1070
|
/*
|
|
1062
|
-
*
|
|
1063
|
-
* MessageClass.encode(msg, options) => bytes
|
|
1071
|
+
* ruby-doc: AbstractMessage.encode
|
|
1064
1072
|
*
|
|
1065
1073
|
* Encodes the given message object to its serialized form in protocol buffers
|
|
1066
1074
|
* wire format.
|
|
1067
|
-
*
|
|
1068
|
-
*
|
|
1075
|
+
*
|
|
1076
|
+
* @param msg [AbstractMessage]
|
|
1077
|
+
* @param options [Hash]
|
|
1078
|
+
* @option recursion_limit [Integer] set to maximum encoding depth for message
|
|
1079
|
+
* (default is 64)
|
|
1080
|
+
* @return [String]
|
|
1069
1081
|
*/
|
|
1070
1082
|
static VALUE Message_encode(int argc, VALUE* argv, VALUE klass) {
|
|
1071
1083
|
Message* msg = ruby_to_Message(argv[0]);
|
|
@@ -1112,14 +1124,17 @@ static VALUE Message_encode(int argc, VALUE* argv, VALUE klass) {
|
|
|
1112
1124
|
}
|
|
1113
1125
|
|
|
1114
1126
|
/*
|
|
1115
|
-
*
|
|
1116
|
-
* MessageClass.encode_json(msg, options = {}) => json_string
|
|
1127
|
+
* ruby-doc: AbstractMessage.encode_json
|
|
1117
1128
|
*
|
|
1118
1129
|
* Encodes the given message object into its serialized JSON representation.
|
|
1119
|
-
*
|
|
1120
|
-
*
|
|
1121
|
-
*
|
|
1122
|
-
*
|
|
1130
|
+
*
|
|
1131
|
+
* @param msg [AbstractMessage]
|
|
1132
|
+
* @param options [Hash]
|
|
1133
|
+
* @option preserve_proto_fieldnames [Boolean] set true to use original
|
|
1134
|
+
* fieldnames (default is to camelCase)
|
|
1135
|
+
* @option emit_defaults [Boolean] set true to emit 0/false values (default is
|
|
1136
|
+
* to omit them)
|
|
1137
|
+
* @return [String]
|
|
1123
1138
|
*/
|
|
1124
1139
|
static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
|
|
1125
1140
|
Message* msg = ruby_to_Message(argv[0]);
|
|
@@ -1187,11 +1202,12 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
|
|
|
1187
1202
|
}
|
|
1188
1203
|
|
|
1189
1204
|
/*
|
|
1190
|
-
*
|
|
1191
|
-
* Message.descriptor => descriptor
|
|
1205
|
+
* ruby-doc: AbstractMessage.descriptor
|
|
1192
1206
|
*
|
|
1193
1207
|
* Class method that returns the Descriptor instance corresponding to this
|
|
1194
1208
|
* message class's type.
|
|
1209
|
+
*
|
|
1210
|
+
* @return [Descriptor]
|
|
1195
1211
|
*/
|
|
1196
1212
|
static VALUE Message_descriptor(VALUE klass) {
|
|
1197
1213
|
return rb_ivar_get(klass, descriptor_instancevar_interned);
|
|
@@ -1214,12 +1230,26 @@ VALUE build_class_from_descriptor(VALUE descriptor) {
|
|
|
1214
1230
|
return klass;
|
|
1215
1231
|
}
|
|
1216
1232
|
|
|
1233
|
+
/* ruby-doc: Enum
|
|
1234
|
+
*
|
|
1235
|
+
* There isn't really a concrete `Enum` module generated by Protobuf. Instead,
|
|
1236
|
+
* you can use this documentation as an indicator of methods that are defined on
|
|
1237
|
+
* each `Enum` module that is generated. E.g. if you have:
|
|
1238
|
+
*
|
|
1239
|
+
* enum my_enum_type
|
|
1240
|
+
*
|
|
1241
|
+
* in your Proto file and generate Ruby code, a module
|
|
1242
|
+
* called `MyEnumType` will be generated with the following methods available.
|
|
1243
|
+
*/
|
|
1244
|
+
|
|
1217
1245
|
/*
|
|
1218
|
-
*
|
|
1219
|
-
* Enum.lookup(number) => name
|
|
1246
|
+
* ruby-doc: Enum.lookup
|
|
1220
1247
|
*
|
|
1221
1248
|
* This module method, provided on each generated enum module, looks up an enum
|
|
1222
1249
|
* value by number and returns its name as a Ruby symbol, or nil if not found.
|
|
1250
|
+
*
|
|
1251
|
+
* @param number [Integer]
|
|
1252
|
+
* @return [String]
|
|
1223
1253
|
*/
|
|
1224
1254
|
static VALUE enum_lookup(VALUE self, VALUE number) {
|
|
1225
1255
|
int32_t num = NUM2INT(number);
|
|
@@ -1234,11 +1264,13 @@ static VALUE enum_lookup(VALUE self, VALUE number) {
|
|
|
1234
1264
|
}
|
|
1235
1265
|
|
|
1236
1266
|
/*
|
|
1237
|
-
*
|
|
1238
|
-
* Enum.resolve(name) => number
|
|
1267
|
+
* ruby-doc: Enum.resolve
|
|
1239
1268
|
*
|
|
1240
1269
|
* This module method, provided on each generated enum module, looks up an enum
|
|
1241
1270
|
* value by name (as a Ruby symbol) and returns its name, or nil if not found.
|
|
1271
|
+
*
|
|
1272
|
+
* @param name [String]
|
|
1273
|
+
* @return [Integer]
|
|
1242
1274
|
*/
|
|
1243
1275
|
static VALUE enum_resolve(VALUE self, VALUE sym) {
|
|
1244
1276
|
const char* name = rb_id2name(SYM2ID(sym));
|
|
@@ -1253,11 +1285,13 @@ static VALUE enum_resolve(VALUE self, VALUE sym) {
|
|
|
1253
1285
|
}
|
|
1254
1286
|
|
|
1255
1287
|
/*
|
|
1256
|
-
*
|
|
1257
|
-
* Enum.descriptor
|
|
1288
|
+
* ruby-doc: Enum.descriptor
|
|
1258
1289
|
*
|
|
1259
1290
|
* This module method, provided on each generated enum module, returns the
|
|
1260
|
-
* EnumDescriptor corresponding to this enum type.
|
|
1291
|
+
* {EnumDescriptor} corresponding to this enum type.
|
|
1292
|
+
*
|
|
1293
|
+
* @return [EnumDescriptor]
|
|
1294
|
+
*
|
|
1261
1295
|
*/
|
|
1262
1296
|
static VALUE enum_descriptor(VALUE self) {
|
|
1263
1297
|
return rb_ivar_get(self, descriptor_instancevar_interned);
|
|
@@ -183,7 +183,7 @@ const rb_data_type_t Arena_type = {
|
|
|
183
183
|
};
|
|
184
184
|
|
|
185
185
|
static void *ruby_upb_allocfunc(upb_alloc *alloc, void *ptr, size_t oldsize,
|
|
186
|
-
size_t size) {
|
|
186
|
+
size_t size, size_t *actual_size) {
|
|
187
187
|
if (size == 0) {
|
|
188
188
|
xfree(ptr);
|
|
189
189
|
return NULL;
|
|
@@ -286,7 +286,8 @@ VALUE ObjectCache_Get(const void *key) {
|
|
|
286
286
|
static VALUE Google_Protobuf_discard_unknown(VALUE self, VALUE msg_rb) {
|
|
287
287
|
const upb_MessageDef *m;
|
|
288
288
|
upb_Message *msg = Message_GetMutable(msg_rb, &m);
|
|
289
|
-
|
|
289
|
+
const upb_DefPool* ext_pool = upb_FileDef_Pool(upb_MessageDef_File(m));
|
|
290
|
+
if (!upb_Message_DiscardUnknown(msg, m, ext_pool, 128)) {
|
|
290
291
|
rb_raise(rb_eRuntimeError, "Messages nested too deeply.");
|
|
291
292
|
}
|
|
292
293
|
|
|
@@ -16,12 +16,6 @@
|
|
|
16
16
|
#undef NDEBUG
|
|
17
17
|
#endif
|
|
18
18
|
|
|
19
|
-
#include <ruby/version.h>
|
|
20
|
-
|
|
21
|
-
#if RUBY_API_VERSION_CODE < 20700
|
|
22
|
-
#error Protobuf requires Ruby >= 2.7
|
|
23
|
-
#endif
|
|
24
|
-
|
|
25
19
|
#include <assert.h> // Must be included after the NDEBUG logic above.
|
|
26
20
|
#include <ruby/encoding.h>
|
|
27
21
|
#include <ruby/vm.h>
|
|
@@ -103,6 +97,4 @@ void Protobuf_CheckNotFrozen(VALUE val, bool upb_frozen);
|
|
|
103
97
|
|
|
104
98
|
#define PBRUBY_MAX(x, y) (((x) > (y)) ? (x) : (y))
|
|
105
99
|
|
|
106
|
-
#define UPB_UNUSED(var) (void)var
|
|
107
|
-
|
|
108
100
|
#endif // __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__
|
|
@@ -192,13 +192,20 @@ static VALUE RepeatedField_subarray(RepeatedField* self, long beg, long len) {
|
|
|
192
192
|
return ary;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
/**
|
|
196
|
+
* ruby-doc: RepeatedField
|
|
197
|
+
*
|
|
198
|
+
*/
|
|
199
|
+
|
|
195
200
|
/*
|
|
196
|
-
*
|
|
197
|
-
* RepeatedField.each(&block)
|
|
201
|
+
* ruby-doc: RepeatedField#each
|
|
198
202
|
*
|
|
199
203
|
* Invokes the block once for each element of the repeated field. RepeatedField
|
|
200
204
|
* also includes Enumerable; combined with this method, the repeated field thus
|
|
201
205
|
* acts like an ordinary Ruby sequence.
|
|
206
|
+
*
|
|
207
|
+
* @yield [Object]
|
|
208
|
+
* @return [self]
|
|
202
209
|
*/
|
|
203
210
|
static VALUE RepeatedField_each(VALUE _self) {
|
|
204
211
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -214,10 +221,12 @@ static VALUE RepeatedField_each(VALUE _self) {
|
|
|
214
221
|
}
|
|
215
222
|
|
|
216
223
|
/*
|
|
217
|
-
*
|
|
218
|
-
* RepeatedField.[](index) => value
|
|
224
|
+
* ruby-doc: RepeatedField#[]
|
|
219
225
|
*
|
|
220
226
|
* Accesses the element at the given index. Returns nil on out-of-bounds
|
|
227
|
+
*
|
|
228
|
+
* @param index [Integer]
|
|
229
|
+
* @return [Object,nil]
|
|
221
230
|
*/
|
|
222
231
|
static VALUE RepeatedField_index(int argc, VALUE* argv, VALUE _self) {
|
|
223
232
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -262,11 +271,14 @@ static VALUE RepeatedField_index(int argc, VALUE* argv, VALUE _self) {
|
|
|
262
271
|
}
|
|
263
272
|
|
|
264
273
|
/*
|
|
265
|
-
*
|
|
266
|
-
* RepeatedField.[]=(index, value)
|
|
274
|
+
* ruby-doc: RepeatedField#[]=
|
|
267
275
|
*
|
|
268
276
|
* Sets the element at the given index. On out-of-bounds assignments, extends
|
|
269
277
|
* the array and fills the hole (if any) with default values.
|
|
278
|
+
*
|
|
279
|
+
* @param index [Integer]
|
|
280
|
+
* @param value [Object
|
|
281
|
+
* @return [nil]
|
|
270
282
|
*/
|
|
271
283
|
static VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val) {
|
|
272
284
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -296,10 +308,12 @@ static VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val) {
|
|
|
296
308
|
}
|
|
297
309
|
|
|
298
310
|
/*
|
|
299
|
-
*
|
|
300
|
-
* RepeatedField.push(value, ...)
|
|
311
|
+
* ruby-doc: RepeatedField#push
|
|
301
312
|
*
|
|
302
313
|
* Adds a new element to the repeated field.
|
|
314
|
+
*
|
|
315
|
+
* @param value [Object]
|
|
316
|
+
* @return [self]
|
|
303
317
|
*/
|
|
304
318
|
static VALUE RepeatedField_push_vararg(int argc, VALUE* argv, VALUE _self) {
|
|
305
319
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -317,10 +331,12 @@ static VALUE RepeatedField_push_vararg(int argc, VALUE* argv, VALUE _self) {
|
|
|
317
331
|
}
|
|
318
332
|
|
|
319
333
|
/*
|
|
320
|
-
*
|
|
321
|
-
* RepeatedField.<<(value)
|
|
334
|
+
* ruby-doc: RepeatedField#<<
|
|
322
335
|
*
|
|
323
336
|
* Adds a new element to the repeated field.
|
|
337
|
+
*
|
|
338
|
+
* @param value [Object]
|
|
339
|
+
* @return [self]
|
|
324
340
|
*/
|
|
325
341
|
static VALUE RepeatedField_push(VALUE _self, VALUE val) {
|
|
326
342
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -355,10 +371,12 @@ static VALUE RepeatedField_pop_one(VALUE _self) {
|
|
|
355
371
|
}
|
|
356
372
|
|
|
357
373
|
/*
|
|
358
|
-
*
|
|
359
|
-
* RepeatedField.replace(list)
|
|
374
|
+
* ruby-doc: RepeatedField#replace
|
|
360
375
|
*
|
|
361
376
|
* Replaces the contents of the repeated field with the given list of elements.
|
|
377
|
+
*
|
|
378
|
+
* @param list [Array]
|
|
379
|
+
* @return [Array]
|
|
362
380
|
*/
|
|
363
381
|
static VALUE RepeatedField_replace(VALUE _self, VALUE list) {
|
|
364
382
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -376,10 +394,11 @@ static VALUE RepeatedField_replace(VALUE _self, VALUE list) {
|
|
|
376
394
|
}
|
|
377
395
|
|
|
378
396
|
/*
|
|
379
|
-
*
|
|
380
|
-
* RepeatedField.clear
|
|
397
|
+
* ruby-doc: RepeatedField#clear
|
|
381
398
|
*
|
|
382
399
|
* Clears (removes all elements from) this repeated field.
|
|
400
|
+
*
|
|
401
|
+
* @return [self]
|
|
383
402
|
*/
|
|
384
403
|
static VALUE RepeatedField_clear(VALUE _self) {
|
|
385
404
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -389,10 +408,11 @@ static VALUE RepeatedField_clear(VALUE _self) {
|
|
|
389
408
|
}
|
|
390
409
|
|
|
391
410
|
/*
|
|
392
|
-
*
|
|
393
|
-
* RepeatedField.length
|
|
411
|
+
* ruby-doc: RepeatedField#length
|
|
394
412
|
*
|
|
395
413
|
* Returns the length of this repeated field.
|
|
414
|
+
*
|
|
415
|
+
* @return [Integer]
|
|
396
416
|
*/
|
|
397
417
|
static VALUE RepeatedField_length(VALUE _self) {
|
|
398
418
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -400,11 +420,12 @@ static VALUE RepeatedField_length(VALUE _self) {
|
|
|
400
420
|
}
|
|
401
421
|
|
|
402
422
|
/*
|
|
403
|
-
*
|
|
404
|
-
* RepeatedField.dup => repeated_field
|
|
423
|
+
* ruby-doc: RepeatedField#dup
|
|
405
424
|
*
|
|
406
425
|
* Duplicates this repeated field with a shallow copy. References to all
|
|
407
426
|
* non-primitive element objects (e.g., submessages) are shared.
|
|
427
|
+
*
|
|
428
|
+
* @return [RepeatedField]
|
|
408
429
|
*/
|
|
409
430
|
static VALUE RepeatedField_dup(VALUE _self) {
|
|
410
431
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -426,11 +447,12 @@ static VALUE RepeatedField_dup(VALUE _self) {
|
|
|
426
447
|
}
|
|
427
448
|
|
|
428
449
|
/*
|
|
429
|
-
*
|
|
430
|
-
* RepeatedField.to_ary => array
|
|
450
|
+
* ruby-doc: RepeatedField#to_ary
|
|
431
451
|
*
|
|
432
452
|
* Used when converted implicitly into array, e.g. compared to an Array.
|
|
433
453
|
* Also called as a fallback of Object#to_a
|
|
454
|
+
*
|
|
455
|
+
* @return [Array]
|
|
434
456
|
*/
|
|
435
457
|
VALUE RepeatedField_to_ary(VALUE _self) {
|
|
436
458
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -448,8 +470,7 @@ VALUE RepeatedField_to_ary(VALUE _self) {
|
|
|
448
470
|
}
|
|
449
471
|
|
|
450
472
|
/*
|
|
451
|
-
*
|
|
452
|
-
* RepeatedField.==(other) => boolean
|
|
473
|
+
* ruby-doc: RepeatedField#==
|
|
453
474
|
*
|
|
454
475
|
* Compares this repeated field to another. Repeated fields are equal if their
|
|
455
476
|
* element types are equal, their lengths are equal, and each element is equal.
|
|
@@ -459,6 +480,9 @@ VALUE RepeatedField_to_ary(VALUE _self) {
|
|
|
459
480
|
* Repeated fields with dissimilar element types are never equal, even if value
|
|
460
481
|
* comparison (for example, between integers and floats) would have otherwise
|
|
461
482
|
* indicated that every element has equal value.
|
|
483
|
+
*
|
|
484
|
+
* @param other [RepeatedField]
|
|
485
|
+
* @return [Boolean]
|
|
462
486
|
*/
|
|
463
487
|
VALUE RepeatedField_eq(VALUE _self, VALUE _other) {
|
|
464
488
|
RepeatedField* self;
|
|
@@ -495,12 +519,13 @@ VALUE RepeatedField_eq(VALUE _self, VALUE _other) {
|
|
|
495
519
|
}
|
|
496
520
|
|
|
497
521
|
/*
|
|
498
|
-
*
|
|
499
|
-
* RepeatedField.frozen? => bool
|
|
522
|
+
* ruby-doc: RepeatedField#frozen?
|
|
500
523
|
*
|
|
501
524
|
* Returns true if the repeated field is frozen in either Ruby or the underlying
|
|
502
525
|
* representation. Freezes the Ruby repeated field object if it is not already
|
|
503
526
|
* frozen in Ruby but it is frozen in the underlying representation.
|
|
527
|
+
*
|
|
528
|
+
* @return [Boolean]
|
|
504
529
|
*/
|
|
505
530
|
VALUE RepeatedField_frozen(VALUE _self) {
|
|
506
531
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -515,11 +540,12 @@ VALUE RepeatedField_frozen(VALUE _self) {
|
|
|
515
540
|
}
|
|
516
541
|
|
|
517
542
|
/*
|
|
518
|
-
*
|
|
519
|
-
* RepeatedField.freeze => self
|
|
543
|
+
* ruby-doc: RepeatedField#freeze
|
|
520
544
|
*
|
|
521
545
|
* Freezes the repeated field object. We have to intercept this so we can freeze
|
|
522
546
|
* the underlying representation, not just the Ruby wrapper.
|
|
547
|
+
*
|
|
548
|
+
* @return [self]
|
|
523
549
|
*/
|
|
524
550
|
VALUE RepeatedField_freeze(VALUE _self) {
|
|
525
551
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -541,10 +567,11 @@ VALUE RepeatedField_freeze(VALUE _self) {
|
|
|
541
567
|
}
|
|
542
568
|
|
|
543
569
|
/*
|
|
544
|
-
*
|
|
545
|
-
* RepeatedField.hash => hash_value
|
|
570
|
+
* ruby-doc: RepeatedField#hash
|
|
546
571
|
*
|
|
547
572
|
* Returns a hash value computed from this repeated field's elements.
|
|
573
|
+
*
|
|
574
|
+
* @return [Integer]
|
|
548
575
|
*/
|
|
549
576
|
VALUE RepeatedField_hash(VALUE _self) {
|
|
550
577
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|
|
@@ -560,12 +587,14 @@ VALUE RepeatedField_hash(VALUE _self) {
|
|
|
560
587
|
}
|
|
561
588
|
|
|
562
589
|
/*
|
|
563
|
-
*
|
|
564
|
-
* RepeatedField.+(other) => repeated field
|
|
590
|
+
* ruby-doc: RepeatedField#+
|
|
565
591
|
*
|
|
566
592
|
* Returns a new repeated field that contains the concatenated list of this
|
|
567
593
|
* repeated field's elements and other's elements. The other (second) list may
|
|
568
594
|
* be either another repeated field or a Ruby array.
|
|
595
|
+
*
|
|
596
|
+
* @param other [Array,RepeatedField]
|
|
597
|
+
* @return [RepeatedField]
|
|
569
598
|
*/
|
|
570
599
|
VALUE RepeatedField_plus(VALUE _self, VALUE list) {
|
|
571
600
|
VALUE dupped_ = RepeatedField_dup(_self);
|
|
@@ -605,10 +634,12 @@ VALUE RepeatedField_plus(VALUE _self, VALUE list) {
|
|
|
605
634
|
}
|
|
606
635
|
|
|
607
636
|
/*
|
|
608
|
-
*
|
|
609
|
-
* RepeatedField.concat(other) => self
|
|
637
|
+
* ruby-doc: RepeatedField#concat
|
|
610
638
|
*
|
|
611
639
|
* concats the passed in array to self. Returns a Ruby array.
|
|
640
|
+
*
|
|
641
|
+
* @param other [RepeatedField]
|
|
642
|
+
* @return [Array]
|
|
612
643
|
*/
|
|
613
644
|
VALUE RepeatedField_concat(VALUE _self, VALUE list) {
|
|
614
645
|
int i;
|
|
@@ -621,15 +652,21 @@ VALUE RepeatedField_concat(VALUE _self, VALUE list) {
|
|
|
621
652
|
}
|
|
622
653
|
|
|
623
654
|
/*
|
|
624
|
-
*
|
|
625
|
-
* RepeatedField.new(type, type_class = nil, initial_elems = [])
|
|
655
|
+
* ruby-doc: RepeatedField#initialize
|
|
626
656
|
*
|
|
627
657
|
* Creates a new repeated field. The provided type must be a Ruby symbol, and
|
|
628
|
-
* can take on the same values as those accepted by FieldDescriptor#type
|
|
658
|
+
* can take on the same values as those accepted by {FieldDescriptor#type=}. If
|
|
629
659
|
* the type is :message or :enum, type_class must be non-nil, and must be the
|
|
630
|
-
* Ruby class or module returned by Descriptor#msgclass or
|
|
631
|
-
* EnumDescriptor#enummodule, respectively. An initial list of elements may
|
|
632
|
-
* be provided.
|
|
660
|
+
* Ruby class or module returned by {Descriptor#msgclass} or
|
|
661
|
+
* {EnumDescriptor#enummodule}, respectively. An initial list of elements may
|
|
662
|
+
* also be provided.
|
|
663
|
+
*
|
|
664
|
+
* @param type [Symbol]
|
|
665
|
+
* @param type_class [Class<AbstractMessage>, Module]
|
|
666
|
+
* @paramdefault type_class nil
|
|
667
|
+
* @param initial_elems [Array]
|
|
668
|
+
* @paramdefault initial_elems []
|
|
669
|
+
* @return [RepeatedField]
|
|
633
670
|
*/
|
|
634
671
|
VALUE RepeatedField_init(int argc, VALUE* argv, VALUE _self) {
|
|
635
672
|
RepeatedField* self = ruby_to_RepeatedField(_self);
|