google-protobuf 3.24.0 → 4.26.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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/ext/google/protobuf_c/Rakefile +3 -0
  3. data/ext/google/protobuf_c/convert.c +28 -72
  4. data/ext/google/protobuf_c/convert.h +3 -26
  5. data/ext/google/protobuf_c/defs.c +175 -50
  6. data/ext/google/protobuf_c/defs.h +3 -26
  7. data/ext/google/protobuf_c/extconf.rb +2 -1
  8. data/ext/google/protobuf_c/glue.c +56 -0
  9. data/ext/google/protobuf_c/map.c +24 -34
  10. data/ext/google/protobuf_c/map.h +6 -26
  11. data/ext/google/protobuf_c/message.c +88 -134
  12. data/ext/google/protobuf_c/message.h +10 -26
  13. data/ext/google/protobuf_c/protobuf.c +35 -37
  14. data/ext/google/protobuf_c/protobuf.h +3 -26
  15. data/ext/google/protobuf_c/repeated_field.c +18 -31
  16. data/ext/google/protobuf_c/repeated_field.h +6 -26
  17. data/ext/google/protobuf_c/ruby-upb.c +12146 -10962
  18. data/ext/google/protobuf_c/ruby-upb.h +7299 -6084
  19. data/ext/google/protobuf_c/shared_convert.c +66 -0
  20. data/ext/google/protobuf_c/shared_convert.h +26 -0
  21. data/ext/google/protobuf_c/shared_message.c +67 -0
  22. data/ext/google/protobuf_c/shared_message.h +25 -0
  23. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +467 -0
  24. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +9 -8
  25. data/ext/google/protobuf_c/wrap_memcpy.c +3 -26
  26. data/lib/google/protobuf/any_pb.rb +1 -22
  27. data/lib/google/protobuf/api_pb.rb +1 -24
  28. data/lib/google/protobuf/descriptor_pb.rb +6 -24
  29. data/lib/google/protobuf/duration_pb.rb +1 -22
  30. data/lib/google/protobuf/empty_pb.rb +1 -22
  31. data/lib/google/protobuf/ffi/descriptor.rb +164 -0
  32. data/lib/google/protobuf/ffi/descriptor_pool.rb +75 -0
  33. data/lib/google/protobuf/ffi/enum_descriptor.rb +171 -0
  34. data/lib/google/protobuf/ffi/ffi.rb +215 -0
  35. data/lib/google/protobuf/ffi/field_descriptor.rb +328 -0
  36. data/lib/google/protobuf/ffi/file_descriptor.rb +47 -0
  37. data/lib/google/protobuf/ffi/internal/arena.rb +66 -0
  38. data/lib/google/protobuf/ffi/internal/convert.rb +289 -0
  39. data/lib/google/protobuf/ffi/internal/pointer_helper.rb +35 -0
  40. data/lib/google/protobuf/ffi/internal/type_safety.rb +25 -0
  41. data/lib/google/protobuf/ffi/map.rb +409 -0
  42. data/lib/google/protobuf/ffi/message.rb +659 -0
  43. data/lib/google/protobuf/ffi/object_cache.rb +30 -0
  44. data/lib/google/protobuf/ffi/oneof_descriptor.rb +95 -0
  45. data/lib/google/protobuf/ffi/repeated_field.rb +385 -0
  46. data/lib/google/protobuf/field_mask_pb.rb +1 -22
  47. data/lib/google/protobuf/internal/object_cache.rb +99 -0
  48. data/lib/google/protobuf/message_exts.rb +3 -26
  49. data/lib/google/protobuf/plugin_pb.rb +2 -24
  50. data/lib/google/protobuf/repeated_field.rb +4 -28
  51. data/lib/google/protobuf/source_context_pb.rb +1 -22
  52. data/lib/google/protobuf/struct_pb.rb +1 -22
  53. data/lib/google/protobuf/timestamp_pb.rb +1 -22
  54. data/lib/google/protobuf/type_pb.rb +1 -24
  55. data/lib/google/protobuf/well_known_types.rb +3 -26
  56. data/lib/google/protobuf/wrappers_pb.rb +1 -22
  57. data/lib/google/protobuf.rb +27 -46
  58. data/lib/google/protobuf_ffi.rb +49 -0
  59. data/lib/google/protobuf_native.rb +19 -0
  60. data/lib/google/tasks/ffi.rake +100 -0
  61. metadata +72 -8
  62. data/ext/google/protobuf_c/third_party/utf8_range/naive.c +0 -92
  63. data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +0 -157
  64. data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +0 -170
  65. data/lib/google/protobuf/descriptor_dsl.rb +0 -465
  66. data/lib/google/protobuf/object_cache.rb +0 -120
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7cee93054ce792ab5f48f53a8b4f11e8463929cdba93302fe84d9d6d576a8178
4
- data.tar.gz: 56bf5d577f780ddd4d57382beb29e2939482c89b81f45aeaa282e5a83c270645
3
+ metadata.gz: b23f00860aa2e86d6e58ad274082a4c60de5a0315d489943d6ab35efb78770a7
4
+ data.tar.gz: 89df3b5d9f88cbed7a77a114737782b94f285823652fee6d5cda6170e7c8c1e7
5
5
  SHA512:
