google-protobuf 3.0.0.alpha.1.0

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.

@@ -0,0 +1,102 @@
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
+ void add_def_obj(const void* def, VALUE value) {
43
+ rb_hash_aset(upb_def_to_ruby_obj_map, ULL2NUM((intptr_t)def), value);
44
+ }
45
+
46
+ VALUE get_def_obj(const void* def) {
47
+ return rb_hash_aref(upb_def_to_ruby_obj_map, ULL2NUM((intptr_t)def));
48
+ }
49
+
50
+ // -----------------------------------------------------------------------------
51
+ // Utilities.
52
+ // -----------------------------------------------------------------------------
53
+
54
+ // Raises a Ruby error if |status| is not OK, using its error message.
55
+ void check_upb_status(const upb_status* status, const char* msg) {
56
+ if (!upb_ok(status)) {
57
+ rb_raise(rb_eRuntimeError, "%s: %s\n", msg, upb_status_errmsg(status));
58
+ }
59
+ }
60
+
61
+ // String encodings: we look these up once, at load time, and then cache them
62
+ // here.
63
+ rb_encoding* kRubyStringUtf8Encoding;
64
+ rb_encoding* kRubyStringASCIIEncoding;
65
+ rb_encoding* kRubyString8bitEncoding;
66
+
67
+ // -----------------------------------------------------------------------------
68
+ // Initialization/entry point.
69
+ // -----------------------------------------------------------------------------
70
+
71
+ // This must be named "Init_protobuf_c" because the Ruby module is named
72
+ // "protobuf_c" -- the VM looks for this symbol in our .so.
73
+ void Init_protobuf_c() {
74
+ VALUE google = rb_define_module("Google");
75
+ VALUE protobuf = rb_define_module_under(google, "Protobuf");
76
+ VALUE internal = rb_define_module_under(protobuf, "Internal");
77
+ DescriptorPool_register(protobuf);
78
+ Descriptor_register(protobuf);
79
+ FieldDescriptor_register(protobuf);
80
+ EnumDescriptor_register(protobuf);
81
+ MessageBuilderContext_register(internal);
82
+ EnumBuilderContext_register(internal);
83
+ Builder_register(internal);
84
+ RepeatedField_register(protobuf);
85
+
86
+ rb_define_singleton_method(protobuf, "encode", Google_Protobuf_encode, 1);
87
+ rb_define_singleton_method(protobuf, "decode", Google_Protobuf_decode, 2);
88
+ rb_define_singleton_method(protobuf, "encode_json",
89
+ Google_Protobuf_encode_json, 1);
90
+ rb_define_singleton_method(protobuf, "decode_json",
91
+ Google_Protobuf_decode_json, 2);
92
+
93
+ rb_define_singleton_method(protobuf, "deep_copy",
94
+ Google_Protobuf_deep_copy, 1);
95
+
96
+ kRubyStringUtf8Encoding = rb_utf8_encoding();
97
+ kRubyStringASCIIEncoding = rb_usascii_encoding();
98
+ kRubyString8bitEncoding = rb_ascii8bit_encoding();
99
+
100
+ upb_def_to_ruby_obj_map = rb_hash_new();
101
+ rb_gc_register_address(&upb_def_to_ruby_obj_map);
102
+ }
@@ -0,0 +1,396 @@
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 MessageHeader;
47
+ struct MessageBuilderContext;
48
+ struct EnumBuilderContext;
49
+ struct Builder;
50
+
51
+ typedef struct DescriptorPool DescriptorPool;
52
+ typedef struct Descriptor Descriptor;
53
+ typedef struct FieldDescriptor FieldDescriptor;
54
+ typedef struct EnumDescriptor EnumDescriptor;
55
+ typedef struct MessageLayout MessageLayout;
56
+ typedef struct MessageHeader MessageHeader;
57
+ typedef struct MessageBuilderContext MessageBuilderContext;
58
+ typedef struct EnumBuilderContext EnumBuilderContext;
59
+ typedef struct Builder Builder;
60
+
61
+ /*
62
+ It can be a bit confusing how the C structs defined below and the Ruby
63
+ objects interact and hold references to each other. First, a few principles:
64
+
65
+ - Ruby's "TypedData" abstraction lets a Ruby VALUE hold a pointer to a C
66
+ struct (or arbitrary memory chunk), own it, and free it when collected.
67
+ Thus, each struct below will have a corresponding Ruby object
68
+ wrapping/owning it.
69
+
70
+ - To get back from an underlying upb {msg,enum}def to the Ruby object, we
71
+ keep a global hashmap, accessed by get_def_obj/add_def_obj below.
72
+
73
+ The in-memory structure is then something like:
74
+
75
+ Ruby | upb
76
+ |
77
+ DescriptorPool ------------|-----------> upb_symtab____________________
78
+ | | (message types) \
79
+ | v \
80
+ Descriptor ---------------|-----------> upb_msgdef (enum types)|
81
+ |--> msgclass | | ^ |
82
+ | (dynamically built) | | | (submsg fields) |
83
+ |--> MessageLayout | | | /
84
+ |--------------------------|> decoder method| | /
85
+ \--------------------------|> serialize | | /
86
+ | handlers v | /
87
+ FieldDescriptor -----------|-----------> upb_fielddef /
88
+ | | /
89
+ | v (enum fields) /
90
+ EnumDescriptor ------------|-----------> upb_enumdef <----------'
91
+ |
92
+ |
93
+ ^ | \___/
94
+ `---------------|-----------------' (get_def_obj map)
95
+ */
96
+
97
+ // -----------------------------------------------------------------------------
98
+ // Ruby class structure definitions.
99
+ // -----------------------------------------------------------------------------
100
+
101
+ struct DescriptorPool {
102
+ upb_symtab* symtab;
103
+ };
104
+
105
+ struct Descriptor {
106
+ const upb_msgdef* msgdef;
107
+ MessageLayout* layout;
108
+ VALUE klass; // begins as nil
109
+ const upb_handlers* fill_handlers;
110
+ const upb_pbdecodermethod* fill_method;
111
+ const upb_handlers* pb_serialize_handlers;
112
+ const upb_handlers* json_serialize_handlers;
113
+ };
114
+
115
+ struct FieldDescriptor {
116
+ const upb_fielddef* fielddef;
117
+ };
118
+
119
+ struct EnumDescriptor {
120
+ const upb_enumdef* enumdef;
121
+ VALUE module; // begins as nil
122
+ };
123
+
124
+ struct MessageBuilderContext {
125
+ VALUE descriptor;
126
+ };
127
+
128
+ struct EnumBuilderContext {
129
+ VALUE enumdesc;
130
+ };
131
+
132
+ struct Builder {
133
+ VALUE pending_list;
134
+ upb_def** defs; // used only while finalizing
135
+ };
136
+
137
+ extern VALUE cDescriptorPool;
138
+ extern VALUE cDescriptor;
139
+ extern VALUE cFieldDescriptor;
140
+ extern VALUE cEnumDescriptor;
141
+ extern VALUE cMessageBuilderContext;
142
+ extern VALUE cEnumBuilderContext;
143
+ extern VALUE cBuilder;
144
+
145
+ extern const char* kDescriptorInstanceVar;
146
+
147
+ // We forward-declare all of the Ruby method implementations here because we
148
+ // sometimes call the methods directly across .c files, rather than going
149
+ // through Ruby's method dispatching (e.g. during message parse). It's cleaner
150
+ // to keep the list of object methods together than to split them between
151
+ // static-in-file definitions and header declarations.
152
+
153
+ void DescriptorPool_mark(void* _self);
154
+ void DescriptorPool_free(void* _self);
155
+ VALUE DescriptorPool_alloc(VALUE klass);
156
+ void DescriptorPool_register(VALUE module);
157
+ DescriptorPool* ruby_to_DescriptorPool(VALUE value);
158
+ VALUE DescriptorPool_add(VALUE _self, VALUE def);
159
+ VALUE DescriptorPool_build(VALUE _self);
160
+ VALUE DescriptorPool_lookup(VALUE _self, VALUE name);
161
+ VALUE DescriptorPool_generated_pool(VALUE _self);
162
+
163
+ void Descriptor_mark(void* _self);
164
+ void Descriptor_free(void* _self);
165
+ VALUE Descriptor_alloc(VALUE klass);
166
+ void Descriptor_register(VALUE module);
167
+ Descriptor* ruby_to_Descriptor(VALUE value);
168
+ VALUE Descriptor_name(VALUE _self);
169
+ VALUE Descriptor_name_set(VALUE _self, VALUE str);
170
+ VALUE Descriptor_each(VALUE _self);
171
+ VALUE Descriptor_lookup(VALUE _self, VALUE name);
172
+ VALUE Descriptor_add_field(VALUE _self, VALUE obj);
173
+ VALUE Descriptor_msgclass(VALUE _self);
174
+ extern const rb_data_type_t _Descriptor_type;
175
+
176
+ void FieldDescriptor_mark(void* _self);
177
+ void FieldDescriptor_free(void* _self);
178
+ VALUE FieldDescriptor_alloc(VALUE klass);
179
+ void FieldDescriptor_register(VALUE module);
180
+ FieldDescriptor* ruby_to_FieldDescriptor(VALUE value);
181
+ VALUE FieldDescriptor_name(VALUE _self);
182
+ VALUE FieldDescriptor_name_set(VALUE _self, VALUE str);
183
+ VALUE FieldDescriptor_type(VALUE _self);
184
+ VALUE FieldDescriptor_type_set(VALUE _self, VALUE type);
185
+ VALUE FieldDescriptor_label(VALUE _self);
186
+ VALUE FieldDescriptor_label_set(VALUE _self, VALUE label);
187
+ VALUE FieldDescriptor_number(VALUE _self);
188
+ VALUE FieldDescriptor_number_set(VALUE _self, VALUE number);
189
+ VALUE FieldDescriptor_submsg_name(VALUE _self);
190
+ VALUE FieldDescriptor_submsg_name_set(VALUE _self, VALUE value);
191
+ VALUE FieldDescriptor_subtype(VALUE _self);
192
+ VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb);
193
+ VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value);
194
+ upb_fieldtype_t ruby_to_fieldtype(VALUE type);
195
+ VALUE fieldtype_to_ruby(upb_fieldtype_t type);
196
+
197
+ void EnumDescriptor_mark(void* _self);
198
+ void EnumDescriptor_free(void* _self);
199
+ VALUE EnumDescriptor_alloc(VALUE klass);
200
+ void EnumDescriptor_register(VALUE module);
201
+ EnumDescriptor* ruby_to_EnumDescriptor(VALUE value);
202
+ VALUE EnumDescriptor_name(VALUE _self);
203
+ VALUE EnumDescriptor_name_set(VALUE _self, VALUE str);
204
+ VALUE EnumDescriptor_add_value(VALUE _self, VALUE name, VALUE number);
205
+ VALUE EnumDescriptor_lookup_name(VALUE _self, VALUE name);
206
+ VALUE EnumDescriptor_lookup_value(VALUE _self, VALUE number);
207
+ VALUE EnumDescriptor_each(VALUE _self);
208
+ VALUE EnumDescriptor_enummodule(VALUE _self);
209
+ extern const rb_data_type_t _EnumDescriptor_type;
210
+
211
+ void MessageBuilderContext_mark(void* _self);
212
+ void MessageBuilderContext_free(void* _self);
213
+ VALUE MessageBuilderContext_alloc(VALUE klass);
214
+ void MessageBuilderContext_register(VALUE module);
215
+ MessageBuilderContext* ruby_to_MessageBuilderContext(VALUE value);
216
+ VALUE MessageBuilderContext_initialize(VALUE _self, VALUE descriptor);
217
+ VALUE MessageBuilderContext_optional(int argc, VALUE* argv, VALUE _self);
218
+ VALUE MessageBuilderContext_required(int argc, VALUE* argv, VALUE _self);
219
+ VALUE MessageBuilderContext_repeated(int argc, VALUE* argv, VALUE _self);
220
+
221
+ void EnumBuilderContext_mark(void* _self);
222
+ void EnumBuilderContext_free(void* _self);
223
+ VALUE EnumBuilderContext_alloc(VALUE klass);
224
+ void EnumBuilderContext_register(VALUE module);
225
+ EnumBuilderContext* ruby_to_EnumBuilderContext(VALUE value);
226
+ VALUE EnumBuilderContext_initialize(VALUE _self, VALUE enumdesc);
227
+ VALUE EnumBuilderContext_value(VALUE _self, VALUE name, VALUE number);
228
+
229
+ void Builder_mark(void* _self);
230
+ void Builder_free(void* _self);
231
+ VALUE Builder_alloc(VALUE klass);
232
+ void Builder_register(VALUE module);
233
+ Builder* ruby_to_Builder(VALUE value);
234
+ VALUE Builder_add_message(VALUE _self, VALUE name);
235
+ VALUE Builder_add_enum(VALUE _self, VALUE name);
236
+ VALUE Builder_finalize_to_pool(VALUE _self, VALUE pool_rb);
237
+
238
+ // -----------------------------------------------------------------------------
239
+ // Native slot storage abstraction.
240
+ // -----------------------------------------------------------------------------
241
+
242
+ size_t native_slot_size(upb_fieldtype_t type);
243
+ void native_slot_set(upb_fieldtype_t type,
244
+ VALUE type_class,
245
+ void* memory,
246
+ VALUE value);
247
+ VALUE native_slot_get(upb_fieldtype_t type,
248
+ VALUE type_class,
249
+ void* memory);
250
+ void native_slot_init(upb_fieldtype_t type, void* memory);
251
+ void native_slot_mark(upb_fieldtype_t type, void* memory);
252
+ void native_slot_dup(upb_fieldtype_t type, void* to, void* from);
253
+ void native_slot_deep_copy(upb_fieldtype_t type, void* to, void* from);
254
+ bool native_slot_eq(upb_fieldtype_t type, void* mem1, void* mem2);
255
+
256
+ void native_slot_validate_string_encoding(upb_fieldtype_t type, VALUE value);
257
+
258
+ extern rb_encoding* kRubyStringUtf8Encoding;
259
+ extern rb_encoding* kRubyStringASCIIEncoding;
260
+ extern rb_encoding* kRubyString8bitEncoding;
261
+
262
+ // -----------------------------------------------------------------------------
263
+ // Repeated field container type.
264
+ // -----------------------------------------------------------------------------
265
+
266
+ typedef struct {
267
+ upb_fieldtype_t field_type;
268
+ VALUE field_type_class;
269
+ void* elements;
270
+ int size;
271
+ int capacity;
272
+ } RepeatedField;
273
+
274
+ void RepeatedField_mark(void* self);
275
+ void RepeatedField_free(void* self);
276
+ VALUE RepeatedField_alloc(VALUE klass);
277
+ VALUE RepeatedField_init(int argc, VALUE* argv, VALUE self);
278
+ void RepeatedField_register(VALUE module);
279
+
280
+ extern const rb_data_type_t RepeatedField_type;
281
+ extern VALUE cRepeatedField;
282
+
283
+ RepeatedField* ruby_to_RepeatedField(VALUE value);
284
+
285
+ void RepeatedField_register(VALUE module);
286
+ VALUE RepeatedField_each(VALUE _self);
287
+ VALUE RepeatedField_index(VALUE _self, VALUE _index);
288
+ void* RepeatedField_index_native(VALUE _self, int index);
289
+ VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val);
290
+ void RepeatedField_reserve(RepeatedField* self, int new_size);
291
+ VALUE RepeatedField_push(VALUE _self, VALUE val);
292
+ void RepeatedField_push_native(VALUE _self, void* data);
293
+ VALUE RepeatedField_pop(VALUE _self);
294
+ VALUE RepeatedField_insert(int argc, VALUE* argv, VALUE _self);
295
+ VALUE RepeatedField_replace(VALUE _self, VALUE list);
296
+ VALUE RepeatedField_clear(VALUE _self);
297
+ VALUE RepeatedField_length(VALUE _self);
298
+ VALUE RepeatedField_dup(VALUE _self);
299
+ VALUE RepeatedField_deep_copy(VALUE _self);
300
+ VALUE RepeatedField_eq(VALUE _self, VALUE _other);
301
+ VALUE RepeatedField_hash(VALUE _self);
302
+ VALUE RepeatedField_inspect(VALUE _self);
303
+ VALUE RepeatedField_plus(VALUE _self, VALUE list);
304
+
305
+ // -----------------------------------------------------------------------------
306
+ // Message layout / storage.
307
+ // -----------------------------------------------------------------------------
308
+
309
+ struct MessageLayout {
310
+ const upb_msgdef* msgdef;
311
+ size_t* offsets;
312
+ size_t size;
313
+ };
314
+
315
+ MessageLayout* create_layout(const upb_msgdef* msgdef);
316
+ void free_layout(MessageLayout* layout);
317
+ VALUE layout_get(MessageLayout* layout,
318
+ void* storage,
319
+ const upb_fielddef* field);
320
+ void layout_set(MessageLayout* layout,
321
+ void* storage,
322
+ const upb_fielddef* field,
323
+ VALUE val);
324
+ void layout_init(MessageLayout* layout, void* storage);
325
+ void layout_mark(MessageLayout* layout, void* storage);
326
+ void layout_dup(MessageLayout* layout, void* to, void* from);
327
+ void layout_deep_copy(MessageLayout* layout, void* to, void* from);
328
+ VALUE layout_eq(MessageLayout* layout, void* msg1, void* msg2);
329
+ VALUE layout_hash(MessageLayout* layout, void* storage);
330
+ VALUE layout_inspect(MessageLayout* layout, void* storage);
331
+
332
+ // -----------------------------------------------------------------------------
333
+ // Message class creation.
334
+ // -----------------------------------------------------------------------------
335
+
336
+ struct MessageHeader {
337
+ Descriptor* descriptor; // kept alive by self.class.descriptor reference.
338
+ // Data comes after this.
339
+ };
340
+
341
+ extern rb_data_type_t Message_type;
342
+
343
+ VALUE build_class_from_descriptor(Descriptor* descriptor);
344
+ void* Message_data(void* msg);
345
+ void Message_mark(void* self);
346
+ void Message_free(void* self);
347
+ VALUE Message_alloc(VALUE klass);
348
+ VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self);
349
+ VALUE Message_initialize(int argc, VALUE* argv, VALUE _self);
350
+ VALUE Message_dup(VALUE _self);
351
+ VALUE Message_deep_copy(VALUE _self);
352
+ VALUE Message_eq(VALUE _self, VALUE _other);
353
+ VALUE Message_hash(VALUE _self);
354
+ VALUE Message_inspect(VALUE _self);
355
+ VALUE Message_index(VALUE _self, VALUE field_name);
356
+ VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value);
357
+ VALUE Message_descriptor(VALUE klass);
358
+ VALUE Message_decode(VALUE klass, VALUE data);
359
+ VALUE Message_encode(VALUE klass, VALUE msg_rb);
360
+ VALUE Message_decode_json(VALUE klass, VALUE data);
361
+ VALUE Message_encode_json(VALUE klass, VALUE msg_rb);
362
+
363
+ VALUE Google_Protobuf_encode(VALUE self, VALUE msg_rb);
364
+ VALUE Google_Protobuf_decode(VALUE self, VALUE klass, VALUE msg_rb);
365
+ VALUE Google_Protobuf_encode_json(VALUE self, VALUE msg_rb);
366
+ VALUE Google_Protobuf_decode_json(VALUE self, VALUE klass, VALUE msg_rb);
367
+
368
+ VALUE Google_Protobuf_deep_copy(VALUE self, VALUE obj);
369
+
370
+ VALUE build_module_from_enumdesc(EnumDescriptor* enumdef);
371
+ VALUE enum_lookup(VALUE self, VALUE number);
372
+ VALUE enum_resolve(VALUE self, VALUE sym);
373
+
374
+ const upb_pbdecodermethod *new_fillmsg_decodermethod(
375
+ Descriptor* descriptor, const void *owner);
376
+
377
+ // -----------------------------------------------------------------------------
378
+ // Global map from upb {msg,enum}defs to wrapper Descriptor/EnumDescriptor
379
+ // instances.
380
+ // -----------------------------------------------------------------------------
381
+ void add_def_obj(const void* def, VALUE value);
382
+ VALUE get_def_obj(const void* def);
383
+
384
+ // -----------------------------------------------------------------------------
385
+ // Utilities.
386
+ // -----------------------------------------------------------------------------
387
+
388
+ void check_upb_status(const upb_status* status, const char* msg);
389
+
390
+ #define CHECK_UPB(code, msg) do { \
391
+ upb_status status = UPB_STATUS_INIT; \
392
+ code; \
393
+ check_upb_status(&status, msg); \
394
+ } while (0)
395
+
396
+ #endif // __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__