google-protobuf 4.27.3 → 4.30.0
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 +32 -14
- data/ext/google/protobuf_c/defs.c +162 -4
- data/ext/google/protobuf_c/extconf.rb +12 -0
- data/ext/google/protobuf_c/glue.c +63 -0
- data/ext/google/protobuf_c/map.c +72 -20
- data/ext/google/protobuf_c/map.h +6 -2
- data/ext/google/protobuf_c/message.c +88 -41
- data/ext/google/protobuf_c/message.h +1 -1
- data/ext/google/protobuf_c/protobuf.c +13 -12
- data/ext/google/protobuf_c/protobuf.h +3 -7
- data/ext/google/protobuf_c/repeated_field.c +61 -17
- data/ext/google/protobuf_c/repeated_field.h +5 -1
- data/ext/google/protobuf_c/ruby-upb.c +6965 -5525
- data/ext/google/protobuf_c/ruby-upb.h +5056 -3492
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +15 -275
- 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/descriptor_pb.rb +2 -1
- data/lib/google/protobuf/ffi/descriptor.rb +11 -2
- data/lib/google/protobuf/ffi/enum_descriptor.rb +10 -0
- data/lib/google/protobuf/ffi/ffi.rb +4 -0
- data/lib/google/protobuf/ffi/field_descriptor.rb +10 -0
- data/lib/google/protobuf/ffi/file_descriptor.rb +10 -0
- data/lib/google/protobuf/ffi/internal/arena.rb +0 -6
- data/lib/google/protobuf/ffi/internal/convert.rb +9 -6
- data/lib/google/protobuf/ffi/map.rb +45 -21
- data/lib/google/protobuf/ffi/message.rb +187 -63
- 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/repeated_field.rb +42 -16
- data/lib/google/protobuf/ffi/service_descriptor.rb +11 -1
- data/lib/google/protobuf_ffi.rb +2 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b0c5b89b191447ed60c0da69ce8561d209c3bfe6ba7e3f61808c0b16a16a197
|
4
|
+
data.tar.gz: 6fb9eb0af4f57a66c9cc5f518933df913b5b5108cea910a26465268c69b4a3ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2196f0dd5263db5043a07622d2af9ec4cbc340f3c36e5f88d37ee4c54fff0672a0245baaa2c59ceecd1bfb141f5a4db9b85c97c270dd7a1fa06aff29d291fc22
|
7
|
+
data.tar.gz: 11dbe8430a49dafcc5b46b9f9fdd88e1a37879bc74f30e2464570949a84d6b2c23c987cca7c6893e5d9d26dbacca5a6cb4f6f794fa48d3e16a57c038f89a6596
|
@@ -104,6 +104,34 @@ unknownval:
|
|
104
104
|
rb_raise(rb_eRangeError, "Unknown symbol value for enum field '%s'.", name);
|
105
105
|
}
|
106
106
|
|
107
|
+
VALUE Convert_CheckStringUtf8(VALUE str) {
|
108
|
+
VALUE utf8 = rb_enc_from_encoding(rb_utf8_encoding());
|
109
|
+
|
110
|
+
if (rb_obj_encoding(str) == utf8) {
|
111
|
+
// Note: Just because a string is marked as having UTF-8 encoding does
|
112
|
+
// not mean that it is *valid* UTF-8. We have to check separately
|
113
|
+
// whether it is valid.
|
114
|
+
if (rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN) {
|
115
|
+
VALUE exc = rb_const_get_at(
|
116
|
+
rb_cEncoding, rb_intern("InvalidByteSequenceError"));
|
117
|
+
rb_raise(exc, "String is invalid UTF-8");
|
118
|
+
}
|
119
|
+
} else {
|
120
|
+
// Note: this will not duplicate underlying string data unless
|
121
|
+
// necessary.
|
122
|
+
//
|
123
|
+
// This will throw an exception if the conversion cannot be performed:
|
124
|
+
// - Encoding::UndefinedConversionError if certain characters cannot be
|
125
|
+
// converted to UTF-8.
|
126
|
+
// - Encoding::InvalidByteSequenceError if certain characters were invalid
|
127
|
+
// in the source encoding.
|
128
|
+
str = rb_str_encode(str, utf8, 0, Qnil);
|
129
|
+
PBRUBY_ASSERT(rb_enc_str_coderange(str) != ENC_CODERANGE_BROKEN);
|
130
|
+
}
|
131
|
+
|
132
|
+
return str;
|
133
|
+
}
|
134
|
+
|
107
135
|
upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
|
108
136
|
TypeInfo type_info, upb_Arena* arena) {
|
109
137
|
upb_MessageValue ret;
|
@@ -137,8 +165,7 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
|
|
137
165
|
}
|
138
166
|
break;
|
139
167
|
}
|
140
|
-
case kUpb_CType_String:
|
141
|
-
VALUE utf8 = rb_enc_from_encoding(rb_utf8_encoding());
|
168
|
+
case kUpb_CType_String:
|
142
169
|
if (rb_obj_class(value) == rb_cSymbol) {
|
143
170
|
value = rb_funcall(value, rb_intern("to_s"), 0);
|
144
171
|
} else if (!rb_obj_is_kind_of(value, rb_cString)) {
|
@@ -147,19 +174,9 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
|
|
147
174
|
rb_class2name(CLASS_OF(value)));
|
148
175
|
}
|
149
176
|
|
150
|
-
|
151
|
-
// Note: this will not duplicate underlying string data unless
|
152
|
-
// necessary.
|
153
|
-
value = rb_str_encode(value, utf8, 0, Qnil);
|
154
|
-
|
155
|
-
if (rb_enc_str_coderange(value) == ENC_CODERANGE_BROKEN) {
|
156
|
-
rb_raise(rb_eEncodingError, "String is invalid UTF-8");
|
157
|
-
}
|
158
|
-
}
|
159
|
-
|
177
|
+
value = Convert_CheckStringUtf8(value);
|
160
178
|
ret.str_val = Convert_StringData(value, arena);
|
161
179
|
break;
|
162
|
-
}
|
163
180
|
case kUpb_CType_Bytes: {
|
164
181
|
VALUE bytes = rb_enc_from_encoding(rb_ascii8bit_encoding());
|
165
182
|
if (rb_obj_class(value) != rb_cString) {
|
@@ -204,7 +221,8 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
|
|
204
221
|
ret.uint64_val = NUM2ULL(value);
|
205
222
|
break;
|
206
223
|
default:
|
207
|
-
|
224
|
+
rb_raise(cTypeError, "Convert_RubyToUpb(): Unexpected type %d",
|
225
|
+
(int)type_info.type);
|
208
226
|
}
|
209
227
|
break;
|
210
228
|
default:
|
@@ -7,7 +7,6 @@
|
|
7
7
|
|
8
8
|
#include <ctype.h>
|
9
9
|
#include <errno.h>
|
10
|
-
#include <ruby/version.h>
|
11
10
|
|
12
11
|
#include "convert.h"
|
13
12
|
#include "message.h"
|
@@ -147,8 +146,8 @@ VALUE DescriptorPool_add_serialized_file(VALUE _self,
|
|
147
146
|
* call-seq:
|
148
147
|
* DescriptorPool.lookup(name) => descriptor
|
149
148
|
*
|
150
|
-
* Finds a Descriptor, EnumDescriptor or
|
151
|
-
* or nil if none exists with the given name.
|
149
|
+
* Finds a Descriptor, EnumDescriptor, FieldDescriptor or ServiceDescriptor by
|
150
|
+
* name and returns it, or nil if none exists with the given name.
|
152
151
|
*/
|
153
152
|
static VALUE DescriptorPool_lookup(VALUE _self, VALUE name) {
|
154
153
|
DescriptorPool* self = ruby_to_DescriptorPool(_self);
|
@@ -452,6 +451,27 @@ static VALUE Descriptor_options(VALUE _self) {
|
|
452
451
|
return message_options;
|
453
452
|
}
|
454
453
|
|
454
|
+
/*
|
455
|
+
* call-seq:
|
456
|
+
* Descriptor.to_proto => DescriptorProto
|
457
|
+
*
|
458
|
+
* Returns the `DescriptorProto` of this `Descriptor`.
|
459
|
+
*/
|
460
|
+
static VALUE Descriptor_to_proto(VALUE _self) {
|
461
|
+
Descriptor* self = ruby_to_Descriptor(_self);
|
462
|
+
upb_Arena* arena = upb_Arena_New();
|
463
|
+
google_protobuf_DescriptorProto* proto =
|
464
|
+
upb_MessageDef_ToProto(self->msgdef, arena);
|
465
|
+
size_t size;
|
466
|
+
const char* serialized =
|
467
|
+
google_protobuf_DescriptorProto_serialize(proto, arena, &size);
|
468
|
+
VALUE proto_class = rb_path2class("Google::Protobuf::DescriptorProto");
|
469
|
+
VALUE proto_rb =
|
470
|
+
Message_decode_bytes(size, serialized, 0, proto_class, false);
|
471
|
+
upb_Arena_Free(arena);
|
472
|
+
return proto_rb;
|
473
|
+
}
|
474
|
+
|
455
475
|
static void Descriptor_register(VALUE module) {
|
456
476
|
VALUE klass = rb_define_class_under(module, "Descriptor", rb_cObject);
|
457
477
|
rb_define_alloc_func(klass, Descriptor_alloc);
|
@@ -464,6 +484,7 @@ static void Descriptor_register(VALUE module) {
|
|
464
484
|
rb_define_method(klass, "name", Descriptor_name, 0);
|
465
485
|
rb_define_method(klass, "file_descriptor", Descriptor_file_descriptor, 0);
|
466
486
|
rb_define_method(klass, "options", Descriptor_options, 0);
|
487
|
+
rb_define_method(klass, "to_proto", Descriptor_to_proto, 0);
|
467
488
|
rb_include_module(klass, rb_mEnumerable);
|
468
489
|
rb_gc_register_address(&cDescriptor);
|
469
490
|
cDescriptor = klass;
|
@@ -559,12 +580,37 @@ static VALUE FileDescriptor_options(VALUE _self) {
|
|
559
580
|
return file_options;
|
560
581
|
}
|
561
582
|
|
583
|
+
/*
|
584
|
+
* call-seq:
|
585
|
+
* FileDescriptor.to_proto => FileDescriptorProto
|
586
|
+
*
|
587
|
+
* Returns the `FileDescriptorProto` of this `FileDescriptor`.
|
588
|
+
*/
|
589
|
+
static VALUE FileDescriptor_to_proto(VALUE _self) {
|
590
|
+
FileDescriptor* self = ruby_to_FileDescriptor(_self);
|
591
|
+
upb_Arena* arena = upb_Arena_New();
|
592
|
+
google_protobuf_FileDescriptorProto* file_proto =
|
593
|
+
upb_FileDef_ToProto(self->filedef, arena);
|
594
|
+
|
595
|
+
size_t size;
|
596
|
+
const char* serialized =
|
597
|
+
google_protobuf_FileDescriptorProto_serialize(file_proto, arena, &size);
|
598
|
+
|
599
|
+
VALUE file_proto_class =
|
600
|
+
rb_path2class("Google::Protobuf::FileDescriptorProto");
|
601
|
+
VALUE proto_rb =
|
602
|
+
Message_decode_bytes(size, serialized, 0, file_proto_class, false);
|
603
|
+
upb_Arena_Free(arena);
|
604
|
+
return proto_rb;
|
605
|
+
}
|
606
|
+
|
562
607
|
static void FileDescriptor_register(VALUE module) {
|
563
608
|
VALUE klass = rb_define_class_under(module, "FileDescriptor", rb_cObject);
|
564
609
|
rb_define_alloc_func(klass, FileDescriptor_alloc);
|
565
610
|
rb_define_method(klass, "initialize", FileDescriptor_initialize, 3);
|
566
611
|
rb_define_method(klass, "name", FileDescriptor_name, 0);
|
567
612
|
rb_define_method(klass, "options", FileDescriptor_options, 0);
|
613
|
+
rb_define_method(klass, "to_proto", FileDescriptor_to_proto, 0);
|
568
614
|
rb_gc_register_address(&cFileDescriptor);
|
569
615
|
cFileDescriptor = klass;
|
570
616
|
}
|
@@ -726,7 +772,7 @@ static VALUE FieldDescriptor__type(VALUE _self) {
|
|
726
772
|
static VALUE FieldDescriptor_default(VALUE _self) {
|
727
773
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
728
774
|
const upb_FieldDef* f = self->fielddef;
|
729
|
-
upb_MessageValue default_val =
|
775
|
+
upb_MessageValue default_val = upb_MessageValue_Zero();
|
730
776
|
if (upb_FieldDef_IsSubMessage(f)) {
|
731
777
|
return Qnil;
|
732
778
|
} else if (!upb_FieldDef_IsRepeated(f)) {
|
@@ -957,6 +1003,27 @@ static VALUE FieldDescriptor_options(VALUE _self) {
|
|
957
1003
|
return field_options;
|
958
1004
|
}
|
959
1005
|
|
1006
|
+
/*
|
1007
|
+
* call-seq:
|
1008
|
+
* FieldDescriptor.to_proto => FieldDescriptorProto
|
1009
|
+
*
|
1010
|
+
* Returns the `FieldDescriptorProto` of this `FieldDescriptor`.
|
1011
|
+
*/
|
1012
|
+
static VALUE FieldDescriptor_to_proto(VALUE _self) {
|
1013
|
+
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
1014
|
+
upb_Arena* arena = upb_Arena_New();
|
1015
|
+
google_protobuf_FieldDescriptorProto* proto =
|
1016
|
+
upb_FieldDef_ToProto(self->fielddef, arena);
|
1017
|
+
size_t size;
|
1018
|
+
const char* serialized =
|
1019
|
+
google_protobuf_FieldDescriptorProto_serialize(proto, arena, &size);
|
1020
|
+
VALUE proto_class = rb_path2class("Google::Protobuf::FieldDescriptorProto");
|
1021
|
+
VALUE proto_rb =
|
1022
|
+
Message_decode_bytes(size, serialized, 0, proto_class, false);
|
1023
|
+
upb_Arena_Free(arena);
|
1024
|
+
return proto_rb;
|
1025
|
+
}
|
1026
|
+
|
960
1027
|
static void FieldDescriptor_register(VALUE module) {
|
961
1028
|
VALUE klass = rb_define_class_under(module, "FieldDescriptor", rb_cObject);
|
962
1029
|
rb_define_alloc_func(klass, FieldDescriptor_alloc);
|
@@ -976,6 +1043,7 @@ static void FieldDescriptor_register(VALUE module) {
|
|
976
1043
|
rb_define_method(klass, "get", FieldDescriptor_get, 1);
|
977
1044
|
rb_define_method(klass, "set", FieldDescriptor_set, 2);
|
978
1045
|
rb_define_method(klass, "options", FieldDescriptor_options, 0);
|
1046
|
+
rb_define_method(klass, "to_proto", FieldDescriptor_to_proto, 0);
|
979
1047
|
rb_gc_register_address(&cFieldDescriptor);
|
980
1048
|
cFieldDescriptor = klass;
|
981
1049
|
}
|
@@ -1094,6 +1162,27 @@ static VALUE OneOfDescriptor_options(VALUE _self) {
|
|
1094
1162
|
return oneof_options;
|
1095
1163
|
}
|
1096
1164
|
|
1165
|
+
/*
|
1166
|
+
* call-seq:
|
1167
|
+
* OneofDescriptor.to_proto => OneofDescriptorProto
|
1168
|
+
*
|
1169
|
+
* Returns the `OneofDescriptorProto` of this `OneofDescriptor`.
|
1170
|
+
*/
|
1171
|
+
static VALUE OneOfDescriptor_to_proto(VALUE _self) {
|
1172
|
+
OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
|
1173
|
+
upb_Arena* arena = upb_Arena_New();
|
1174
|
+
google_protobuf_OneofDescriptorProto* proto =
|
1175
|
+
upb_OneofDef_ToProto(self->oneofdef, arena);
|
1176
|
+
size_t size;
|
1177
|
+
const char* serialized =
|
1178
|
+
google_protobuf_OneofDescriptorProto_serialize(proto, arena, &size);
|
1179
|
+
VALUE proto_class = rb_path2class("Google::Protobuf::OneofDescriptorProto");
|
1180
|
+
VALUE proto_rb =
|
1181
|
+
Message_decode_bytes(size, serialized, 0, proto_class, false);
|
1182
|
+
upb_Arena_Free(arena);
|
1183
|
+
return proto_rb;
|
1184
|
+
}
|
1185
|
+
|
1097
1186
|
static void OneofDescriptor_register(VALUE module) {
|
1098
1187
|
VALUE klass = rb_define_class_under(module, "OneofDescriptor", rb_cObject);
|
1099
1188
|
rb_define_alloc_func(klass, OneofDescriptor_alloc);
|
@@ -1101,6 +1190,7 @@ static void OneofDescriptor_register(VALUE module) {
|
|
1101
1190
|
rb_define_method(klass, "name", OneofDescriptor_name, 0);
|
1102
1191
|
rb_define_method(klass, "each", OneofDescriptor_each, 0);
|
1103
1192
|
rb_define_method(klass, "options", OneOfDescriptor_options, 0);
|
1193
|
+
rb_define_method(klass, "to_proto", OneOfDescriptor_to_proto, 0);
|
1104
1194
|
rb_include_module(klass, rb_mEnumerable);
|
1105
1195
|
rb_gc_register_address(&cOneofDescriptor);
|
1106
1196
|
cOneofDescriptor = klass;
|
@@ -1299,6 +1389,29 @@ static VALUE EnumDescriptor_options(VALUE _self) {
|
|
1299
1389
|
return enum_options;
|
1300
1390
|
}
|
1301
1391
|
|
1392
|
+
/*
|
1393
|
+
* call-seq:
|
1394
|
+
* EnumDescriptor.to_proto => EnumDescriptorProto
|
1395
|
+
*
|
1396
|
+
* Returns the `EnumDescriptorProto` of this `EnumDescriptor`.
|
1397
|
+
*/
|
1398
|
+
static VALUE EnumDescriptor_to_proto(VALUE _self) {
|
1399
|
+
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
1400
|
+
upb_Arena* arena = upb_Arena_New();
|
1401
|
+
google_protobuf_EnumDescriptorProto* proto =
|
1402
|
+
upb_EnumDef_ToProto(self->enumdef, arena);
|
1403
|
+
|
1404
|
+
size_t size;
|
1405
|
+
const char* serialized =
|
1406
|
+
google_protobuf_EnumDescriptorProto_serialize(proto, arena, &size);
|
1407
|
+
|
1408
|
+
VALUE proto_class = rb_path2class("Google::Protobuf::EnumDescriptorProto");
|
1409
|
+
VALUE proto_rb =
|
1410
|
+
Message_decode_bytes(size, serialized, 0, proto_class, false);
|
1411
|
+
upb_Arena_Free(arena);
|
1412
|
+
return proto_rb;
|
1413
|
+
}
|
1414
|
+
|
1302
1415
|
static void EnumDescriptor_register(VALUE module) {
|
1303
1416
|
VALUE klass = rb_define_class_under(module, "EnumDescriptor", rb_cObject);
|
1304
1417
|
rb_define_alloc_func(klass, EnumDescriptor_alloc);
|
@@ -1311,6 +1424,7 @@ static void EnumDescriptor_register(VALUE module) {
|
|
1311
1424
|
rb_define_method(klass, "file_descriptor", EnumDescriptor_file_descriptor, 0);
|
1312
1425
|
rb_define_method(klass, "is_closed?", EnumDescriptor_is_closed, 0);
|
1313
1426
|
rb_define_method(klass, "options", EnumDescriptor_options, 0);
|
1427
|
+
rb_define_method(klass, "to_proto", EnumDescriptor_to_proto, 0);
|
1314
1428
|
rb_include_module(klass, rb_mEnumerable);
|
1315
1429
|
rb_gc_register_address(&cEnumDescriptor);
|
1316
1430
|
cEnumDescriptor = klass;
|
@@ -1439,6 +1553,27 @@ static VALUE ServiceDescriptor_options(VALUE _self) {
|
|
1439
1553
|
return service_options;
|
1440
1554
|
}
|
1441
1555
|
|
1556
|
+
/*
|
1557
|
+
* call-seq:
|
1558
|
+
* ServiceDescriptor.to_proto => ServiceDescriptorProto
|
1559
|
+
*
|
1560
|
+
* Returns the `ServiceDescriptorProto` of this `ServiceDescriptor`.
|
1561
|
+
*/
|
1562
|
+
static VALUE ServiceDescriptor_to_proto(VALUE _self) {
|
1563
|
+
ServiceDescriptor* self = ruby_to_ServiceDescriptor(_self);
|
1564
|
+
upb_Arena* arena = upb_Arena_New();
|
1565
|
+
google_protobuf_ServiceDescriptorProto* proto =
|
1566
|
+
upb_ServiceDef_ToProto(self->servicedef, arena);
|
1567
|
+
size_t size;
|
1568
|
+
const char* serialized =
|
1569
|
+
google_protobuf_ServiceDescriptorProto_serialize(proto, arena, &size);
|
1570
|
+
VALUE proto_class = rb_path2class("Google::Protobuf::ServiceDescriptorProto");
|
1571
|
+
VALUE proto_rb =
|
1572
|
+
Message_decode_bytes(size, serialized, 0, proto_class, false);
|
1573
|
+
upb_Arena_Free(arena);
|
1574
|
+
return proto_rb;
|
1575
|
+
}
|
1576
|
+
|
1442
1577
|
static void ServiceDescriptor_register(VALUE module) {
|
1443
1578
|
VALUE klass = rb_define_class_under(module, "ServiceDescriptor", rb_cObject);
|
1444
1579
|
rb_define_alloc_func(klass, ServiceDescriptor_alloc);
|
@@ -1448,6 +1583,7 @@ static void ServiceDescriptor_register(VALUE module) {
|
|
1448
1583
|
rb_define_method(klass, "file_descriptor", ServiceDescriptor_file_descriptor,
|
1449
1584
|
0);
|
1450
1585
|
rb_define_method(klass, "options", ServiceDescriptor_options, 0);
|
1586
|
+
rb_define_method(klass, "to_proto", ServiceDescriptor_to_proto, 0);
|
1451
1587
|
rb_include_module(klass, rb_mEnumerable);
|
1452
1588
|
rb_gc_register_address(&cServiceDescriptor);
|
1453
1589
|
cServiceDescriptor = klass;
|
@@ -1581,6 +1717,27 @@ static VALUE MethodDescriptor_client_streaming(VALUE _self) {
|
|
1581
1717
|
return upb_MethodDef_ClientStreaming(self->methoddef) ? Qtrue : Qfalse;
|
1582
1718
|
}
|
1583
1719
|
|
1720
|
+
/*
|
1721
|
+
* call-seq:
|
1722
|
+
* MethodDescriptor.to_proto => MethodDescriptorProto
|
1723
|
+
*
|
1724
|
+
* Returns the `MethodDescriptorProto` of this `MethodDescriptor`.
|
1725
|
+
*/
|
1726
|
+
static VALUE MethodDescriptor_to_proto(VALUE _self) {
|
1727
|
+
MethodDescriptor* self = ruby_to_MethodDescriptor(_self);
|
1728
|
+
upb_Arena* arena = upb_Arena_New();
|
1729
|
+
google_protobuf_MethodDescriptorProto* proto =
|
1730
|
+
upb_MethodDef_ToProto(self->methoddef, arena);
|
1731
|
+
size_t size;
|
1732
|
+
const char* serialized =
|
1733
|
+
google_protobuf_MethodDescriptorProto_serialize(proto, arena, &size);
|
1734
|
+
VALUE proto_class = rb_path2class("Google::Protobuf::MethodDescriptorProto");
|
1735
|
+
VALUE proto_rb =
|
1736
|
+
Message_decode_bytes(size, serialized, 0, proto_class, false);
|
1737
|
+
upb_Arena_Free(arena);
|
1738
|
+
return proto_rb;
|
1739
|
+
}
|
1740
|
+
|
1584
1741
|
/*
|
1585
1742
|
* call-seq:
|
1586
1743
|
* MethodDescriptor.server_streaming => bool
|
@@ -1604,6 +1761,7 @@ static void MethodDescriptor_register(VALUE module) {
|
|
1604
1761
|
0);
|
1605
1762
|
rb_define_method(klass, "server_streaming", MethodDescriptor_server_streaming,
|
1606
1763
|
0);
|
1764
|
+
rb_define_method(klass, "to_proto", MethodDescriptor_to_proto, 0);
|
1607
1765
|
rb_gc_register_address(&cMethodDescriptor);
|
1608
1766
|
cMethodDescriptor = klass;
|
1609
1767
|
}
|
@@ -6,6 +6,18 @@ ext_name = "google/protobuf_c"
|
|
6
6
|
|
7
7
|
dir_config(ext_name)
|
8
8
|
|
9
|
+
if ENV["CC"]
|
10
|
+
RbConfig::CONFIG["CC"] = RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"]
|
11
|
+
end
|
12
|
+
|
13
|
+
if ENV["CXX"]
|
14
|
+
RbConfig::CONFIG["CXX"] = RbConfig::MAKEFILE_CONFIG["CXX"] = ENV["CXX"]
|
15
|
+
end
|
16
|
+
|
17
|
+
if ENV["LD"]
|
18
|
+
RbConfig::CONFIG["LD"] = RbConfig::MAKEFILE_CONFIG["LD"] = ENV["LD"]
|
19
|
+
end
|
20
|
+
|
9
21
|
if RUBY_PLATFORM =~ /darwin/ || RUBY_PLATFORM =~ /linux/ || RUBY_PLATFORM =~ /freebsd/
|
10
22
|
$CFLAGS += " -std=gnu99 -O3 -DNDEBUG -fvisibility=hidden -Wall -Wsign-compare -Wno-declaration-after-statement"
|
11
23
|
else
|
@@ -26,6 +26,15 @@ char* EnumDescriptor_serialized_options(const upb_EnumDef* enumdef,
|
|
26
26
|
return serialized;
|
27
27
|
}
|
28
28
|
|
29
|
+
char* EnumDescriptor_serialized_to_proto(const upb_EnumDef* enumdef,
|
30
|
+
size_t* size, upb_Arena* arena) {
|
31
|
+
const google_protobuf_EnumDescriptorProto* file_proto =
|
32
|
+
upb_EnumDef_ToProto(enumdef, arena);
|
33
|
+
char* serialized =
|
34
|
+
google_protobuf_EnumDescriptorProto_serialize(file_proto, arena, size);
|
35
|
+
return serialized;
|
36
|
+
}
|
37
|
+
|
29
38
|
char* FileDescriptor_serialized_options(const upb_FileDef* filedef,
|
30
39
|
size_t* size, upb_Arena* arena) {
|
31
40
|
const google_protobuf_FileOptions* opts = upb_FileDef_Options(filedef);
|
@@ -33,6 +42,15 @@ char* FileDescriptor_serialized_options(const upb_FileDef* filedef,
|
|
33
42
|
return serialized;
|
34
43
|
}
|
35
44
|
|
45
|
+
char* FileDescriptor_serialized_to_proto(const upb_FileDef* filedef,
|
46
|
+
size_t* size, upb_Arena* arena) {
|
47
|
+
const google_protobuf_FileDescriptorProto* file_proto =
|
48
|
+
upb_FileDef_ToProto(filedef, arena);
|
49
|
+
char* serialized =
|
50
|
+
google_protobuf_FileDescriptorProto_serialize(file_proto, arena, size);
|
51
|
+
return serialized;
|
52
|
+
}
|
53
|
+
|
36
54
|
char* Descriptor_serialized_options(const upb_MessageDef* msgdef, size_t* size,
|
37
55
|
upb_Arena* arena) {
|
38
56
|
const google_protobuf_MessageOptions* opts = upb_MessageDef_Options(msgdef);
|
@@ -41,6 +59,15 @@ char* Descriptor_serialized_options(const upb_MessageDef* msgdef, size_t* size,
|
|
41
59
|
return serialized;
|
42
60
|
}
|
43
61
|
|
62
|
+
char* Descriptor_serialized_to_proto(const upb_MessageDef* msgdef, size_t* size,
|
63
|
+
upb_Arena* arena) {
|
64
|
+
const google_protobuf_DescriptorProto* proto =
|
65
|
+
upb_MessageDef_ToProto(msgdef, arena);
|
66
|
+
char* serialized =
|
67
|
+
google_protobuf_DescriptorProto_serialize(proto, arena, size);
|
68
|
+
return serialized;
|
69
|
+
}
|
70
|
+
|
44
71
|
char* OneOfDescriptor_serialized_options(const upb_OneofDef* oneofdef,
|
45
72
|
size_t* size, upb_Arena* arena) {
|
46
73
|
const google_protobuf_OneofOptions* opts = upb_OneofDef_Options(oneofdef);
|
@@ -48,6 +75,15 @@ char* OneOfDescriptor_serialized_options(const upb_OneofDef* oneofdef,
|
|
48
75
|
return serialized;
|
49
76
|
}
|
50
77
|
|
78
|
+
char* OneOfDescriptor_serialized_to_proto(const upb_OneofDef* oneofdef,
|
79
|
+
size_t* size, upb_Arena* arena) {
|
80
|
+
const google_protobuf_OneofDescriptorProto* proto =
|
81
|
+
upb_OneofDef_ToProto(oneofdef, arena);
|
82
|
+
char* serialized =
|
83
|
+
google_protobuf_OneofDescriptorProto_serialize(proto, arena, size);
|
84
|
+
return serialized;
|
85
|
+
}
|
86
|
+
|
51
87
|
char* FieldDescriptor_serialized_options(const upb_FieldDef* fielddef,
|
52
88
|
size_t* size, upb_Arena* arena) {
|
53
89
|
const google_protobuf_FieldOptions* opts = upb_FieldDef_Options(fielddef);
|
@@ -55,6 +91,15 @@ char* FieldDescriptor_serialized_options(const upb_FieldDef* fielddef,
|
|
55
91
|
return serialized;
|
56
92
|
}
|
57
93
|
|
94
|
+
char* FieldDescriptor_serialized_to_proto(const upb_FieldDef* fieldef,
|
95
|
+
size_t* size, upb_Arena* arena) {
|
96
|
+
const google_protobuf_FieldDescriptorProto* proto =
|
97
|
+
upb_FieldDef_ToProto(fieldef, arena);
|
98
|
+
char* serialized =
|
99
|
+
google_protobuf_FieldDescriptorProto_serialize(proto, arena, size);
|
100
|
+
return serialized;
|
101
|
+
}
|
102
|
+
|
58
103
|
char* ServiceDescriptor_serialized_options(const upb_ServiceDef* servicedef,
|
59
104
|
size_t* size, upb_Arena* arena) {
|
60
105
|
const google_protobuf_ServiceOptions* opts =
|
@@ -64,9 +109,27 @@ char* ServiceDescriptor_serialized_options(const upb_ServiceDef* servicedef,
|
|
64
109
|
return serialized;
|
65
110
|
}
|
66
111
|
|
112
|
+
char* ServiceDescriptor_serialized_to_proto(const upb_ServiceDef* servicedef,
|
113
|
+
size_t* size, upb_Arena* arena) {
|
114
|
+
const google_protobuf_ServiceDescriptorProto* proto =
|
115
|
+
upb_ServiceDef_ToProto(servicedef, arena);
|
116
|
+
char* serialized =
|
117
|
+
google_protobuf_ServiceDescriptorProto_serialize(proto, arena, size);
|
118
|
+
return serialized;
|
119
|
+
}
|
120
|
+
|
67
121
|
char* MethodDescriptor_serialized_options(const upb_MethodDef* methoddef,
|
68
122
|
size_t* size, upb_Arena* arena) {
|
69
123
|
const google_protobuf_MethodOptions* opts = upb_MethodDef_Options(methoddef);
|
70
124
|
char* serialized = google_protobuf_MethodOptions_serialize(opts, arena, size);
|
71
125
|
return serialized;
|
72
126
|
}
|
127
|
+
|
128
|
+
char* MethodDescriptor_serialized_to_proto(const upb_MethodDef* methodef,
|
129
|
+
size_t* size, upb_Arena* arena) {
|
130
|
+
const google_protobuf_MethodDescriptorProto* proto =
|
131
|
+
upb_MethodDef_ToProto(methodef, arena);
|
132
|
+
char* serialized =
|
133
|
+
google_protobuf_MethodDescriptorProto_serialize(proto, arena, size);
|
134
|
+
return serialized;
|
135
|
+
}
|
data/ext/google/protobuf_c/map.c
CHANGED
@@ -63,9 +63,10 @@ static VALUE Map_alloc(VALUE klass) {
|
|
63
63
|
return TypedData_Wrap_Struct(klass, &Map_type, self);
|
64
64
|
}
|
65
65
|
|
66
|
-
VALUE Map_GetRubyWrapper(upb_Map* map, upb_CType key_type,
|
67
|
-
VALUE arena) {
|
66
|
+
VALUE Map_GetRubyWrapper(const upb_Map* map, upb_CType key_type,
|
67
|
+
TypeInfo value_type, VALUE arena) {
|
68
68
|
PBRUBY_ASSERT(map);
|
69
|
+
PBRUBY_ASSERT(arena != Qnil);
|
69
70
|
|
70
71
|
VALUE val = ObjectCache_Get(map);
|
71
72
|
|
@@ -83,7 +84,6 @@ VALUE Map_GetRubyWrapper(upb_Map* map, upb_CType key_type, TypeInfo value_type,
|
|
83
84
|
}
|
84
85
|
return ObjectCache_TryAdd(map, val);
|
85
86
|
}
|
86
|
-
|
87
87
|
return val;
|
88
88
|
}
|
89
89
|
|
@@ -105,8 +105,9 @@ static TypeInfo Map_keyinfo(Map* self) {
|
|
105
105
|
}
|
106
106
|
|
107
107
|
static upb_Map* Map_GetMutable(VALUE _self) {
|
108
|
-
|
109
|
-
|
108
|
+
const upb_Map* map = ruby_to_Map(_self)->map;
|
109
|
+
Protobuf_CheckNotFrozen(_self, upb_Map_IsFrozen(map));
|
110
|
+
return (upb_Map*)map;
|
110
111
|
}
|
111
112
|
|
112
113
|
VALUE Map_CreateHash(const upb_Map* map, upb_CType key_type,
|
@@ -439,14 +440,14 @@ static VALUE Map_has_key(VALUE _self, VALUE key) {
|
|
439
440
|
* nil if none was present. Throws an exception if the key is of the wrong type.
|
440
441
|
*/
|
441
442
|
static VALUE Map_delete(VALUE _self, VALUE key) {
|
443
|
+
upb_Map* map = Map_GetMutable(_self);
|
442
444
|
Map* self = ruby_to_Map(_self);
|
443
|
-
rb_check_frozen(_self);
|
444
445
|
|
445
446
|
upb_MessageValue key_upb =
|
446
447
|
Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
|
447
448
|
upb_MessageValue val_upb;
|
448
449
|
|
449
|
-
if (upb_Map_Delete(
|
450
|
+
if (upb_Map_Delete(map, key_upb, &val_upb)) {
|
450
451
|
return Convert_UpbToRuby(val_upb, self->value_type_info, self->arena);
|
451
452
|
} else {
|
452
453
|
return Qnil;
|
@@ -560,29 +561,79 @@ VALUE Map_eq(VALUE _self, VALUE _other) {
|
|
560
561
|
|
561
562
|
/*
|
562
563
|
* call-seq:
|
563
|
-
*
|
564
|
+
* Map.frozen? => bool
|
565
|
+
*
|
566
|
+
* Returns true if the map is frozen in either Ruby or the underlying
|
567
|
+
* representation. Freezes the Ruby map object if it is not already frozen in
|
568
|
+
* Ruby but it is frozen in the underlying representation.
|
569
|
+
*/
|
570
|
+
VALUE Map_frozen(VALUE _self) {
|
571
|
+
Map* self = ruby_to_Map(_self);
|
572
|
+
if (!upb_Map_IsFrozen(self->map)) {
|
573
|
+
PBRUBY_ASSERT(!RB_OBJ_FROZEN(_self));
|
574
|
+
return Qfalse;
|
575
|
+
}
|
576
|
+
|
577
|
+
// Lazily freeze the Ruby wrapper.
|
578
|
+
if (!RB_OBJ_FROZEN(_self)) RB_OBJ_FREEZE(_self);
|
579
|
+
return Qtrue;
|
580
|
+
}
|
581
|
+
|
582
|
+
/*
|
583
|
+
* call-seq:
|
584
|
+
* Map.freeze => self
|
564
585
|
*
|
565
|
-
* Freezes the
|
566
|
-
*
|
586
|
+
* Freezes the map object. We have to intercept this so we can freeze the
|
587
|
+
* underlying representation, not just the Ruby wrapper.
|
567
588
|
*/
|
568
589
|
VALUE Map_freeze(VALUE _self) {
|
569
590
|
Map* self = ruby_to_Map(_self);
|
591
|
+
if (RB_OBJ_FROZEN(_self)) {
|
592
|
+
PBRUBY_ASSERT(upb_Map_IsFrozen(self->map));
|
593
|
+
return _self;
|
594
|
+
}
|
595
|
+
|
596
|
+
if (!upb_Map_IsFrozen(self->map)) {
|
597
|
+
if (self->value_type_info.type == kUpb_CType_Message) {
|
598
|
+
upb_Map_Freeze(
|
599
|
+
Map_GetMutable(_self),
|
600
|
+
upb_MessageDef_MiniTable(self->value_type_info.def.msgdef));
|
601
|
+
} else {
|
602
|
+
upb_Map_Freeze(Map_GetMutable(_self), NULL);
|
603
|
+
}
|
604
|
+
}
|
570
605
|
|
571
|
-
if (RB_OBJ_FROZEN(_self)) return _self;
|
572
|
-
Arena_Pin(self->arena, _self);
|
573
606
|
RB_OBJ_FREEZE(_self);
|
574
607
|
|
575
|
-
|
576
|
-
|
577
|
-
|
608
|
+
return _self;
|
609
|
+
}
|
610
|
+
|
611
|
+
VALUE Map_EmptyFrozen(const upb_FieldDef* f) {
|
612
|
+
PBRUBY_ASSERT(upb_FieldDef_IsMap(f));
|
613
|
+
VALUE val = ObjectCache_Get(f);
|
578
614
|
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
615
|
+
if (val == Qnil) {
|
616
|
+
const upb_FieldDef* key_f = map_field_key(f);
|
617
|
+
const upb_FieldDef* val_f = map_field_value(f);
|
618
|
+
upb_CType key_type = upb_FieldDef_CType(key_f);
|
619
|
+
TypeInfo value_type_info = TypeInfo_get(val_f);
|
620
|
+
val = Map_alloc(cMap);
|
621
|
+
Map* self;
|
622
|
+
TypedData_Get_Struct(val, Map, &Map_type, self);
|
623
|
+
self->arena = Arena_new();
|
624
|
+
self->map =
|
625
|
+
upb_Map_New(Arena_get(self->arena), key_type, value_type_info.type);
|
626
|
+
self->key_type = key_type;
|
627
|
+
self->value_type_info = value_type_info;
|
628
|
+
if (self->value_type_info.type == kUpb_CType_Message) {
|
629
|
+
const upb_MessageDef* val_m = value_type_info.def.msgdef;
|
630
|
+
self->value_type_class = Descriptor_DefToClass(val_m);
|
583
631
|
}
|
632
|
+
return ObjectCache_TryAdd(f, Map_freeze(val));
|
584
633
|
}
|
585
|
-
|
634
|
+
PBRUBY_ASSERT(RB_OBJ_FROZEN(val));
|
635
|
+
PBRUBY_ASSERT(upb_Map_IsFrozen(ruby_to_Map(val)->map));
|
636
|
+
return val;
|
586
637
|
}
|
587
638
|
|
588
639
|
/*
|
@@ -671,6 +722,7 @@ void Map_register(VALUE module) {
|
|
671
722
|
rb_define_method(klass, "clone", Map_dup, 0);
|
672
723
|
rb_define_method(klass, "==", Map_eq, 1);
|
673
724
|
rb_define_method(klass, "freeze", Map_freeze, 0);
|
725
|
+
rb_define_method(klass, "frozen?", Map_frozen, 0);
|
674
726
|
rb_define_method(klass, "hash", Map_hash, 0);
|
675
727
|
rb_define_method(klass, "to_h", Map_to_h, 0);
|
676
728
|
rb_define_method(klass, "inspect", Map_inspect, 0);
|
data/ext/google/protobuf_c/map.h
CHANGED
@@ -11,10 +11,14 @@
|
|
11
11
|
#include "protobuf.h"
|
12
12
|
#include "ruby-upb.h"
|
13
13
|
|
14
|
+
// Returns a frozen sentinel Ruby wrapper object for an empty upb_Map with the
|
15
|
+
// key and value types specified by the field. Creates one if it doesn't exist.
|
16
|
+
VALUE Map_EmptyFrozen(const upb_FieldDef* f);
|
17
|
+
|
14
18
|
// Returns a Ruby wrapper object for the given map, which will be created if
|
15
19
|
// one does not exist already.
|
16
|
-
VALUE Map_GetRubyWrapper(upb_Map *map, upb_CType key_type,
|
17
|
-
VALUE arena);
|
20
|
+
VALUE Map_GetRubyWrapper(const upb_Map *map, upb_CType key_type,
|
21
|
+
TypeInfo value_type, VALUE arena);
|
18
22
|
|
19
23
|
// Gets the underlying upb_Map for this Ruby map object, which must have
|
20
24
|
// key/value type that match |field|. If this is not a map or the type doesn't
|