6
- metadata.gz: 6750c6f04099f53618bea170202b8b004ec36f81d126ef3d4d2a64d95775146a5f088f8d5c938faf8ebef7a87a04dc1819038faab961c0102248ac8ba4d08e7f
7
- data.tar.gz: 715496a5698143bc68e3f845ad29de4a27f67ba1132092f8eeba73445a9b5e38965e555461e025e6f2a6e7410d6e542c094907a5d1182ca0bafbee17df942cf1
6
+ metadata.gz: 2b21bee58bb16f0f284434997e95c8c5d279c03fdcb0f35c2a7e623c67b39c0356c9731840422b69330a5a5744dde3bbce9b7dc776ee3810f15dacf8a27b7811
7
+ data.tar.gz: d972c3191e8ad50741e5f4dc98fd3b6a833113a524988a602a698a425909eab7aaf0f0b107e22c9fbf5f1338e1c11673fad7db5b46bf6592926360a9dad72d17
@@ -0,0 +1,3 @@
1
+ import '../../../lib/google/tasks/ffi.rake'
2
+
3
+ task default: ['ffi-protobuf:default']
@@ -1,32 +1,9 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2008 Google Inc. All rights reserved.
3
- // https://developers.google.com/protocol-buffers/
4
3
  //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  // -----------------------------------------------------------------------------
32
9
  // Ruby <-> upb data conversion functions.
@@ -41,6 +18,7 @@
41
18
 
42
19
  #include "message.h"
43
20
  #include "protobuf.h"
21
+ #include "shared_convert.h"
44
22
 
