google-protobuf 3.14.0 → 4.31.1
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 +335 -0
- data/ext/google/protobuf_c/convert.h +50 -0
- data/ext/google/protobuf_c/defs.c +1174 -1608
- data/ext/google/protobuf_c/defs.h +82 -0
- data/ext/google/protobuf_c/extconf.rb +31 -8
- data/ext/google/protobuf_c/glue.c +135 -0
- data/ext/google/protobuf_c/map.c +380 -485
- data/ext/google/protobuf_c/map.h +48 -0
- data/ext/google/protobuf_c/message.c +1098 -531
- data/ext/google/protobuf_c/message.h +82 -0
- data/ext/google/protobuf_c/protobuf.c +313 -92
- data/ext/google/protobuf_c/protobuf.h +59 -624
- data/ext/google/protobuf_c/repeated_field.c +358 -353
- data/ext/google/protobuf_c/repeated_field.h +45 -0
- data/ext/google/protobuf_c/ruby-upb.c +18305 -0
- data/ext/google/protobuf_c/ruby-upb.h +16315 -0
- data/ext/google/protobuf_c/shared_convert.c +69 -0
- data/ext/google/protobuf_c/shared_convert.h +26 -0
- data/ext/google/protobuf_c/shared_message.c +37 -0
- data/ext/google/protobuf_c/shared_message.h +21 -0
- data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +22 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +207 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +22 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_neon.inc +117 -0
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_sse.inc +272 -0
- data/ext/google/protobuf_c/wrap_memcpy.c +7 -29
- data/lib/google/protobuf/any_pb.rb +6 -8
- data/lib/google/protobuf/api_pb.rb +7 -26
- data/lib/google/protobuf/descriptor_pb.rb +70 -0
- data/lib/google/protobuf/duration_pb.rb +6 -8
- data/lib/google/protobuf/empty_pb.rb +6 -6
- data/lib/google/protobuf/ffi/descriptor.rb +175 -0
- data/lib/google/protobuf/ffi/descriptor_pool.rb +79 -0
- data/lib/google/protobuf/ffi/enum_descriptor.rb +183 -0
- data/lib/google/protobuf/ffi/ffi.rb +214 -0
- data/lib/google/protobuf/ffi/field_descriptor.rb +346 -0
- data/lib/google/protobuf/ffi/file_descriptor.rb +85 -0
- data/lib/google/protobuf/ffi/internal/arena.rb +60 -0
- data/lib/google/protobuf/ffi/internal/convert.rb +292 -0
- data/lib/google/protobuf/ffi/internal/pointer_helper.rb +36 -0
- data/lib/google/protobuf/ffi/internal/type_safety.rb +25 -0
- data/lib/google/protobuf/ffi/map.rb +433 -0
- data/lib/google/protobuf/ffi/message.rb +783 -0
- data/lib/google/protobuf/ffi/method_descriptor.rb +124 -0
- data/lib/google/protobuf/ffi/object_cache.rb +30 -0
- data/lib/google/protobuf/ffi/oneof_descriptor.rb +107 -0
- data/lib/google/protobuf/ffi/repeated_field.rb +411 -0
- data/lib/google/protobuf/ffi/service_descriptor.rb +117 -0
- data/lib/google/protobuf/field_mask_pb.rb +6 -7
- data/lib/google/protobuf/internal/object_cache.rb +99 -0
- data/lib/google/protobuf/message_exts.rb +14 -28
- data/lib/google/protobuf/plugin_pb.rb +25 -0
- data/lib/google/protobuf/repeated_field.rb +22 -33
- data/lib/google/protobuf/source_context_pb.rb +6 -7
- data/lib/google/protobuf/struct_pb.rb +6 -23
- data/lib/google/protobuf/timestamp_pb.rb +6 -8
- data/lib/google/protobuf/type_pb.rb +7 -71
- data/lib/google/protobuf/well_known_types.rb +17 -36
- data/lib/google/protobuf/wrappers_pb.rb +6 -31
- data/lib/google/protobuf.rb +32 -118
- data/lib/google/protobuf_ffi.rb +52 -0
- data/lib/google/protobuf_native.rb +19 -0
- data/lib/google/tasks/ffi.rake +100 -0
- metadata +107 -38
- data/ext/google/protobuf_c/encode_decode.c +0 -1795
- data/ext/google/protobuf_c/storage.c +0 -1198
- data/ext/google/protobuf_c/upb.c +0 -13817
- data/ext/google/protobuf_c/upb.h +0 -6777
- data/tests/basic.rb +0 -543
- data/tests/generated_code_test.rb +0 -23
- data/tests/stress.rb +0 -38
@@ -1,667 +1,102 @@
|
|
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_proto3_optional(int argc, VALUE* argv, VALUE _self);
|
289
|
-
VALUE MessageBuilderContext_required(int argc, VALUE* argv, VALUE _self);
|
290
|
-
VALUE MessageBuilderContext_repeated(int argc, VALUE* argv, VALUE _self);
|
291
|
-
VALUE MessageBuilderContext_map(int argc, VALUE* argv, VALUE _self);
|
292
|
-
VALUE MessageBuilderContext_oneof(VALUE _self, VALUE name);
|
293
|
-
|
294
|
-
void OneofBuilderContext_mark(void* _self);
|
295
|
-
void OneofBuilderContext_free(void* _self);
|
296
|
-
VALUE OneofBuilderContext_alloc(VALUE klass);
|
297
|
-
void OneofBuilderContext_register(VALUE module);
|
298
|
-
OneofBuilderContext* ruby_to_OneofBuilderContext(VALUE value);
|
299
|
-
VALUE OneofBuilderContext_initialize(VALUE _self,
|
300
|
-
VALUE descriptor,
|
301
|
-
VALUE builder);
|
302
|
-
VALUE OneofBuilderContext_optional(int argc, VALUE* argv, VALUE _self);
|
303
|
-
|
304
|
-
void EnumBuilderContext_mark(void* _self);
|
305
|
-
void EnumBuilderContext_free(void* _self);
|
306
|
-
VALUE EnumBuilderContext_alloc(VALUE klass);
|
307
|
-
void EnumBuilderContext_register(VALUE module);
|
308
|
-
EnumBuilderContext* ruby_to_EnumBuilderContext(VALUE value);
|
309
|
-
VALUE EnumBuilderContext_initialize(VALUE _self, VALUE _file_builder,
|
310
|
-
VALUE name);
|
311
|
-
VALUE EnumBuilderContext_value(VALUE _self, VALUE name, VALUE number);
|
312
|
-
|
313
|
-
void FileBuilderContext_mark(void* _self);
|
314
|
-
void FileBuilderContext_free(void* _self);
|
315
|
-
VALUE FileBuilderContext_alloc(VALUE klass);
|
316
|
-
void FileBuilderContext_register(VALUE module);
|
317
|
-
FileBuilderContext* ruby_to_FileBuilderContext(VALUE _self);
|
318
|
-
upb_strview FileBuilderContext_strdup(VALUE _self, VALUE rb_str);
|
319
|
-
upb_strview FileBuilderContext_strdup_name(VALUE _self, VALUE rb_str);
|
320
|
-
upb_strview FileBuilderContext_strdup_sym(VALUE _self, VALUE rb_sym);
|
321
|
-
VALUE FileBuilderContext_initialize(VALUE _self, VALUE descriptor_pool,
|
322
|
-
VALUE name, VALUE options);
|
323
|
-
VALUE FileBuilderContext_add_message(VALUE _self, VALUE name);
|
324
|
-
VALUE FileBuilderContext_add_enum(VALUE _self, VALUE name);
|
325
|
-
VALUE FileBuilderContext_pending_descriptors(VALUE _self);
|
326
|
-
|
327
|
-
void Builder_mark(void* _self);
|
328
|
-
void Builder_free(void* _self);
|
329
|
-
VALUE Builder_alloc(VALUE klass);
|
330
|
-
void Builder_register(VALUE module);
|
331
|
-
Builder* ruby_to_Builder(VALUE value);
|
332
|
-
VALUE Builder_build(VALUE _self);
|
333
|
-
VALUE Builder_initialize(VALUE _self, VALUE descriptor_pool);
|
334
|
-
VALUE Builder_add_file(int argc, VALUE *argv, VALUE _self);
|
335
|
-
VALUE Builder_add_message(VALUE _self, VALUE name);
|
336
|
-
VALUE Builder_add_enum(VALUE _self, VALUE name);
|
337
|
-
VALUE Builder_finalize_to_pool(VALUE _self, VALUE pool_rb);
|
338
|
-
|
339
|
-
// -----------------------------------------------------------------------------
|
340
|
-
// Native slot storage abstraction.
|
341
|
-
// -----------------------------------------------------------------------------
|
342
|
-
|
343
|
-
#define NATIVE_SLOT_MAX_SIZE sizeof(uint64_t)
|
344
|
-
|
345
|
-
size_t native_slot_size(upb_fieldtype_t type);
|
346
|
-
void native_slot_set(const char* name,
|
347
|
-
upb_fieldtype_t type,
|
348
|
-
VALUE type_class,
|
349
|
-
void* memory,
|
350
|
-
VALUE value);
|
351
|
-
// Atomically (with respect to Ruby VM calls) either update the value and set a
|
352
|
-
// oneof case, or do neither. If |case_memory| is null, then no case value is
|
353
|
-
// set.
|
354
|
-
void native_slot_set_value_and_case(const char* name,
|
355
|
-
upb_fieldtype_t type,
|
356
|
-
VALUE type_class,
|
357
|
-
void* memory,
|
358
|
-
VALUE value,
|
359
|
-
uint32_t* case_memory,
|
360
|
-
uint32_t case_number);
|
361
|
-
VALUE native_slot_get(upb_fieldtype_t type,
|
362
|
-
VALUE type_class,
|
363
|
-
const void* memory);
|
364
|
-
void native_slot_init(upb_fieldtype_t type, void* memory);
|
365
|
-
void native_slot_mark(upb_fieldtype_t type, void* memory);
|
366
|
-
void native_slot_dup(upb_fieldtype_t type, void* to, void* from);
|
367
|
-
void native_slot_deep_copy(upb_fieldtype_t type, VALUE type_class, void* to,
|
368
|
-
void* from);
|
369
|
-
bool native_slot_eq(upb_fieldtype_t type, VALUE type_class, void* mem1,
|
370
|
-
void* mem2);
|
371
|
-
|
372
|
-
VALUE native_slot_encode_and_freeze_string(upb_fieldtype_t type, VALUE value);
|
373
|
-
void native_slot_check_int_range_precision(const char* name, upb_fieldtype_t type, VALUE value);
|
374
|
-
uint32_t slot_read_oneof_case(MessageLayout* layout, const void* storage,
|
375
|
-
const upb_oneofdef* oneof);
|
376
|
-
bool is_value_field(const upb_fielddef* f);
|
377
|
-
|
378
|
-
extern rb_encoding* kRubyStringUtf8Encoding;
|
379
|
-
extern rb_encoding* kRubyStringASCIIEncoding;
|
380
|
-
extern rb_encoding* kRubyString8bitEncoding;
|
381
|
-
|
382
|
-
VALUE field_type_class(const MessageLayout* layout, const upb_fielddef* field);
|
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
|
383
18
|
|
384
|
-
#
|
385
|
-
#
|
19
|
+
#include <assert.h> // Must be included after the NDEBUG logic above.
|
20
|
+
#include <ruby/encoding.h>
|
21
|
+
#include <ruby/vm.h>
|
386
22
|
|
387
|
-
|
388
|
-
|
389
|
-
// have a number of 0.
|
390
|
-
#define ONEOF_CASE_NONE 0
|
23
|
+
#include "defs.h"
|
24
|
+
#include "ruby-upb.h"
|
391
25
|
|
392
26
|
// These operate on a map field (i.e., a repeated field of submessages whose
|
393
27
|
// submessage type is a map-entry msgdef).
|
394
|
-
|
395
|
-
const
|
396
|
-
const upb_fielddef* map_field_value(const upb_fielddef* field);
|
397
|
-
|
398
|
-
// These operate on a map-entry msgdef.
|
399
|
-
const upb_fielddef* map_entry_key(const upb_msgdef* msgdef);
|
400
|
-
const upb_fielddef* map_entry_value(const upb_msgdef* msgdef);
|
28
|
+
const upb_FieldDef* map_field_key(const upb_FieldDef* field);
|
29
|
+
const upb_FieldDef* map_field_value(const upb_FieldDef* field);
|
401
30
|
|
402
31
|
// -----------------------------------------------------------------------------
|
403
|
-
//
|
32
|
+
// Arena
|
404
33
|
// -----------------------------------------------------------------------------
|
405
34
|
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
int size;
|
411
|
-
int capacity;
|
412
|
-
} RepeatedField;
|
413
|
-
|
414
|
-
void RepeatedField_mark(void* self);
|
415
|
-
void RepeatedField_free(void* self);
|
416
|
-
VALUE RepeatedField_alloc(VALUE klass);
|
417
|
-
VALUE RepeatedField_init(int argc, VALUE* argv, VALUE self);
|
418
|
-
void RepeatedField_register(VALUE module);
|
419
|
-
|
420
|
-
extern const rb_data_type_t RepeatedField_type;
|
421
|
-
extern VALUE cRepeatedField;
|
422
|
-
|
423
|
-
RepeatedField* ruby_to_RepeatedField(VALUE value);
|
35
|
+
// A Ruby object that wraps an underlying upb_Arena. Any objects that are
|
36
|
+
// allocated from this arena should reference the Arena in rb_gc_mark(), to
|
37
|
+
// ensure that the object's underlying memory outlives any Ruby object that can
|
38
|
+
// reach it.
|
424
39
|
|
425
|
-
VALUE
|
426
|
-
|
427
|
-
VALUE RepeatedField_index(int argc, VALUE* argv, VALUE _self);
|
428
|
-
void* RepeatedField_index_native(VALUE _self, int index);
|
429
|
-
int RepeatedField_size(VALUE _self);
|
430
|
-
VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val);
|
431
|
-
void RepeatedField_reserve(RepeatedField* self, int new_size);
|
432
|
-
VALUE RepeatedField_push(VALUE _self, VALUE val);
|
433
|
-
void RepeatedField_push_native(VALUE _self, void* data);
|
434
|
-
VALUE RepeatedField_pop_one(VALUE _self);
|
435
|
-
VALUE RepeatedField_insert(int argc, VALUE* argv, VALUE _self);
|
436
|
-
VALUE RepeatedField_replace(VALUE _self, VALUE list);
|
437
|
-
VALUE RepeatedField_clear(VALUE _self);
|
438
|
-
VALUE RepeatedField_length(VALUE _self);
|
439
|
-
VALUE RepeatedField_dup(VALUE _self);
|
440
|
-
VALUE RepeatedField_deep_copy(VALUE _self);
|
441
|
-
VALUE RepeatedField_to_ary(VALUE _self);
|
442
|
-
VALUE RepeatedField_eq(VALUE _self, VALUE _other);
|
443
|
-
VALUE RepeatedField_hash(VALUE _self);
|
444
|
-
VALUE RepeatedField_inspect(VALUE _self);
|
445
|
-
VALUE RepeatedField_plus(VALUE _self, VALUE list);
|
40
|
+
VALUE Arena_new();
|
41
|
+
upb_Arena* Arena_get(VALUE arena);
|
446
42
|
|
447
|
-
//
|
448
|
-
|
43
|
+
// Fuses this arena to another, throwing a Ruby exception if this is not
|
44
|
+
// possible.
|
45
|
+
void Arena_fuse(VALUE arena, upb_Arena* other);
|
449
46
|
|
450
47
|
// -----------------------------------------------------------------------------
|
451
|
-
//
|
48
|
+
// ObjectCache
|
452
49
|
// -----------------------------------------------------------------------------
|
453
50
|
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
upb_strtable table;
|
460
|
-
} Map;
|
461
|
-
|
462
|
-
void Map_mark(void* self);
|
463
|
-
void Map_free(void* self);
|
464
|
-
VALUE Map_alloc(VALUE klass);
|
465
|
-
VALUE Map_init(int argc, VALUE* argv, VALUE self);
|
466
|
-
void Map_register(VALUE module);
|
467
|
-
VALUE Map_set_frame(VALUE self, VALUE val);
|
468
|
-
|
469
|
-
extern const rb_data_type_t Map_type;
|
470
|
-
extern VALUE cMap;
|
471
|
-
|
472
|
-
Map* ruby_to_Map(VALUE value);
|
473
|
-
|
474
|
-
VALUE Map_new_this_type(VALUE _self);
|
475
|
-
VALUE Map_each(VALUE _self);
|
476
|
-
VALUE Map_keys(VALUE _self);
|
477
|
-
VALUE Map_values(VALUE _self);
|
478
|
-
VALUE Map_index(VALUE _self, VALUE key);
|
479
|
-
VALUE Map_index_set(VALUE _self, VALUE key, VALUE value);
|
480
|
-
VALUE Map_has_key(VALUE _self, VALUE key);
|
481
|
-
VALUE Map_delete(VALUE _self, VALUE key);
|
482
|
-
VALUE Map_clear(VALUE _self);
|
483
|
-
VALUE Map_length(VALUE _self);
|
484
|
-
VALUE Map_dup(VALUE _self);
|
485
|
-
VALUE Map_deep_copy(VALUE _self);
|
486
|
-
VALUE Map_eq(VALUE _self, VALUE _other);
|
487
|
-
VALUE Map_hash(VALUE _self);
|
488
|
-
VALUE Map_to_h(VALUE _self);
|
489
|
-
VALUE Map_inspect(VALUE _self);
|
490
|
-
VALUE Map_merge(VALUE _self, VALUE hashmap);
|
491
|
-
VALUE Map_merge_into_self(VALUE _self, VALUE hashmap);
|
492
|
-
|
493
|
-
typedef struct {
|
494
|
-
Map* self;
|
495
|
-
upb_strtable_iter it;
|
496
|
-
} Map_iter;
|
497
|
-
|
498
|
-
void Map_begin(VALUE _self, Map_iter* iter);
|
499
|
-
void Map_next(Map_iter* iter);
|
500
|
-
bool Map_done(Map_iter* iter);
|
501
|
-
VALUE Map_iter_key(Map_iter* iter);
|
502
|
-
VALUE Map_iter_value(Map_iter* iter);
|
503
|
-
|
504
|
-
// -----------------------------------------------------------------------------
|
505
|
-
// Message layout / storage.
|
506
|
-
// -----------------------------------------------------------------------------
|
507
|
-
|
508
|
-
#define MESSAGE_FIELD_NO_HASBIT ((uint32_t)-1)
|
509
|
-
|
510
|
-
struct MessageField {
|
511
|
-
uint32_t offset;
|
512
|
-
uint32_t hasbit;
|
513
|
-
};
|
514
|
-
|
515
|
-
struct MessageOneof {
|
516
|
-
uint32_t offset;
|
517
|
-
uint32_t case_offset;
|
518
|
-
};
|
519
|
-
|
520
|
-
// MessageLayout is owned by the enclosing Descriptor, which must outlive us.
|
521
|
-
struct MessageLayout {
|
522
|
-
const Descriptor* desc;
|
523
|
-
const upb_msgdef* msgdef;
|
524
|
-
void* empty_template; // Can memcpy() onto a layout to clear it.
|
525
|
-
MessageField* fields;
|
526
|
-
MessageOneof* oneofs;
|
527
|
-
uint32_t size;
|
528
|
-
uint32_t value_offset;
|
529
|
-
int value_count;
|
530
|
-
int repeated_count;
|
531
|
-
int map_count;
|
532
|
-
};
|
533
|
-
|
534
|
-
#define ONEOF_CASE_MASK 0x80000000
|
51
|
+
// Global object cache from upb array/map/message/symtab to wrapper object.
|
52
|
+
//
|
53
|
+
// This is a conceptually "weak" cache, in that it does not prevent "val" from
|
54
|
+
// being collected (though in Ruby <2.7 is it effectively strong, due to
|
55
|
+
// implementation limitations).
|
535
56
|
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
const upb_fielddef* field);
|
540
|
-
VALUE layout_get_default(const upb_fielddef* field);
|
541
|
-
VALUE layout_get(MessageLayout* layout,
|
542
|
-
const void* storage,
|
543
|
-
const upb_fielddef* field);
|
544
|
-
void layout_set(MessageLayout* layout,
|
545
|
-
void* storage,
|
546
|
-
const upb_fielddef* field,
|
547
|
-
VALUE val);
|
548
|
-
VALUE layout_has(MessageLayout* layout,
|
549
|
-
const void* storage,
|
550
|
-
const upb_fielddef* field);
|
551
|
-
void layout_clear(MessageLayout* layout,
|
552
|
-
const void* storage,
|
553
|
-
const upb_fielddef* field);
|
554
|
-
void layout_init(MessageLayout* layout, void* storage);
|
555
|
-
void layout_mark(MessageLayout* layout, void* storage);
|
556
|
-
void layout_dup(MessageLayout* layout, void* to, void* from);
|
557
|
-
void layout_deep_copy(MessageLayout* layout, void* to, void* from);
|
558
|
-
VALUE layout_eq(MessageLayout* layout, void* msg1, void* msg2);
|
559
|
-
VALUE layout_hash(MessageLayout* layout, void* storage);
|
560
|
-
VALUE layout_inspect(MessageLayout* layout, void* storage);
|
57
|
+
// Tries to add a new entry to the cache, returning the newly installed value or
|
58
|
+
// the pre-existing entry.
|
59
|
+
VALUE ObjectCache_TryAdd(const void* key, VALUE val);
|
561
60
|
|
562
|
-
|
563
|
-
VALUE
|
61
|
+
// Returns the cached object for this key, if any. Otherwise returns Qnil.
|
62
|
+
VALUE ObjectCache_Get(const void* key);
|
564
63
|
|
565
64
|
// -----------------------------------------------------------------------------
|
566
|
-
//
|
65
|
+
// StringBuilder, for inspect
|
567
66
|
// -----------------------------------------------------------------------------
|
568
67
|
|
569
|
-
|
570
|
-
|
571
|
-
typedef struct {
|
572
|
-
upb_byteshandler handler;
|
573
|
-
upb_bytessink sink;
|
574
|
-
char *ptr;
|
575
|
-
size_t len, size;
|
576
|
-
} stringsink;
|
577
|
-
|
578
|
-
void stringsink_uninit(stringsink *sink);
|
68
|
+
struct StringBuilder;
|
69
|
+
typedef struct StringBuilder StringBuilder;
|
579
70
|
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
};
|
71
|
+
StringBuilder* StringBuilder_New();
|
72
|
+
void StringBuilder_Free(StringBuilder* b);
|
73
|
+
void StringBuilder_Printf(StringBuilder* b, const char* fmt, ...);
|
74
|
+
VALUE StringBuilder_ToRubyString(StringBuilder* b);
|
585
75
|
|
586
|
-
|
587
|
-
|
588
|
-
VALUE build_class_from_descriptor(VALUE descriptor);
|
589
|
-
void* Message_data(void* msg);
|
590
|
-
void Message_mark(void* self);
|
591
|
-
void Message_free(void* self);
|
592
|
-
VALUE Message_alloc(VALUE klass);
|
593
|
-
VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self);
|
594
|
-
VALUE Message_initialize(int argc, VALUE* argv, VALUE _self);
|
595
|
-
VALUE Message_dup(VALUE _self);
|
596
|
-
VALUE Message_deep_copy(VALUE _self);
|
597
|
-
VALUE Message_eq(VALUE _self, VALUE _other);
|
598
|
-
VALUE Message_hash(VALUE _self);
|
599
|
-
VALUE Message_inspect(VALUE _self);
|
600
|
-
VALUE Message_to_h(VALUE _self);
|
601
|
-
VALUE Message_index(VALUE _self, VALUE field_name);
|
602
|
-
VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value);
|
603
|
-
VALUE Message_descriptor(VALUE klass);
|
604
|
-
VALUE Message_decode(VALUE klass, VALUE data);
|
605
|
-
VALUE Message_encode(VALUE klass, VALUE msg_rb);
|
606
|
-
VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass);
|
607
|
-
VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass);
|
608
|
-
|
609
|
-
VALUE Google_Protobuf_discard_unknown(VALUE self, VALUE msg_rb);
|
610
|
-
VALUE Google_Protobuf_deep_copy(VALUE self, VALUE obj);
|
611
|
-
|
612
|
-
VALUE build_module_from_enumdesc(VALUE _enumdesc);
|
613
|
-
VALUE enum_lookup(VALUE self, VALUE number);
|
614
|
-
VALUE enum_resolve(VALUE self, VALUE sym);
|
615
|
-
VALUE enum_descriptor(VALUE self);
|
616
|
-
|
617
|
-
const upb_pbdecodermethod *new_fillmsg_decodermethod(
|
618
|
-
Descriptor* descriptor, const void *owner);
|
619
|
-
void add_handlers_for_message(const void *closure, upb_handlers *h);
|
620
|
-
|
621
|
-
// Maximum depth allowed during encoding, to avoid stack overflows due to
|
622
|
-
// cycles.
|
623
|
-
#define ENCODE_MAX_NESTING 63
|
624
|
-
|
625
|
-
// -----------------------------------------------------------------------------
|
626
|
-
// A cache of frozen string objects to use as field defaults.
|
627
|
-
// -----------------------------------------------------------------------------
|
628
|
-
VALUE get_frozen_string(const char* data, size_t size, bool binary);
|
629
|
-
|
630
|
-
// -----------------------------------------------------------------------------
|
631
|
-
// Global map from upb {msg,enum}defs to wrapper Descriptor/EnumDescriptor
|
632
|
-
// instances.
|
633
|
-
// -----------------------------------------------------------------------------
|
634
|
-
VALUE get_msgdef_obj(VALUE descriptor_pool, const upb_msgdef* def);
|
635
|
-
VALUE get_enumdef_obj(VALUE descriptor_pool, const upb_enumdef* def);
|
636
|
-
VALUE get_fielddef_obj(VALUE descriptor_pool, const upb_fielddef* def);
|
637
|
-
VALUE get_filedef_obj(VALUE descriptor_pool, const upb_filedef* def);
|
638
|
-
VALUE get_oneofdef_obj(VALUE descriptor_pool, const upb_oneofdef* def);
|
76
|
+
void StringBuilder_PrintMsgval(StringBuilder* b, upb_MessageValue val,
|
77
|
+
TypeInfo info);
|
639
78
|
|
640
79
|
// -----------------------------------------------------------------------------
|
641
80
|
// Utilities.
|
642
81
|
// -----------------------------------------------------------------------------
|
643
82
|
|
644
|
-
|
645
|
-
|
646
|
-
#define CHECK_UPB(code, msg) do { \
|
647
|
-
upb_status status = UPB_STATUS_INIT; \
|
648
|
-
code; \
|
649
|
-
check_upb_status(&status, msg); \
|
650
|
-
} while (0)
|
651
|
-
|
652
|
-
extern ID descriptor_instancevar_interned;
|
653
|
-
|
654
|
-
// A distinct object that is not accessible from Ruby. We use this as a
|
655
|
-
// constructor argument to enforce that certain objects cannot be created from
|
656
|
-
// Ruby.
|
657
|
-
extern VALUE c_only_cookie;
|
83
|
+
extern VALUE cTypeError;
|
658
84
|
|
659
85
|
#ifdef NDEBUG
|
660
|
-
#define
|
86
|
+
#define PBRUBY_ASSERT(expr) \
|
87
|
+
do { \
|
88
|
+
} while (false && (expr))
|
661
89
|
#else
|
662
|
-
#define
|
90
|
+
#define PBRUBY_ASSERT(expr) \
|
91
|
+
if (!(expr)) \
|
92
|
+
rb_bug("Assertion failed at %s:%d, expr: %s", __FILE__, __LINE__, #expr)
|
663
93
|
#endif
|
664
94
|
|
95
|
+
// Raises a Ruby error if val is frozen in Ruby or upb_frozen is true.
|
96
|
+
void Protobuf_CheckNotFrozen(VALUE val, bool upb_frozen);
|
97
|
+
|
98
|
+
#define PBRUBY_MAX(x, y) (((x) > (y)) ? (x) : (y))
|
99
|
+
|
665
100
|
#define UPB_UNUSED(var) (void)var
|
666
101
|
|
667
102
|
#endif // __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__
|