ruby/ext/google/protobuf_c/encode_decode.c
Go to the documentation of this file.
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 // This function is equivalent to rb_str_cat(), but unlike the real
34 // rb_str_cat(), it doesn't leak memory in some versions of Ruby.
35 // For more information, see:
36 // https://bugs.ruby-lang.org/issues/11328
37 VALUE noleak_rb_str_cat(VALUE rb_str, const char *str, long len) {
38  char *p;
39  size_t oldlen = RSTRING_LEN(rb_str);
40  rb_str_modify_expand(rb_str, len);
41  p = RSTRING_PTR(rb_str);
42  memcpy(p + oldlen, str, len);
43  rb_str_set_len(rb_str, oldlen + len);
44  return rb_str;
45 }
46 
47 // The code below also comes from upb's prototype Ruby binding, developed by
48 // haberman@.
49 
50 /* stringsink *****************************************************************/
51 
52 static void *stringsink_start(void *_sink, const void *hd, size_t size_hint) {
53  stringsink *sink = _sink;
54  sink->len = 0;
55  return sink;
56 }
57 
58 static size_t stringsink_string(void *_sink, const void *hd, const char *ptr,
59  size_t len, const upb_bufhandle *handle) {
60  stringsink *sink = _sink;
61  size_t new_size = sink->size;
62 
63  UPB_UNUSED(hd);
64  UPB_UNUSED(handle);
65 
66  while (sink->len + len > new_size) {
67  new_size *= 2;
68  }
69 
70  if (new_size != sink->size) {
71  sink->ptr = realloc(sink->ptr, new_size);
72  sink->size = new_size;
73  }
74 
75  memcpy(sink->ptr + sink->len, ptr, len);
76  sink->len += len;
77 
78  return len;
79 }
80 
85 
86  upb_bytessink_reset(&sink->sink, &sink->handler, sink);
87 
88  sink->size = 32;
89  sink->ptr = malloc(sink->size);
90  sink->len = 0;
91 }
92 
94  free(sink->ptr);
95 }
96 
97 // -----------------------------------------------------------------------------
98 // Parsing.
99 // -----------------------------------------------------------------------------
100 
101 #define DEREF(msg, ofs, type) *(type*)(((uint8_t *)msg) + ofs)
102 
103 typedef struct {
104  size_t ofs;
105  int32_t hasbit;
107 
108 // Creates a handlerdata that contains the offset and the hasbit for the field
109 static const void* newhandlerdata(upb_handlers* h, uint32_t ofs, int32_t hasbit) {
111  hd->ofs = ofs;
112  hd->hasbit = hasbit;
113  upb_handlers_addcleanup(h, hd, xfree);
114  return hd;
115 }
116 
117 typedef struct {
118  size_t ofs;
119  int32_t hasbit;
120  const upb_msgdef *md;
122 
123 // Creates a handlerdata that contains offset and submessage type information.
124 static const void *newsubmsghandlerdata(upb_handlers* h,
125  uint32_t ofs,
126  int32_t hasbit,
127  const upb_fielddef* f) {
129  hd->ofs = ofs;
130  hd->hasbit = hasbit;
131  hd->md = upb_fielddef_msgsubdef(f);
132  upb_handlers_addcleanup(h, hd, xfree);
133  return hd;
134 }
135 
136 typedef struct {
137  size_t ofs; // union data slot
138  size_t case_ofs; // oneof_case field
139  uint32_t oneof_case_num; // oneof-case number to place in oneof_case field
140  const upb_msgdef *md; // msgdef, for oneof submessage handler
142 
143 static const void *newoneofhandlerdata(upb_handlers *h,
144  uint32_t ofs,
145  uint32_t case_ofs,
146  const upb_fielddef *f) {
148  hd->ofs = ofs;
149  hd->case_ofs = case_ofs;
150  // We reuse the field tag number as a oneof union discriminant tag. Note that
151  // we don't expose these numbers to the user, so the only requirement is that
152  // we have some unique ID for each union case/possibility. The field tag
153  // numbers are already present and are easy to use so there's no reason to
154  // create a separate ID space. In addition, using the field tag number here
155  // lets us easily look up the field in the oneof accessor.
158  hd->md = upb_fielddef_msgsubdef(f);
159  } else {
160  hd->md = NULL;
161  }
162  upb_handlers_addcleanup(h, hd, xfree);
163  return hd;
164 }
165 
166 // A handler that starts a repeated field. Gets the Repeated*Field instance for
167 // this field (such an instance always exists even in an empty message).
168 static void *startseq_handler(void* closure, const void* hd) {
169  MessageHeader* msg = closure;
170  const size_t *ofs = hd;
171  return (void*)DEREF(msg, *ofs, VALUE);
172 }
173 
174 // Handlers that append primitive values to a repeated field.
175 #define DEFINE_APPEND_HANDLER(type, ctype) \
176  static bool append##type##_handler(void *closure, const void *hd, \
177  ctype val) { \
178  VALUE ary = (VALUE)closure; \
179  RepeatedField_push_native(ary, &val); \
180  return true; \
181  }
182 
183 DEFINE_APPEND_HANDLER(bool, bool)
185 DEFINE_APPEND_HANDLER(uint32, uint32_t)
186 DEFINE_APPEND_HANDLER(float, float)
188 DEFINE_APPEND_HANDLER(uint64, uint64_t)
189 DEFINE_APPEND_HANDLER(double, double)
190 
191 // Appends a string to a repeated field.
192 static void* appendstr_handler(void *closure,
193  const void *hd,
194  size_t size_hint) {
195  VALUE ary = (VALUE)closure;
196  VALUE str = rb_str_new2("");
197  rb_enc_associate(str, kRubyStringUtf8Encoding);
199  return (void*)str;
200 }
201 
202 static void set_hasbit(void *closure, int32_t hasbit) {
203  if (hasbit > 0) {
204  uint8_t* storage = closure;
205  storage[hasbit/8] |= 1 << (hasbit % 8);
206  }
207 }
208 
209 // Appends a 'bytes' string to a repeated field.
210 static void* appendbytes_handler(void *closure,
211  const void *hd,
212  size_t size_hint) {
213  VALUE ary = (VALUE)closure;
214  VALUE str = rb_str_new2("");
215  rb_enc_associate(str, kRubyString8bitEncoding);
217  return (void*)str;
218 }
219 
220 // Sets a non-repeated string field in a message.
221 static void* str_handler(void *closure,
222  const void *hd,
223  size_t size_hint) {
224  MessageHeader* msg = closure;
225  const field_handlerdata_t *fieldhandler = hd;
226 
227  VALUE str = rb_str_new2("");
228  rb_enc_associate(str, kRubyStringUtf8Encoding);
229  DEREF(msg, fieldhandler->ofs, VALUE) = str;
230  set_hasbit(closure, fieldhandler->hasbit);
231  return (void*)str;
232 }
233 
234 // Sets a non-repeated 'bytes' field in a message.
235 static void* bytes_handler(void *closure,
236  const void *hd,
237  size_t size_hint) {
238  MessageHeader* msg = closure;
239  const field_handlerdata_t *fieldhandler = hd;
240 
241  VALUE str = rb_str_new2("");
242  rb_enc_associate(str, kRubyString8bitEncoding);
243  DEREF(msg, fieldhandler->ofs, VALUE) = str;
244  set_hasbit(closure, fieldhandler->hasbit);
245  return (void*)str;
246 }
247 
248 static size_t stringdata_handler(void* closure, const void* hd,
249  const char* str, size_t len,
250  const upb_bufhandle* handle) {
251  VALUE rb_str = (VALUE)closure;
252  noleak_rb_str_cat(rb_str, str, len);
253  return len;
254 }
255 
256 static bool stringdata_end_handler(void* closure, const void* hd) {
257  VALUE rb_str = closure;
258  rb_obj_freeze(rb_str);
259  return true;
260 }
261 
262 static bool appendstring_end_handler(void* closure, const void* hd) {
263  VALUE rb_str = closure;
264  rb_obj_freeze(rb_str);
265  return true;
266 }
267 
268 // Appends a submessage to a repeated field (a regular Ruby array for now).
269 static void *appendsubmsg_handler(void *closure, const void *hd) {
270  VALUE ary = (VALUE)closure;
271  const submsg_handlerdata_t *submsgdata = hd;
272  VALUE subdesc =
273  get_def_obj((void*)submsgdata->md);
274  VALUE subklass = Descriptor_msgclass(subdesc);
275  MessageHeader* submsg;
276 
277  VALUE submsg_rb = rb_class_new_instance(0, NULL, subklass);
278  RepeatedField_push(ary, submsg_rb);
279 
280  TypedData_Get_Struct(submsg_rb, MessageHeader, &Message_type, submsg);
281  return submsg;
282 }
283 
284 // Sets a non-repeated submessage field in a message.
285 static void *submsg_handler(void *closure, const void *hd) {
286  MessageHeader* msg = closure;
287  const submsg_handlerdata_t* submsgdata = hd;
288  VALUE subdesc =
289  get_def_obj((void*)submsgdata->md);
290  VALUE subklass = Descriptor_msgclass(subdesc);
291  VALUE submsg_rb;
292  MessageHeader* submsg;
293 
294  if (DEREF(msg, submsgdata->ofs, VALUE) == Qnil) {
295  DEREF(msg, submsgdata->ofs, VALUE) =
296  rb_class_new_instance(0, NULL, subklass);
297  }
298 
299  set_hasbit(closure, submsgdata->hasbit);
300 
301  submsg_rb = DEREF(msg, submsgdata->ofs, VALUE);
302  TypedData_Get_Struct(submsg_rb, MessageHeader, &Message_type, submsg);
303 
304  return submsg;
305 }
306 
307 // Handler data for startmap/endmap handlers.
308 typedef struct {
309  size_t ofs;
310  upb_fieldtype_t key_field_type;
311  upb_fieldtype_t value_field_type;
312 
313  // We know that we can hold this reference because the handlerdata has the
314  // same lifetime as the upb_handlers struct, and the upb_handlers struct holds
315  // a reference to the upb_msgdef, which in turn has references to its subdefs.
318 
319 // Temporary frame for map parsing: at the beginning of a map entry message, a
320 // submsg handler allocates a frame to hold (i) a reference to the Map object
321 // into which this message will be inserted and (ii) storage slots to
322 // temporarily hold the key and value for this map entry until the end of the
323 // submessage. When the submessage ends, another handler is called to insert the
324 // value into the map.
325 typedef struct {
326  VALUE map;
328  char key_storage[NATIVE_SLOT_MAX_SIZE];
329  char value_storage[NATIVE_SLOT_MAX_SIZE];
331 
332 static void MapParseFrame_mark(void* _self) {
333  map_parse_frame_t* frame = _self;
334 
335  // This shouldn't strictly be necessary since this should be rooted by the
336  // message itself, but it can't hurt.
337  rb_gc_mark(frame->map);
338 
341 }
342 
343 void MapParseFrame_free(void* self) {
344  xfree(self);
345 }
346 
347 rb_data_type_t MapParseFrame_type = {
348  "MapParseFrame",
350 };
351 
353  const map_handlerdata_t* handlerdata) {
355  frame->handlerdata = handlerdata;
356  frame->map = map;
357  native_slot_init(handlerdata->key_field_type, &frame->key_storage);
358  native_slot_init(handlerdata->value_field_type, &frame->value_storage);
359 
361  TypedData_Wrap_Struct(rb_cObject, &MapParseFrame_type, frame));
362 
363  return frame;
364 }
365 
366 // Handler to begin a map entry: allocates a temporary frame. This is the
367 // 'startsubmsg' handler on the msgdef that contains the map field.
368 static void *startmapentry_handler(void *closure, const void *hd) {
369  MessageHeader* msg = closure;
370  const map_handlerdata_t* mapdata = hd;
371  VALUE map_rb = DEREF(msg, mapdata->ofs, VALUE);
372 
373  return map_push_frame(map_rb, mapdata);
374 }
375 
376 // Handler to end a map entry: inserts the value defined during the message into
377 // the map. This is the 'endmsg' handler on the map entry msgdef.
378 static bool endmap_handler(void *closure, const void *hd, upb_status* s) {
379  map_parse_frame_t* frame = closure;
380  const map_handlerdata_t* mapdata = hd;
381 
382  VALUE key = native_slot_get(
383  mapdata->key_field_type, Qnil,
384  &frame->key_storage);
385 
386  VALUE value_field_typeclass = Qnil;
387  VALUE value;
388 
389  if (mapdata->value_field_type == UPB_TYPE_MESSAGE ||
390  mapdata->value_field_type == UPB_TYPE_ENUM) {
391  value_field_typeclass = get_def_obj(mapdata->value_field_subdef);
392  if (mapdata->value_field_type == UPB_TYPE_ENUM) {
393  value_field_typeclass = EnumDescriptor_enummodule(value_field_typeclass);
394  }
395  }
396 
398  mapdata->value_field_type, value_field_typeclass,
399  &frame->value_storage);
400 
401  Map_index_set(frame->map, key, value);
402  Map_set_frame(frame->map, Qnil);
403 
404  return true;
405 }
406 
407 // Allocates a new map_handlerdata_t given the map entry message definition. If
408 // the offset of the field within the parent message is also given, that is
409 // added to the handler data as well. Note that this is called *twice* per map
410 // field: once in the parent message handler setup when setting the startsubmsg
411 // handler and once in the map entry message handler setup when setting the
412 // key/value and endmsg handlers. The reason is that there is no easy way to
413 // pass the handlerdata down to the sub-message handler setup.
415  size_t ofs,
416  const upb_msgdef* mapentry_def,
417  Descriptor* desc) {
418  const upb_fielddef* key_field;
419  const upb_fielddef* value_field;
421  hd->ofs = ofs;
422  key_field = upb_msgdef_itof(mapentry_def, MAP_KEY_FIELD);
423  assert(key_field != NULL);
424  hd->key_field_type = upb_fielddef_type(key_field);
425  value_field = upb_msgdef_itof(mapentry_def, MAP_VALUE_FIELD);
426  assert(value_field != NULL);
427  hd->value_field_type = upb_fielddef_type(value_field);
428  hd->value_field_subdef = upb_fielddef_subdef(value_field);
429 
430  return hd;
431 }
432 
433 // Handlers that set primitive values in oneofs.
434 #define DEFINE_ONEOF_HANDLER(type, ctype) \
435  static bool oneof##type##_handler(void *closure, const void *hd, \
436  ctype val) { \
437  const oneof_handlerdata_t *oneofdata = hd; \
438  DEREF(closure, oneofdata->case_ofs, uint32_t) = \
439  oneofdata->oneof_case_num; \
440  DEREF(closure, oneofdata->ofs, ctype) = val; \
441  return true; \
442  }
443 
444 DEFINE_ONEOF_HANDLER(bool, bool)
445 DEFINE_ONEOF_HANDLER(int32, int32_t)
446 DEFINE_ONEOF_HANDLER(uint32, uint32_t)
447 DEFINE_ONEOF_HANDLER(float, float)
448 DEFINE_ONEOF_HANDLER(int64, int64_t)
449 DEFINE_ONEOF_HANDLER(uint64, uint64_t)
450 DEFINE_ONEOF_HANDLER(double, double)
451 
452 #undef DEFINE_ONEOF_HANDLER
453 
454 // Handlers for strings in a oneof.
455 static void *oneofstr_handler(void *closure,
456  const void *hd,
457  size_t size_hint) {
458  MessageHeader* msg = closure;
459  const oneof_handlerdata_t *oneofdata = hd;
460  VALUE str = rb_str_new2("");
461  rb_enc_associate(str, kRubyStringUtf8Encoding);
462  DEREF(msg, oneofdata->case_ofs, uint32_t) =
463  oneofdata->oneof_case_num;
464  DEREF(msg, oneofdata->ofs, VALUE) = str;
465  return (void*)str;
466 }
467 
468 static void *oneofbytes_handler(void *closure,
469  const void *hd,
470  size_t size_hint) {
471  MessageHeader* msg = closure;
472  const oneof_handlerdata_t *oneofdata = hd;
473  VALUE str = rb_str_new2("");
474  rb_enc_associate(str, kRubyString8bitEncoding);
475  DEREF(msg, oneofdata->case_ofs, uint32_t) =
476  oneofdata->oneof_case_num;
477  DEREF(msg, oneofdata->ofs, VALUE) = str;
478  return (void*)str;
479 }
480 
481 static bool oneofstring_end_handler(void* closure, const void* hd) {
482  VALUE rb_str = rb_str_new2("");
483  rb_obj_freeze(rb_str);
484  return true;
485 }
486 
487 // Handler for a submessage field in a oneof.
488 static void *oneofsubmsg_handler(void *closure,
489  const void *hd) {
490  MessageHeader* msg = closure;
491  const oneof_handlerdata_t *oneofdata = hd;
492  uint32_t oldcase = DEREF(msg, oneofdata->case_ofs, uint32_t);
493 
494  VALUE subdesc =
495  get_def_obj((void*)oneofdata->md);
496  VALUE subklass = Descriptor_msgclass(subdesc);
497  VALUE submsg_rb;
498  MessageHeader* submsg;
499 
500  if (oldcase != oneofdata->oneof_case_num ||
501  DEREF(msg, oneofdata->ofs, VALUE) == Qnil) {
502  DEREF(msg, oneofdata->ofs, VALUE) =
503  rb_class_new_instance(0, NULL, subklass);
504  }
505  // Set the oneof case *after* allocating the new class instance -- otherwise,
506  // if the Ruby GC is invoked as part of a call into the VM, it might invoke
507  // our mark routines, and our mark routines might see the case value
508  // indicating a VALUE is present and expect a valid VALUE. See comment in
509  // layout_set() for more detail: basically, the change to the value and the
510  // case must be atomic w.r.t. the Ruby VM.
511  DEREF(msg, oneofdata->case_ofs, uint32_t) =
512  oneofdata->oneof_case_num;
513 
514  submsg_rb = DEREF(msg, oneofdata->ofs, VALUE);
515  TypedData_Get_Struct(submsg_rb, MessageHeader, &Message_type, submsg);
516  return submsg;
517 }
518 
519 // Set up handlers for a repeated field.
521  const upb_fielddef *f,
522  size_t offset) {
526  upb_handlerattr_uninit(&attr);
527 
528  switch (upb_fielddef_type(f)) {
529 
530 #define SET_HANDLER(utype, ltype) \
531  case utype: \
532  upb_handlers_set##ltype(h, f, append##ltype##_handler, NULL); \
533  break;
534 
535  SET_HANDLER(UPB_TYPE_BOOL, bool);
539  SET_HANDLER(UPB_TYPE_FLOAT, float);
542  SET_HANDLER(UPB_TYPE_DOUBLE, double);
543 
544 #undef SET_HANDLER
545 
546  case UPB_TYPE_STRING:
547  case UPB_TYPE_BYTES: {
548  bool is_bytes = upb_fielddef_type(f) == UPB_TYPE_BYTES;
549  upb_handlers_setstartstr(h, f, is_bytes ?
551  NULL);
554  break;
555  }
556  case UPB_TYPE_MESSAGE: {
560  upb_handlerattr_uninit(&attr);
561  break;
562  }
563  }
564 }
565 
566 // Set up handlers for a singular field.
568  const upb_fielddef *f,
569  size_t offset,
570  size_t hasbit_off) {
571  // The offset we pass to UPB points to the start of the Message,
572  // rather than the start of where our data is stored.
573  int32_t hasbit = -1;
574  if (hasbit_off != MESSAGE_FIELD_NO_HASBIT) {
575  hasbit = hasbit_off + sizeof(MessageHeader) * 8;
576  }
577 
578  switch (upb_fielddef_type(f)) {
579  case UPB_TYPE_BOOL:
580  case UPB_TYPE_INT32:
581  case UPB_TYPE_UINT32:
582  case UPB_TYPE_ENUM:
583  case UPB_TYPE_FLOAT:
584  case UPB_TYPE_INT64:
585  case UPB_TYPE_UINT64:
586  case UPB_TYPE_DOUBLE:
587  upb_msg_setscalarhandler(h, f, offset, hasbit);
588  break;
589  case UPB_TYPE_STRING:
590  case UPB_TYPE_BYTES: {
591  bool is_bytes = upb_fielddef_type(f) == UPB_TYPE_BYTES;
595  is_bytes ? bytes_handler : str_handler,
596  &attr);
599  upb_handlerattr_uninit(&attr);
600  break;
601  }
602  case UPB_TYPE_MESSAGE: {
606  hasbit, f));
608  upb_handlerattr_uninit(&attr);
609  break;
610  }
611  }
612 }
613 
614 // Adds handlers to a map field.
616  const upb_fielddef* fielddef,
617  size_t offset,
618  Descriptor* desc) {
619  const upb_msgdef* map_msgdef = upb_fielddef_msgsubdef(fielddef);
620  map_handlerdata_t* hd = new_map_handlerdata(offset, map_msgdef, desc);
622 
623  upb_handlers_addcleanup(h, hd, xfree);
626  upb_handlerattr_uninit(&attr);
627 }
628 
629 // Adds handlers to a map-entry msgdef.
631  upb_handlers* h,
632  Descriptor* desc) {
633  const upb_fielddef* key_field = map_entry_key(msgdef);
634  const upb_fielddef* value_field = map_entry_value(msgdef);
637 
638  upb_handlers_addcleanup(h, hd, xfree);
641 
643  h, key_field,
644  offsetof(map_parse_frame_t, key_storage),
647  h, value_field,
648  offsetof(map_parse_frame_t, value_storage),
650 }
651 
652 // Set up handlers for a oneof field.
654  const upb_fielddef *f,
655  size_t offset,
656  size_t oneof_case_offset) {
657 
660  &attr, newoneofhandlerdata(h, offset, oneof_case_offset, f));
661 
662  switch (upb_fielddef_type(f)) {
663 
664 #define SET_HANDLER(utype, ltype) \
665  case utype: \
666  upb_handlers_set##ltype(h, f, oneof##ltype##_handler, &attr); \
667  break;
668 
669  SET_HANDLER(UPB_TYPE_BOOL, bool);
673  SET_HANDLER(UPB_TYPE_FLOAT, float);
676  SET_HANDLER(UPB_TYPE_DOUBLE, double);
677 
678 #undef SET_HANDLER
679 
680  case UPB_TYPE_STRING:
681  case UPB_TYPE_BYTES: {
682  bool is_bytes = upb_fielddef_type(f) == UPB_TYPE_BYTES;
683  upb_handlers_setstartstr(h, f, is_bytes ?
685  &attr);
688  break;
689  }
690  case UPB_TYPE_MESSAGE: {
692  break;
693  }
694  }
695 
696  upb_handlerattr_uninit(&attr);
697 }
698 
699 static bool unknown_field_handler(void* closure, const void* hd,
700  const char* buf, size_t size) {
701  UPB_UNUSED(hd);
702 
703  MessageHeader* msg = (MessageHeader*)closure;
704  if (msg->unknown_fields == NULL) {
705  msg->unknown_fields = malloc(sizeof(stringsink));
707  }
708 
710 
711  return true;
712 }
713 
714 static void add_handlers_for_message(const void *closure, upb_handlers *h) {
718 
719  // If this is a mapentry message type, set up a special set of handlers and
720  // bail out of the normal (user-defined) message type handling.
723  return;
724  }
725 
726  // Ensure layout exists. We may be invoked to create handlers for a given
727  // message if we are included as a submsg of another message type before our
728  // class is actually built, so to work around this, we just create the layout
729  // (and handlers, in the class-building function) on-demand.
730  if (desc->layout == NULL) {
731  desc->layout = create_layout(desc->msgdef);
732  }
733 
736 
737  for (upb_msg_field_begin(&i, desc->msgdef);
739  upb_msg_field_next(&i)) {
740  const upb_fielddef *f = upb_msg_iter_field(&i);
741  size_t offset = desc->layout->fields[upb_fielddef_index(f)].offset +
742  sizeof(MessageHeader);
743 
745  size_t oneof_case_offset =
746  desc->layout->fields[upb_fielddef_index(f)].case_offset +
747  sizeof(MessageHeader);
748  add_handlers_for_oneof_field(h, f, offset, oneof_case_offset);
749  } else if (is_map_field(f)) {
751  } else if (upb_fielddef_isseq(f)) {
753  } else {
755  h, f, offset, desc->layout->fields[upb_fielddef_index(f)].hasbit);
756  }
757  }
758 }
759 
760 // Creates upb handlers for populating a message.
762  const void* owner) {
763  // TODO(cfallin, haberman): once upb gets a caching/memoization layer for
764  // handlers, reuse subdef handlers so that e.g. if we already parse
765  // B-with-field-of-type-C, we don't have to rebuild the whole hierarchy to
766  // parse A-with-field-of-type-B-with-field-of-type-C.
767  return upb_handlers_newfrozen(desc->msgdef, owner,
769 }
770 
771 // Constructs the handlers for filling a message's data into an in-memory
772 // object.
774  if (!desc->fill_handlers) {
775  desc->fill_handlers =
776  new_fill_handlers(desc, &desc->fill_handlers);
777  }
778  return desc->fill_handlers;
779 }
780 
781 // Constructs the upb decoder method for parsing messages of this type.
782 // This is called from the message class creation code.
784  const void* owner) {
785  const upb_handlers* handlers = get_fill_handlers(desc);
786  upb_pbdecodermethodopts opts;
787  upb_pbdecodermethodopts_init(&opts, handlers);
788 
789  return upb_pbdecodermethod_new(&opts, owner);
790 }
791 
793  if (desc->fill_method == NULL) {
794  desc->fill_method = new_fillmsg_decodermethod(
795  desc, &desc->fill_method);
796  }
797  return desc->fill_method;
798 }
799 
801  if (desc->json_fill_method == NULL) {
802  desc->json_fill_method =
803  upb_json_parsermethod_new(desc->msgdef, &desc->json_fill_method);
804  }
805  return desc->json_fill_method;
806 }
807 
808 
809 // Stack-allocated context during an encode/decode operation. Contains the upb
810 // environment and its stack-based allocator, an initial buffer for allocations
811 // to avoid malloc() when possible, and a template for Ruby exception messages
812 // if any error occurs.
813 #define STACK_ENV_STACKBYTES 4096
814 typedef struct {
816  const char* ruby_error_template;
817  char allocbuf[STACK_ENV_STACKBYTES];
818 } stackenv;
819 
820 static void stackenv_init(stackenv* se, const char* errmsg);
821 static void stackenv_uninit(stackenv* se);
822 
823 // Callback invoked by upb if any error occurs during parsing or serialization.
824 static bool env_error_func(void* ud, const upb_status* status) {
825  stackenv* se = ud;
826  // Free the env -- rb_raise will longjmp up the stack past the encode/decode
827  // function so it would not otherwise have been freed.
828  stackenv_uninit(se);
829 
830  // TODO(haberman): have a way to verify that this is actually a parse error,
831  // instead of just throwing "parse error" unconditionally.
832  rb_raise(cParseError, se->ruby_error_template, upb_status_errmsg(status));
833  // Never reached: rb_raise() always longjmp()s up the stack, past all of our
834  // code, back to Ruby.
835  return false;
836 }
837 
838 static void stackenv_init(stackenv* se, const char* errmsg) {
839  se->ruby_error_template = errmsg;
840  upb_env_init2(&se->env, se->allocbuf, sizeof(se->allocbuf), NULL);
842 }
843 
844 static void stackenv_uninit(stackenv* se) {
845  upb_env_uninit(&se->env);
846 }
847 
848 /*
849  * call-seq:
850  * MessageClass.decode(data) => message
851  *
852  * Decodes the given data (as a string containing bytes in protocol buffers wire
853  * format) under the interpretration given by this message class's definition
854  * and returns a message object with the corresponding field values.
855  */
856 VALUE Message_decode(VALUE klass, VALUE data) {
857  VALUE descriptor = rb_ivar_get(klass, descriptor_instancevar_interned);
859  VALUE msgklass = Descriptor_msgclass(descriptor);
860  VALUE msg_rb;
861  MessageHeader* msg;
862 
863  if (TYPE(data) != T_STRING) {
864  rb_raise(rb_eArgError, "Expected string for binary protobuf data.");
865  }
866 
867  msg_rb = rb_class_new_instance(0, NULL, msgklass);
868  TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg);
869 
870  {
873  stackenv se;
874  upb_sink sink;
876  stackenv_init(&se, "Error occurred during parsing: %s");
877 
878  upb_sink_reset(&sink, h, msg);
879  decoder = upb_pbdecoder_create(&se.env, method, &sink);
880  upb_bufsrc_putbuf(RSTRING_PTR(data), RSTRING_LEN(data),
882 
883  stackenv_uninit(&se);
884  }
885 
886  return msg_rb;
887 }
888 
889 /*
890  * call-seq:
891  * MessageClass.decode_json(data, options = {}) => message
892  *
893  * Decodes the given data (as a string containing bytes in protocol buffers wire
894  * format) under the interpretration given by this message class's definition
895  * and returns a message object with the corresponding field values.
896  *
897  * @param options [Hash] options for the decoder
898  * ignore_unknown_fields: set true to ignore unknown fields (default is to raise an error)
899  */
900 VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
901  VALUE descriptor = rb_ivar_get(klass, descriptor_instancevar_interned);
903  VALUE msgklass = Descriptor_msgclass(descriptor);
904  VALUE msg_rb;
905  VALUE data = argv[0];
906  VALUE ignore_unknown_fields = Qfalse;
907  MessageHeader* msg;
908 
909  if (argc < 1 || argc > 2) {
910  rb_raise(rb_eArgError, "Expected 1 or 2 arguments.");
911  }
912 
913  if (argc == 2) {
914  VALUE hash_args = argv[1];
915  if (TYPE(hash_args) != T_HASH) {
916  rb_raise(rb_eArgError, "Expected hash arguments.");
917  }
918 
919  ignore_unknown_fields = rb_hash_lookup2(
920  hash_args, ID2SYM(rb_intern("ignore_unknown_fields")), Qfalse);
921  }
922 
923  if (TYPE(data) != T_STRING) {
924  rb_raise(rb_eArgError, "Expected string for JSON data.");
925  }
926  // TODO(cfallin): Check and respect string encoding. If not UTF-8, we need to
927  // convert, because string handlers pass data directly to message string
928  // fields.
929 
930  msg_rb = rb_class_new_instance(0, NULL, msgklass);
931  TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg);
932 
933  {
935  stackenv se;
936  upb_sink sink;
939  stackenv_init(&se, "Error occurred during parsing: %s");
940 
941  upb_sink_reset(&sink, get_fill_handlers(desc), msg);
942  parser = upb_json_parser_create(&se.env, method, pool->symtab,
943  &sink, ignore_unknown_fields);
944  upb_bufsrc_putbuf(RSTRING_PTR(data), RSTRING_LEN(data),
946 
947  stackenv_uninit(&se);
948  }
949 
950  return msg_rb;
951 }
952 
953 // -----------------------------------------------------------------------------
954 // Serializing.
955 // -----------------------------------------------------------------------------
956 
957 /* msgvisitor *****************************************************************/
958 
959 static void putmsg(VALUE msg, const Descriptor* desc,
960  upb_sink *sink, int depth, bool emit_defaults,
961  bool is_json, bool open_msg);
962 
964  upb_selector_t ret;
965  bool ok = upb_handlers_getselector(f, type, &ret);
966  UPB_ASSERT(ok);
967  return ret;
968 }
969 
970 static void putstr(VALUE str, const upb_fielddef *f, upb_sink *sink) {
971  upb_sink subsink;
972 
973  if (str == Qnil) return;
974 
975  assert(BUILTIN_TYPE(str) == RUBY_T_STRING);
976 
977  // We should be guaranteed that the string has the correct encoding because
978  // we ensured this at assignment time and then froze the string.
980  assert(rb_enc_from_index(ENCODING_GET(str)) == kRubyStringUtf8Encoding);
981  } else {
982  assert(rb_enc_from_index(ENCODING_GET(str)) == kRubyString8bitEncoding);
983  }
984 
985  upb_sink_startstr(sink, getsel(f, UPB_HANDLER_STARTSTR), RSTRING_LEN(str),
986  &subsink);
987  upb_sink_putstring(&subsink, getsel(f, UPB_HANDLER_STRING), RSTRING_PTR(str),
988  RSTRING_LEN(str), NULL);
990 }
991 
992 static void putsubmsg(VALUE submsg, const upb_fielddef *f, upb_sink *sink,
993  int depth, bool emit_defaults, bool is_json) {
994  upb_sink subsink;
995  VALUE descriptor;
996  Descriptor* subdesc;
997 
998  if (submsg == Qnil) return;
999 
1000  descriptor = rb_ivar_get(submsg, descriptor_instancevar_interned);
1001  subdesc = ruby_to_Descriptor(descriptor);
1002 
1004  putmsg(submsg, subdesc, &subsink, depth + 1, emit_defaults, is_json, true);
1006 }
1007 
1008 static void putary(VALUE ary, const upb_fielddef *f, upb_sink *sink,
1009  int depth, bool emit_defaults, bool is_json) {
1010  upb_sink subsink;
1012  upb_selector_t sel = 0;
1013  int size;
1014 
1015  if (ary == Qnil) return;
1016  if (!emit_defaults && NUM2INT(RepeatedField_length(ary)) == 0) return;
1017 
1018  size = NUM2INT(RepeatedField_length(ary));
1019  if (size == 0 && !emit_defaults) return;
1020 
1021  upb_sink_startseq(sink, getsel(f, UPB_HANDLER_STARTSEQ), &subsink);
1022 
1023  if (upb_fielddef_isprimitive(f)) {
1025  }
1026 
1027  for (int i = 0; i < size; i++) {
1028  void* memory = RepeatedField_index_native(ary, i);
1029  switch (type) {
1030 #define T(upbtypeconst, upbtype, ctype) \
1031  case upbtypeconst: \
1032  upb_sink_put##upbtype(&subsink, sel, *((ctype *)memory)); \
1033  break;
1034 
1035  T(UPB_TYPE_FLOAT, float, float)
1036  T(UPB_TYPE_DOUBLE, double, double)
1037  T(UPB_TYPE_BOOL, bool, int8_t)
1038  case UPB_TYPE_ENUM:
1039  T(UPB_TYPE_INT32, int32, int32_t)
1040  T(UPB_TYPE_UINT32, uint32, uint32_t)
1041  T(UPB_TYPE_INT64, int64, int64_t)
1042  T(UPB_TYPE_UINT64, uint64, uint64_t)
1043 
1044  case UPB_TYPE_STRING:
1045  case UPB_TYPE_BYTES:
1046  putstr(*((VALUE *)memory), f, &subsink);
1047  break;
1048  case UPB_TYPE_MESSAGE:
1049  putsubmsg(*((VALUE *)memory), f, &subsink, depth,
1050  emit_defaults, is_json);
1051  break;
1052 
1053 #undef T
1054 
1055  }
1056  }
1058 }
1059 
1060 static void put_ruby_value(VALUE value,
1061  const upb_fielddef *f,
1062  VALUE type_class,
1063  int depth,
1064  upb_sink *sink,
1065  bool emit_defaults,
1066  bool is_json) {
1067  if (depth > ENCODE_MAX_NESTING) {
1068  rb_raise(rb_eRuntimeError,
1069  "Maximum recursion depth exceeded during encoding.");
1070  }
1071 
1072  upb_selector_t sel = 0;
1073  if (upb_fielddef_isprimitive(f)) {
1075  }
1076 
1077  switch (upb_fielddef_type(f)) {
1078  case UPB_TYPE_INT32:
1079  upb_sink_putint32(sink, sel, NUM2INT(value));
1080  break;
1081  case UPB_TYPE_INT64:
1082  upb_sink_putint64(sink, sel, NUM2LL(value));
1083  break;
1084  case UPB_TYPE_UINT32:
1085  upb_sink_putuint32(sink, sel, NUM2UINT(value));
1086  break;
1087  case UPB_TYPE_UINT64:
1088  upb_sink_putuint64(sink, sel, NUM2ULL(value));
1089  break;
1090  case UPB_TYPE_FLOAT:
1091  upb_sink_putfloat(sink, sel, NUM2DBL(value));
1092  break;
1093  case UPB_TYPE_DOUBLE:
1094  upb_sink_putdouble(sink, sel, NUM2DBL(value));
1095  break;
1096  case UPB_TYPE_ENUM: {
1097  if (TYPE(value) == T_SYMBOL) {
1098  value = rb_funcall(type_class, rb_intern("resolve"), 1, value);
1099  }
1100  upb_sink_putint32(sink, sel, NUM2INT(value));
1101  break;
1102  }
1103  case UPB_TYPE_BOOL:
1104  upb_sink_putbool(sink, sel, value == Qtrue);
1105  break;
1106  case UPB_TYPE_STRING:
1107  case UPB_TYPE_BYTES:
1108  putstr(value, f, sink);
1109  break;
1110  case UPB_TYPE_MESSAGE:
1111  putsubmsg(value, f, sink, depth, emit_defaults, is_json);
1112  }
1113 }
1114 
1115 static void putmap(VALUE map, const upb_fielddef *f, upb_sink *sink,
1116  int depth, bool emit_defaults, bool is_json) {
1117  Map* self;
1118  upb_sink subsink;
1119  const upb_fielddef* key_field;
1120  const upb_fielddef* value_field;
1121  Map_iter it;
1122 
1123  if (map == Qnil) return;
1124  if (!emit_defaults && Map_length(map) == 0) return;
1125 
1126  self = ruby_to_Map(map);
1127 
1128  upb_sink_startseq(sink, getsel(f, UPB_HANDLER_STARTSEQ), &subsink);
1129 
1130  assert(upb_fielddef_type(f) == UPB_TYPE_MESSAGE);
1131  key_field = map_field_key(f);
1132  value_field = map_field_value(f);
1133 
1134  for (Map_begin(map, &it); !Map_done(&it); Map_next(&it)) {
1135  VALUE key = Map_iter_key(&it);
1136  VALUE value = Map_iter_value(&it);
1137  upb_status status;
1138 
1139  upb_sink entry_sink;
1141  &entry_sink);
1142  upb_sink_startmsg(&entry_sink);
1143 
1144  put_ruby_value(key, key_field, Qnil, depth + 1, &entry_sink,
1145  emit_defaults, is_json);
1146  put_ruby_value(value, value_field, self->value_type_class, depth + 1,
1147  &entry_sink, emit_defaults, is_json);
1148 
1149  upb_sink_endmsg(&entry_sink, &status);
1151  }
1152 
1154 }
1155 
1157  Descriptor* desc, bool preserve_proto_fieldnames);
1158 
1159 static void putjsonany(VALUE msg_rb, const Descriptor* desc,
1160  upb_sink* sink, int depth, bool emit_defaults) {
1161  upb_status status;
1162  MessageHeader* msg = NULL;
1163  const upb_fielddef* type_field = upb_msgdef_itof(desc->msgdef, UPB_ANY_TYPE);
1164  const upb_fielddef* value_field = upb_msgdef_itof(desc->msgdef, UPB_ANY_VALUE);
1165 
1166  size_t type_url_offset;
1167  VALUE type_url_str_rb;
1168  const upb_msgdef *payload_type = NULL;
1169 
1170  TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg);
1171 
1172  upb_sink_startmsg(sink);
1173 
1174  /* Handle type url */
1175  type_url_offset = desc->layout->fields[upb_fielddef_index(type_field)].offset;
1176  type_url_str_rb = DEREF(Message_data(msg), type_url_offset, VALUE);
1177  if (RSTRING_LEN(type_url_str_rb) > 0) {
1178  putstr(type_url_str_rb, type_field, sink);
1179  }
1180 
1181  {
1182  const char* type_url_str = RSTRING_PTR(type_url_str_rb);
1183  size_t type_url_len = RSTRING_LEN(type_url_str_rb);
1185 
1186  if (type_url_len <= 20 ||
1187  strncmp(type_url_str, "type.googleapis.com/", 20) != 0) {
1188  rb_raise(rb_eRuntimeError, "Invalid type url: %s", type_url_str);
1189  return;
1190  }
1191 
1192  /* Resolve type url */
1193  type_url_str += 20;
1194  type_url_len -= 20;
1195 
1196  payload_type = upb_symtab_lookupmsg2(
1197  pool->symtab, type_url_str, type_url_len);
1198  if (payload_type == NULL) {
1199  rb_raise(rb_eRuntimeError, "Unknown type: %s", type_url_str);
1200  return;
1201  }
1202  }
1203 
1204  {
1205  uint32_t value_offset;
1206  VALUE value_str_rb;
1207  const char* value_str;
1208  size_t value_len;
1209 
1210  value_offset = desc->layout->fields[upb_fielddef_index(value_field)].offset;
1211  value_str_rb = DEREF(Message_data(msg), value_offset, VALUE);
1212  value_str = RSTRING_PTR(value_str_rb);
1213  value_len = RSTRING_LEN(value_str_rb);
1214 
1215  if (value_len > 0) {
1216  VALUE payload_desc_rb = get_def_obj(payload_type);
1217  Descriptor* payload_desc = ruby_to_Descriptor(payload_desc_rb);
1218  VALUE payload_class = Descriptor_msgclass(payload_desc_rb);
1219  upb_sink subsink;
1220  bool is_wellknown;
1221 
1222  VALUE payload_msg_rb = Message_decode(payload_class, value_str_rb);
1223 
1224  is_wellknown =
1225  upb_msgdef_wellknowntype(payload_desc->msgdef) !=
1227  if (is_wellknown) {
1228  upb_sink_startstr(sink, getsel(value_field, UPB_HANDLER_STARTSTR), 0,
1229  &subsink);
1230  }
1231 
1232  subsink.handlers =
1233  msgdef_json_serialize_handlers(payload_desc, true);
1234  subsink.closure = sink->closure;
1235  putmsg(payload_msg_rb, payload_desc, &subsink, depth, emit_defaults, true,
1236  is_wellknown);
1237  }
1238  }
1239 
1240  upb_sink_endmsg(sink, &status);
1241 }
1242 
1243 static void putjsonlistvalue(
1244  VALUE msg_rb, const Descriptor* desc,
1245  upb_sink* sink, int depth, bool emit_defaults) {
1246  upb_status status;
1247  upb_sink subsink;
1248  MessageHeader* msg = NULL;
1249  const upb_fielddef* f = upb_msgdef_itof(desc->msgdef, 1);
1250  uint32_t offset =
1251  desc->layout->fields[upb_fielddef_index(f)].offset +
1252  sizeof(MessageHeader);
1253  VALUE ary;
1254 
1255  TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg);
1256 
1257  upb_sink_startmsg(sink);
1258 
1259  ary = DEREF(msg, offset, VALUE);
1260 
1261  if (ary == Qnil || RepeatedField_size(ary) == 0) {
1262  upb_sink_startseq(sink, getsel(f, UPB_HANDLER_STARTSEQ), &subsink);
1264  } else {
1265  putary(ary, f, sink, depth, emit_defaults, true);
1266  }
1267 
1268  upb_sink_endmsg(sink, &status);
1269 }
1270 
1271 static void putmsg(VALUE msg_rb, const Descriptor* desc,
1272  upb_sink *sink, int depth, bool emit_defaults,
1273  bool is_json, bool open_msg) {
1274  MessageHeader* msg;
1276  upb_status status;
1277 
1278  if (is_json &&
1280  putjsonany(msg_rb, desc, sink, depth, emit_defaults);
1281  return;
1282  }
1283 
1284  if (is_json &&
1286  putjsonlistvalue(msg_rb, desc, sink, depth, emit_defaults);
1287  return;
1288  }
1289 
1290  if (open_msg) {
1291  upb_sink_startmsg(sink);
1292  }
1293 
1294  // Protect against cycles (possible because users may freely reassign message
1295  // and repeated fields) by imposing a maximum recursion depth.
1296  if (depth > ENCODE_MAX_NESTING) {
1297  rb_raise(rb_eRuntimeError,
1298  "Maximum recursion depth exceeded during encoding.");
1299  }
1300 
1301  TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg);
1302 
1303  if (desc != msg->descriptor) {
1304  rb_raise(rb_eArgError,
1305  "The type of given msg is '%s', expect '%s'.",
1307  upb_msgdef_fullname(desc->msgdef));
1308  }
1309 
1310  for (upb_msg_field_begin(&i, desc->msgdef);
1311  !upb_msg_field_done(&i);
1312  upb_msg_field_next(&i)) {
1314  bool is_matching_oneof = false;
1315  uint32_t offset =
1316  desc->layout->fields[upb_fielddef_index(f)].offset +
1317  sizeof(MessageHeader);
1318 
1320  uint32_t oneof_case_offset =
1321  desc->layout->fields[upb_fielddef_index(f)].case_offset +
1322  sizeof(MessageHeader);
1323  // For a oneof, check that this field is actually present -- skip all the
1324  // below if not.
1325  if (DEREF(msg, oneof_case_offset, uint32_t) !=
1327  continue;
1328  }
1329  // Otherwise, fall through to the appropriate singular-field handler
1330  // below.
1331  is_matching_oneof = true;
1332  }
1333 
1334  if (is_map_field(f)) {
1335  VALUE map = DEREF(msg, offset, VALUE);
1336  if (map != Qnil || emit_defaults) {
1337  putmap(map, f, sink, depth, emit_defaults, is_json);
1338  }
1339  } else if (upb_fielddef_isseq(f)) {
1340  VALUE ary = DEREF(msg, offset, VALUE);
1341  if (ary != Qnil) {
1342  putary(ary, f, sink, depth, emit_defaults, is_json);
1343  }
1344  } else if (upb_fielddef_isstring(f)) {
1345  VALUE str = DEREF(msg, offset, VALUE);
1346  bool is_default = false;
1347 
1348  if (upb_msgdef_syntax(desc->msgdef) == UPB_SYNTAX_PROTO2) {
1349  is_default = layout_has(desc->layout, Message_data(msg), f) == Qfalse;
1350  } else if (upb_msgdef_syntax(desc->msgdef) == UPB_SYNTAX_PROTO3) {
1351  is_default = RSTRING_LEN(str) == 0;
1352  }
1353 
1354  if (is_matching_oneof || emit_defaults || !is_default) {
1355  putstr(str, f, sink);
1356  }
1357  } else if (upb_fielddef_issubmsg(f)) {
1358  putsubmsg(DEREF(msg, offset, VALUE), f, sink, depth,
1359  emit_defaults, is_json);
1360  } else {
1362 
1363 #define T(upbtypeconst, upbtype, ctype, default_value) \
1364  case upbtypeconst: { \
1365  ctype value = DEREF(msg, offset, ctype); \
1366  bool is_default = false; \
1367  if (upb_fielddef_haspresence(f)) { \
1368  is_default = layout_has(desc->layout, Message_data(msg), f) == Qfalse; \
1369  } else if (upb_msgdef_syntax(desc->msgdef) == UPB_SYNTAX_PROTO3) { \
1370  is_default = default_value == value; \
1371  } \
1372  if (is_matching_oneof || emit_defaults || !is_default) { \
1373  upb_sink_put##upbtype(sink, sel, value); \
1374  } \
1375  } \
1376  break;
1377 
1378  switch (upb_fielddef_type(f)) {
1379  T(UPB_TYPE_FLOAT, float, float, 0.0)
1380  T(UPB_TYPE_DOUBLE, double, double, 0.0)
1381  T(UPB_TYPE_BOOL, bool, uint8_t, 0)
1382  case UPB_TYPE_ENUM:
1383  T(UPB_TYPE_INT32, int32, int32_t, 0)
1384  T(UPB_TYPE_UINT32, uint32, uint32_t, 0)
1385  T(UPB_TYPE_INT64, int64, int64_t, 0)
1386  T(UPB_TYPE_UINT64, uint64, uint64_t, 0)
1387 
1388  case UPB_TYPE_STRING:
1389  case UPB_TYPE_BYTES:
1390  case UPB_TYPE_MESSAGE: rb_raise(rb_eRuntimeError, "Internal error.");
1391  }
1392 
1393 #undef T
1394 
1395  }
1396  }
1397 
1398  stringsink* unknown = msg->unknown_fields;
1399  if (unknown != NULL) {
1400  upb_sink_putunknown(sink, unknown->ptr, unknown->len);
1401  }
1402 
1403  if (open_msg) {
1404  upb_sink_endmsg(sink, &status);
1405  }
1406 }
1407 
1409  if (desc->pb_serialize_handlers == NULL) {
1410  desc->pb_serialize_handlers =
1411  upb_pb_encoder_newhandlers(desc->msgdef, &desc->pb_serialize_handlers);
1412  }
1413  return desc->pb_serialize_handlers;
1414 }
1415 
1417  Descriptor* desc, bool preserve_proto_fieldnames) {
1418  if (preserve_proto_fieldnames) {
1419  if (desc->json_serialize_handlers == NULL) {
1420  desc->json_serialize_handlers =
1422  desc->msgdef, true, &desc->json_serialize_handlers);
1423  }
1424  return desc->json_serialize_handlers;
1425  } else {
1426  if (desc->json_serialize_handlers_preserve == NULL) {
1427  desc->json_serialize_handlers_preserve =
1429  desc->msgdef, false, &desc->json_serialize_handlers_preserve);
1430  }
1431  return desc->json_serialize_handlers_preserve;
1432  }
1433 }
1434 
1435 /*
1436  * call-seq:
1437  * MessageClass.encode(msg) => bytes
1438  *
1439  * Encodes the given message object to its serialized form in protocol buffers
1440  * wire format.
1441  */
1442 VALUE Message_encode(VALUE klass, VALUE msg_rb) {
1443  VALUE descriptor = rb_ivar_get(klass, descriptor_instancevar_interned);
1445 
1446  stringsink sink;
1447  stringsink_init(&sink);
1448 
1449  {
1450  const upb_handlers* serialize_handlers =
1452 
1453  stackenv se;
1455  VALUE ret;
1456 
1457  stackenv_init(&se, "Error occurred during encoding: %s");
1458  encoder = upb_pb_encoder_create(&se.env, serialize_handlers, &sink.sink);
1459 
1460  putmsg(msg_rb, desc, upb_pb_encoder_input(encoder), 0, false, false, true);
1461 
1462  ret = rb_str_new(sink.ptr, sink.len);
1463 
1464  stackenv_uninit(&se);
1465  stringsink_uninit(&sink);
1466 
1467  return ret;
1468  }
1469 }
1470 
1471 /*
1472  * call-seq:
1473  * MessageClass.encode_json(msg, options = {}) => json_string
1474  *
1475  * Encodes the given message object into its serialized JSON representation.
1476  * @param options [Hash] options for the decoder
1477  * preserve_proto_fieldnames: set true to use original fieldnames (default is to camelCase)
1478  * emit_defaults: set true to emit 0/false values (default is to omit them)
1479  */
1480 VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
1481  VALUE descriptor = rb_ivar_get(klass, descriptor_instancevar_interned);
1483  VALUE msg_rb;
1484  VALUE preserve_proto_fieldnames = Qfalse;
1485  VALUE emit_defaults = Qfalse;
1486  stringsink sink;
1487 
1488  if (argc < 1 || argc > 2) {
1489  rb_raise(rb_eArgError, "Expected 1 or 2 arguments.");
1490  }
1491 
1492  msg_rb = argv[0];
1493 
1494  if (argc == 2) {
1495  VALUE hash_args = argv[1];
1496  if (TYPE(hash_args) != T_HASH) {
1497  rb_raise(rb_eArgError, "Expected hash arguments.");
1498  }
1499  preserve_proto_fieldnames = rb_hash_lookup2(
1500  hash_args, ID2SYM(rb_intern("preserve_proto_fieldnames")), Qfalse);
1501 
1502  emit_defaults = rb_hash_lookup2(
1503  hash_args, ID2SYM(rb_intern("emit_defaults")), Qfalse);
1504  }
1505 
1506  stringsink_init(&sink);
1507 
1508  {
1509  const upb_handlers* serialize_handlers =
1510  msgdef_json_serialize_handlers(desc, RTEST(preserve_proto_fieldnames));
1511  upb_json_printer* printer;
1512  stackenv se;
1513  VALUE ret;
1514 
1515  stackenv_init(&se, "Error occurred during encoding: %s");
1516  printer = upb_json_printer_create(&se.env, serialize_handlers, &sink.sink);
1517 
1518  putmsg(msg_rb, desc, upb_json_printer_input(printer), 0,
1519  RTEST(emit_defaults), true, true);
1520 
1521  ret = rb_enc_str_new(sink.ptr, sink.len, rb_utf8_encoding());
1522 
1523  stackenv_uninit(&se);
1524  stringsink_uninit(&sink);
1525 
1526  return ret;
1527  }
1528 }
1529 
1530 static void discard_unknown(VALUE msg_rb, const Descriptor* desc) {
1531  MessageHeader* msg;
1533 
1534  TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg);
1535 
1536  stringsink* unknown = msg->unknown_fields;
1537  if (unknown != NULL) {
1538  stringsink_uninit(unknown);
1539  msg->unknown_fields = NULL;
1540  }
1541 
1542  for (upb_msg_field_begin(&it, desc->msgdef);
1544  upb_msg_field_next(&it)) {
1546  uint32_t offset =
1547  desc->layout->fields[upb_fielddef_index(f)].offset +
1548  sizeof(MessageHeader);
1549 
1551  uint32_t oneof_case_offset =
1552  desc->layout->fields[upb_fielddef_index(f)].case_offset +
1553  sizeof(MessageHeader);
1554  // For a oneof, check that this field is actually present -- skip all the
1555  // below if not.
1556  if (DEREF(msg, oneof_case_offset, uint32_t) !=
1558  continue;
1559  }
1560  // Otherwise, fall through to the appropriate singular-field handler
1561  // below.
1562  }
1563 
1564  if (!upb_fielddef_issubmsg(f)) {
1565  continue;
1566  }
1567 
1568  if (is_map_field(f)) {
1569  if (!upb_fielddef_issubmsg(map_field_value(f))) continue;
1570  VALUE map = DEREF(msg, offset, VALUE);
1571  if (map == Qnil) continue;
1572  Map_iter map_it;
1573  for (Map_begin(map, &map_it); !Map_done(&map_it); Map_next(&map_it)) {
1574  VALUE submsg = Map_iter_value(&map_it);
1575  VALUE descriptor = rb_ivar_get(submsg, descriptor_instancevar_interned);
1576  const Descriptor* subdesc = ruby_to_Descriptor(descriptor);
1577  discard_unknown(submsg, subdesc);
1578  }
1579  } else if (upb_fielddef_isseq(f)) {
1580  VALUE ary = DEREF(msg, offset, VALUE);
1581  if (ary == Qnil) continue;
1582  int size = NUM2INT(RepeatedField_length(ary));
1583  for (int i = 0; i < size; i++) {
1584  void* memory = RepeatedField_index_native(ary, i);
1585  VALUE submsg = *((VALUE *)memory);
1586  VALUE descriptor = rb_ivar_get(submsg, descriptor_instancevar_interned);
1587  const Descriptor* subdesc = ruby_to_Descriptor(descriptor);
1588  discard_unknown(submsg, subdesc);
1589  }
1590  } else {
1591  VALUE submsg = DEREF(msg, offset, VALUE);
1592  if (submsg == Qnil) continue;
1593  VALUE descriptor = rb_ivar_get(submsg, descriptor_instancevar_interned);
1594  const Descriptor* subdesc = ruby_to_Descriptor(descriptor);
1595  discard_unknown(submsg, subdesc);
1596  }
1597  }
1598 }
1599 
1600 /*
1601  * call-seq:
1602  * Google::Protobuf.discard_unknown(msg)
1603  *
1604  * Discard unknown fields in the given message object and recursively discard
1605  * unknown fields in submessages.
1606  */
1607 VALUE Google_Protobuf_discard_unknown(VALUE self, VALUE msg_rb) {
1608  VALUE klass = CLASS_OF(msg_rb);
1609  VALUE descriptor = rb_ivar_get(klass, descriptor_instancevar_interned);
1611  if (klass == cRepeatedField || klass == cMap) {
1612  rb_raise(rb_eArgError, "Expected proto msg for discard unknown.");
1613  } else {
1614  discard_unknown(msg_rb, desc);
1615  }
1616  return Qnil;
1617 }
RepeatedField_push_native
void RepeatedField_push_native(VALUE _self, void *data)
Definition: repeated_field.c:234
STACK_ENV_STACKBYTES
#define STACK_ENV_STACKBYTES
Definition: ruby/ext/google/protobuf_c/encode_decode.c:813
upb_pbdecoder_input
upb_bytessink upb_pbdecoder_input(upb_pbdecoder *d)
Definition: php/ext/google/protobuf/upb.c:7762
upb_pb_encoder_input
upb_sink upb_pb_encoder_input(upb_pb_encoder *e)
Definition: php/ext/google/protobuf/upb.c:8368
oneof_handlerdata_t::md
const upb_msgdef * md
Definition: php/ext/google/protobuf/encode_decode.c:183
msgdef
const upb_msgdef * msgdef
Definition: php/ext/google/protobuf/protobuf.h:799
UPB_SYNTAX_PROTO2
@ UPB_SYNTAX_PROTO2
Definition: php/ext/google/protobuf/upb.h:3140
appendstr_handler
static void * appendstr_handler(void *closure, const void *hd, size_t size_hint)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:192
ruby_to_DescriptorPool
DescriptorPool * ruby_to_DescriptorPool(VALUE value)
upb_selector_t
int32_t upb_selector_t
Definition: php/ext/google/protobuf/upb.h:4062
map_parse_frame_t::key_storage
char key_storage[NATIVE_SLOT_MAX_SIZE]
Definition: ruby/ext/google/protobuf_c/encode_decode.c:328
UPB_UNUSED
#define UPB_UNUSED(var)
Definition: php/ext/google/protobuf/upb.h:141
upb_handlers_getselector
bool upb_handlers_getselector(const upb_fielddef *f, upb_handlertype_t type, upb_selector_t *s)
Definition: php/ext/google/protobuf/upb.c:3563
UPB_HANDLER_ENDSEQ
@ UPB_HANDLER_ENDSEQ
Definition: php/ext/google/protobuf/upb.h:4049
cMap
VALUE cMap
Definition: ruby/ext/google/protobuf_c/map.c:137
env_error_func
static bool env_error_func(void *ud, const upb_status *status)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:824
upb_handlers_setunknown
bool upb_handlers_setunknown(upb_handlers *h, upb_unknown_handlerfunc *func, const upb_handlerattr *attr)
Definition: php/ext/google/protobuf/upb.c:3484
UPB_HANDLER_STARTSUBMSG
@ UPB_HANDLER_STARTSUBMSG
Definition: php/ext/google/protobuf/upb.h:4046
newsubmsghandlerdata
static const void * newsubmsghandlerdata(upb_handlers *h, uint32_t ofs, int32_t hasbit, const upb_fielddef *f)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:124
upb_pb_encoder_newhandlers
const upb_handlers * upb_pb_encoder_newhandlers(const upb_msgdef *m, const void *owner)
Definition: ruby/ext/google/protobuf_c/upb.c:12098
discard_unknown
static void discard_unknown(VALUE msg_rb, const Descriptor *desc)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:1530
benchmarks.python.py_benchmark.const
const
Definition: py_benchmark.py:14
Map
Definition: ruby/ext/google/protobuf_c/protobuf.h:442
cRepeatedField
VALUE cRepeatedField
Definition: repeated_field.c:42
upb_json_parsermethod
Definition: php/ext/google/protobuf/upb.c:9068
upb_status
Definition: php/ext/google/protobuf/upb.h:170
upb_msgdef_mapentry
bool upb_msgdef_mapentry(const upb_msgdef *m)
Definition: php/ext/google/protobuf/upb.c:1809
endmap_handler
static bool endmap_handler(void *closure, const void *hd, upb_status *s)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:378
upb_pb_encoder_create
upb_pb_encoder * upb_pb_encoder_create(upb_arena *arena, const upb_handlers *h, upb_bytessink output)
Definition: php/ext/google/protobuf/upb.c:8329
map_handlerdata_t::value_field_type
upb_fieldtype_t value_field_type
Definition: php/ext/google/protobuf/encode_decode.c:456
MessageHeader::unknown_fields
stringsink * unknown_fields
Definition: ruby/ext/google/protobuf_c/protobuf.h:553
putmsg
static void putmsg(VALUE msg, const Descriptor *desc, upb_sink *sink, int depth, bool emit_defaults, bool is_json, bool open_msg)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:1271
upb_json_printer
Definition: php/ext/google/protobuf/upb.c:12238
NULL
NULL
Definition: test_security_zap.cpp:405
Message_decode
VALUE Message_decode(VALUE klass, VALUE data)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:856
fielddef
const upb_fielddef * fielddef
Definition: php/ext/google/protobuf/protobuf.h:816
google::protobuf::int64
int64_t int64
Definition: protobuf/src/google/protobuf/stubs/port.h:151
field_handlerdata_t::hasbit
int32_t hasbit
Definition: ruby/ext/google/protobuf_c/encode_decode.c:105
upb_json_parser_input
upb_bytessink upb_json_parser_input(upb_json_parser *p)
Definition: php/ext/google/protobuf/upb.c:12164
MessageHeader::descriptor
Descriptor * descriptor
Definition: ruby/ext/google/protobuf_c/protobuf.h:552
native_slot_init
void native_slot_init(upb_fieldtype_t type, void *memory, CACHED_VALUE *cache)
Definition: php/ext/google/protobuf/storage.c:276
upb_pbdecoder
Definition: php/ext/google/protobuf/upb.h:6600
MessageHeader
Definition: ruby/ext/google/protobuf_c/protobuf.h:551
upb_msg_field_begin
void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m)
Definition: php/ext/google/protobuf/upb.c:1823
stringsink::size
size_t size
Definition: php/ext/google/protobuf/protobuf.h:1464
msgdef_jsonparsermethod
static const upb_json_parsermethod * msgdef_jsonparsermethod(Descriptor *desc)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:800
upb_env_init2
void upb_env_init2(upb_env *e, void *mem, size_t n, upb_alloc *alloc)
Definition: ruby/ext/google/protobuf_c/upb.c:7619
stringsink_start
static void * stringsink_start(void *_sink, const void *hd, size_t size_hint)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:52
upb_pbdecodermethodopts_init
void upb_pbdecodermethodopts_init(upb_pbdecodermethodopts *opts, const upb_handlers *h)
Definition: ruby/ext/google/protobuf_c/upb.c:10485
upb_json_parser_create
upb_json_parser * upb_json_parser_create(upb_arena *arena, const upb_json_parsermethod *method, const upb_symtab *symtab, upb_sink output, upb_status *status, bool ignore_json_unknown)
Definition: php/ext/google/protobuf/upb.c:12122
upb_handlers_setstartseq
bool upb_handlers_setstartseq(upb_handlers *h, const upb_fielddef *f, upb_startfield_handlerfunc *func, const upb_handlerattr *attr)
UPB_TYPE_INT32
@ UPB_TYPE_INT32
Definition: php/ext/google/protobuf/upb.h:415
Map_iter
Definition: ruby/ext/google/protobuf_c/protobuf.h:480
descriptor_instancevar_interned
ID descriptor_instancevar_interned
Definition: ruby/ext/google/protobuf_c/protobuf.c:78
unknown_field_handler
static bool unknown_field_handler(void *closure, const void *hd, const char *buf, size_t size)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:699
upb_fielddef_issubmsg
bool upb_fielddef_issubmsg(const upb_fielddef *f)
Definition: php/ext/google/protobuf/upb.c:1687
putsubmsg
static void putsubmsg(VALUE submsg, const upb_fielddef *f, upb_sink *sink, int depth, bool emit_defaults, bool is_json)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:992
self
PHP_PROTO_OBJECT_FREE_END PHP_PROTO_OBJECT_DTOR_END intern self
Definition: php/ext/google/protobuf/map.c:543
upb_handlers_setendstr
bool upb_handlers_setendstr(upb_handlers *h, const upb_fielddef *f, upb_endfield_handlerfunc *func, const upb_handlerattr *attr)
EnumDescriptor_enummodule
VALUE EnumDescriptor_enummodule(VALUE _self)
Definition: defs.c:1460
protobuf.h
upb_symtab_lookupmsg2
const upb_msgdef * upb_symtab_lookupmsg2(const upb_symtab *s, const char *sym, size_t len)
Definition: php/ext/google/protobuf/upb.c:2771
upb_json_printer_create
upb_json_printer * upb_json_printer_create(upb_arena *a, const upb_handlers *h, upb_bytessink output)
Definition: php/ext/google/protobuf/upb.c:13596
google::protobuf::uint32
uint32_t uint32
Definition: protobuf/src/google/protobuf/stubs/port.h:155
stringsink::sink
upb_bytessink sink
Definition: php/ext/google/protobuf/protobuf.h:1462
RepeatedField_push
VALUE RepeatedField_push(VALUE _self, VALUE val)
Definition: repeated_field.c:212
upb_handlerattr_uninit
void upb_handlerattr_uninit(upb_handlerattr *attr)
Definition: ruby/ext/google/protobuf_c/upb.c:4537
DEFINE_APPEND_HANDLER
#define DEFINE_APPEND_HANDLER(type, ctype)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:175
is_map_field
bool is_map_field(const upb_fielddef *field)
Definition: php/ext/google/protobuf/storage.c:526
desc
#define desc
Definition: extension_set.h:342
map_handlerdata_t::value_field_subdef
const upb_def * value_field_subdef
Definition: ruby/ext/google/protobuf_c/encode_decode.c:316
Map_done
bool Map_done(Map_iter *iter)
Definition: ruby/ext/google/protobuf_c/map.c:812
UPB_ASSERT
#define UPB_ASSERT(expr)
Definition: php/ext/google/protobuf/upb.h:146
map_entry_key
const upb_fielddef * map_entry_key(const upb_msgdef *msgdef)
Definition: php/ext/google/protobuf/storage.c:540
upb_fielddef_subdef
const upb_def * upb_fielddef_subdef(const upb_fielddef *f)
Definition: ruby/ext/google/protobuf_c/upb.c:2081
startseq_handler
static void * startseq_handler(void *closure, const void *hd)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:168
ruby_to_Descriptor
Descriptor * ruby_to_Descriptor(VALUE value)
upb_sink_putstring
UPB_INLINE size_t upb_sink_putstring(upb_sink s, upb_selector_t sel, const char *buf, size_t n, const upb_bufhandle *handle)
Definition: php/ext/google/protobuf/upb.h:5704
Message_data
void * Message_data(void *msg)
Definition: ruby/ext/google/protobuf_c/message.c:37
encoder
static char encoder[85+1]
Definition: zmq_utils.cpp:72
RepeatedField_length
VALUE RepeatedField_length(VALUE _self)
Definition: repeated_field.c:314
str_handler
static void * str_handler(void *closure, const void *hd, size_t size_hint)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:221
upb_fielddef_isprimitive
bool upb_fielddef_isprimitive(const upb_fielddef *f)
Definition: php/ext/google/protobuf/upb.c:1700
Message_type
rb_data_type_t Message_type
Definition: ruby/ext/google/protobuf_c/message.c:55
DEREF
#define DEREF(msg, ofs, type)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:101
descriptor
Descriptor * descriptor
Definition: php/ext/google/protobuf/protobuf.h:936
UPB_TYPE_FLOAT
@ UPB_TYPE_FLOAT
Definition: php/ext/google/protobuf/upb.h:414
DEFINE_ONEOF_HANDLER
#define DEFINE_ONEOF_HANDLER(type, ctype)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:434
map
zval * map
Definition: php/ext/google/protobuf/encode_decode.c:473
upb_env_uninit
void upb_env_uninit(upb_env *e)
Definition: ruby/ext/google/protobuf_c/upb.c:7624
upb_handlers_getprimitivehandlertype
upb_handlertype_t upb_handlers_getprimitivehandlertype(const upb_fielddef *f)
Definition: php/ext/google/protobuf/upb.c:3549
map_field_value
const upb_fielddef * map_field_value(const upb_fielddef *field)
Definition: php/ext/google/protobuf/storage.c:535
MapParseFrame_type
rb_data_type_t MapParseFrame_type
Definition: ruby/ext/google/protobuf_c/encode_decode.c:347
UPB_ANY_VALUE
#define UPB_ANY_VALUE
Definition: php/ext/google/protobuf/upb.h:3482
upb_sink::handlers
const upb_handlers * handlers
Definition: php/ext/google/protobuf/upb.h:5674
stringdata_end_handler
static bool stringdata_end_handler(void *closure, const void *hd)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:256
map_parse_frame_t
Definition: ruby/ext/google/protobuf_c/encode_decode.c:325
Descriptor
Definition: ruby/ext/google/protobuf_c/protobuf.h:113
upb_handlers_msgdef
const upb_msgdef * upb_handlers_msgdef(const upb_handlers *h)
Definition: php/ext/google/protobuf/upb.c:3543
get_fill_handlers
const upb_handlers * get_fill_handlers(Descriptor *desc)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:773
upb_json_printer_newhandlers
const upb_handlers * upb_json_printer_newhandlers(const upb_msgdef *md, bool preserve_fieldnames, const void *owner)
Definition: ruby/ext/google/protobuf_c/upb.c:17487
ruby_to_Map
Map * ruby_to_Map(VALUE _self)
Definition: ruby/ext/google/protobuf_c/map.c:139
upb_fielddef_isstring
bool upb_fielddef_isstring(const upb_fielddef *f)
Definition: php/ext/google/protobuf/upb.c:1691
UPB_WELLKNOWN_ANY
@ UPB_WELLKNOWN_ANY
Definition: php/ext/google/protobuf/upb.h:3150
ok
ROSCPP_DECL bool ok()
ALLOC
#define ALLOC(class_name)
Definition: php/ext/google/protobuf/protobuf.h:1477
upb_handlers_setstartstr
bool upb_handlers_setstartstr(upb_handlers *h, const upb_fielddef *f, upb_startstr_handlerfunc *func, const upb_handlerattr *attr)
upb_sink_startstr
UPB_INLINE bool upb_sink_startstr(upb_sink s, upb_selector_t sel, size_t size_hint, upb_sink *sub)
Definition: php/ext/google/protobuf/upb.h:5779
upb_env_seterrorfunc
void upb_env_seterrorfunc(upb_env *e, upb_error_func *func, void *ud)
Definition: ruby/ext/google/protobuf_c/upb.c:7628
upb_fielddef_isseq
bool upb_fielddef_isseq(const upb_fielddef *f)
Definition: php/ext/google/protobuf/upb.c:1696
UPB_HANDLERATTR_INITIALIZER
#define UPB_HANDLERATTR_INITIALIZER
Definition: ruby/ext/google/protobuf_c/upb.h:4261
startmapentry_handler
static void * startmapentry_handler(void *closure, const void *hd)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:368
bytes_handler
static void * bytes_handler(void *closure, const void *hd, size_t size_hint)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:235
upb_env
Definition: ruby/ext/google/protobuf_c/upb.h:798
UPB_TYPE_UINT32
@ UPB_TYPE_UINT32
Definition: php/ext/google/protobuf/upb.h:416
add_handlers_for_mapentry
static void add_handlers_for_mapentry(const upb_msgdef *msgdef, upb_handlers *h, Descriptor *desc)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:630
stackenv_uninit
static void stackenv_uninit(stackenv *se)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:844
oneof_handlerdata_t
Definition: php/ext/google/protobuf/encode_decode.c:178
google::protobuf::int32
int32_t int32
Definition: protobuf/src/google/protobuf/stubs/port.h:150
field_handlerdata_t
Definition: ruby/ext/google/protobuf_c/encode_decode.c:103
cParseError
VALUE cParseError
Definition: ruby/ext/google/protobuf_c/protobuf.c:43
UPB_SYNTAX_PROTO3
@ UPB_SYNTAX_PROTO3
Definition: php/ext/google/protobuf/upb.h:3141
getsel
static upb_selector_t getsel(const upb_fielddef *f, upb_handlertype_t type)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:963
MapParseFrame_mark
static void MapParseFrame_mark(void *_self)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:332
new_fill_handlers
static const upb_handlers * new_fill_handlers(Descriptor *desc, const void *owner)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:761
upb_bufhandle
Definition: php/ext/google/protobuf/upb.h:4095
upb_sink_putunknown
UPB_INLINE bool upb_sink_putunknown(upb_sink s, const char *buf, size_t n)
Definition: php/ext/google/protobuf/upb.h:5717
upb_sink_endseq
UPB_INLINE bool upb_sink_endseq(upb_sink s, upb_selector_t sel)
Definition: php/ext/google/protobuf/upb.h:5768
stringdata_handler
static size_t stringdata_handler(void *closure, const void *hd, const char *str, size_t len, const upb_bufhandle *handle)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:248
map_handlerdata_t::key_field_type
upb_fieldtype_t key_field_type
Definition: php/ext/google/protobuf/encode_decode.c:455
upb_sink_startmsg
UPB_INLINE bool upb_sink_startmsg(upb_sink s)
Definition: php/ext/google/protobuf/upb.h:5729
upb_inttable_iter
Definition: php/ext/google/protobuf/upb.h:3088
offset
GLintptr offset
Definition: glcorearb.h:2944
UPB_HANDLER_ENDSTR
@ UPB_HANDLER_ENDSTR
Definition: php/ext/google/protobuf/upb.h:4045
Map_next
void Map_next(Map_iter *iter)
Definition: ruby/ext/google/protobuf_c/map.c:808
submsg_handlerdata_t::hasbit
int32_t hasbit
Definition: ruby/ext/google/protobuf_c/encode_decode.c:119
generated_pool
InternalDescriptorPool * generated_pool
Definition: def.c:582
oneofstr_handler
static void * oneofstr_handler(void *closure, const void *hd, size_t size_hint)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:455
stringsink::len
size_t len
Definition: php/ext/google/protobuf/protobuf.h:1464
msgdef_pb_serialize_handlers
static const upb_handlers * msgdef_pb_serialize_handlers(Descriptor *desc)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:1408
Descriptor::msgdef
const upb_msgdef * msgdef
Definition: ruby/ext/google/protobuf_c/protobuf.h:114
upb_byteshandler_setstartstr
bool upb_byteshandler_setstartstr(upb_byteshandler *h, upb_startstr_handlerfunc *func, void *d)
Definition: php/ext/google/protobuf/upb.c:3727
kRubyStringUtf8Encoding
rb_encoding * kRubyStringUtf8Encoding
Definition: ruby/ext/google/protobuf_c/protobuf.c:67
MESSAGE_FIELD_NO_HASBIT
#define MESSAGE_FIELD_NO_HASBIT
Definition: ruby/ext/google/protobuf_c/protobuf.h:496
native_slot_mark
void native_slot_mark(upb_fieldtype_t type, void *memory)
Definition: ruby/ext/google/protobuf_c/storage.c:346
Google_Protobuf_discard_unknown
VALUE Google_Protobuf_discard_unknown(VALUE self, VALUE msg_rb)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:1607
newoneofhandlerdata
static const void * newoneofhandlerdata(upb_handlers *h, uint32_t ofs, uint32_t case_ofs, const upb_fielddef *f)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:143
update_failure_list.str
str
Definition: update_failure_list.py:41
upb_fielddef_containingoneof
const upb_oneofdef * upb_fielddef_containingoneof(const upb_fielddef *f)
Definition: php/ext/google/protobuf/upb.c:1619
new_fillmsg_decodermethod
const upb_pbdecodermethod * new_fillmsg_decodermethod(Descriptor *desc, const void *owner)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:783
msgdef_json_serialize_handlers
static const upb_handlers * msgdef_json_serialize_handlers(Descriptor *desc, bool preserve_proto_fieldnames)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:1416
set_hasbit
static void set_hasbit(void *closure, int32_t hasbit)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:202
T
#define T(upbtypeconst, upbtype, ctype)
map_entry_value
const upb_fielddef * map_entry_value(const upb_msgdef *msgdef)
Definition: php/ext/google/protobuf/storage.c:546
p
const char * p
Definition: gmock-matchers_test.cc:3863
putary
static void putary(VALUE ary, const upb_fielddef *f, upb_sink *sink, int depth, bool emit_defaults, bool is_json)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:1008
UPB_WELLKNOWN_UNSPECIFIED
@ UPB_WELLKNOWN_UNSPECIFIED
Definition: php/ext/google/protobuf/upb.h:3149
upb_byteshandler_init
UPB_INLINE void upb_byteshandler_init(upb_byteshandler *handler)
Definition: php/ext/google/protobuf/upb.h:4659
UPB_TYPE_DOUBLE
@ UPB_TYPE_DOUBLE
Definition: php/ext/google/protobuf/upb.h:423
UPB_TYPE_STRING
@ UPB_TYPE_STRING
Definition: php/ext/google/protobuf/upb.h:419
UPB_HANDLER_STARTSEQ
@ UPB_HANDLER_STARTSEQ
Definition: php/ext/google/protobuf/upb.h:4048
upb_sink_startseq
UPB_INLINE bool upb_sink_startseq(upb_sink s, upb_selector_t sel, upb_sink *sub)
Definition: php/ext/google/protobuf/upb.h:5753
google::protobuf::uint64
uint64_t uint64
Definition: protobuf/src/google/protobuf/stubs/port.h:156
map_parse_frame_t::value_storage
char value_storage[NATIVE_SLOT_MAX_SIZE]
Definition: ruby/ext/google/protobuf_c/encode_decode.c:329
size
#define size
Definition: glcorearb.h:2944
oneof_handlerdata_t::oneof_case_num
uint32_t oneof_case_num
Definition: php/ext/google/protobuf/encode_decode.c:182
stackenv
Definition: php/ext/google/protobuf/encode_decode.c:91
upb_fielddef
Definition: php/ext/google/protobuf/upb.c:1118
submsg_handler
static void * submsg_handler(void *closure, const void *hd)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:285
layout_has
VALUE layout_has(MessageLayout *layout, const void *storage, const upb_fielddef *field)
Definition: ruby/ext/google/protobuf_c/storage.c:640
add_handlers_for_oneof_field
static void add_handlers_for_oneof_field(upb_handlers *h, const upb_fielddef *f, size_t offset, size_t oneof_case_offset)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:653
kRubyString8bitEncoding
rb_encoding * kRubyString8bitEncoding
Definition: ruby/ext/google/protobuf_c/protobuf.c:69
upb_pb_encoder
Definition: php/ext/google/protobuf/upb.c:7892
native_slot_get
void native_slot_get(upb_fieldtype_t type, const void *memory, CACHED_VALUE *cache TSRMLS_DC)
Definition: php/ext/google/protobuf/storage.c:311
map_handlerdata_t::ofs
size_t ofs
Definition: php/ext/google/protobuf/encode_decode.c:454
Message_encode_json
VALUE Message_encode_json(int argc, VALUE *argv, VALUE klass)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:1480
UPB_TYPE_MESSAGE
@ UPB_TYPE_MESSAGE
Definition: php/ext/google/protobuf/upb.h:421
Map_begin
void Map_begin(VALUE _self, Map_iter *iter)
Definition: ruby/ext/google/protobuf_c/map.c:802
UPB_ANY_TYPE
#define UPB_ANY_TYPE
Definition: php/ext/google/protobuf/upb.h:3481
upb_handlerattr_sethandlerdata
bool upb_handlerattr_sethandlerdata(upb_handlerattr *attr, const void *hd)
Definition: ruby/ext/google/protobuf_c/upb.c:4541
buf
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:4175
UPB_TYPE_ENUM
@ UPB_TYPE_ENUM
Definition: php/ext/google/protobuf/upb.h:417
key
const SETUP_TEARDOWN_TESTCONTEXT char * key
Definition: test_wss_transport.cpp:10
depth
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glcorearb.h:2859
put_ruby_value
static void put_ruby_value(VALUE value, const upb_fielddef *f, VALUE type_class, int depth, upb_sink *sink, bool emit_defaults, bool is_json)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:1060
stringsink::ptr
char * ptr
Definition: php/ext/google/protobuf/protobuf.h:1463
Map_length
VALUE Map_length(VALUE _self)
Definition: ruby/ext/google/protobuf_c/map.c:487
map_parse_frame_t
typedefPHP_PROTO_WRAP_OBJECT_END struct map_parse_frame_t map_parse_frame_t
Definition: php/ext/google/protobuf/encode_decode.c:479
MapParseFrame_free
void MapParseFrame_free(void *self)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:343
upb_sink_endstr
UPB_INLINE bool upb_sink_endstr(upb_sink s, upb_selector_t sel)
Definition: php/ext/google/protobuf/upb.h:5794
pool
InternalDescriptorPool * pool
Definition: php/ext/google/protobuf/protobuf.h:798
decoder
static uint8_t decoder[96]
Definition: zmq_utils.cpp:85
UPB_TYPE_UINT64
@ UPB_TYPE_UINT64
Definition: php/ext/google/protobuf/upb.h:425
upb_sink_endsubmsg
UPB_INLINE bool upb_sink_endsubmsg(upb_sink s, upb_selector_t sel)
Definition: php/ext/google/protobuf/upb.h:5823
upb_handlers_addcleanup
bool upb_handlers_addcleanup(upb_handlers *h, void *p, upb_handlerfree *func)
Definition: php/ext/google/protobuf/upb.c:3545
Message_encode
VALUE Message_encode(VALUE klass, VALUE msg_rb)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:1442
i
int i
Definition: gmock-matchers_test.cc:764
stringsink_init
void stringsink_init(stringsink *sink)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:81
upb_sink_reset
UPB_INLINE void upb_sink_reset(upb_sink *s, const upb_handlers *h, void *c)
Definition: php/ext/google/protobuf/upb.h:5699
upb_json_parser
Definition: php/ext/google/protobuf/upb.c:9009
upb_msg_iter_field
upb_fielddef * upb_msg_iter_field(const upb_msg_field_iter *iter)
Definition: php/ext/google/protobuf/upb.c:1833
upb_fielddef_type
upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f)
Definition: php/ext/google/protobuf/upb.c:1505
putstr
static void putstr(VALUE str, const upb_fielddef *f, upb_sink *sink)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:970
add_handlers_for_message
static void add_handlers_for_message(const void *closure, upb_handlers *h)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:714
upb_sink
Definition: php/ext/google/protobuf/upb.h:5673
UPB_HANDLER_STRING
@ UPB_HANDLER_STRING
Definition: php/ext/google/protobuf/upb.h:4044
upb_msgdef_wellknowntype
upb_wellknowntype_t upb_msgdef_wellknowntype(const upb_msgdef *m)
Definition: php/ext/google/protobuf/upb.c:1813
map_field_key
const upb_fielddef * map_field_key(const upb_fielddef *field)
Definition: php/ext/google/protobuf/storage.c:530
upb_handlers_setstartsubmsg
bool upb_handlers_setstartsubmsg(upb_handlers *h, const upb_fielddef *f, upb_startfield_handlerfunc *func, const upb_handlerattr *attr)
map_push_frame
static map_parse_frame_t * map_push_frame(VALUE map, const map_handlerdata_t *handlerdata)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:352
oneofstring_end_handler
static bool oneofstring_end_handler(void *closure, const void *hd)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:481
type
GLenum type
Definition: glcorearb.h:2695
add_handlers_for_repeated_field
static void add_handlers_for_repeated_field(upb_handlers *h, const upb_fielddef *f, size_t offset)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:520
map_parse_frame_t::handlerdata
const map_handlerdata_t * handlerdata
Definition: ruby/ext/google/protobuf_c/encode_decode.c:327
upb_pbdecoder_create
upb_pbdecoder * upb_pbdecoder_create(upb_arena *a, const upb_pbdecodermethod *m, upb_sink sink, upb_status *status)
Definition: php/ext/google/protobuf/upb.c:7717
MessageHeader
struct MessageHeader MessageHeader
Definition: php/ext/google/protobuf/protobuf.h:650
upb_pbdecodermethod_new
const upb_pbdecodermethod * upb_pbdecodermethod_new(const upb_pbdecodermethodopts *opts, const void *owner)
Definition: ruby/ext/google/protobuf_c/upb.c:9616
len
int len
Definition: php/ext/google/protobuf/map.c:206
upb_fielddef_msgsubdef
const upb_msgdef * upb_fielddef_msgsubdef(const upb_fielddef *f)
Definition: php/ext/google/protobuf/upb.c:1677
create_layout
PHP_PROTO_WRAP_OBJECT_END MessageLayout * create_layout(const upb_msgdef *msgdef)
Definition: php/ext/google/protobuf/storage.c:591
upb_json_parsermethod_new
upb_json_parsermethod * upb_json_parsermethod_new(const upb_msgdef *md, const void *owner)
Definition: ruby/ext/google/protobuf_c/upb.c:16065
stringsink_uninit
void stringsink_uninit(stringsink *sink)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:93
upb_msg_field_next
void upb_msg_field_next(upb_msg_field_iter *iter)
Definition: php/ext/google/protobuf/upb.c:1827
Map_index_set
VALUE Map_index_set(VALUE _self, VALUE key, VALUE value)
Definition: ruby/ext/google/protobuf_c/map.c:388
upb_msg_setscalarhandler
bool upb_msg_setscalarhandler(upb_handlers *h, const upb_fielddef *f, size_t offset, int32_t hasbit)
Definition: php/ext/google/protobuf/upb.c:3774
upb_bytessink_reset
UPB_INLINE void upb_bytessink_reset(upb_bytessink *s, const upb_byteshandler *h, void *closure)
Definition: php/ext/google/protobuf/upb.h:6036
upb_sink_startsubmsg
UPB_INLINE bool upb_sink_startsubmsg(upb_sink s, upb_selector_t sel, upb_sink *sub)
Definition: php/ext/google/protobuf/upb.h:5805
UPB_WELLKNOWN_LISTVALUE
@ UPB_WELLKNOWN_LISTVALUE
Definition: php/ext/google/protobuf/upb.h:3166
get_def_obj
PHP_PROTO_HASHTABLE_VALUE get_def_obj(const void *def)
Definition: php/ext/google/protobuf/protobuf.c:112
Map_set_frame
VALUE Map_set_frame(VALUE map, VALUE val)
Definition: ruby/ext/google/protobuf_c/map.c:178
upb_handlers_newfrozen
const upb_handlers * upb_handlers_newfrozen(const upb_msgdef *m, const void *owner, upb_handlers_callback *callback, const void *closure)
Definition: ruby/ext/google/protobuf_c/upb.c:4222
add_handlers_for_mapfield
static void add_handlers_for_mapfield(upb_handlers *h, const upb_fielddef *fielddef, size_t offset, Descriptor *desc)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:615
Descriptor_msgclass
VALUE Descriptor_msgclass(VALUE _self)
Definition: defs.c:493
NATIVE_SLOT_MAX_SIZE
#define NATIVE_SLOT_MAX_SIZE
Definition: php/ext/google/protobuf/protobuf.h:1021
size
GLsizeiptr size
Definition: glcorearb.h:2943
map_handlerdata_t
Definition: php/ext/google/protobuf/encode_decode.c:453
stackenv::ruby_error_template
const char * ruby_error_template
Definition: ruby/ext/google/protobuf_c/encode_decode.c:816
oneofbytes_handler
static void * oneofbytes_handler(void *closure, const void *hd, size_t size_hint)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:468
upb_byteshandler_setstring
bool upb_byteshandler_setstring(upb_byteshandler *h, upb_string_handlerfunc *func, void *d)
Definition: php/ext/google/protobuf/upb.c:3734
upb_msg_field_done
bool upb_msg_field_done(const upb_msg_field_iter *iter)
Definition: php/ext/google/protobuf/upb.c:1829
stringsink::handler
upb_byteshandler handler
Definition: php/ext/google/protobuf/protobuf.h:1461
oneof_handlerdata_t::case_ofs
size_t case_ofs
Definition: php/ext/google/protobuf/encode_decode.c:180
putjsonlistvalue
static void putjsonlistvalue(VALUE msg_rb, const Descriptor *desc, upb_sink *sink, int depth, bool emit_defaults)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:1243
upb_msgdef_itof
const upb_fielddef * upb_msgdef_itof(const upb_msgdef *m, uint32_t i)
Definition: php/ext/google/protobuf/upb.c:1757
appendbytes_handler
static void * appendbytes_handler(void *closure, const void *hd, size_t size_hint)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:210
submsg_handlerdata_t::md
const upb_msgdef * md
Definition: php/ext/google/protobuf/encode_decode.c:164
msgdef_decodermethod
static const upb_pbdecodermethod * msgdef_decodermethod(Descriptor *desc)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:792
ENCODE_MAX_NESTING
#define ENCODE_MAX_NESTING
Definition: php/ext/google/protobuf/protobuf.h:969
RepeatedField_index_native
void * RepeatedField_index_native(VALUE _self, int index)
Definition: repeated_field.c:246
appendstring_end_handler
static bool appendstring_end_handler(void *closure, const void *hd)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:262
newhandlerdata
static const void * newhandlerdata(upb_handlers *h, uint32_t ofs, int32_t hasbit)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:109
UPB_TYPE_BYTES
@ UPB_TYPE_BYTES
Definition: php/ext/google/protobuf/upb.h:420
UPB_HANDLER_ENDSUBMSG
@ UPB_HANDLER_ENDSUBMSG
Definition: php/ext/google/protobuf/upb.h:4047
Message_decode_json
VALUE Message_decode_json(int argc, VALUE *argv, VALUE klass)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:900
upb_fielddef_number
uint32_t upb_fielddef_number(const upb_fielddef *f)
Definition: php/ext/google/protobuf/upb.c:1552
new_map_handlerdata
static map_handlerdata_t * new_map_handlerdata(size_t ofs, const upb_msgdef *mapentry_def, Descriptor *desc)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:414
stackenv::env
upb_env env
Definition: ruby/ext/google/protobuf_c/encode_decode.c:815
TYPE
#define TYPE(u, l)
Definition: php/ext/google/protobuf/upb.c:8510
UPB_TYPE_INT64
@ UPB_TYPE_INT64
Definition: php/ext/google/protobuf/upb.h:424
upb_handlerattr
Definition: php/ext/google/protobuf/upb.h:4085
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: glcorearb.h:2879
upb_def
Definition: ruby/ext/google/protobuf_c/upb.h:1844
upb_pbdecodermethod_desthandlers
const upb_handlers * upb_pbdecodermethod_desthandlers(const upb_pbdecodermethod *m)
Definition: php/ext/google/protobuf/upb.c:5839
upb_json_printer_input
upb_sink upb_json_printer_input(upb_json_printer *p)
Definition: php/ext/google/protobuf/upb.c:13617
oneofsubmsg_handler
static void * oneofsubmsg_handler(void *closure, const void *hd)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:488
submsg_handlerdata_t::ofs
size_t ofs
Definition: php/ext/google/protobuf/encode_decode.c:163
appendsubmsg_handler
static void * appendsubmsg_handler(void *closure, const void *hd)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:269
upb_status_errmsg
const char * upb_status_errmsg(const upb_status *status)
Definition: php/ext/google/protobuf/upb.c:5575
noleak_rb_str_cat
VALUE noleak_rb_str_cat(VALUE rb_str, const char *str, long len)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:37
f
GLfloat f
Definition: glcorearb.h:3964
Map_iter_value
VALUE Map_iter_value(Map_iter *iter)
Definition: ruby/ext/google/protobuf_c/map.c:823
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
MAP_KEY_FIELD
#define MAP_KEY_FIELD
Definition: php/ext/google/protobuf/protobuf.h:1093
upb_sink::closure
void * closure
Definition: php/ext/google/protobuf/upb.h:5675
UPB_HANDLER_STARTSTR
@ UPB_HANDLER_STARTSTR
Definition: php/ext/google/protobuf/upb.h:4043
stackenv::allocbuf
char allocbuf[STACK_ENV_STACKBYTES]
Definition: php/ext/google/protobuf/encode_decode.c:95
add_handlers_for_singular_field
static void add_handlers_for_singular_field(upb_handlers *h, const upb_fielddef *f, size_t offset, size_t hasbit_off)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:567
benchmarks.python.py_benchmark.parser
parser
Definition: py_benchmark.py:10
upb_msgdef_syntax
upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m)
Definition: php/ext/google/protobuf/upb.c:1745
UPB_TYPE_BOOL
@ UPB_TYPE_BOOL
Definition: php/ext/google/protobuf/upb.h:412
DescriptorPool
Definition: ruby/ext/google/protobuf_c/protobuf.h:109
Map_iter_key
VALUE Map_iter_key(Map_iter *iter)
Definition: ruby/ext/google/protobuf_c/map.c:816
putmap
static void putmap(VALUE map, const upb_fielddef *f, upb_sink *sink, int depth, bool emit_defaults, bool is_json)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:1115
MAP_VALUE_FIELD
#define MAP_VALUE_FIELD
Definition: php/ext/google/protobuf/protobuf.h:1094
upb_msgdef_fullname
const char * upb_msgdef_fullname(const upb_msgdef *m)
Definition: php/ext/google/protobuf/upb.c:1733
upb_handlers
Definition: php/ext/google/protobuf/upb.c:3269
map_parse_frame_t::map
VALUE map
Definition: ruby/ext/google/protobuf_c/encode_decode.c:326
submsg_handlerdata_t
Definition: php/ext/google/protobuf/encode_decode.c:162
upb_handlertype_t
upb_handlertype_t
Definition: php/ext/google/protobuf/upb.h:4035
upb_fielddef_index
uint32_t upb_fielddef_index(const upb_fielddef *f)
Definition: php/ext/google/protobuf/upb.c:1544
upb_handlers_setendmsg
bool upb_handlers_setendmsg(upb_handlers *h, upb_endmsg_handlerfunc *func, const upb_handlerattr *attr)
Definition: php/ext/google/protobuf/upb.c:3496
klass
zend_class_entry * klass
Definition: php/ext/google/protobuf/protobuf.h:801
it
MapIter it
Definition: php/ext/google/protobuf/map.c:205
stackenv_init
static void stackenv_init(stackenv *se, const char *errmsg)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:838
stringsink_string
static size_t stringsink_string(void *_sink, const void *hd, const char *ptr, size_t len, const upb_bufhandle *handle)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:58
RepeatedField_size
int RepeatedField_size(VALUE _self)
Definition: repeated_field.c:253
upb_msgdef
Definition: php/ext/google/protobuf/upb.c:1146
putjsonany
static void putjsonany(VALUE msg_rb, const Descriptor *desc, upb_sink *sink, int depth, bool emit_defaults)
Definition: ruby/ext/google/protobuf_c/encode_decode.c:1159
upb_fieldtype_t
upb_fieldtype_t
Definition: php/ext/google/protobuf/upb.h:410
google::protobuf::method
const Descriptor::ReservedRange const EnumValueDescriptor method
Definition: src/google/protobuf/descriptor.h:1973
h
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:4147
stringsink
Definition: php/ext/google/protobuf/protobuf.h:1460
field_handlerdata_t::ofs
size_t ofs
Definition: ruby/ext/google/protobuf_c/encode_decode.c:104
oneof_handlerdata_t::ofs
size_t ofs
Definition: php/ext/google/protobuf/encode_decode.c:179
upb_bufsrc_putbuf
bool upb_bufsrc_putbuf(const char *buf, size_t len, upb_bytessink sink)
Definition: php/ext/google/protobuf/upb.c:4623
SET_HANDLER
#define SET_HANDLER(utype, ltype)
upb_pbdecodermethod
Definition: php/ext/google/protobuf/upb.h:6574
upb_sink_endmsg
UPB_INLINE bool upb_sink_endmsg(upb_sink s, upb_status *status)
Definition: php/ext/google/protobuf/upb.h:5741
upb_handlers_setstring
bool upb_handlers_setstring(upb_handlers *h, const upb_fielddef *f, upb_string_handlerfunc *func, const upb_handlerattr *attr)


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:51