45
23
  static upb_StringView Convert_StringData(VALUE str, upb_Arena* arena) {
46
24
  upb_StringView ret;
@@ -111,8 +89,7 @@ static int32_t Convert_ToEnum(VALUE value, const char* name,
111
89
  case T_SYMBOL: {
112
90
  const upb_EnumValueDef* ev =
113
91
  upb_EnumDef_FindValueByName(e, rb_id2name(SYM2ID(value)));
114
- if (!ev)
115
- goto unknownval;
92
+ if (!ev) goto unknownval;
116
93
  val = upb_EnumValueDef_Number(ev);
117
94
  break;
118
95
  }
@@ -164,7 +141,7 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
164
141
  VALUE utf8 = rb_enc_from_encoding(rb_utf8_encoding());
165
142
  if (rb_obj_class(value) == rb_cSymbol) {
166
143
  value = rb_funcall(value, rb_intern("to_s"), 0);
167
- } else if (rb_obj_class(value) != rb_cString) {
144
+ } else if (!rb_obj_is_kind_of(value, rb_cString)) {
168
145
  rb_raise(cTypeError,
169
146
  "Invalid argument for string field '%s' (given %s).", name,
170
147
  rb_class2name(CLASS_OF(value)));
@@ -194,7 +171,7 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
194
171
  if (rb_obj_encoding(value) != bytes) {
195
172
  // Note: this will not duplicate underlying string data unless
196
173
  // necessary.
197
- // TODO(haberman): is this really necessary to get raw bytes?
174
+ // TODO: is this really necessary to get raw bytes?
198
175
  value = rb_str_encode(value, bytes, 0, Qnil);
199
176
  }
200
177
 
@@ -231,7 +208,8 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name,
231
208
  }
232
209
  break;
233
210
  default:
234
- break;
211
+ rb_raise(cTypeError,
212
+ "Convert_RubyToUpb(): Unexpected type %d", (int)type_info.type);
235
213
  }
236
214
 
237
215
  return ret;
@@ -255,7 +233,7 @@ VALUE Convert_UpbToRuby(upb_MessageValue upb_val, TypeInfo type_info,
255
233
  case kUpb_CType_UInt64:
256
234
  return ULL2NUM(upb_val.int64_val);
257
235
  case kUpb_CType_Enum: {
258
- const upb_EnumValueDef *ev = upb_EnumDef_FindValueByNumber(
236
+ const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNumber(
259
237
  type_info.def.enumdef, upb_val.int32_val);
260
238
  if (ev) {
261
239
  return ID2SYM(rb_intern(upb_EnumValueDef_Name(ev)));
@@ -312,50 +290,28 @@ upb_MessageValue Msgval_DeepCopy(upb_MessageValue msgval, TypeInfo type_info,
312
290
 
313
291
  bool Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2,
314
292
  TypeInfo type_info) {
315
- switch (type_info.type) {
316
- case kUpb_CType_Bool:
317
- return memcmp(&val1, &val2, 1) == 0;
318
- case kUpb_CType_Float:
319
- case kUpb_CType_Int32:
320
- case kUpb_CType_UInt32:
321
- case kUpb_CType_Enum:
322
- return memcmp(&val1, &val2, 4) == 0;
323
- case kUpb_CType_Double:
324
- case kUpb_CType_Int64:
325
- case kUpb_CType_UInt64:
326
- return memcmp(&val1, &val2, 8) == 0;
327
- case kUpb_CType_String:
328
- case kUpb_CType_Bytes:
329
- return val1.str_val.size == val2.str_val.size &&
330
- memcmp(val1.str_val.data, val2.str_val.data, val1.str_val.size) ==
331
- 0;
332
- case kUpb_CType_Message:
333
- return Message_Equal(val1.msg_val, val2.msg_val, type_info.def.msgdef);
334
- default:
335
- rb_raise(rb_eRuntimeError, "Internal error, unexpected type");
293
+ upb_Status status;
294
+ upb_Status_Clear(&status);
295
+ bool return_value = shared_Msgval_IsEqual(val1, val2, type_info.type,
296
+ type_info.def.msgdef, &status);
297
+ if (upb_Status_IsOk(&status)) {
298
+ return return_value;
299
+ } else {
300
+ rb_raise(rb_eRuntimeError, "Msgval_IsEqual(): %s",
301
+ upb_Status_ErrorMessage(&status));
336
302
  }
337
303
  }
338
304
 
339
305
  uint64_t Msgval_GetHash(upb_MessageValue val, TypeInfo type_info,
340
306
  uint64_t seed) {
341
- switch (type_info.type) {
342
- case kUpb_CType_Bool:
343
- return _upb_Hash(&val, 1, seed);
344
- case kUpb_CType_Float:
345
- case kUpb_CType_Int32:
346
- case kUpb_CType_UInt32:
347
- case kUpb_CType_Enum:
348
- return _upb_Hash(&val, 4, seed);
349
- case kUpb_CType_Double:
350
- case kUpb_CType_Int64:
351
- case kUpb_CType_UInt64:
352
- return _upb_Hash(&val, 8, seed);
353
- case kUpb_CType_String:
354
- case kUpb_CType_Bytes:
355
- return _upb_Hash(val.str_val.data, val.str_val.size, seed);
356
- case kUpb_CType_Message:
357
- return Message_Hash(val.msg_val, type_info.def.msgdef, seed);
358
- default:
359
- rb_raise(rb_eRuntimeError, "Internal error, unexpected type");
307
+ upb_Status status;
308
+ upb_Status_Clear(&status);
309
+ uint64_t return_value = shared_Msgval_GetHash(
310
+ val, type_info.type, type_info.def.msgdef, seed, &status);
311
+ if (upb_Status_IsOk(&status)) {
312
+ return return_value;
313
+ } else {
314
+ rb_raise(rb_eRuntimeError, "Msgval_GetHash(): %s",
315
+ upb_Status_ErrorMessage(&status));
360
316
  }
361
317
  }
@@ -1,32 +1,9 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2008 Google Inc. All rights reserved.
3
- // https://developers.google.com/protocol-buffers/
4
3
  //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  #ifndef RUBY_PROTOBUF_CONVERT_H_
32
9
  #define RUBY_PROTOBUF_CONVERT_H_
@@ -1,32 +1,9 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2014 Google Inc. All rights reserved.
3
- // https://developers.google.com/protocol-buffers/
4
3
  //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  #include <ctype.h>
32
9
  #include <errno.h>
@@ -67,7 +44,7 @@ static VALUE rb_str_maybe_null(const char* s) {
67
44
  }
68
45
  return rb_str_new2(s);
69
46
  }
70
-
47
+ static ID options_instancevar_interned;
71
48
  // -----------------------------------------------------------------------------
72
49
  // DescriptorPool.
73
50
  // -----------------------------------------------------------------------------
@@ -167,20 +144,26 @@ VALUE DescriptorPool_add_serialized_file(VALUE _self,
167
144
  * call-seq:
168
145
  * DescriptorPool.lookup(name) => descriptor
169
146
  *
170
- * Finds a Descriptor or EnumDescriptor by name and returns it, or nil if none
171
- * exists with the given name.
147
+ * Finds a Descriptor, EnumDescriptor or FieldDescriptor by name and returns it,
148
+ * or nil if none exists with the given name.
172
149
  */
173
150
  static VALUE DescriptorPool_lookup(VALUE _self, VALUE name) {
174
151
  DescriptorPool* self = ruby_to_DescriptorPool(_self);
175
152
  const char* name_str = get_str(name);
176
153
  const upb_MessageDef* msgdef;
177
154
  const upb_EnumDef* enumdef;
155
+ const upb_FieldDef* fielddef;
178
156
 
179
157
  msgdef = upb_DefPool_FindMessageByName(self->symtab, name_str);
180
158
  if (msgdef) {
181
159
  return get_msgdef_obj(_self, msgdef);
182
160
  }
183
161
 
162
+ fielddef = upb_DefPool_FindExtensionByName(self->symtab, name_str);
163
+ if (fielddef) {
164
+ return get_fielddef_obj(_self, fielddef);
165
+ }
166
+
184
167
  enumdef = upb_DefPool_FindEnumByName(self->symtab, name_str);
185
168
  if (enumdef) {
186
169
  return get_enumdef_obj(_self, enumdef);
@@ -215,6 +198,7 @@ static void DescriptorPool_register(VALUE module) {
215
198
 
216
199
  rb_gc_register_address(&generated_pool);
217
200
  generated_pool = rb_class_new_instance(0, NULL, klass);
201
+ options_instancevar_interned = rb_intern("options");
218
202
  }
219
203
 
220
204
  // -----------------------------------------------------------------------------
@@ -249,6 +233,35 @@ static Descriptor* ruby_to_Descriptor(VALUE val) {
249
233
  return ret;
250
234
  }
251
235
 
236
+ // Decode and return a frozen instance of a Descriptor Option for the given pool
237
+ static VALUE decode_options(VALUE self, const char* option_type, int size,
238
+ const char* bytes, VALUE descriptor_pool) {
239
+ VALUE options_rb = rb_ivar_get(self, options_instancevar_interned);
240
+ if (options_rb != Qnil) {
241
+ return options_rb;
242
+ }
243
+
244
+ static const char* prefix = "google.protobuf.";
245
+ char fullname
246
+ [/*strlen(prefix)*/ 16 +
247
+ /*strln(longest option type supported e.g. "MessageOptions")*/ 14 +
248
+ /*null terminator*/ 1];
249
+
250
+ snprintf(fullname, sizeof(fullname), "%s%s", prefix, option_type);
251
+ const upb_MessageDef* msgdef = upb_DefPool_FindMessageByName(
252
+ ruby_to_DescriptorPool(descriptor_pool)->symtab, fullname);
253
+ if (!msgdef) {
254
+ rb_raise(rb_eRuntimeError, "Cannot find %s in DescriptorPool", option_type);
255
+ }
256
+
257
+ VALUE desc_rb = get_msgdef_obj(descriptor_pool, msgdef);
258
+ const Descriptor* desc = ruby_to_Descriptor(desc_rb);
259
+
260
+ options_rb = Message_decode_bytes(size, bytes, 0, desc->klass, true);
261
+ rb_ivar_set(self, options_instancevar_interned, options_rb);
262
+ return options_rb;
263
+ }
264
+
252
265
  /*
253
266
  * call-seq:
254
267
  * Descriptor.new => descriptor
@@ -397,6 +410,26 @@ static VALUE Descriptor_msgclass(VALUE _self) {
397
410
  return self->klass;
398
411
  }
399
412
 
413
+ /*
414
+ * call-seq:
415
+ * Descriptor.options => options
416
+ *
417
+ * Returns the `MessageOptions` for this `Descriptor`.
418
+ */
419
+ static VALUE Descriptor_options(VALUE _self) {
420
+ Descriptor* self = ruby_to_Descriptor(_self);
421
+ const google_protobuf_MessageOptions* opts =
422
+ upb_MessageDef_Options(self->msgdef);
423
+ upb_Arena* arena = upb_Arena_New();
424
+ size_t size;
425
+ char* serialized =
426
+ google_protobuf_MessageOptions_serialize(opts, arena, &size);
427
+ VALUE message_options = decode_options(_self, "MessageOptions", size,
428
+ serialized, self->descriptor_pool);
429
+ upb_Arena_Free(arena);
430
+ return message_options;
431
+ }
432
+
400
433
  static void Descriptor_register(VALUE module) {
401
434
  VALUE klass = rb_define_class_under(module, "Descriptor", rb_cObject);
402
435
  rb_define_alloc_func(klass, Descriptor_alloc);
@@ -408,6 +441,7 @@ static void Descriptor_register(VALUE module) {
408
441
  rb_define_method(klass, "msgclass", Descriptor_msgclass, 0);
409
442
  rb_define_method(klass, "name", Descriptor_name, 0);
410
443
  rb_define_method(klass, "file_descriptor", Descriptor_file_descriptor, 0);
444
+ rb_define_method(klass, "options", Descriptor_options, 0);
411
445
  rb_include_module(klass, rb_mEnumerable);
412
446
  rb_gc_register_address(&cDescriptor);
413
447
  cDescriptor = klass;
@@ -455,7 +489,7 @@ static VALUE FileDescriptor_alloc(VALUE klass) {
455
489
  * call-seq:
456
490
  * FileDescriptor.new => file
457
491
  *
458
- * Returns a new file descriptor. The syntax must be set before it's passed
492
+ * Returns a new file descriptor. May
459
493
  * to a builder.
460
494
  */
461
495
  static VALUE FileDescriptor_initialize(VALUE _self, VALUE cookie,
@@ -487,24 +521,20 @@ static VALUE FileDescriptor_name(VALUE _self) {
487
521
 
488
522
  /*
489
523
  * call-seq:
490
- * FileDescriptor.syntax => syntax
491
- *
492
- * Returns this file descriptors syntax.
524
+ * FileDescriptor.options => options
493
525
  *
494
- * Valid syntax versions are:
495
- * :proto2 or :proto3.
526
+ * Returns the `FileOptions` for this `FileDescriptor`.
496
527
  */
497
- static VALUE FileDescriptor_syntax(VALUE _self) {
528
+ static VALUE FileDescriptor_options(VALUE _self) {
498
529
  FileDescriptor* self = ruby_to_FileDescriptor(_self);
499
-
500
- switch (upb_FileDef_Syntax(self->filedef)) {
501
- case kUpb_Syntax_Proto3:
502
- return ID2SYM(rb_intern("proto3"));
503
- case kUpb_Syntax_Proto2:
504
- return ID2SYM(rb_intern("proto2"));
505
- default:
506
- return Qnil;
507
- }
530
+ const google_protobuf_FileOptions* opts = upb_FileDef_Options(self->filedef);
531
+ upb_Arena* arena = upb_Arena_New();
532
+ size_t size;
533
+ char* serialized = google_protobuf_FileOptions_serialize(opts, arena, &size);
534
+ VALUE file_options = decode_options(_self, "FileOptions", size, serialized,
535
+ self->descriptor_pool);
536
+ upb_Arena_Free(arena);
537
+ return file_options;
508
538
  }
509
539
 
510
540
  static void FileDescriptor_register(VALUE module) {
@@ -512,7 +542,7 @@ static void FileDescriptor_register(VALUE module) {
512
542
  rb_define_alloc_func(klass, FileDescriptor_alloc);
513
543
  rb_define_method(klass, "initialize", FileDescriptor_initialize, 3);
514
544
  rb_define_method(klass, "name", FileDescriptor_name, 0);
515
- rb_define_method(klass, "syntax", FileDescriptor_syntax, 0);
545
+ rb_define_method(klass, "options", FileDescriptor_options, 0);
516
546
  rb_gc_register_address(&cFileDescriptor);
517
547
  cFileDescriptor = klass;
518
548
  }
@@ -563,7 +593,7 @@ static VALUE FieldDescriptor_alloc(VALUE klass) {
563
593
 
564
594
  /*
565
595
  * call-seq:
566
- * EnumDescriptor.new(c_only_cookie, pool, ptr) => EnumDescriptor
596
+ * FieldDescriptor.new(c_only_cookie, pool, ptr) => FieldDescriptor
567
597
  *
568
598
  * Creates a descriptor wrapper object. May only be called from C.
569
599
  */
@@ -683,6 +713,28 @@ static VALUE FieldDescriptor_default(VALUE _self) {
683
713
  return Convert_UpbToRuby(default_val, TypeInfo_get(self->fielddef), Qnil);
684
714
  }
685
715
 
716
+ /*
717
+ * call-seq:
718
+ * FieldDescriptor.has_presence? => bool
719
+ *
720
+ * Returns whether this field tracks presence.
721
+ */
722
+ static VALUE FieldDescriptor_has_presence(VALUE _self) {
723
+ FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
724
+ return upb_FieldDef_HasPresence(self->fielddef) ? Qtrue : Qfalse;
725
+ }
726
+
727
+ /*
728
+ * call-seq:
729
+ * FieldDescriptor.is_packed? => bool
730
+ *
731
+ * Returns whether this is a repeated field that uses packed encoding.
732
+ */
733
+ static VALUE FieldDescriptor_is_packed(VALUE _self) {
734
+ FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
735
+ return upb_FieldDef_IsPacked(self->fielddef) ? Qtrue : Qfalse;
736
+ }
737
+
686
738
  /*
687
739
  * call-seq:
688
740
  * FieldDescriptor.json_name => json_name
@@ -809,7 +861,7 @@ static VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) {
809
861
  static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
810
862
  FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
811
863
  const upb_MessageDef* m;
812
- const upb_MessageDef* msg = Message_Get(msg_rb, &m);
864
+ const upb_Message* msg = Message_Get(msg_rb, &m);
813
865
 
814
866
  if (m != upb_FieldDef_ContainingType(self->fielddef)) {
815
867
  rb_raise(cTypeError, "has method called on wrong message type");
@@ -829,7 +881,7 @@ static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
829
881
  static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
830
882
  FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
831
883
  const upb_MessageDef* m;
832
- upb_MessageDef* msg = Message_GetMutable(msg_rb, &m);
884
+ upb_Message* msg = Message_GetMutable(msg_rb, &m);
833
885
 
834
886
  if (m != upb_FieldDef_ContainingType(self->fielddef)) {
835
887
  rb_raise(cTypeError, "has method called on wrong message type");
@@ -850,7 +902,7 @@ static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
850
902
  static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) {
851
903
  FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
852
904
  const upb_MessageDef* m;
853
- upb_MessageDef* msg = Message_GetMutable(msg_rb, &m);
905
+ upb_Message* msg = Message_GetMutable(msg_rb, &m);
854
906
  upb_Arena* arena = Arena_get(Message_GetArena(msg_rb));
855
907
  upb_MessageValue msgval;
856
908
 
@@ -864,6 +916,25 @@ static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) {
864
916
  return Qnil;
865
917
  }
866
918
 
919
+ /*
920
+ * call-seq:
921
+ * FieldDescriptor.options => options
922
+ *
923
+ * Returns the `FieldOptions` for this `FieldDescriptor`.
924
+ */
925
+ static VALUE FieldDescriptor_options(VALUE _self) {
926
+ FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
927
+ const google_protobuf_FieldOptions* opts =
928
+ upb_FieldDef_Options(self->fielddef);
929
+ upb_Arena* arena = upb_Arena_New();
930
+ size_t size;
931
+ char* serialized = google_protobuf_FieldOptions_serialize(opts, arena, &size);
932
+ VALUE field_options = decode_options(_self, "FieldOptions", size, serialized,
933
+ self->descriptor_pool);
934
+ upb_Arena_Free(arena);
935
+ return field_options;
936
+ }
937
+
867
938
  static void FieldDescriptor_register(VALUE module) {
868
939
  VALUE klass = rb_define_class_under(module, "FieldDescriptor", rb_cObject);
869
940
  rb_define_alloc_func(klass, FieldDescriptor_alloc);
@@ -871,6 +942,8 @@ static void FieldDescriptor_register(VALUE module) {
871
942
  rb_define_method(klass, "name", FieldDescriptor_name, 0);
872
943
  rb_define_method(klass, "type", FieldDescriptor__type, 0);
873
944
  rb_define_method(klass, "default", FieldDescriptor_default, 0);
945
+ rb_define_method(klass, "has_presence?", FieldDescriptor_has_presence, 0);
946
+ rb_define_method(klass, "is_packed?", FieldDescriptor_is_packed, 0);
874
947
  rb_define_method(klass, "json_name", FieldDescriptor_json_name, 0);
875
948
  rb_define_method(klass, "label", FieldDescriptor_label, 0);
876
949
  rb_define_method(klass, "number", FieldDescriptor_number, 0);
@@ -880,6 +953,7 @@ static void FieldDescriptor_register(VALUE module) {
880
953
  rb_define_method(klass, "clear", FieldDescriptor_clear, 1);
881
954
  rb_define_method(klass, "get", FieldDescriptor_get, 1);
882
955
  rb_define_method(klass, "set", FieldDescriptor_set, 2);
956
+ rb_define_method(klass, "options", FieldDescriptor_options, 0);
883
957
  rb_gc_register_address(&cFieldDescriptor);
884
958
  cFieldDescriptor = klass;
885
959
  }
@@ -979,12 +1053,32 @@ static VALUE OneofDescriptor_each(VALUE _self) {
979
1053
  return Qnil;
980
1054
  }
981
1055
 
1056
+ /*
1057
+ * call-seq:
1058
+ * OneofDescriptor.options => options
1059
+ *
1060
+ * Returns the `OneofOptions` for this `OneofDescriptor`.
1061
+ */
1062
+ static VALUE OneOfDescriptor_options(VALUE _self) {
1063
+ OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
1064
+ const google_protobuf_OneofOptions* opts =
1065
+ upb_OneofDef_Options(self->oneofdef);
1066
+ upb_Arena* arena = upb_Arena_New();
1067
+ size_t size;
1068
+ char* serialized = google_protobuf_OneofOptions_serialize(opts, arena, &size);
1069
+ VALUE oneof_options = decode_options(_self, "OneofOptions", size, serialized,
1070
+ self->descriptor_pool);
1071
+ upb_Arena_Free(arena);
1072
+ return oneof_options;
1073
+ }
1074
+
982
1075
  static void OneofDescriptor_register(VALUE module) {
983
1076
  VALUE klass = rb_define_class_under(module, "OneofDescriptor", rb_cObject);
984
1077
  rb_define_alloc_func(klass, OneofDescriptor_alloc);
985
1078
  rb_define_method(klass, "initialize", OneofDescriptor_initialize, 3);
986
1079
  rb_define_method(klass, "name", OneofDescriptor_name, 0);
987
1080
  rb_define_method(klass, "each", OneofDescriptor_each, 0);
1081
+ rb_define_method(klass, "options", OneOfDescriptor_options, 0);
988
1082
  rb_include_module(klass, rb_mEnumerable);
989
1083
  rb_gc_register_address(&cOneofDescriptor);
990
1084
  cOneofDescriptor = klass;
@@ -1070,6 +1164,17 @@ static VALUE EnumDescriptor_file_descriptor(VALUE _self) {
1070
1164
  upb_EnumDef_File(self->enumdef));
1071
1165
  }
1072
1166
 
1167
+ /*
1168
+ * call-seq:
1169
+ * EnumDescriptor.is_closed? => bool
1170
+ *
1171
+ * Returns whether this enum is open or closed.
1172
+ */
1173
+ static VALUE EnumDescriptor_is_closed(VALUE _self) {
1174
+ EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
1175
+ return upb_EnumDef_IsClosed(self->enumdef) ? Qtrue : Qfalse;
1176
+ }
1177
+
1073
1178
  /*
1074
1179
  * call-seq:
1075
1180
  * EnumDescriptor.name => name
@@ -1154,6 +1259,24 @@ static VALUE EnumDescriptor_enummodule(VALUE _self) {
1154
1259
  return self->module;
1155
1260
  }
1156
1261
 
1262
+ /*
1263
+ * call-seq:
1264
+ * EnumDescriptor.options => options
1265
+ *
1266
+ * Returns the `EnumOptions` for this `EnumDescriptor`.
1267
+ */
1268
+ static VALUE EnumDescriptor_options(VALUE _self) {
1269
+ EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
1270
+ const google_protobuf_EnumOptions* opts = upb_EnumDef_Options(self->enumdef);
1271
+ upb_Arena* arena = upb_Arena_New();
1272
+ size_t size;
1273
+ char* serialized = google_protobuf_EnumOptions_serialize(opts, arena, &size);
1274
+ VALUE enum_options = decode_options(_self, "EnumOptions", size, serialized,
1275
+ self->descriptor_pool);
1276
+ upb_Arena_Free(arena);
1277
+ return enum_options;
1278
+ }
1279
+
1157
1280
  static void EnumDescriptor_register(VALUE module) {
1158
1281
  VALUE klass = rb_define_class_under(module, "EnumDescriptor", rb_cObject);
1159
1282
  rb_define_alloc_func(klass, EnumDescriptor_alloc);
@@ -1164,6 +1287,8 @@ static void EnumDescriptor_register(VALUE module) {
1164
1287
  rb_define_method(klass, "each", EnumDescriptor_each, 0);
1165
1288
  rb_define_method(klass, "enummodule", EnumDescriptor_enummodule, 0);
1166
1289
  rb_define_method(klass, "file_descriptor", EnumDescriptor_file_descriptor, 0);
1290
+ rb_define_method(klass, "is_closed?", EnumDescriptor_is_closed, 0);
1291
+ rb_define_method(klass, "options", EnumDescriptor_options, 0);
1167
1292
  rb_include_module(klass, rb_mEnumerable);
1168
1293
  rb_gc_register_address(&cEnumDescriptor);
1169
1294
  cEnumDescriptor = klass;
@@ -1,32 +1,9 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2008 Google Inc. All rights reserved.
3
- // https://developers.google.com/protocol-buffers/
4
3
  //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file or at
6
+ // https://developers.google.com/open-source/licenses/bsd
30
7
 
31
8
  #ifndef RUBY_PROTOBUF_DEFS_H_
32
9
  #define RUBY_PROTOBUF_DEFS_H_
@@ -22,6 +22,7 @@ $INCFLAGS += " -I$(srcdir)/third_party/utf8_range"
22
22
 
23
23
  $srcs = ["protobuf.c", "convert.c", "defs.c", "message.c",
24
24
  "repeated_field.c", "map.c", "ruby-upb.c", "wrap_memcpy.c",
25
- "naive.c", "range2-neon.c", "range2-sse.c"]
25
+ "utf8_range.c", "shared_convert.c",
26
+ "shared_message.c"]
26
27
 
27
28
  create_makefile(ext_name)