google-protobuf 3.24.4 → 3.25.6
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/Rakefile +3 -0
- data/ext/google/protobuf_c/convert.c +27 -71
- data/ext/google/protobuf_c/convert.h +3 -26
- data/ext/google/protobuf_c/defs.c +145 -33
- data/ext/google/protobuf_c/defs.h +3 -26
- data/ext/google/protobuf_c/extconf.rb +2 -1
- data/ext/google/protobuf_c/glue.c +56 -0
- data/ext/google/protobuf_c/map.c +25 -28
- data/ext/google/protobuf_c/map.h +6 -26
- data/ext/google/protobuf_c/message.c +73 -80
- data/ext/google/protobuf_c/message.h +10 -26
- data/ext/google/protobuf_c/protobuf.c +3 -26
- data/ext/google/protobuf_c/protobuf.h +3 -26
- data/ext/google/protobuf_c/repeated_field.c +23 -27
- data/ext/google/protobuf_c/repeated_field.h +6 -26
- data/ext/google/protobuf_c/ruby-upb.c +8419 -8202
- data/ext/google/protobuf_c/ruby-upb.h +4079 -3786
- data/ext/google/protobuf_c/shared_convert.c +64 -0
- data/ext/google/protobuf_c/shared_convert.h +26 -0
- data/ext/google/protobuf_c/shared_message.c +66 -0
- data/ext/google/protobuf_c/shared_message.h +25 -0
- data/ext/google/protobuf_c/wrap_memcpy.c +3 -26
- data/lib/google/protobuf/any_pb.rb +1 -1
- data/lib/google/protobuf/api_pb.rb +1 -1
- data/lib/google/protobuf/descriptor_pb.rb +6 -3
- data/lib/google/protobuf/duration_pb.rb +1 -1
- data/lib/google/protobuf/empty_pb.rb +1 -1
- data/lib/google/protobuf/ffi/descriptor.rb +165 -0
- data/lib/google/protobuf/ffi/descriptor_pool.rb +75 -0
- data/lib/google/protobuf/ffi/enum_descriptor.rb +171 -0
- data/lib/google/protobuf/ffi/ffi.rb +213 -0
- data/lib/google/protobuf/ffi/field_descriptor.rb +319 -0
- data/lib/google/protobuf/ffi/file_descriptor.rb +59 -0
- data/lib/google/protobuf/ffi/internal/arena.rb +66 -0
- data/lib/google/protobuf/ffi/internal/convert.rb +305 -0
- data/lib/google/protobuf/ffi/internal/pointer_helper.rb +35 -0
- data/lib/google/protobuf/ffi/internal/type_safety.rb +25 -0
- data/lib/google/protobuf/ffi/map.rb +407 -0
- data/lib/google/protobuf/ffi/message.rb +662 -0
- data/lib/google/protobuf/ffi/object_cache.rb +30 -0
- data/lib/google/protobuf/ffi/oneof_descriptor.rb +95 -0
- data/lib/google/protobuf/ffi/repeated_field.rb +383 -0
- data/lib/google/protobuf/field_mask_pb.rb +1 -1
- data/lib/google/protobuf/message_exts.rb +3 -26
- data/lib/google/protobuf/object_cache.rb +3 -26
- data/lib/google/protobuf/plugin_pb.rb +1 -1
- data/lib/google/protobuf/repeated_field.rb +3 -26
- data/lib/google/protobuf/source_context_pb.rb +1 -1
- data/lib/google/protobuf/struct_pb.rb +1 -1
- data/lib/google/protobuf/timestamp_pb.rb +1 -1
- data/lib/google/protobuf/type_pb.rb +1 -1
- data/lib/google/protobuf/well_known_types.rb +3 -26
- data/lib/google/protobuf/wrappers_pb.rb +1 -1
- data/lib/google/protobuf.rb +26 -45
- data/lib/google/protobuf_ffi.rb +50 -0
- data/lib/google/protobuf_native.rb +20 -0
- data/lib/google/tasks/ffi.rake +102 -0
- metadata +70 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ed4bd55ed50c29cd40fecbbd93d294546fe6f1d942c7440ec1fce2a26e2bc04
|
4
|
+
data.tar.gz: 9f499fbc0539610fe54b04da07fe65323b40edfc4220e0c2234ecfb9d1166108
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35d44491d7a2163b7ce827e242ab59851d13ec5bb99be8feb0e0560945f62b54e7efd38a4aeaaf5721678b69d300fd769a0694294b63447f6cbca7db9f8d2aaf
|
7
|
+
data.tar.gz: 42035d41193b5343016af24fd141e7d27259d265e4b10dc15a467244a06a4d8d8daf3acc45865bcffa946162fce4fbadc4b31fbba406b4c52b30350a55e82935
|
@@ -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
|
-
//
|
6
|
-
//
|
7
|
-
//
|
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
|
}
|
@@ -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
|
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
|
-
|
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
|
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
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
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
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
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
|
-
//
|
6
|
-
//
|
7
|
-
//
|
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
|
-
//
|
6
|
-
//
|
7
|
-
//
|
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
|
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;
|
@@ -507,12 +541,31 @@ static VALUE FileDescriptor_syntax(VALUE _self) {
|
|
507
541
|
}
|
508
542
|
}
|
509
543
|
|
544
|
+
/*
|
545
|
+
* call-seq:
|
546
|
+
* FileDescriptor.options => options
|
547
|
+
*
|
548
|
+
* Returns the `FileOptions` for this `FileDescriptor`.
|
549
|
+
*/
|
550
|
+
static VALUE FileDescriptor_options(VALUE _self) {
|
551
|
+
FileDescriptor* self = ruby_to_FileDescriptor(_self);
|
552
|
+
const google_protobuf_FileOptions* opts = upb_FileDef_Options(self->filedef);
|
553
|
+
upb_Arena* arena = upb_Arena_New();
|
554
|
+
size_t size;
|
555
|
+
char* serialized = google_protobuf_FileOptions_serialize(opts, arena, &size);
|
556
|
+
VALUE file_options = decode_options(_self, "FileOptions", size, serialized,
|
557
|
+
self->descriptor_pool);
|
558
|
+
upb_Arena_Free(arena);
|
559
|
+
return file_options;
|
560
|
+
}
|
561
|
+
|
510
562
|
static void FileDescriptor_register(VALUE module) {
|
511
563
|
VALUE klass = rb_define_class_under(module, "FileDescriptor", rb_cObject);
|
512
564
|
rb_define_alloc_func(klass, FileDescriptor_alloc);
|
513
565
|
rb_define_method(klass, "initialize", FileDescriptor_initialize, 3);
|
514
566
|
rb_define_method(klass, "name", FileDescriptor_name, 0);
|
515
567
|
rb_define_method(klass, "syntax", FileDescriptor_syntax, 0);
|
568
|
+
rb_define_method(klass, "options", FileDescriptor_options, 0);
|
516
569
|
rb_gc_register_address(&cFileDescriptor);
|
517
570
|
cFileDescriptor = klass;
|
518
571
|
}
|
@@ -563,7 +616,7 @@ static VALUE FieldDescriptor_alloc(VALUE klass) {
|
|
563
616
|
|
564
617
|
/*
|
565
618
|
* call-seq:
|
566
|
-
*
|
619
|
+
* FieldDescriptor.new(c_only_cookie, pool, ptr) => FieldDescriptor
|
567
620
|
*
|
568
621
|
* Creates a descriptor wrapper object. May only be called from C.
|
569
622
|
*/
|
@@ -809,7 +862,7 @@ static VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) {
|
|
809
862
|
static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
|
810
863
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
811
864
|
const upb_MessageDef* m;
|
812
|
-
const
|
865
|
+
const upb_Message* msg = Message_Get(msg_rb, &m);
|
813
866
|
|
814
867
|
if (m != upb_FieldDef_ContainingType(self->fielddef)) {
|
815
868
|
rb_raise(cTypeError, "has method called on wrong message type");
|
@@ -829,7 +882,7 @@ static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) {
|
|
829
882
|
static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
|
830
883
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
831
884
|
const upb_MessageDef* m;
|
832
|
-
|
885
|
+
upb_Message* msg = Message_GetMutable(msg_rb, &m);
|
833
886
|
|
834
887
|
if (m != upb_FieldDef_ContainingType(self->fielddef)) {
|
835
888
|
rb_raise(cTypeError, "has method called on wrong message type");
|
@@ -850,7 +903,7 @@ static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) {
|
|
850
903
|
static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) {
|
851
904
|
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
852
905
|
const upb_MessageDef* m;
|
853
|
-
|
906
|
+
upb_Message* msg = Message_GetMutable(msg_rb, &m);
|
854
907
|
upb_Arena* arena = Arena_get(Message_GetArena(msg_rb));
|
855
908
|
upb_MessageValue msgval;
|
856
909
|
|
@@ -864,6 +917,25 @@ static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) {
|
|
864
917
|
return Qnil;
|
865
918
|
}
|
866
919
|
|
920
|
+
/*
|
921
|
+
* call-seq:
|
922
|
+
* FieldDescriptor.options => options
|
923
|
+
*
|
924
|
+
* Returns the `FieldOptions` for this `FieldDescriptor`.
|
925
|
+
*/
|
926
|
+
static VALUE FieldDescriptor_options(VALUE _self) {
|
927
|
+
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
|
928
|
+
const google_protobuf_FieldOptions* opts =
|
929
|
+
upb_FieldDef_Options(self->fielddef);
|
930
|
+
upb_Arena* arena = upb_Arena_New();
|
931
|
+
size_t size;
|
932
|
+
char* serialized = google_protobuf_FieldOptions_serialize(opts, arena, &size);
|
933
|
+
VALUE field_options = decode_options(_self, "FieldOptions", size, serialized,
|
934
|
+
self->descriptor_pool);
|
935
|
+
upb_Arena_Free(arena);
|
936
|
+
return field_options;
|
937
|
+
}
|
938
|
+
|
867
939
|
static void FieldDescriptor_register(VALUE module) {
|
868
940
|
VALUE klass = rb_define_class_under(module, "FieldDescriptor", rb_cObject);
|
869
941
|
rb_define_alloc_func(klass, FieldDescriptor_alloc);
|
@@ -880,6 +952,7 @@ static void FieldDescriptor_register(VALUE module) {
|
|
880
952
|
rb_define_method(klass, "clear", FieldDescriptor_clear, 1);
|
881
953
|
rb_define_method(klass, "get", FieldDescriptor_get, 1);
|
882
954
|
rb_define_method(klass, "set", FieldDescriptor_set, 2);
|
955
|
+
rb_define_method(klass, "options", FieldDescriptor_options, 0);
|
883
956
|
rb_gc_register_address(&cFieldDescriptor);
|
884
957
|
cFieldDescriptor = klass;
|
885
958
|
}
|
@@ -979,12 +1052,32 @@ static VALUE OneofDescriptor_each(VALUE _self) {
|
|
979
1052
|
return Qnil;
|
980
1053
|
}
|
981
1054
|
|
1055
|
+
/*
|
1056
|
+
* call-seq:
|
1057
|
+
* OneofDescriptor.options => options
|
1058
|
+
*
|
1059
|
+
* Returns the `OneofOptions` for this `OneofDescriptor`.
|
1060
|
+
*/
|
1061
|
+
static VALUE OneOfDescriptor_options(VALUE _self) {
|
1062
|
+
OneofDescriptor* self = ruby_to_OneofDescriptor(_self);
|
1063
|
+
const google_protobuf_OneofOptions* opts =
|
1064
|
+
upb_OneofDef_Options(self->oneofdef);
|
1065
|
+
upb_Arena* arena = upb_Arena_New();
|
1066
|
+
size_t size;
|
1067
|
+
char* serialized = google_protobuf_OneofOptions_serialize(opts, arena, &size);
|
1068
|
+
VALUE oneof_options = decode_options(_self, "OneofOptions", size, serialized,
|
1069
|
+
self->descriptor_pool);
|
1070
|
+
upb_Arena_Free(arena);
|
1071
|
+
return oneof_options;
|
1072
|
+
}
|
1073
|
+
|
982
1074
|
static void OneofDescriptor_register(VALUE module) {
|
983
1075
|
VALUE klass = rb_define_class_under(module, "OneofDescriptor", rb_cObject);
|
984
1076
|
rb_define_alloc_func(klass, OneofDescriptor_alloc);
|
985
1077
|
rb_define_method(klass, "initialize", OneofDescriptor_initialize, 3);
|
986
1078
|
rb_define_method(klass, "name", OneofDescriptor_name, 0);
|
987
1079
|
rb_define_method(klass, "each", OneofDescriptor_each, 0);
|
1080
|
+
rb_define_method(klass, "options", OneOfDescriptor_options, 0);
|
988
1081
|
rb_include_module(klass, rb_mEnumerable);
|
989
1082
|
rb_gc_register_address(&cOneofDescriptor);
|
990
1083
|
cOneofDescriptor = klass;
|
@@ -1154,6 +1247,24 @@ static VALUE EnumDescriptor_enummodule(VALUE _self) {
|
|
1154
1247
|
return self->module;
|
1155
1248
|
}
|
1156
1249
|
|
1250
|
+
/*
|
1251
|
+
* call-seq:
|
1252
|
+
* EnumDescriptor.options => options
|
1253
|
+
*
|
1254
|
+
* Returns the `EnumOptions` for this `EnumDescriptor`.
|
1255
|
+
*/
|
1256
|
+
static VALUE EnumDescriptor_options(VALUE _self) {
|
1257
|
+
EnumDescriptor* self = ruby_to_EnumDescriptor(_self);
|
1258
|
+
const google_protobuf_EnumOptions* opts = upb_EnumDef_Options(self->enumdef);
|
1259
|
+
upb_Arena* arena = upb_Arena_New();
|
1260
|
+
size_t size;
|
1261
|
+
char* serialized = google_protobuf_EnumOptions_serialize(opts, arena, &size);
|
1262
|
+
VALUE enum_options = decode_options(_self, "EnumOptions", size, serialized,
|
1263
|
+
self->descriptor_pool);
|
1264
|
+
upb_Arena_Free(arena);
|
1265
|
+
return enum_options;
|
1266
|
+
}
|
1267
|
+
|
1157
1268
|
static void EnumDescriptor_register(VALUE module) {
|
1158
1269
|
VALUE klass = rb_define_class_under(module, "EnumDescriptor", rb_cObject);
|
1159
1270
|
rb_define_alloc_func(klass, EnumDescriptor_alloc);
|
@@ -1164,6 +1275,7 @@ static void EnumDescriptor_register(VALUE module) {
|
|
1164
1275
|
rb_define_method(klass, "each", EnumDescriptor_each, 0);
|
1165
1276
|
rb_define_method(klass, "enummodule", EnumDescriptor_enummodule, 0);
|
1166
1277
|
rb_define_method(klass, "file_descriptor", EnumDescriptor_file_descriptor, 0);
|
1278
|
+
rb_define_method(klass, "options", EnumDescriptor_options, 0);
|
1167
1279
|
rb_include_module(klass, rb_mEnumerable);
|
1168
1280
|
rb_gc_register_address(&cEnumDescriptor);
|
1169
1281
|
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
|
-
//
|
6
|
-
//
|
7
|
-
//
|
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
|
+
"naive.c", "range2-neon.c", "range2-sse.c", "shared_convert.c",
|
26
|
+
"shared_message.c"]
|
26
27
|
|
27
28
|
create_makefile(ext_name)
|
@@ -0,0 +1,56 @@
|
|
1
|
+
// Protocol Buffers - Google's data interchange format
|
2
|
+
// Copyright 2023 Google Inc. All rights reserved.
|
3
|
+
//
|
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
|
7
|
+
|
8
|
+
// -----------------------------------------------------------------------------
|
9
|
+
// Exposing inlined UPB functions. Strictly free of dependencies on
|
10
|
+
// Ruby interpreter internals.
|
11
|
+
|
12
|
+
#include "ruby-upb.h"
|
13
|
+
|
14
|
+
upb_Arena* Arena_create() { return upb_Arena_Init(NULL, 0, &upb_alloc_global); }
|
15
|
+
|
16
|
+
google_protobuf_FileDescriptorProto* FileDescriptorProto_parse(
|
17
|
+
const char* serialized_file_proto, size_t length, upb_Arena* arena) {
|
18
|
+
return google_protobuf_FileDescriptorProto_parse(serialized_file_proto,
|
19
|
+
length, arena);
|
20
|
+
}
|
21
|
+
|
22
|
+
char* EnumDescriptor_serialized_options(const upb_EnumDef* enumdef,
|
23
|
+
size_t* size, upb_Arena* arena) {
|
24
|
+
const google_protobuf_EnumOptions* opts = upb_EnumDef_Options(enumdef);
|
25
|
+
char* serialized = google_protobuf_EnumOptions_serialize(opts, arena, size);
|
26
|
+
return serialized;
|
27
|
+
}
|
28
|
+
|
29
|
+
char* FileDescriptor_serialized_options(const upb_FileDef* filedef,
|
30
|
+
size_t* size, upb_Arena* arena) {
|
31
|
+
const google_protobuf_FileOptions* opts = upb_FileDef_Options(filedef);
|
32
|
+
char* serialized = google_protobuf_FileOptions_serialize(opts, arena, size);
|
33
|
+
return serialized;
|
34
|
+
}
|
35
|
+
|
36
|
+
char* Descriptor_serialized_options(const upb_MessageDef* msgdef, size_t* size,
|
37
|
+
upb_Arena* arena) {
|
38
|
+
const google_protobuf_MessageOptions* opts = upb_MessageDef_Options(msgdef);
|
39
|
+
char* serialized =
|
40
|
+
google_protobuf_MessageOptions_serialize(opts, arena, size);
|
41
|
+
return serialized;
|
42
|
+
}
|
43
|
+
|
44
|
+
char* OneOfDescriptor_serialized_options(const upb_OneofDef* oneofdef,
|
45
|
+
size_t* size, upb_Arena* arena) {
|
46
|
+
const google_protobuf_OneofOptions* opts = upb_OneofDef_Options(oneofdef);
|
47
|
+
char* serialized = google_protobuf_OneofOptions_serialize(opts, arena, size);
|
48
|
+
return serialized;
|
49
|
+
}
|
50
|
+
|
51
|
+
char* FieldDescriptor_serialized_options(const upb_FieldDef* fielddef,
|
52
|
+
size_t* size, upb_Arena* arena) {
|
53
|
+
const google_protobuf_FieldOptions* opts = upb_FieldDef_Options(fielddef);
|
54
|
+
char* serialized = google_protobuf_FieldOptions_serialize(opts, arena, size);
|
55
|
+
return serialized;
|
56
|
+
}
|