google-protobuf 4.28.2 → 4.30.2
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 +161 -3
- data/ext/google/protobuf_c/extconf.rb +12 -0
- data/ext/google/protobuf_c/glue.c +63 -0
- data/ext/google/protobuf_c/message.c +14 -6
- data/ext/google/protobuf_c/protobuf.c +2 -3
- data/ext/google/protobuf_c/ruby-upb.c +6959 -5814
- data/ext/google/protobuf_c/ruby-upb.h +4699 -3916
- 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 +10 -0
- 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/convert.rb +1 -5
- data/lib/google/protobuf/ffi/message.rb +5 -3
- 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_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: b5125cc8af8296e8ccc158044588e8aa997acb0a4dfc12b8f70207c4b6e0e312
|
4
|
+
data.tar.gz: 9aaaeb8e9c9b0ced47d7c14a5d3d2da37e43c6b12fd32177d87fa055b59426d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc4490fe009fdf955ac03163cde61170975faba127c6987819321d6c45ef9d20823f44d25b883881c5bb2faab630c01e8a0519a20466abc624d018a759a73b33
|
7
|
+
data.tar.gz: 7b2364e5c5a7056df7684eed5be81b03f4806a53e8f8f9e381f879b8c11e640e191ab72e1abbf7db56f1aae8e299d4f260b2138367f657911542ad87174f031a
|
@@ -112,16 +112,9 @@ VALUE Convert_CheckStringUtf8(VALUE str) {
|
|
112
112
|
// not mean that it is *valid* UTF-8. We have to check separately
|
113
113
|
// whether it is valid.
|
114
114
|
if (rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN) {
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
rb_warn(
|
120
|
-
"String is invalid UTF-8. This will be an error in a future "
|
121
|
-
"version.");
|
122
|
-
// VALUE exc = rb_const_get_at(
|
123
|
-
// rb_cEncoding, rb_intern("InvalidByteSequenceError"));
|
124
|
-
// rb_raise(exc, "String is invalid UTF-8");
|
115
|
+
VALUE exc = rb_const_get_at(
|
116
|
+
rb_cEncoding, rb_intern("InvalidByteSequenceError"));
|
117
|
+
rb_raise(exc, "String is invalid UTF-8");
|
125
118
|
}
|
126
119
|
} else {
|
127
120
|
// Note: this will not duplicate underlying string data unless
|
@@ -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
|
}
|
@@ -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
|
+
}
|
@@ -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)) {
|
@@ -1038,11 +1039,18 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
|
|
1038
1039
|
|
1039
1040
|
upb_Status_Clear(&status);
|
1040
1041
|
const upb_DefPool* pool = upb_FileDef_Pool(upb_MessageDef_File(msg->msgdef));
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1042
|
+
|
1043
|
+
int result = upb_JsonDecodeDetectingNonconformance(
|
1044
|
+
RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg,
|
1045
|
+
msg->msgdef, pool, options, Arena_get(msg->arena), &status);
|
1046
|
+
|
1047
|
+
switch (result) {
|
1048
|
+
case kUpb_JsonDecodeResult_Ok:
|
1049
|
+
break;
|
1050
|
+
case kUpb_JsonDecodeResult_Error:
|
1051
|
+
rb_raise(cParseError, "Error occurred during parsing: %s",
|
1052
|
+
upb_Status_ErrorMessage(&status));
|
1053
|
+
break;
|
1046
1054
|
}
|
1047
1055
|
|
1048
1056
|
return msg_rb;
|
@@ -7,8 +7,6 @@
|
|
7
7
|
|
8
8
|
#include "protobuf.h"
|
9
9
|
|
10
|
-
#include <ruby/version.h>
|
11
|
-
|
12
10
|
#include "defs.h"
|
13
11
|
#include "map.h"
|
14
12
|
#include "message.h"
|
@@ -288,7 +286,8 @@ VALUE ObjectCache_Get(const void *key) {
|
|
288
286
|
static VALUE Google_Protobuf_discard_unknown(VALUE self, VALUE msg_rb) {
|
289
287
|
const upb_MessageDef *m;
|
290
288
|
upb_Message *msg = Message_GetMutable(msg_rb, &m);
|
291
|
-
|
289
|
+
const upb_DefPool* ext_pool = upb_FileDef_Pool(upb_MessageDef_File(m));
|
290
|
+
if (!upb_Message_DiscardUnknown(msg, m, ext_pool, 128)) {
|
292
291
|
rb_raise(rb_eRuntimeError, "Messages nested too deeply.");
|
293
292
|
}
|
294
293
|
|