google-protobuf 3.11.1 → 3.25.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/google/protobuf_c/Rakefile +3 -0
- data/ext/google/protobuf_c/convert.c +314 -0
- data/ext/google/protobuf_c/convert.h +50 -0
- data/ext/google/protobuf_c/defs.c +745 -1620
- data/ext/google/protobuf_c/defs.h +82 -0
- data/ext/google/protobuf_c/extconf.rb +15 -8
- data/ext/google/protobuf_c/glue.c +56 -0
- data/ext/google/protobuf_c/map.c +336 -512
- data/ext/google/protobuf_c/map.h +44 -0
- data/ext/google/protobuf_c/message.c +1096 -520
- data/ext/google/protobuf_c/message.h +86 -0
- data/ext/google/protobuf_c/protobuf.c +301 -94
- data/ext/google/protobuf_c/protobuf.h +66 -620
- data/ext/google/protobuf_c/repeated_field.c +323 -353
- data/ext/google/protobuf_c/repeated_field.h +41 -0
- data/ext/google/protobuf_c/ruby-upb.c +14414 -0
- data/ext/google/protobuf_c/ruby-upb.h +13044 -0
- 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 +65 -0
- data/ext/google/protobuf_c/shared_message.h +25 -0
- data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +22 -0
- data/ext/google/protobuf_c/third_party/utf8_range/naive.c +92 -0
- data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +157 -0
- data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +170 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +21 -0
- data/ext/google/protobuf_c/wrap_memcpy.c +7 -29
- data/lib/google/protobuf/any_pb.rb +24 -5
- data/lib/google/protobuf/api_pb.rb +27 -23
- data/lib/google/protobuf/descriptor_dsl.rb +465 -0
- data/lib/google/protobuf/descriptor_pb.rb +86 -0
- data/lib/google/protobuf/duration_pb.rb +24 -5
- data/lib/google/protobuf/empty_pb.rb +24 -3
- 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 +24 -4
- data/lib/google/protobuf/message_exts.rb +10 -28
- data/lib/google/protobuf/object_cache.rb +97 -0
- data/lib/google/protobuf/plugin_pb.rb +47 -0
- data/lib/google/protobuf/repeated_field.rb +18 -28
- data/lib/google/protobuf/source_context_pb.rb +24 -4
- data/lib/google/protobuf/struct_pb.rb +24 -20
- data/lib/google/protobuf/timestamp_pb.rb +24 -5
- data/lib/google/protobuf/type_pb.rb +27 -68
- data/lib/google/protobuf/well_known_types.rb +17 -36
- data/lib/google/protobuf/wrappers_pb.rb +24 -28
- data/lib/google/protobuf.rb +32 -118
- 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 +92 -32
- data/ext/google/protobuf_c/encode_decode.c +0 -1758
- data/ext/google/protobuf_c/storage.c +0 -1149
- data/ext/google/protobuf_c/upb.c +0 -13289
- data/ext/google/protobuf_c/upb.h +0 -7085
- data/tests/basic.rb +0 -445
- data/tests/generated_code_test.rb +0 -23
- data/tests/stress.rb +0 -38
@@ -1,666 +1,112 @@
|
|
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
|
#ifndef __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__
|
32
9
|
#define __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__
|
33
10
|
|
34
|
-
|
35
|
-
#
|
36
|
-
#include <ruby
|
37
|
-
|
38
|
-
#include
|
39
|
-
|
40
|
-
|
41
|
-
struct DescriptorPool;
|
42
|
-
struct Descriptor;
|
43
|
-
struct FileDescriptor;
|
44
|
-
struct FieldDescriptor;
|
45
|
-
struct EnumDescriptor;
|
46
|
-
struct MessageLayout;
|
47
|
-
struct MessageField;
|
48
|
-
struct MessageHeader;
|
49
|
-
struct MessageBuilderContext;
|
50
|
-
struct EnumBuilderContext;
|
51
|
-
struct FileBuilderContext;
|
52
|
-
struct Builder;
|
53
|
-
|
54
|
-
typedef struct DescriptorPool DescriptorPool;
|
55
|
-
typedef struct Descriptor Descriptor;
|
56
|
-
typedef struct FileDescriptor FileDescriptor;
|
57
|
-
typedef struct FieldDescriptor FieldDescriptor;
|
58
|
-
typedef struct OneofDescriptor OneofDescriptor;
|
59
|
-
typedef struct EnumDescriptor EnumDescriptor;
|
60
|
-
typedef struct MessageLayout MessageLayout;
|
61
|
-
typedef struct MessageField MessageField;
|
62
|
-
typedef struct MessageOneof MessageOneof;
|
63
|
-
typedef struct MessageHeader MessageHeader;
|
64
|
-
typedef struct MessageBuilderContext MessageBuilderContext;
|
65
|
-
typedef struct OneofBuilderContext OneofBuilderContext;
|
66
|
-
typedef struct EnumBuilderContext EnumBuilderContext;
|
67
|
-
typedef struct FileBuilderContext FileBuilderContext;
|
68
|
-
typedef struct Builder Builder;
|
69
|
-
|
70
|
-
/*
|
71
|
-
It can be a bit confusing how the C structs defined below and the Ruby
|
72
|
-
objects interact and hold references to each other. First, a few principles:
|
73
|
-
|
74
|
-
- Ruby's "TypedData" abstraction lets a Ruby VALUE hold a pointer to a C
|
75
|
-
struct (or arbitrary memory chunk), own it, and free it when collected.
|
76
|
-
Thus, each struct below will have a corresponding Ruby object
|
77
|
-
wrapping/owning it.
|
78
|
-
|
79
|
-
- To get back from an underlying upb {msg,enum}def to the Ruby object, we
|
80
|
-
keep a global hashmap, accessed by get_def_obj/add_def_obj below.
|
81
|
-
|
82
|
-
The in-memory structure is then something like:
|
83
|
-
|
84
|
-
Ruby | upb
|
85
|
-
|
|
86
|
-
DescriptorPool ------------|-----------> upb_symtab____________________
|
87
|
-
| | (message types) \
|
88
|
-
| v \
|
89
|
-
Descriptor ---------------|-----------> upb_msgdef (enum types)|
|
90
|
-
|--> msgclass | | ^ |
|
91
|
-
| (dynamically built) | | | (submsg fields) |
|
92
|
-
|--> MessageLayout | | | /
|
93
|
-
|--------------------------|> decoder method| | /
|
94
|
-
\--------------------------|> serialize | | /
|
95
|
-
| handlers v | /
|
96
|
-
FieldDescriptor -----------|-----------> upb_fielddef /
|
97
|
-
| | /
|
98
|
-
| v (enum fields) /
|
99
|
-
EnumDescriptor ------------|-----------> upb_enumdef <----------'
|
100
|
-
|
|
101
|
-
|
|
102
|
-
^ | \___/
|
103
|
-
`---------------|-----------------' (get_def_obj map)
|
104
|
-
*/
|
105
|
-
|
106
|
-
// -----------------------------------------------------------------------------
|
107
|
-
// Ruby class structure definitions.
|
108
|
-
// -----------------------------------------------------------------------------
|
109
|
-
|
110
|
-
struct DescriptorPool {
|
111
|
-
VALUE def_to_descriptor; // Hash table of def* -> Ruby descriptor.
|
112
|
-
upb_symtab* symtab;
|
113
|
-
upb_handlercache* fill_handler_cache;
|
114
|
-
upb_handlercache* pb_serialize_handler_cache;
|
115
|
-
upb_handlercache* json_serialize_handler_cache;
|
116
|
-
upb_handlercache* json_serialize_handler_preserve_cache;
|
117
|
-
upb_pbcodecache* fill_method_cache;
|
118
|
-
upb_json_codecache* json_fill_method_cache;
|
119
|
-
};
|
120
|
-
|
121
|
-
struct Descriptor {
|
122
|
-
const upb_msgdef* msgdef;
|
123
|
-
MessageLayout* layout;
|
124
|
-
VALUE klass;
|
125
|
-
VALUE descriptor_pool;
|
126
|
-
};
|
127
|
-
|
128
|
-
struct FileDescriptor {
|
129
|
-
const upb_filedef* filedef;
|
130
|
-
VALUE descriptor_pool; // Owns the upb_filedef.
|
131
|
-
};
|
132
|
-
|
133
|
-
struct FieldDescriptor {
|
134
|
-
const upb_fielddef* fielddef;
|
135
|
-
VALUE descriptor_pool; // Owns the upb_fielddef.
|
136
|
-
};
|
137
|
-
|
138
|
-
struct OneofDescriptor {
|
139
|
-
const upb_oneofdef* oneofdef;
|
140
|
-
VALUE descriptor_pool; // Owns the upb_oneofdef.
|
141
|
-
};
|
142
|
-
|
143
|
-
struct EnumDescriptor {
|
144
|
-
const upb_enumdef* enumdef;
|
145
|
-
VALUE module; // begins as nil
|
146
|
-
VALUE descriptor_pool; // Owns the upb_enumdef.
|
147
|
-
};
|
148
|
-
|
149
|
-
struct MessageBuilderContext {
|
150
|
-
google_protobuf_DescriptorProto* msg_proto;
|
151
|
-
VALUE file_builder;
|
152
|
-
};
|
153
|
-
|
154
|
-
struct OneofBuilderContext {
|
155
|
-
int oneof_index;
|
156
|
-
VALUE message_builder;
|
157
|
-
};
|
158
|
-
|
159
|
-
struct EnumBuilderContext {
|
160
|
-
google_protobuf_EnumDescriptorProto* enum_proto;
|
161
|
-
VALUE file_builder;
|
162
|
-
};
|
163
|
-
|
164
|
-
struct FileBuilderContext {
|
165
|
-
upb_arena *arena;
|
166
|
-
google_protobuf_FileDescriptorProto* file_proto;
|
167
|
-
VALUE descriptor_pool;
|
168
|
-
};
|
169
|
-
|
170
|
-
struct Builder {
|
171
|
-
VALUE descriptor_pool;
|
172
|
-
VALUE default_file_builder;
|
173
|
-
};
|
174
|
-
|
175
|
-
extern VALUE cDescriptorPool;
|
176
|
-
extern VALUE cDescriptor;
|
177
|
-
extern VALUE cFileDescriptor;
|
178
|
-
extern VALUE cFieldDescriptor;
|
179
|
-
extern VALUE cEnumDescriptor;
|
180
|
-
extern VALUE cMessageBuilderContext;
|
181
|
-
extern VALUE cOneofBuilderContext;
|
182
|
-
extern VALUE cEnumBuilderContext;
|
183
|
-
extern VALUE cFileBuilderContext;
|
184
|
-
extern VALUE cBuilder;
|
185
|
-
|
186
|
-
extern VALUE cError;
|
187
|
-
extern VALUE cParseError;
|
188
|
-
extern VALUE cTypeError;
|
189
|
-
|
190
|
-
// We forward-declare all of the Ruby method implementations here because we
|
191
|
-
// sometimes call the methods directly across .c files, rather than going
|
192
|
-
// through Ruby's method dispatching (e.g. during message parse). It's cleaner
|
193
|
-
// to keep the list of object methods together than to split them between
|
194
|
-
// static-in-file definitions and header declarations.
|
195
|
-
|
196
|
-
void DescriptorPool_mark(void* _self);
|
197
|
-
void DescriptorPool_free(void* _self);
|
198
|
-
VALUE DescriptorPool_alloc(VALUE klass);
|
199
|
-
void DescriptorPool_register(VALUE module);
|
200
|
-
DescriptorPool* ruby_to_DescriptorPool(VALUE value);
|
201
|
-
VALUE DescriptorPool_build(int argc, VALUE* argv, VALUE _self);
|
202
|
-
VALUE DescriptorPool_lookup(VALUE _self, VALUE name);
|
203
|
-
VALUE DescriptorPool_generated_pool(VALUE _self);
|
204
|
-
|
205
|
-
extern VALUE generated_pool;
|
206
|
-
|
207
|
-
void Descriptor_mark(void* _self);
|
208
|
-
void Descriptor_free(void* _self);
|
209
|
-
VALUE Descriptor_alloc(VALUE klass);
|
210
|
-
void Descriptor_register(VALUE module);
|
211
|
-
Descriptor* ruby_to_Descriptor(VALUE value);
|
212
|
-
VALUE Descriptor_initialize(VALUE _self, VALUE cookie, VALUE descriptor_pool,
|
213
|
-
VALUE ptr);
|
214
|
-
VALUE Descriptor_name(VALUE _self);
|
215
|
-
VALUE Descriptor_each(VALUE _self);
|
216
|
-
VALUE Descriptor_lookup(VALUE _self, VALUE name);
|
217
|
-
VALUE Descriptor_each_oneof(VALUE _self);
|
218
|
-
VALUE Descriptor_lookup_oneof(VALUE _self, VALUE name);
|
219
|
-
VALUE Descriptor_msgclass(VALUE _self);
|
220
|
-
VALUE Descriptor_file_descriptor(VALUE _self);
|
221
|
-
extern const rb_data_type_t _Descriptor_type;
|
222
|
-
|
223
|
-
void FileDescriptor_mark(void* _self);
|
224
|
-
void FileDescriptor_free(void* _self);
|
225
|
-
VALUE FileDescriptor_alloc(VALUE klass);
|
226
|
-
void FileDescriptor_register(VALUE module);
|
227
|
-
FileDescriptor* ruby_to_FileDescriptor(VALUE value);
|
228
|
-
VALUE FileDescriptor_initialize(VALUE _self, VALUE cookie,
|
229
|
-
VALUE descriptor_pool, VALUE ptr);
|
230
|
-
VALUE FileDescriptor_name(VALUE _self);
|
231
|
-
VALUE FileDescriptor_syntax(VALUE _self);
|
232
|
-
|
233
|
-
void FieldDescriptor_mark(void* _self);
|
234
|
-
void FieldDescriptor_free(void* _self);
|
235
|
-
VALUE FieldDescriptor_alloc(VALUE klass);
|
236
|
-
void FieldDescriptor_register(VALUE module);
|
237
|
-
FieldDescriptor* ruby_to_FieldDescriptor(VALUE value);
|
238
|
-
VALUE FieldDescriptor_initialize(VALUE _self, VALUE cookie,
|
239
|
-
VALUE descriptor_pool, VALUE ptr);
|
240
|
-
VALUE FieldDescriptor_name(VALUE _self);
|
241
|
-
VALUE FieldDescriptor_type(VALUE _self);
|
242
|
-
VALUE FieldDescriptor_default(VALUE _self);
|
243
|
-
VALUE FieldDescriptor_label(VALUE _self);
|
244
|
-
VALUE FieldDescriptor_number(VALUE _self);
|
245
|
-
VALUE FieldDescriptor_submsg_name(VALUE _self);
|
246
|
-
VALUE FieldDescriptor_subtype(VALUE _self);
|
247
|
-
VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb);
|
248
|
-
VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb);
|
249
|
-
VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb);
|
250
|
-
VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value);
|
251
|
-
upb_fieldtype_t ruby_to_fieldtype(VALUE type);
|
252
|
-
VALUE fieldtype_to_ruby(upb_fieldtype_t type);
|
253
|
-
|
254
|
-
void OneofDescriptor_mark(void* _self);
|
255
|
-
void OneofDescriptor_free(void* _self);
|
256
|
-
VALUE OneofDescriptor_alloc(VALUE klass);
|
257
|
-
void OneofDescriptor_register(VALUE module);
|
258
|
-
OneofDescriptor* ruby_to_OneofDescriptor(VALUE value);
|
259
|
-
VALUE OneofDescriptor_initialize(VALUE _self, VALUE cookie,
|
260
|
-
VALUE descriptor_pool, VALUE ptr);
|
261
|
-
VALUE OneofDescriptor_name(VALUE _self);
|
262
|
-
VALUE OneofDescriptor_each(VALUE _self);
|
263
|
-
|
264
|
-
void EnumDescriptor_mark(void* _self);
|
265
|
-
void EnumDescriptor_free(void* _self);
|
266
|
-
VALUE EnumDescriptor_alloc(VALUE klass);
|
267
|
-
VALUE EnumDescriptor_initialize(VALUE _self, VALUE cookie,
|
268
|
-
VALUE descriptor_pool, VALUE ptr);
|
269
|
-
void EnumDescriptor_register(VALUE module);
|
270
|
-
EnumDescriptor* ruby_to_EnumDescriptor(VALUE value);
|
271
|
-
VALUE EnumDescriptor_file_descriptor(VALUE _self);
|
272
|
-
VALUE EnumDescriptor_name(VALUE _self);
|
273
|
-
VALUE EnumDescriptor_lookup_name(VALUE _self, VALUE name);
|
274
|
-
VALUE EnumDescriptor_lookup_value(VALUE _self, VALUE number);
|
275
|
-
VALUE EnumDescriptor_each(VALUE _self);
|
276
|
-
VALUE EnumDescriptor_enummodule(VALUE _self);
|
277
|
-
extern const rb_data_type_t _EnumDescriptor_type;
|
278
|
-
|
279
|
-
void MessageBuilderContext_mark(void* _self);
|
280
|
-
void MessageBuilderContext_free(void* _self);
|
281
|
-
VALUE MessageBuilderContext_alloc(VALUE klass);
|
282
|
-
void MessageBuilderContext_register(VALUE module);
|
283
|
-
MessageBuilderContext* ruby_to_MessageBuilderContext(VALUE value);
|
284
|
-
VALUE MessageBuilderContext_initialize(VALUE _self,
|
285
|
-
VALUE _file_builder,
|
286
|
-
VALUE name);
|
287
|
-
VALUE MessageBuilderContext_optional(int argc, VALUE* argv, VALUE _self);
|
288
|
-
VALUE MessageBuilderContext_required(int argc, VALUE* argv, VALUE _self);
|
289
|
-
VALUE MessageBuilderContext_repeated(int argc, VALUE* argv, VALUE _self);
|
290
|
-
VALUE MessageBuilderContext_map(int argc, VALUE* argv, VALUE _self);
|
291
|
-
VALUE MessageBuilderContext_oneof(VALUE _self, VALUE name);
|
292
|
-
|
293
|
-
void OneofBuilderContext_mark(void* _self);
|
294
|
-
void OneofBuilderContext_free(void* _self);
|
295
|
-
VALUE OneofBuilderContext_alloc(VALUE klass);
|
296
|
-
void OneofBuilderContext_register(VALUE module);
|
297
|
-
OneofBuilderContext* ruby_to_OneofBuilderContext(VALUE value);
|
298
|
-
VALUE OneofBuilderContext_initialize(VALUE _self,
|
299
|
-
VALUE descriptor,
|
300
|
-
VALUE builder);
|
301
|
-
VALUE OneofBuilderContext_optional(int argc, VALUE* argv, VALUE _self);
|
302
|
-
|
303
|
-
void EnumBuilderContext_mark(void* _self);
|
304
|
-
void EnumBuilderContext_free(void* _self);
|
305
|
-
VALUE EnumBuilderContext_alloc(VALUE klass);
|
306
|
-
void EnumBuilderContext_register(VALUE module);
|
307
|
-
EnumBuilderContext* ruby_to_EnumBuilderContext(VALUE value);
|
308
|
-
VALUE EnumBuilderContext_initialize(VALUE _self, VALUE _file_builder,
|
309
|
-
VALUE name);
|
310
|
-
VALUE EnumBuilderContext_value(VALUE _self, VALUE name, VALUE number);
|
311
|
-
|
312
|
-
void FileBuilderContext_mark(void* _self);
|
313
|
-
void FileBuilderContext_free(void* _self);
|
314
|
-
VALUE FileBuilderContext_alloc(VALUE klass);
|
315
|
-
void FileBuilderContext_register(VALUE module);
|
316
|
-
FileBuilderContext* ruby_to_FileBuilderContext(VALUE _self);
|
317
|
-
upb_strview FileBuilderContext_strdup(VALUE _self, VALUE rb_str);
|
318
|
-
upb_strview FileBuilderContext_strdup_name(VALUE _self, VALUE rb_str);
|
319
|
-
upb_strview FileBuilderContext_strdup_sym(VALUE _self, VALUE rb_sym);
|
320
|
-
VALUE FileBuilderContext_initialize(VALUE _self, VALUE descriptor_pool,
|
321
|
-
VALUE name, VALUE options);
|
322
|
-
VALUE FileBuilderContext_add_message(VALUE _self, VALUE name);
|
323
|
-
VALUE FileBuilderContext_add_enum(VALUE _self, VALUE name);
|
324
|
-
VALUE FileBuilderContext_pending_descriptors(VALUE _self);
|
325
|
-
|
326
|
-
void Builder_mark(void* _self);
|
327
|
-
void Builder_free(void* _self);
|
328
|
-
VALUE Builder_alloc(VALUE klass);
|
329
|
-
void Builder_register(VALUE module);
|
330
|
-
Builder* ruby_to_Builder(VALUE value);
|
331
|
-
VALUE Builder_build(VALUE _self);
|
332
|
-
VALUE Builder_initialize(VALUE _self, VALUE descriptor_pool);
|
333
|
-
VALUE Builder_add_file(int argc, VALUE *argv, VALUE _self);
|
334
|
-
VALUE Builder_add_message(VALUE _self, VALUE name);
|
335
|
-
VALUE Builder_add_enum(VALUE _self, VALUE name);
|
336
|
-
VALUE Builder_finalize_to_pool(VALUE _self, VALUE pool_rb);
|
337
|
-
|
338
|
-
// -----------------------------------------------------------------------------
|
339
|
-
// Native slot storage abstraction.
|
340
|
-
// -----------------------------------------------------------------------------
|
341
|
-
|
342
|
-
#define NATIVE_SLOT_MAX_SIZE sizeof(uint64_t)
|
343
|
-
|
344
|
-
size_t native_slot_size(upb_fieldtype_t type);
|
345
|
-
void native_slot_set(const char* name,
|
346
|
-
upb_fieldtype_t type,
|
347
|
-
VALUE type_class,
|
348
|
-
void* memory,
|
349
|
-
VALUE value);
|
350
|
-
// Atomically (with respect to Ruby VM calls) either update the value and set a
|
351
|
-
// oneof case, or do neither. If |case_memory| is null, then no case value is
|
352
|
-
// set.
|
353
|
-
void native_slot_set_value_and_case(const char* name,
|
354
|
-
upb_fieldtype_t type,
|
355
|
-
VALUE type_class,
|
356
|
-
void* memory,
|
357
|
-
VALUE value,
|
358
|
-
uint32_t* case_memory,
|
359
|
-
uint32_t case_number);
|
360
|
-
VALUE native_slot_get(upb_fieldtype_t type,
|
361
|
-
VALUE type_class,
|
362
|
-
const void* memory);
|
363
|
-
void native_slot_init(upb_fieldtype_t type, void* memory);
|
364
|
-
void native_slot_mark(upb_fieldtype_t type, void* memory);
|
365
|
-
void native_slot_dup(upb_fieldtype_t type, void* to, void* from);
|
366
|
-
void native_slot_deep_copy(upb_fieldtype_t type, VALUE type_class, void* to,
|
367
|
-
void* from);
|
368
|
-
bool native_slot_eq(upb_fieldtype_t type, VALUE type_class, void* mem1,
|
369
|
-
void* mem2);
|
370
|
-
|
371
|
-
VALUE native_slot_encode_and_freeze_string(upb_fieldtype_t type, VALUE value);
|
372
|
-
void native_slot_check_int_range_precision(const char* name, upb_fieldtype_t type, VALUE value);
|
373
|
-
uint32_t slot_read_oneof_case(MessageLayout* layout, const void* storage,
|
374
|
-
const upb_oneofdef* oneof);
|
375
|
-
bool is_value_field(const upb_fielddef* f);
|
11
|
+
// Ruby 3+ defines NDEBUG itself, see: https://bugs.ruby-lang.org/issues/18777
|
12
|
+
#ifdef NDEBUG
|
13
|
+
#include <ruby.h>
|
14
|
+
#else
|
15
|
+
#include <ruby.h>
|
16
|
+
#undef NDEBUG
|
17
|
+
#endif
|
376
18
|
|
377
|
-
|
378
|
-
extern rb_encoding* kRubyStringASCIIEncoding;
|
379
|
-
extern rb_encoding* kRubyString8bitEncoding;
|
19
|
+
#include <ruby/version.h>
|
380
20
|
|
381
|
-
|
21
|
+
#if RUBY_API_VERSION_CODE < 20700
|
22
|
+
#error Protobuf requires Ruby >= 2.7
|
23
|
+
#endif
|
382
24
|
|
383
|
-
#
|
384
|
-
#
|
25
|
+
#include <assert.h> // Must be included after the NDEBUG logic above.
|
26
|
+
#include <ruby/encoding.h>
|
27
|
+
#include <ruby/vm.h>
|
385
28
|
|
386
|
-
|
387
|
-
|
388
|
-
// have a number of 0.
|
389
|
-
#define ONEOF_CASE_NONE 0
|
29
|
+
#include "defs.h"
|
30
|
+
#include "ruby-upb.h"
|
390
31
|
|
391
32
|
// These operate on a map field (i.e., a repeated field of submessages whose
|
392
33
|
// submessage type is a map-entry msgdef).
|
393
|
-
|
394
|
-
const
|
395
|
-
const upb_fielddef* map_field_value(const upb_fielddef* field);
|
396
|
-
|
397
|
-
// These operate on a map-entry msgdef.
|
398
|
-
const upb_fielddef* map_entry_key(const upb_msgdef* msgdef);
|
399
|
-
const upb_fielddef* map_entry_value(const upb_msgdef* msgdef);
|
34
|
+
const upb_FieldDef* map_field_key(const upb_FieldDef* field);
|
35
|
+
const upb_FieldDef* map_field_value(const upb_FieldDef* field);
|
400
36
|
|
401
37
|
// -----------------------------------------------------------------------------
|
402
|
-
//
|
38
|
+
// Arena
|
403
39
|
// -----------------------------------------------------------------------------
|
404
40
|
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
int size;
|
410
|
-
int capacity;
|
411
|
-
} RepeatedField;
|
412
|
-
|
413
|
-
void RepeatedField_mark(void* self);
|
414
|
-
void RepeatedField_free(void* self);
|
415
|
-
VALUE RepeatedField_alloc(VALUE klass);
|
416
|
-
VALUE RepeatedField_init(int argc, VALUE* argv, VALUE self);
|
417
|
-
void RepeatedField_register(VALUE module);
|
418
|
-
|
419
|
-
extern const rb_data_type_t RepeatedField_type;
|
420
|
-
extern VALUE cRepeatedField;
|
421
|
-
|
422
|
-
RepeatedField* ruby_to_RepeatedField(VALUE value);
|
41
|
+
// A Ruby object that wraps an underlying upb_Arena. Any objects that are
|
42
|
+
// allocated from this arena should reference the Arena in rb_gc_mark(), to
|
43
|
+
// ensure that the object's underlying memory outlives any Ruby object that can
|
44
|
+
// reach it.
|
423
45
|
|
424
|
-
VALUE
|
425
|
-
|
426
|
-
VALUE RepeatedField_index(int argc, VALUE* argv, VALUE _self);
|
427
|
-
void* RepeatedField_index_native(VALUE _self, int index);
|
428
|
-
int RepeatedField_size(VALUE _self);
|
429
|
-
VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val);
|
430
|
-
void RepeatedField_reserve(RepeatedField* self, int new_size);
|
431
|
-
VALUE RepeatedField_push(VALUE _self, VALUE val);
|
432
|
-
void RepeatedField_push_native(VALUE _self, void* data);
|
433
|
-
VALUE RepeatedField_pop_one(VALUE _self);
|
434
|
-
VALUE RepeatedField_insert(int argc, VALUE* argv, VALUE _self);
|
435
|
-
VALUE RepeatedField_replace(VALUE _self, VALUE list);
|
436
|
-
VALUE RepeatedField_clear(VALUE _self);
|
437
|
-
VALUE RepeatedField_length(VALUE _self);
|
438
|
-
VALUE RepeatedField_dup(VALUE _self);
|
439
|
-
VALUE RepeatedField_deep_copy(VALUE _self);
|
440
|
-
VALUE RepeatedField_to_ary(VALUE _self);
|
441
|
-
VALUE RepeatedField_eq(VALUE _self, VALUE _other);
|
442
|
-
VALUE RepeatedField_hash(VALUE _self);
|
443
|
-
VALUE RepeatedField_inspect(VALUE _self);
|
444
|
-
VALUE RepeatedField_plus(VALUE _self, VALUE list);
|
46
|
+
VALUE Arena_new();
|
47
|
+
upb_Arena* Arena_get(VALUE arena);
|
445
48
|
|
446
|
-
//
|
447
|
-
|
49
|
+
// Fuses this arena to another, throwing a Ruby exception if this is not
|
50
|
+
// possible.
|
51
|
+
void Arena_fuse(VALUE arena, upb_Arena* other);
|
448
52
|
|
449
|
-
//
|
450
|
-
//
|
451
|
-
//
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
upb_fieldtype_t value_type;
|
456
|
-
VALUE value_type_class;
|
457
|
-
VALUE parse_frame;
|
458
|
-
upb_strtable table;
|
459
|
-
} Map;
|
460
|
-
|
461
|
-
void Map_mark(void* self);
|
462
|
-
void Map_free(void* self);
|
463
|
-
VALUE Map_alloc(VALUE klass);
|
464
|
-
VALUE Map_init(int argc, VALUE* argv, VALUE self);
|
465
|
-
void Map_register(VALUE module);
|
466
|
-
VALUE Map_set_frame(VALUE self, VALUE val);
|
467
|
-
|
468
|
-
extern const rb_data_type_t Map_type;
|
469
|
-
extern VALUE cMap;
|
470
|
-
|
471
|
-
Map* ruby_to_Map(VALUE value);
|
472
|
-
|
473
|
-
VALUE Map_new_this_type(VALUE _self);
|
474
|
-
VALUE Map_each(VALUE _self);
|
475
|
-
VALUE Map_keys(VALUE _self);
|
476
|
-
VALUE Map_values(VALUE _self);
|
477
|
-
VALUE Map_index(VALUE _self, VALUE key);
|
478
|
-
VALUE Map_index_set(VALUE _self, VALUE key, VALUE value);
|
479
|
-
VALUE Map_has_key(VALUE _self, VALUE key);
|
480
|
-
VALUE Map_delete(VALUE _self, VALUE key);
|
481
|
-
VALUE Map_clear(VALUE _self);
|
482
|
-
VALUE Map_length(VALUE _self);
|
483
|
-
VALUE Map_dup(VALUE _self);
|
484
|
-
VALUE Map_deep_copy(VALUE _self);
|
485
|
-
VALUE Map_eq(VALUE _self, VALUE _other);
|
486
|
-
VALUE Map_hash(VALUE _self);
|
487
|
-
VALUE Map_to_h(VALUE _self);
|
488
|
-
VALUE Map_inspect(VALUE _self);
|
489
|
-
VALUE Map_merge(VALUE _self, VALUE hashmap);
|
490
|
-
VALUE Map_merge_into_self(VALUE _self, VALUE hashmap);
|
491
|
-
|
492
|
-
typedef struct {
|
493
|
-
Map* self;
|
494
|
-
upb_strtable_iter it;
|
495
|
-
} Map_iter;
|
496
|
-
|
497
|
-
void Map_begin(VALUE _self, Map_iter* iter);
|
498
|
-
void Map_next(Map_iter* iter);
|
499
|
-
bool Map_done(Map_iter* iter);
|
500
|
-
VALUE Map_iter_key(Map_iter* iter);
|
501
|
-
VALUE Map_iter_value(Map_iter* iter);
|
53
|
+
// Pins this Ruby object to the lifetime of this arena, so that as long as the
|
54
|
+
// arena is alive this object will not be collected.
|
55
|
+
//
|
56
|
+
// We use this to guarantee that the "frozen" bit on the object will be
|
57
|
+
// remembered, even if the user drops their reference to this precise object.
|
58
|
+
void Arena_Pin(VALUE arena, VALUE obj);
|
502
59
|
|
503
60
|
// -----------------------------------------------------------------------------
|
504
|
-
//
|
61
|
+
// ObjectCache
|
505
62
|
// -----------------------------------------------------------------------------
|
506
63
|
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
};
|
513
|
-
|
514
|
-
struct MessageOneof {
|
515
|
-
uint32_t offset;
|
516
|
-
uint32_t case_offset;
|
517
|
-
};
|
518
|
-
|
519
|
-
// MessageLayout is owned by the enclosing Descriptor, which must outlive us.
|
520
|
-
struct MessageLayout {
|
521
|
-
const Descriptor* desc;
|
522
|
-
const upb_msgdef* msgdef;
|
523
|
-
void* empty_template; // Can memcpy() onto a layout to clear it.
|
524
|
-
MessageField* fields;
|
525
|
-
MessageOneof* oneofs;
|
526
|
-
uint32_t size;
|
527
|
-
uint32_t value_offset;
|
528
|
-
int value_count;
|
529
|
-
int repeated_count;
|
530
|
-
int map_count;
|
531
|
-
};
|
532
|
-
|
533
|
-
#define ONEOF_CASE_MASK 0x80000000
|
64
|
+
// Global object cache from upb array/map/message/symtab to wrapper object.
|
65
|
+
//
|
66
|
+
// This is a conceptually "weak" cache, in that it does not prevent "val" from
|
67
|
+
// being collected (though in Ruby <2.7 is it effectively strong, due to
|
68
|
+
// implementation limitations).
|
534
69
|
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
const upb_fielddef* field);
|
539
|
-
VALUE layout_get_default(const upb_fielddef* field);
|
540
|
-
VALUE layout_get(MessageLayout* layout,
|
541
|
-
const void* storage,
|
542
|
-
const upb_fielddef* field);
|
543
|
-
void layout_set(MessageLayout* layout,
|
544
|
-
void* storage,
|
545
|
-
const upb_fielddef* field,
|
546
|
-
VALUE val);
|
547
|
-
VALUE layout_has(MessageLayout* layout,
|
548
|
-
const void* storage,
|
549
|
-
const upb_fielddef* field);
|
550
|
-
void layout_clear(MessageLayout* layout,
|
551
|
-
const void* storage,
|
552
|
-
const upb_fielddef* field);
|
553
|
-
void layout_init(MessageLayout* layout, void* storage);
|
554
|
-
void layout_mark(MessageLayout* layout, void* storage);
|
555
|
-
void layout_dup(MessageLayout* layout, void* to, void* from);
|
556
|
-
void layout_deep_copy(MessageLayout* layout, void* to, void* from);
|
557
|
-
VALUE layout_eq(MessageLayout* layout, void* msg1, void* msg2);
|
558
|
-
VALUE layout_hash(MessageLayout* layout, void* storage);
|
559
|
-
VALUE layout_inspect(MessageLayout* layout, void* storage);
|
70
|
+
// Tries to add a new entry to the cache, returning the newly installed value or
|
71
|
+
// the pre-existing entry.
|
72
|
+
VALUE ObjectCache_TryAdd(const void* key, VALUE val);
|
560
73
|
|
561
|
-
|
562
|
-
VALUE
|
74
|
+
// Returns the cached object for this key, if any. Otherwise returns Qnil.
|
75
|
+
VALUE ObjectCache_Get(const void* key);
|
563
76
|
|
564
77
|
// -----------------------------------------------------------------------------
|
565
|
-
//
|
78
|
+
// StringBuilder, for inspect
|
566
79
|
// -----------------------------------------------------------------------------
|
567
80
|
|
568
|
-
|
569
|
-
|
570
|
-
typedef struct {
|
571
|
-
upb_byteshandler handler;
|
572
|
-
upb_bytessink sink;
|
573
|
-
char *ptr;
|
574
|
-
size_t len, size;
|
575
|
-
} stringsink;
|
576
|
-
|
577
|
-
void stringsink_uninit(stringsink *sink);
|
578
|
-
|
579
|
-
struct MessageHeader {
|
580
|
-
Descriptor* descriptor; // kept alive by self.class.descriptor reference.
|
581
|
-
stringsink* unknown_fields; // store unknown fields in decoding.
|
582
|
-
// Data comes after this.
|
583
|
-
};
|
584
|
-
|
585
|
-
extern rb_data_type_t Message_type;
|
586
|
-
|
587
|
-
VALUE build_class_from_descriptor(VALUE descriptor);
|
588
|
-
void* Message_data(void* msg);
|
589
|
-
void Message_mark(void* self);
|
590
|
-
void Message_free(void* self);
|
591
|
-
VALUE Message_alloc(VALUE klass);
|
592
|
-
VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self);
|
593
|
-
VALUE Message_initialize(int argc, VALUE* argv, VALUE _self);
|
594
|
-
VALUE Message_dup(VALUE _self);
|
595
|
-
VALUE Message_deep_copy(VALUE _self);
|
596
|
-
VALUE Message_eq(VALUE _self, VALUE _other);
|
597
|
-
VALUE Message_hash(VALUE _self);
|
598
|
-
VALUE Message_inspect(VALUE _self);
|
599
|
-
VALUE Message_to_h(VALUE _self);
|
600
|
-
VALUE Message_index(VALUE _self, VALUE field_name);
|
601
|
-
VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value);
|
602
|
-
VALUE Message_descriptor(VALUE klass);
|
603
|
-
VALUE Message_decode(VALUE klass, VALUE data);
|
604
|
-
VALUE Message_encode(VALUE klass, VALUE msg_rb);
|
605
|
-
VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass);
|
606
|
-
VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass);
|
607
|
-
|
608
|
-
VALUE Google_Protobuf_discard_unknown(VALUE self, VALUE msg_rb);
|
609
|
-
VALUE Google_Protobuf_deep_copy(VALUE self, VALUE obj);
|
610
|
-
|
611
|
-
VALUE build_module_from_enumdesc(VALUE _enumdesc);
|
612
|
-
VALUE enum_lookup(VALUE self, VALUE number);
|
613
|
-
VALUE enum_resolve(VALUE self, VALUE sym);
|
614
|
-
VALUE enum_descriptor(VALUE self);
|
81
|
+
struct StringBuilder;
|
82
|
+
typedef struct StringBuilder StringBuilder;
|
615
83
|
|
616
|
-
|
617
|
-
|
618
|
-
void
|
84
|
+
StringBuilder* StringBuilder_New();
|
85
|
+
void StringBuilder_Free(StringBuilder* b);
|
86
|
+
void StringBuilder_Printf(StringBuilder* b, const char* fmt, ...);
|
87
|
+
VALUE StringBuilder_ToRubyString(StringBuilder* b);
|
619
88
|
|
620
|
-
|
621
|
-
|
622
|
-
#define ENCODE_MAX_NESTING 63
|
623
|
-
|
624
|
-
// -----------------------------------------------------------------------------
|
625
|
-
// A cache of frozen string objects to use as field defaults.
|
626
|
-
// -----------------------------------------------------------------------------
|
627
|
-
VALUE get_frozen_string(const char* data, size_t size, bool binary);
|
628
|
-
|
629
|
-
// -----------------------------------------------------------------------------
|
630
|
-
// Global map from upb {msg,enum}defs to wrapper Descriptor/EnumDescriptor
|
631
|
-
// instances.
|
632
|
-
// -----------------------------------------------------------------------------
|
633
|
-
VALUE get_msgdef_obj(VALUE descriptor_pool, const upb_msgdef* def);
|
634
|
-
VALUE get_enumdef_obj(VALUE descriptor_pool, const upb_enumdef* def);
|
635
|
-
VALUE get_fielddef_obj(VALUE descriptor_pool, const upb_fielddef* def);
|
636
|
-
VALUE get_filedef_obj(VALUE descriptor_pool, const upb_filedef* def);
|
637
|
-
VALUE get_oneofdef_obj(VALUE descriptor_pool, const upb_oneofdef* def);
|
89
|
+
void StringBuilder_PrintMsgval(StringBuilder* b, upb_MessageValue val,
|
90
|
+
TypeInfo info);
|
638
91
|
|
639
92
|
// -----------------------------------------------------------------------------
|
640
93
|
// Utilities.
|
641
94
|
// -----------------------------------------------------------------------------
|
642
95
|
|
643
|
-
|
644
|
-
|
645
|
-
#define CHECK_UPB(code, msg) do { \
|
646
|
-
upb_status status = UPB_STATUS_INIT; \
|
647
|
-
code; \
|
648
|
-
check_upb_status(&status, msg); \
|
649
|
-
} while (0)
|
650
|
-
|
651
|
-
extern ID descriptor_instancevar_interned;
|
652
|
-
|
653
|
-
// A distinct object that is not accessible from Ruby. We use this as a
|
654
|
-
// constructor argument to enforce that certain objects cannot be created from
|
655
|
-
// Ruby.
|
656
|
-
extern VALUE c_only_cookie;
|
96
|
+
extern VALUE cTypeError;
|
657
97
|
|
658
98
|
#ifdef NDEBUG
|
659
|
-
#define
|
99
|
+
#define PBRUBY_ASSERT(expr) \
|
100
|
+
do { \
|
101
|
+
} while (false && (expr))
|
660
102
|
#else
|
661
|
-
#define
|
103
|
+
#define PBRUBY_ASSERT(expr) \
|
104
|
+
if (!(expr)) \
|
105
|
+
rb_bug("Assertion failed at %s:%d, expr: %s", __FILE__, __LINE__, #expr)
|
662
106
|
#endif
|
663
107
|
|
108
|
+
#define PBRUBY_MAX(x, y) (((x) > (y)) ? (x) : (y))
|
109
|
+
|
664
110
|
#define UPB_UNUSED(var) (void)var
|
665
111
|
|
666
112
|
#endif // __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__
|