@@ -451,6 +451,27 @@ static VALUE Descriptor_options(VALUE _self) {
451
451
return message_options ;
452
452
}
453
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
+
454
475
static void Descriptor_register (VALUE module ) {
455
476
VALUE klass = rb_define_class_under (module , "Descriptor" , rb_cObject );
456
477
rb_define_alloc_func (klass , Descriptor_alloc );
@@ -463,6 +484,7 @@ static void Descriptor_register(VALUE module) {
463
484
rb_define_method (klass , "name" , Descriptor_name , 0 );
464
485
rb_define_method (klass , "file_descriptor" , Descriptor_file_descriptor , 0 );
465
486
rb_define_method (klass , "options" , Descriptor_options , 0 );
487
+ rb_define_method (klass , "to_proto" , Descriptor_to_proto , 0 );
466
488
rb_include_module (klass , rb_mEnumerable );
467
489
rb_gc_register_address (& cDescriptor );
468
490
cDescriptor = klass ;
@@ -558,12 +580,37 @@ static VALUE FileDescriptor_options(VALUE _self) {
558
580
return file_options ;
559
581
}
560
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
+
561
607
static void FileDescriptor_register (VALUE module ) {
562
608
VALUE klass = rb_define_class_under (module , "FileDescriptor" , rb_cObject );
563
609
rb_define_alloc_func (klass , FileDescriptor_alloc );
564
610
rb_define_method (klass , "initialize" , FileDescriptor_initialize , 3 );
565
611
rb_define_method (klass , "name" , FileDescriptor_name , 0 );
566
612
rb_define_method (klass , "options" , FileDescriptor_options , 0 );
613
+ rb_define_method (klass , "to_proto" , FileDescriptor_to_proto , 0 );
567
614
rb_gc_register_address (& cFileDescriptor );
568
615
cFileDescriptor = klass ;
569
616
}
@@ -956,6 +1003,27 @@ static VALUE FieldDescriptor_options(VALUE _self) {
956
1003
return field_options ;
957
1004
}
958
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
+
959
1027
static void FieldDescriptor_register (VALUE module ) {
960
1028
VALUE klass = rb_define_class_under (module , "FieldDescriptor" , rb_cObject );
961
1029
rb_define_alloc_func (klass , FieldDescriptor_alloc );
@@ -975,6 +1043,7 @@ static void FieldDescriptor_register(VALUE module) {
975
1043
rb_define_method (klass , "get" , FieldDescriptor_get , 1 );
976
1044
rb_define_method (klass , "set" , FieldDescriptor_set , 2 );
977
1045
rb_define_method (klass , "options" , FieldDescriptor_options , 0 );
1046
+ rb_define_method (klass , "to_proto" , FieldDescriptor_to_proto , 0 );
978
1047
rb_gc_register_address (& cFieldDescriptor );
979
1048
cFieldDescriptor = klass ;
980
1049
}
@@ -1093,13 +1162,35 @@ static VALUE OneOfDescriptor_options(VALUE _self) {
1093
1162
return oneof_options ;
1094
1163
}
1095
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
+
1096
1186
static void OneofDescriptor_register (VALUE module ) {
1097
1187
VALUE klass = rb_define_class_under (module , "OneofDescriptor" , rb_cObject );
1098
1188
rb_define_alloc_func (klass , OneofDescriptor_alloc );
1099
1189
rb_define_method (klass , "initialize" , OneofDescriptor_initialize , 3 );
1100
1190
rb_define_method (klass , "name" , OneofDescriptor_name , 0 );
1101
1191
rb_define_method (klass , "each" , OneofDescriptor_each , 0 );
1102
1192
rb_define_method (klass , "options" , OneOfDescriptor_options , 0 );
1193
+ rb_define_method (klass , "to_proto" , OneOfDescriptor_to_proto , 0 );
1103
1194
rb_include_module (klass , rb_mEnumerable );
1104
1195
rb_gc_register_address (& cOneofDescriptor );
1105
1196
cOneofDescriptor = klass ;
@@ -1298,6 +1389,29 @@ static VALUE EnumDescriptor_options(VALUE _self) {
1298
1389
return enum_options ;
1299
1390
}
1300
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
+
1301
1415
static void EnumDescriptor_register (VALUE module ) {
1302
1416
VALUE klass = rb_define_class_under (module , "EnumDescriptor" , rb_cObject );
1303
1417
rb_define_alloc_func (klass , EnumDescriptor_alloc );
@@ -1310,6 +1424,7 @@ static void EnumDescriptor_register(VALUE module) {
1310
1424
rb_define_method (klass , "file_descriptor" , EnumDescriptor_file_descriptor , 0 );
1311
1425
rb_define_method (klass , "is_closed?" , EnumDescriptor_is_closed , 0 );
1312
1426
rb_define_method (klass , "options" , EnumDescriptor_options , 0 );
1427
+ rb_define_method (klass , "to_proto" , EnumDescriptor_to_proto , 0 );
1313
1428
rb_include_module (klass , rb_mEnumerable );
1314
1429
rb_gc_register_address (& cEnumDescriptor );
1315
1430
cEnumDescriptor = klass ;
@@ -1438,6 +1553,27 @@ static VALUE ServiceDescriptor_options(VALUE _self) {
1438
1553
return service_options ;
1439
1554
}
1440
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
+
1441
1577
static void ServiceDescriptor_register (VALUE module ) {
1442
1578
VALUE klass = rb_define_class_under (module , "ServiceDescriptor" , rb_cObject );
1443
1579
rb_define_alloc_func (klass , ServiceDescriptor_alloc );
@@ -1447,6 +1583,7 @@ static void ServiceDescriptor_register(VALUE module) {
1447
1583
rb_define_method (klass , "file_descriptor" , ServiceDescriptor_file_descriptor ,
1448
1584
0 );
1449
1585
rb_define_method (klass , "options" , ServiceDescriptor_options , 0 );
1586
+ rb_define_method (klass , "to_proto" , ServiceDescriptor_to_proto , 0 );
1450
1587
rb_include_module (klass , rb_mEnumerable );
1451
1588
rb_gc_register_address (& cServiceDescriptor );
1452
1589
cServiceDescriptor = klass ;
@@ -1580,6 +1717,27 @@ static VALUE MethodDescriptor_client_streaming(VALUE _self) {
1580
1717
return upb_MethodDef_ClientStreaming (self -> methoddef ) ? Qtrue : Qfalse ;
1581
1718
}
1582
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
+
1583
1741
/*
1584
1742
* call-seq:
1585
1743
* MethodDescriptor.server_streaming => bool
@@ -1603,6 +1761,7 @@ static void MethodDescriptor_register(VALUE module) {
1603
1761
0 );
1604
1762
rb_define_method (klass , "server_streaming" , MethodDescriptor_server_streaming ,
1605
1763
0 );
1764
+ rb_define_method (klass , "to_proto" , MethodDescriptor_to_proto , 0 );
1606
1765
rb_gc_register_address (& cMethodDescriptor );
1607
1766
cMethodDescriptor = klass ;
1608
1767
}
0 commit comments