google-protobuf 3.0.0.alpha.5.0.3-universal-darwin
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of google-protobuf might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/ext/google/protobuf_c/defs.c +1753 -0
- data/ext/google/protobuf_c/encode_decode.c +1200 -0
- data/ext/google/protobuf_c/extconf.rb +10 -0
- data/ext/google/protobuf_c/map.c +808 -0
- data/ext/google/protobuf_c/message.c +580 -0
- data/ext/google/protobuf_c/protobuf.c +115 -0
- data/ext/google/protobuf_c/protobuf.h +536 -0
- data/ext/google/protobuf_c/repeated_field.c +651 -0
- data/ext/google/protobuf_c/storage.c +863 -0
- data/ext/google/protobuf_c/upb.c +11990 -0
- data/ext/google/protobuf_c/upb.h +8217 -0
- data/lib/google/2.0/protobuf_c.bundle +0 -0
- data/lib/google/2.1/protobuf_c.bundle +0 -0
- data/lib/google/2.2/protobuf_c.bundle +0 -0
- data/lib/google/2.3/protobuf_c.bundle +0 -0
- data/lib/google/protobuf.rb +76 -0
- data/lib/google/protobuf/message_exts.rb +53 -0
- data/lib/google/protobuf/repeated_field.rb +188 -0
- data/tests/basic.rb +1140 -0
- data/tests/generated_code_test.rb +17 -0
- data/tests/stress.rb +38 -0
- metadata +123 -0
@@ -0,0 +1,115 @@
|
|
1
|
+
// Protocol Buffers - Google's data interchange format
|
2
|
+
// Copyright 2014 Google Inc. All rights reserved.
|
3
|
+
// https://developers.google.com/protocol-buffers/
|
4
|
+
//
|
5
|
+
// Redistribution and use in source and binary forms, with or without
|
6
|
+
// modification, are permitted provided that the following conditions are
|
7
|
+
// met:
|
8
|
+
//
|
9
|
+
// * Redistributions of source code must retain the above copyright
|
10
|
+
// notice, this list of conditions and the following disclaimer.
|
11
|
+
// * Redistributions in binary form must reproduce the above
|
12
|
+
// copyright notice, this list of conditions and the following disclaimer
|
13
|
+
// in the documentation and/or other materials provided with the
|
14
|
+
// distribution.
|
15
|
+
// * Neither the name of Google Inc. nor the names of its
|
16
|
+
// contributors may be used to endorse or promote products derived from
|
17
|
+
// this software without specific prior written permission.
|
18
|
+
//
|
19
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
20
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
21
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
22
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
25
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
26
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
27
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
#include "protobuf.h"
|
32
|
+
|
33
|
+
// -----------------------------------------------------------------------------
|
34
|
+
// Global map from upb {msg,enum}defs to wrapper Descriptor/EnumDescriptor
|
35
|
+
// instances.
|
36
|
+
// -----------------------------------------------------------------------------
|
37
|
+
|
38
|
+
// This is a hash table from def objects (encoded by converting pointers to
|
39
|
+
// Ruby integers) to MessageDef/EnumDef instances (as Ruby values).
|
40
|
+
VALUE upb_def_to_ruby_obj_map;
|
41
|
+
|
42
|
+
VALUE cError;
|
43
|
+
VALUE cParseError;
|
44
|
+
|
45
|
+
void add_def_obj(const void* def, VALUE value) {
|
46
|
+
rb_hash_aset(upb_def_to_ruby_obj_map, ULL2NUM((intptr_t)def), value);
|
47
|
+
}
|
48
|
+
|
49
|
+
VALUE get_def_obj(const void* def) {
|
50
|
+
return rb_hash_aref(upb_def_to_ruby_obj_map, ULL2NUM((intptr_t)def));
|
51
|
+
}
|
52
|
+
|
53
|
+
// -----------------------------------------------------------------------------
|
54
|
+
// Utilities.
|
55
|
+
// -----------------------------------------------------------------------------
|
56
|
+
|
57
|
+
// Raises a Ruby error if |status| is not OK, using its error message.
|
58
|
+
void check_upb_status(const upb_status* status, const char* msg) {
|
59
|
+
if (!upb_ok(status)) {
|
60
|
+
rb_raise(rb_eRuntimeError, "%s: %s\n", msg, upb_status_errmsg(status));
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
// String encodings: we look these up once, at load time, and then cache them
|
65
|
+
// here.
|
66
|
+
rb_encoding* kRubyStringUtf8Encoding;
|
67
|
+
rb_encoding* kRubyStringASCIIEncoding;
|
68
|
+
rb_encoding* kRubyString8bitEncoding;
|
69
|
+
|
70
|
+
// Ruby-interned string: "descriptor". We use this identifier to store an
|
71
|
+
// instance variable on message classes we create in order to link them back to
|
72
|
+
// their descriptors.
|
73
|
+
//
|
74
|
+
// We intern this once at module load time then use the interned identifier at
|
75
|
+
// runtime in order to avoid the cost of repeatedly interning in hot paths.
|
76
|
+
const char* kDescriptorInstanceVar = "descriptor";
|
77
|
+
ID descriptor_instancevar_interned;
|
78
|
+
|
79
|
+
// -----------------------------------------------------------------------------
|
80
|
+
// Initialization/entry point.
|
81
|
+
// -----------------------------------------------------------------------------
|
82
|
+
|
83
|
+
// This must be named "Init_protobuf_c" because the Ruby module is named
|
84
|
+
// "protobuf_c" -- the VM looks for this symbol in our .so.
|
85
|
+
void Init_protobuf_c() {
|
86
|
+
VALUE google = rb_define_module("Google");
|
87
|
+
VALUE protobuf = rb_define_module_under(google, "Protobuf");
|
88
|
+
VALUE internal = rb_define_module_under(protobuf, "Internal");
|
89
|
+
|
90
|
+
descriptor_instancevar_interned = rb_intern(kDescriptorInstanceVar);
|
91
|
+
DescriptorPool_register(protobuf);
|
92
|
+
Descriptor_register(protobuf);
|
93
|
+
FieldDescriptor_register(protobuf);
|
94
|
+
OneofDescriptor_register(protobuf);
|
95
|
+
EnumDescriptor_register(protobuf);
|
96
|
+
MessageBuilderContext_register(internal);
|
97
|
+
OneofBuilderContext_register(internal);
|
98
|
+
EnumBuilderContext_register(internal);
|
99
|
+
Builder_register(internal);
|
100
|
+
RepeatedField_register(protobuf);
|
101
|
+
Map_register(protobuf);
|
102
|
+
|
103
|
+
cError = rb_const_get(protobuf, rb_intern("Error"));
|
104
|
+
cParseError = rb_const_get(protobuf, rb_intern("ParseError"));
|
105
|
+
|
106
|
+
rb_define_singleton_method(protobuf, "deep_copy",
|
107
|
+
Google_Protobuf_deep_copy, 1);
|
108
|
+
|
109
|
+
kRubyStringUtf8Encoding = rb_utf8_encoding();
|
110
|
+
kRubyStringASCIIEncoding = rb_usascii_encoding();
|
111
|
+
kRubyString8bitEncoding = rb_ascii8bit_encoding();
|
112
|
+
|
113
|
+
upb_def_to_ruby_obj_map = rb_hash_new();
|
114
|
+
rb_gc_register_address(&upb_def_to_ruby_obj_map);
|
115
|
+
}
|
@@ -0,0 +1,536 @@
|
|
1
|
+
// Protocol Buffers - Google's data interchange format
|
2
|
+
// Copyright 2014 Google Inc. All rights reserved.
|
3
|
+
// https://developers.google.com/protocol-buffers/
|
4
|
+
//
|
5
|
+
// Redistribution and use in source and binary forms, with or without
|
6
|
+
// modification, are permitted provided that the following conditions are
|
7
|
+
// met:
|
8
|
+
//
|
9
|
+
// * Redistributions of source code must retain the above copyright
|
10
|
+
// notice, this list of conditions and the following disclaimer.
|
11
|
+
// * Redistributions in binary form must reproduce the above
|
12
|
+
// copyright notice, this list of conditions and the following disclaimer
|
13
|
+
// in the documentation and/or other materials provided with the
|
14
|
+
// distribution.
|
15
|
+
// * Neither the name of Google Inc. nor the names of its
|
16
|
+
// contributors may be used to endorse or promote products derived from
|
17
|
+
// this software without specific prior written permission.
|
18
|
+
//
|
19
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
20
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
21
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
22
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
25
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
26
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
27
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
#ifndef __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__
|
32
|
+
#define __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__
|
33
|
+
|
34
|
+
#include <ruby/ruby.h>
|
35
|
+
#include <ruby/vm.h>
|
36
|
+
#include <ruby/encoding.h>
|
37
|
+
|
38
|
+
#include "upb.h"
|
39
|
+
|
40
|
+
// Forward decls.
|
41
|
+
struct DescriptorPool;
|
42
|
+
struct Descriptor;
|
43
|
+
struct FieldDescriptor;
|
44
|
+
struct EnumDescriptor;
|
45
|
+
struct MessageLayout;
|
46
|
+
struct MessageField;
|
47
|
+
struct MessageHeader;
|
48
|
+
struct MessageBuilderContext;
|
49
|
+
struct EnumBuilderContext;
|
50
|
+
struct Builder;
|
51
|
+
|
52
|
+
typedef struct DescriptorPool DescriptorPool;
|
53
|
+
typedef struct Descriptor Descriptor;
|
54
|
+
typedef struct FieldDescriptor FieldDescriptor;
|
55
|
+
typedef struct OneofDescriptor OneofDescriptor;
|
56
|
+
typedef struct EnumDescriptor EnumDescriptor;
|
57
|
+
typedef struct MessageLayout MessageLayout;
|
58
|
+
typedef struct MessageField MessageField;
|
59
|
+
typedef struct MessageHeader MessageHeader;
|
60
|
+
typedef struct MessageBuilderContext MessageBuilderContext;
|
61
|
+
typedef struct OneofBuilderContext OneofBuilderContext;
|
62
|
+
typedef struct EnumBuilderContext EnumBuilderContext;
|
63
|
+
typedef struct Builder Builder;
|
64
|
+
|
65
|
+
/*
|
66
|
+
It can be a bit confusing how the C structs defined below and the Ruby
|
67
|
+
objects interact and hold references to each other. First, a few principles:
|
68
|
+
|
69
|
+
- Ruby's "TypedData" abstraction lets a Ruby VALUE hold a pointer to a C
|
70
|
+
struct (or arbitrary memory chunk), own it, and free it when collected.
|
71
|
+
Thus, each struct below will have a corresponding Ruby object
|
72
|
+
wrapping/owning it.
|
73
|
+
|
74
|
+
- To get back from an underlying upb {msg,enum}def to the Ruby object, we
|
75
|
+
keep a global hashmap, accessed by get_def_obj/add_def_obj below.
|
76
|
+
|
77
|
+
The in-memory structure is then something like:
|
78
|
+
|
79
|
+
Ruby | upb
|
80
|
+
|
|
81
|
+
DescriptorPool ------------|-----------> upb_symtab____________________
|
82
|
+
| | (message types) \
|
83
|
+
| v \
|
84
|
+
Descriptor ---------------|-----------> upb_msgdef (enum types)|
|
85
|
+
|--> msgclass | | ^ |
|
86
|
+
| (dynamically built) | | | (submsg fields) |
|
87
|
+
|--> MessageLayout | | | /
|
88
|
+
|--------------------------|> decoder method| | /
|
89
|
+
\--------------------------|> serialize | | /
|
90
|
+
| handlers v | /
|
91
|
+
FieldDescriptor -----------|-----------> upb_fielddef /
|
92
|
+
| | /
|
93
|
+
| v (enum fields) /
|
94
|
+
EnumDescriptor ------------|-----------> upb_enumdef <----------'
|
95
|
+
|
|
96
|
+
|
|
97
|
+
^ | \___/
|
98
|
+
`---------------|-----------------' (get_def_obj map)
|
99
|
+
*/
|
100
|
+
|
101
|
+
// -----------------------------------------------------------------------------
|
102
|
+
// Ruby class structure definitions.
|
103
|
+
// -----------------------------------------------------------------------------
|
104
|
+
|
105
|
+
struct DescriptorPool {
|
106
|
+
upb_symtab* symtab;
|
107
|
+
};
|
108
|
+
|
109
|
+
struct Descriptor {
|
110
|
+
const upb_msgdef* msgdef;
|
111
|
+
MessageLayout* layout;
|
112
|
+
VALUE klass; // begins as nil
|
113
|
+
const upb_handlers* fill_handlers;
|
114
|
+
const upb_pbdecodermethod* fill_method;
|
115
|
+
const upb_handlers* pb_serialize_handlers;
|
116
|
+
const upb_handlers* json_serialize_handlers;
|
117
|
+
// Handlers hold type class references for sub-message fields directly in some
|
118
|
+
// cases. We need to keep these rooted because they might otherwise be
|
119
|
+
// collected.
|
120
|
+
VALUE typeclass_references;
|
121
|
+
};
|
122
|
+
|
123
|
+
struct FieldDescriptor {
|
124
|
+
const upb_fielddef* fielddef;
|
125
|
+
};
|
126
|
+
|
127
|
+
struct OneofDescriptor {
|
128
|
+
const upb_oneofdef* oneofdef;
|
129
|
+
};
|
130
|
+
|
131
|
+
struct EnumDescriptor {
|
132
|
+
const upb_enumdef* enumdef;
|
133
|
+
VALUE module; // begins as nil
|
134
|
+
};
|
135
|
+
|
136
|
+
struct MessageBuilderContext {
|
137
|
+
VALUE descriptor;
|
138
|
+
VALUE builder;
|
139
|
+
};
|
140
|
+
|
141
|
+
struct OneofBuilderContext {
|
142
|
+
VALUE descriptor;
|
143
|
+
VALUE builder;
|
144
|
+
};
|
145
|
+
|
146
|
+
struct EnumBuilderContext {
|
147
|
+
VALUE enumdesc;
|
148
|
+
};
|
149
|
+
|
150
|
+
struct Builder {
|
151
|
+
VALUE pending_list;
|
152
|
+
upb_def** defs; // used only while finalizing
|
153
|
+
};
|
154
|
+
|
155
|
+
extern VALUE cDescriptorPool;
|
156
|
+
extern VALUE cDescriptor;
|
157
|
+
extern VALUE cFieldDescriptor;
|
158
|
+
extern VALUE cEnumDescriptor;
|
159
|
+
extern VALUE cMessageBuilderContext;
|
160
|
+
extern VALUE cOneofBuilderContext;
|
161
|
+
extern VALUE cEnumBuilderContext;
|
162
|
+
extern VALUE cBuilder;
|
163
|
+
|
164
|
+
extern VALUE cError;
|
165
|
+
extern VALUE cParseError;
|
166
|
+
|
167
|
+
// We forward-declare all of the Ruby method implementations here because we
|
168
|
+
// sometimes call the methods directly across .c files, rather than going
|
169
|
+
// through Ruby's method dispatching (e.g. during message parse). It's cleaner
|
170
|
+
// to keep the list of object methods together than to split them between
|
171
|
+
// static-in-file definitions and header declarations.
|
172
|
+
|
173
|
+
void DescriptorPool_mark(void* _self);
|
174
|
+
void DescriptorPool_free(void* _self);
|
175
|
+
VALUE DescriptorPool_alloc(VALUE klass);
|
176
|
+
void DescriptorPool_register(VALUE module);
|
177
|
+
DescriptorPool* ruby_to_DescriptorPool(VALUE value);
|
178
|
+
VALUE DescriptorPool_add(VALUE _self, VALUE def);
|
179
|
+
VALUE DescriptorPool_build(VALUE _self);
|
180
|
+
VALUE DescriptorPool_lookup(VALUE _self, VALUE name);
|
181
|
+
VALUE DescriptorPool_generated_pool(VALUE _self);
|
182
|
+
|
183
|
+
void Descriptor_mark(void* _self);
|
184
|
+
void Descriptor_free(void* _self);
|
185
|
+
VALUE Descriptor_alloc(VALUE klass);
|
186
|
+
void Descriptor_register(VALUE module);
|
187
|
+
Descriptor* ruby_to_Descriptor(VALUE value);
|
188
|
+
VALUE Descriptor_name(VALUE _self);
|
189
|
+
VALUE Descriptor_name_set(VALUE _self, VALUE str);
|
190
|
+
VALUE Descriptor_each(VALUE _self);
|
191
|
+
VALUE Descriptor_lookup(VALUE _self, VALUE name);
|
192
|
+
VALUE Descriptor_add_field(VALUE _self, VALUE obj);
|
193
|
+
VALUE Descriptor_add_oneof(VALUE _self, VALUE obj);
|
194
|
+
VALUE Descriptor_each_oneof(VALUE _self);
|
195
|
+
VALUE Descriptor_lookup_oneof(VALUE _self, VALUE name);
|
196
|
+
VALUE Descriptor_msgclass(VALUE _self);
|
197
|
+
extern const rb_data_type_t _Descriptor_type;
|
198
|
+
|
199
|
+
void FieldDescriptor_mark(void* _self);
|
200
|
+
void FieldDescriptor_free(void* _self);
|
201
|
+
VALUE FieldDescriptor_alloc(VALUE klass);
|
202
|
+
void FieldDescriptor_register(VALUE module);
|
203
|
+
FieldDescriptor* ruby_to_FieldDescriptor(VALUE value);
|
204
|
+
VALUE FieldDescriptor_name(VALUE _self);
|
205
|
+
VALUE FieldDescriptor_name_set(VALUE _self, VALUE str);
|
206
|
+
VALUE FieldDescriptor_type(VALUE _self);
|
207
|
+
VALUE FieldDescriptor_type_set(VALUE _self, VALUE type);
|
208
|
+
VALUE FieldDescriptor_label(VALUE _self);
|
209
|
+
VALUE FieldDescriptor_label_set(VALUE _self, VALUE label);
|
210
|
+
VALUE FieldDescriptor_number(VALUE _self);
|
211
|
+
VALUE FieldDescriptor_number_set(VALUE _self, VALUE number);
|
212
|
+
VALUE FieldDescriptor_submsg_name(VALUE _self);
|
213
|
+
VALUE FieldDescriptor_submsg_name_set(VALUE _self, VALUE value);
|
214
|
+
VALUE FieldDescriptor_subtype(VALUE _self);
|
215
|
+
VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb);
|
216
|
+
VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value);
|
217
|
+
upb_fieldtype_t ruby_to_fieldtype(VALUE type);
|
218
|
+
VALUE fieldtype_to_ruby(upb_fieldtype_t type);
|
219
|
+
|
220
|
+
void OneofDescriptor_mark(void* _self);
|
221
|
+
void OneofDescriptor_free(void* _self);
|
222
|
+
VALUE OneofDescriptor_alloc(VALUE klass);
|
223
|
+
void OneofDescriptor_register(VALUE module);
|
224
|
+
OneofDescriptor* ruby_to_OneofDescriptor(VALUE value);
|
225
|
+
VALUE OneofDescriptor_name(VALUE _self);
|
226
|
+
VALUE OneofDescriptor_name_set(VALUE _self, VALUE value);
|
227
|
+
VALUE OneofDescriptor_add_field(VALUE _self, VALUE field);
|
228
|
+
VALUE OneofDescriptor_each(VALUE _self, VALUE field);
|
229
|
+
|
230
|
+
void EnumDescriptor_mark(void* _self);
|
231
|
+
void EnumDescriptor_free(void* _self);
|
232
|
+
VALUE EnumDescriptor_alloc(VALUE klass);
|
233
|
+
void EnumDescriptor_register(VALUE module);
|
234
|
+
EnumDescriptor* ruby_to_EnumDescriptor(VALUE value);
|
235
|
+
VALUE EnumDescriptor_name(VALUE _self);
|
236
|
+
VALUE EnumDescriptor_name_set(VALUE _self, VALUE str);
|
237
|
+
VALUE EnumDescriptor_add_value(VALUE _self, VALUE name, VALUE number);
|
238
|
+
VALUE EnumDescriptor_lookup_name(VALUE _self, VALUE name);
|
239
|
+
VALUE EnumDescriptor_lookup_value(VALUE _self, VALUE number);
|
240
|
+
VALUE EnumDescriptor_each(VALUE _self);
|
241
|
+
VALUE EnumDescriptor_enummodule(VALUE _self);
|
242
|
+
extern const rb_data_type_t _EnumDescriptor_type;
|
243
|
+
|
244
|
+
void MessageBuilderContext_mark(void* _self);
|
245
|
+
void MessageBuilderContext_free(void* _self);
|
246
|
+
VALUE MessageBuilderContext_alloc(VALUE klass);
|
247
|
+
void MessageBuilderContext_register(VALUE module);
|
248
|
+
MessageBuilderContext* ruby_to_MessageBuilderContext(VALUE value);
|
249
|
+
VALUE MessageBuilderContext_initialize(VALUE _self,
|
250
|
+
VALUE descriptor,
|
251
|
+
VALUE builder);
|
252
|
+
VALUE MessageBuilderContext_optional(int argc, VALUE* argv, VALUE _self);
|
253
|
+
VALUE MessageBuilderContext_required(int argc, VALUE* argv, VALUE _self);
|
254
|
+
VALUE MessageBuilderContext_repeated(int argc, VALUE* argv, VALUE _self);
|
255
|
+
VALUE MessageBuilderContext_map(int argc, VALUE* argv, VALUE _self);
|
256
|
+
VALUE MessageBuilderContext_oneof(VALUE _self, VALUE name);
|
257
|
+
|
258
|
+
void OneofBuilderContext_mark(void* _self);
|
259
|
+
void OneofBuilderContext_free(void* _self);
|
260
|
+
VALUE OneofBuilderContext_alloc(VALUE klass);
|
261
|
+
void OneofBuilderContext_register(VALUE module);
|
262
|
+
OneofBuilderContext* ruby_to_OneofBuilderContext(VALUE value);
|
263
|
+
VALUE OneofBuilderContext_initialize(VALUE _self,
|
264
|
+
VALUE descriptor,
|
265
|
+
VALUE builder);
|
266
|
+
VALUE OneofBuilderContext_optional(int argc, VALUE* argv, VALUE _self);
|
267
|
+
|
268
|
+
void EnumBuilderContext_mark(void* _self);
|
269
|
+
void EnumBuilderContext_free(void* _self);
|
270
|
+
VALUE EnumBuilderContext_alloc(VALUE klass);
|
271
|
+
void EnumBuilderContext_register(VALUE module);
|
272
|
+
EnumBuilderContext* ruby_to_EnumBuilderContext(VALUE value);
|
273
|
+
VALUE EnumBuilderContext_initialize(VALUE _self, VALUE enumdesc);
|
274
|
+
VALUE EnumBuilderContext_value(VALUE _self, VALUE name, VALUE number);
|
275
|
+
|
276
|
+
void Builder_mark(void* _self);
|
277
|
+
void Builder_free(void* _self);
|
278
|
+
VALUE Builder_alloc(VALUE klass);
|
279
|
+
void Builder_register(VALUE module);
|
280
|
+
Builder* ruby_to_Builder(VALUE value);
|
281
|
+
VALUE Builder_add_message(VALUE _self, VALUE name);
|
282
|
+
VALUE Builder_add_enum(VALUE _self, VALUE name);
|
283
|
+
VALUE Builder_finalize_to_pool(VALUE _self, VALUE pool_rb);
|
284
|
+
|
285
|
+
// -----------------------------------------------------------------------------
|
286
|
+
// Native slot storage abstraction.
|
287
|
+
// -----------------------------------------------------------------------------
|
288
|
+
|
289
|
+
#define NATIVE_SLOT_MAX_SIZE sizeof(uint64_t)
|
290
|
+
|
291
|
+
size_t native_slot_size(upb_fieldtype_t type);
|
292
|
+
void native_slot_set(upb_fieldtype_t type,
|
293
|
+
VALUE type_class,
|
294
|
+
void* memory,
|
295
|
+
VALUE value);
|
296
|
+
// Atomically (with respect to Ruby VM calls) either update the value and set a
|
297
|
+
// oneof case, or do neither. If |case_memory| is null, then no case value is
|
298
|
+
// set.
|
299
|
+
void native_slot_set_value_and_case(upb_fieldtype_t type,
|
300
|
+
VALUE type_class,
|
301
|
+
void* memory,
|
302
|
+
VALUE value,
|
303
|
+
uint32_t* case_memory,
|
304
|
+
uint32_t case_number);
|
305
|
+
VALUE native_slot_get(upb_fieldtype_t type,
|
306
|
+
VALUE type_class,
|
307
|
+
const void* memory);
|
308
|
+
void native_slot_init(upb_fieldtype_t type, void* memory);
|
309
|
+
void native_slot_mark(upb_fieldtype_t type, void* memory);
|
310
|
+
void native_slot_dup(upb_fieldtype_t type, void* to, void* from);
|
311
|
+
void native_slot_deep_copy(upb_fieldtype_t type, void* to, void* from);
|
312
|
+
bool native_slot_eq(upb_fieldtype_t type, void* mem1, void* mem2);
|
313
|
+
|
314
|
+
void native_slot_validate_string_encoding(upb_fieldtype_t type, VALUE value);
|
315
|
+
void native_slot_check_int_range_precision(upb_fieldtype_t type, VALUE value);
|
316
|
+
|
317
|
+
extern rb_encoding* kRubyStringUtf8Encoding;
|
318
|
+
extern rb_encoding* kRubyStringASCIIEncoding;
|
319
|
+
extern rb_encoding* kRubyString8bitEncoding;
|
320
|
+
|
321
|
+
VALUE field_type_class(const upb_fielddef* field);
|
322
|
+
|
323
|
+
#define MAP_KEY_FIELD 1
|
324
|
+
#define MAP_VALUE_FIELD 2
|
325
|
+
|
326
|
+
// Oneof case slot value to indicate that no oneof case is set. The value `0` is
|
327
|
+
// safe because field numbers are used as case identifiers, and no field can
|
328
|
+
// have a number of 0.
|
329
|
+
#define ONEOF_CASE_NONE 0
|
330
|
+
|
331
|
+
// These operate on a map field (i.e., a repeated field of submessages whose
|
332
|
+
// submessage type is a map-entry msgdef).
|
333
|
+
bool is_map_field(const upb_fielddef* field);
|
334
|
+
const upb_fielddef* map_field_key(const upb_fielddef* field);
|
335
|
+
const upb_fielddef* map_field_value(const upb_fielddef* field);
|
336
|
+
|
337
|
+
// These operate on a map-entry msgdef.
|
338
|
+
const upb_fielddef* map_entry_key(const upb_msgdef* msgdef);
|
339
|
+
const upb_fielddef* map_entry_value(const upb_msgdef* msgdef);
|
340
|
+
|
341
|
+
// -----------------------------------------------------------------------------
|
342
|
+
// Repeated field container type.
|
343
|
+
// -----------------------------------------------------------------------------
|
344
|
+
|
345
|
+
typedef struct {
|
346
|
+
upb_fieldtype_t field_type;
|
347
|
+
VALUE field_type_class;
|
348
|
+
void* elements;
|
349
|
+
int size;
|
350
|
+
int capacity;
|
351
|
+
} RepeatedField;
|
352
|
+
|
353
|
+
void RepeatedField_mark(void* self);
|
354
|
+
void RepeatedField_free(void* self);
|
355
|
+
VALUE RepeatedField_alloc(VALUE klass);
|
356
|
+
VALUE RepeatedField_init(int argc, VALUE* argv, VALUE self);
|
357
|
+
void RepeatedField_register(VALUE module);
|
358
|
+
|
359
|
+
extern const rb_data_type_t RepeatedField_type;
|
360
|
+
extern VALUE cRepeatedField;
|
361
|
+
|
362
|
+
RepeatedField* ruby_to_RepeatedField(VALUE value);
|
363
|
+
|
364
|
+
VALUE RepeatedField_each(VALUE _self);
|
365
|
+
VALUE RepeatedField_index(int argc, VALUE* argv, VALUE _self);
|
366
|
+
void* RepeatedField_index_native(VALUE _self, int index);
|
367
|
+
VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val);
|
368
|
+
void RepeatedField_reserve(RepeatedField* self, int new_size);
|
369
|
+
VALUE RepeatedField_push(VALUE _self, VALUE val);
|
370
|
+
void RepeatedField_push_native(VALUE _self, void* data);
|
371
|
+
VALUE RepeatedField_pop_one(VALUE _self);
|
372
|
+
VALUE RepeatedField_insert(int argc, VALUE* argv, VALUE _self);
|
373
|
+
VALUE RepeatedField_replace(VALUE _self, VALUE list);
|
374
|
+
VALUE RepeatedField_clear(VALUE _self);
|
375
|
+
VALUE RepeatedField_length(VALUE _self);
|
376
|
+
VALUE RepeatedField_dup(VALUE _self);
|
377
|
+
VALUE RepeatedField_deep_copy(VALUE _self);
|
378
|
+
VALUE RepeatedField_to_ary(VALUE _self);
|
379
|
+
VALUE RepeatedField_eq(VALUE _self, VALUE _other);
|
380
|
+
VALUE RepeatedField_hash(VALUE _self);
|
381
|
+
VALUE RepeatedField_inspect(VALUE _self);
|
382
|
+
VALUE RepeatedField_plus(VALUE _self, VALUE list);
|
383
|
+
|
384
|
+
// Defined in repeated_field.c; also used by Map.
|
385
|
+
void validate_type_class(upb_fieldtype_t type, VALUE klass);
|
386
|
+
|
387
|
+
// -----------------------------------------------------------------------------
|
388
|
+
// Map container type.
|
389
|
+
// -----------------------------------------------------------------------------
|
390
|
+
|
391
|
+
typedef struct {
|
392
|
+
upb_fieldtype_t key_type;
|
393
|
+
upb_fieldtype_t value_type;
|
394
|
+
VALUE value_type_class;
|
395
|
+
upb_strtable table;
|
396
|
+
} Map;
|
397
|
+
|
398
|
+
void Map_mark(void* self);
|
399
|
+
void Map_free(void* self);
|
400
|
+
VALUE Map_alloc(VALUE klass);
|
401
|
+
VALUE Map_init(int argc, VALUE* argv, VALUE self);
|
402
|
+
void Map_register(VALUE module);
|
403
|
+
|
404
|
+
extern const rb_data_type_t Map_type;
|
405
|
+
extern VALUE cMap;
|
406
|
+
|
407
|
+
Map* ruby_to_Map(VALUE value);
|
408
|
+
|
409
|
+
VALUE Map_each(VALUE _self);
|
410
|
+
VALUE Map_keys(VALUE _self);
|
411
|
+
VALUE Map_values(VALUE _self);
|
412
|
+
VALUE Map_index(VALUE _self, VALUE key);
|
413
|
+
VALUE Map_index_set(VALUE _self, VALUE key, VALUE value);
|
414
|
+
VALUE Map_has_key(VALUE _self, VALUE key);
|
415
|
+
VALUE Map_delete(VALUE _self, VALUE key);
|
416
|
+
VALUE Map_clear(VALUE _self);
|
417
|
+
VALUE Map_length(VALUE _self);
|
418
|
+
VALUE Map_dup(VALUE _self);
|
419
|
+
VALUE Map_deep_copy(VALUE _self);
|
420
|
+
VALUE Map_eq(VALUE _self, VALUE _other);
|
421
|
+
VALUE Map_hash(VALUE _self);
|
422
|
+
VALUE Map_inspect(VALUE _self);
|
423
|
+
VALUE Map_merge(VALUE _self, VALUE hashmap);
|
424
|
+
VALUE Map_merge_into_self(VALUE _self, VALUE hashmap);
|
425
|
+
|
426
|
+
typedef struct {
|
427
|
+
Map* self;
|
428
|
+
upb_strtable_iter it;
|
429
|
+
} Map_iter;
|
430
|
+
|
431
|
+
void Map_begin(VALUE _self, Map_iter* iter);
|
432
|
+
void Map_next(Map_iter* iter);
|
433
|
+
bool Map_done(Map_iter* iter);
|
434
|
+
VALUE Map_iter_key(Map_iter* iter);
|
435
|
+
VALUE Map_iter_value(Map_iter* iter);
|
436
|
+
|
437
|
+
// -----------------------------------------------------------------------------
|
438
|
+
// Message layout / storage.
|
439
|
+
// -----------------------------------------------------------------------------
|
440
|
+
|
441
|
+
#define MESSAGE_FIELD_NO_CASE ((size_t)-1)
|
442
|
+
|
443
|
+
struct MessageField {
|
444
|
+
size_t offset;
|
445
|
+
size_t case_offset; // for oneofs, a uint32. Else, MESSAGE_FIELD_NO_CASE.
|
446
|
+
};
|
447
|
+
|
448
|
+
struct MessageLayout {
|
449
|
+
const upb_msgdef* msgdef;
|
450
|
+
MessageField* fields;
|
451
|
+
size_t size;
|
452
|
+
};
|
453
|
+
|
454
|
+
MessageLayout* create_layout(const upb_msgdef* msgdef);
|
455
|
+
void free_layout(MessageLayout* layout);
|
456
|
+
VALUE layout_get(MessageLayout* layout,
|
457
|
+
const void* storage,
|
458
|
+
const upb_fielddef* field);
|
459
|
+
void layout_set(MessageLayout* layout,
|
460
|
+
void* storage,
|
461
|
+
const upb_fielddef* field,
|
462
|
+
VALUE val);
|
463
|
+
void layout_init(MessageLayout* layout, void* storage);
|
464
|
+
void layout_mark(MessageLayout* layout, void* storage);
|
465
|
+
void layout_dup(MessageLayout* layout, void* to, void* from);
|
466
|
+
void layout_deep_copy(MessageLayout* layout, void* to, void* from);
|
467
|
+
VALUE layout_eq(MessageLayout* layout, void* msg1, void* msg2);
|
468
|
+
VALUE layout_hash(MessageLayout* layout, void* storage);
|
469
|
+
VALUE layout_inspect(MessageLayout* layout, void* storage);
|
470
|
+
|
471
|
+
// -----------------------------------------------------------------------------
|
472
|
+
// Message class creation.
|
473
|
+
// -----------------------------------------------------------------------------
|
474
|
+
|
475
|
+
struct MessageHeader {
|
476
|
+
Descriptor* descriptor; // kept alive by self.class.descriptor reference.
|
477
|
+
// Data comes after this.
|
478
|
+
};
|
479
|
+
|
480
|
+
extern rb_data_type_t Message_type;
|
481
|
+
|
482
|
+
VALUE build_class_from_descriptor(Descriptor* descriptor);
|
483
|
+
void* Message_data(void* msg);
|
484
|
+
void Message_mark(void* self);
|
485
|
+
void Message_free(void* self);
|
486
|
+
VALUE Message_alloc(VALUE klass);
|
487
|
+
VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self);
|
488
|
+
VALUE Message_initialize(int argc, VALUE* argv, VALUE _self);
|
489
|
+
VALUE Message_dup(VALUE _self);
|
490
|
+
VALUE Message_deep_copy(VALUE _self);
|
491
|
+
VALUE Message_eq(VALUE _self, VALUE _other);
|
492
|
+
VALUE Message_hash(VALUE _self);
|
493
|
+
VALUE Message_inspect(VALUE _self);
|
494
|
+
VALUE Message_index(VALUE _self, VALUE field_name);
|
495
|
+
VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value);
|
496
|
+
VALUE Message_descriptor(VALUE klass);
|
497
|
+
VALUE Message_decode(VALUE klass, VALUE data);
|
498
|
+
VALUE Message_encode(VALUE klass, VALUE msg_rb);
|
499
|
+
VALUE Message_decode_json(VALUE klass, VALUE data);
|
500
|
+
VALUE Message_encode_json(VALUE klass, VALUE msg_rb);
|
501
|
+
|
502
|
+
VALUE Google_Protobuf_deep_copy(VALUE self, VALUE obj);
|
503
|
+
|
504
|
+
VALUE build_module_from_enumdesc(EnumDescriptor* enumdef);
|
505
|
+
VALUE enum_lookup(VALUE self, VALUE number);
|
506
|
+
VALUE enum_resolve(VALUE self, VALUE sym);
|
507
|
+
|
508
|
+
const upb_pbdecodermethod *new_fillmsg_decodermethod(
|
509
|
+
Descriptor* descriptor, const void *owner);
|
510
|
+
|
511
|
+
// Maximum depth allowed during encoding, to avoid stack overflows due to
|
512
|
+
// cycles.
|
513
|
+
#define ENCODE_MAX_NESTING 63
|
514
|
+
|
515
|
+
// -----------------------------------------------------------------------------
|
516
|
+
// Global map from upb {msg,enum}defs to wrapper Descriptor/EnumDescriptor
|
517
|
+
// instances.
|
518
|
+
// -----------------------------------------------------------------------------
|
519
|
+
void add_def_obj(const void* def, VALUE value);
|
520
|
+
VALUE get_def_obj(const void* def);
|
521
|
+
|
522
|
+
// -----------------------------------------------------------------------------
|
523
|
+
// Utilities.
|
524
|
+
// -----------------------------------------------------------------------------
|
525
|
+
|
526
|
+
void check_upb_status(const upb_status* status, const char* msg);
|
527
|
+
|
528
|
+
#define CHECK_UPB(code, msg) do { \
|
529
|
+
upb_status status = UPB_STATUS_INIT; \
|
530
|
+
code; \
|
531
|
+
check_upb_status(&status, msg); \
|
532
|
+
} while (0)
|
533
|
+
|
534
|
+
extern ID descriptor_instancevar_interned;
|
535
|
+
|
536
|
+
#endif // __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__
|