php/ext/google/protobuf/encode_decode.c
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 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 <php.h>
32 #include <Zend/zend_exceptions.h>
33 
34 #include "protobuf.h"
35 #include "utf8.h"
36 
37 /* stringsink *****************************************************************/
38 
39 static void *stringsink_start(void *_sink, const void *hd, size_t size_hint) {
40  stringsink *sink = _sink;
41  sink->len = 0;
42  return sink;
43 }
44 
45 size_t stringsink_string(void *_sink, const void *hd, const char *ptr,
46  size_t len, const upb_bufhandle *handle) {
47  stringsink *sink = _sink;
48  size_t new_size = sink->size;
49 
50  PHP_PROTO_UNUSED(hd);
52 
53  while (sink->len + len > new_size) {
54  new_size *= 2;
55  }
56 
57  if (new_size != sink->size) {
58  sink->ptr = realloc(sink->ptr, new_size);
59  sink->size = new_size;
60  }
61 
62  memcpy(sink->ptr + sink->len, ptr, len);
63  sink->len += len;
64 
65  return len;
66 }
67 
69  upb_byteshandler_init(&sink->handler);
72 
73  upb_bytessink_reset(&sink->sink, &sink->handler, sink);
74 
75  sink->size = 32;
76  sink->ptr = malloc(sink->size);
77  PHP_PROTO_ASSERT(sink->ptr != NULL);
78  sink->len = 0;
79 }
80 
81 void stringsink_uninit(stringsink *sink) { free(sink->ptr); }
82 
84 
85 /* stackenv *****************************************************************/
86 
87 // Stack-allocated context during an encode/decode operation. Contains the upb
88 // environment and its stack-based allocator, an initial buffer for allocations
89 // to avoid malloc() when possible, and a template for PHP exception messages
90 // if any error occurs.
91 #define STACK_ENV_STACKBYTES 4096
92 typedef struct {
95  const char *php_error_template;
96  char allocbuf[STACK_ENV_STACKBYTES];
97 } stackenv;
98 
99 
100 static void stackenv_init(stackenv* se, const char* errmsg);
101 static void stackenv_uninit(stackenv* se);
102 
103 static void stackenv_init(stackenv* se, const char* errmsg) {
104  se->php_error_template = errmsg;
105  se->arena = upb_arena_new();
106  upb_status_clear(&se->status);
107 }
108 
109 static void stackenv_uninit(stackenv* se) {
110  upb_arena_free(se->arena);
111 
112  if (!upb_ok(&se->status)) {
113  // TODO(teboring): have a way to verify that this is actually a parse error,
114  // instead of just throwing "parse error" unconditionally.
115  TSRMLS_FETCH();
116  zend_throw_exception_ex(NULL, 0 TSRMLS_CC, se->php_error_template,
117  upb_status_errmsg(&se->status));
118  }
119 }
120 
121 // -----------------------------------------------------------------------------
122 // Parsing.
123 // -----------------------------------------------------------------------------
124 
125 // TODO(teboring): This shoud be a bit in upb_msgdef
126 static bool is_wrapper_msg(const upb_msgdef *msg) {
127  return !strcmp(upb_filedef_name(upb_msgdef_file(msg)),
128  "google/protobuf/wrappers.proto");
129 }
130 
131 #define DEREF(msg, ofs, type) *(type*)(((uint8_t *)msg) + ofs)
132 
133 // Creates a handlerdata that simply contains the offset for this field.
134 static const void* newhandlerdata(upb_handlers* h, uint32_t ofs) {
135  size_t* hd_ofs = (size_t*)malloc(sizeof(size_t));
136  PHP_PROTO_ASSERT(hd_ofs != NULL);
137  *hd_ofs = ofs;
138  upb_handlers_addcleanup(h, hd_ofs, free);
139  return hd_ofs;
140 }
141 
142 typedef struct {
143  void* closure;
146 
147 typedef size_t (*encodeunknown_handlerfunc)(void* _sink, const void* hd,
148  const char* ptr, size_t len,
149  const upb_bufhandle* handle);
150 
151 typedef struct {
154 
155 // Creates a handlerdata for unknown fields.
159  PHP_PROTO_ASSERT(hd != NULL);
161  upb_handlers_addcleanup(h, hd, free);
162  return hd;
163 }
164 
165 typedef struct {
166  size_t ofs;
167  const upb_msgdef *md;
169 
170 // Creates a handlerdata that contains offset and submessage type information.
171 static const void *newsubmsghandlerdata(upb_handlers* h, uint32_t ofs,
172  const upb_fielddef* f) {
174  (submsg_handlerdata_t*)malloc(sizeof(submsg_handlerdata_t));
175  PHP_PROTO_ASSERT(hd != NULL);
176  hd->ofs = ofs;
177  hd->md = upb_fielddef_msgsubdef(f);
178  upb_handlers_addcleanup(h, hd, free);
179  return hd;
180 }
181 
182 typedef struct {
183  size_t ofs; // union data slot
184  size_t case_ofs; // oneof_case field
185  int property_ofs; // properties table cache
186  uint32_t oneof_case_num; // oneof-case number to place in oneof_case field
187  const upb_msgdef *md; // msgdef, for oneof submessage handler
188  const upb_msgdef *parent_md; // msgdef, for parent submessage
190 
191 static const void *newoneofhandlerdata(upb_handlers *h,
192  uint32_t ofs,
193  uint32_t case_ofs,
194  int property_ofs,
195  const upb_msgdef *m,
196  const upb_fielddef *f) {
197  oneof_handlerdata_t* hd =
198  (oneof_handlerdata_t*)malloc(sizeof(oneof_handlerdata_t));
199  PHP_PROTO_ASSERT(hd != NULL);
200  hd->ofs = ofs;
201  hd->case_ofs = case_ofs;
202  hd->property_ofs = property_ofs;
203  hd->parent_md = m;
204  // We reuse the field tag number as a oneof union discriminant tag. Note that
205  // we don't expose these numbers to the user, so the only requirement is that
206  // we have some unique ID for each union case/possibility. The field tag
207  // numbers are already present and are easy to use so there's no reason to
208  // create a separate ID space. In addition, using the field tag number here
209  // lets us easily look up the field in the oneof accessor.
212  hd->md = upb_fielddef_msgsubdef(f);
213  } else {
214  hd->md = NULL;
215  }
216  upb_handlers_addcleanup(h, hd, free);
217  return hd;
218 }
219 
220 // A handler that starts a repeated field. Gets the Repeated*Field instance for
221 // this field (such an instance always exists even in an empty message).
222 static void *startseq_handler(void* closure, const void* hd) {
224  const size_t *ofs = hd;
226 }
227 
228 // Handlers that append primitive values to a repeated field.
229 #define DEFINE_APPEND_HANDLER(type, ctype) \
230  static bool append##type##_handler(void* closure, const void* hd, \
231  ctype val) { \
232  zval* array = (zval*)closure; \
233  TSRMLS_FETCH(); \
234  RepeatedField* intern = UNBOX(RepeatedField, array); \
235  repeated_field_push_native(intern, &val); \
236  return true; \
237  }
238 
239 DEFINE_APPEND_HANDLER(bool, bool)
242 DEFINE_APPEND_HANDLER(float, float)
245 DEFINE_APPEND_HANDLER(double, double)
246 
247 // Appends a string or 'bytes' string to a repeated field.
248 static void* appendstr_handler(void *closure,
249  const void *hd,
250  size_t size_hint) {
251  PHP_PROTO_UNUSED(hd);
252 
255  PHP_PROTO_ASSERT(frame != NULL);
256  frame->closure = closure;
257  stringsink_init(&frame->sink);
258 
259  return frame;
260 }
261 
262 static bool appendstr_end_handler(void *closure, const void *hd) {
264 
265  zval* array = (zval*)frame->closure;
266  TSRMLS_FETCH();
268 
269 #if PHP_MAJOR_VERSION < 7
270  zval* str;
271  MAKE_STD_ZVAL(str);
272  PHP_PROTO_ZVAL_STRINGL(str, frame->sink.ptr, frame->sink.len, 1);
274 #else
275  zend_string* str = zend_string_init(frame->sink.ptr, frame->sink.len, 1);
277 #endif
278 
279  stringsink_uninit(&frame->sink);
280  free(frame);
281 
282  return true;
283 }
284 
285 // Handlers that append primitive values to a repeated field.
286 #define DEFINE_SINGULAR_HANDLER(type, ctype) \
287  static bool type##_handler(void* closure, const void* hd, \
288  ctype val) { \
289  MessageHeader* msg = (MessageHeader*)closure; \
290  const size_t *ofs = hd; \
291  DEREF(message_data(msg), *ofs, ctype) = val; \
292  return true; \
293  }
294 
295 DEFINE_SINGULAR_HANDLER(bool, bool)
298 DEFINE_SINGULAR_HANDLER(float, float)
301 DEFINE_SINGULAR_HANDLER(double, double)
302 
303 #undef DEFINE_SINGULAR_HANDLER
304 
305 #if PHP_MAJOR_VERSION < 7
306 static void *empty_php_string(zval** value_ptr) {
307  SEPARATE_ZVAL_IF_NOT_REF(value_ptr);
308  if (Z_TYPE_PP(value_ptr) == IS_STRING &&
309  !IS_INTERNED(Z_STRVAL_PP(value_ptr))) {
310  FREE(Z_STRVAL_PP(value_ptr));
311  }
312  ZVAL_EMPTY_STRING(*value_ptr);
313  return (void*)(*value_ptr);
314 }
315 #else
316 static void *empty_php_string(zval* value_ptr) {
317  if (Z_TYPE_P(value_ptr) == IS_STRING) {
318  zend_string_release(Z_STR_P(value_ptr));
319  }
320  ZVAL_EMPTY_STRING(value_ptr);
321  return value_ptr;
322 }
323 #endif
324 #if PHP_MAJOR_VERSION < 7
325 static void *empty_php_string2(zval** value_ptr) {
326  SEPARATE_ZVAL_IF_NOT_REF(value_ptr);
327  if (Z_TYPE_PP(value_ptr) == IS_STRING &&
328  !IS_INTERNED(Z_STRVAL_PP(value_ptr))) {
329  FREE(Z_STRVAL_PP(value_ptr));
330  }
331  ZVAL_EMPTY_STRING(*value_ptr);
332  return (void*)(*value_ptr);
333 }
334 static void new_php_string(zval** value_ptr, const char* str, size_t len) {
335  SEPARATE_ZVAL_IF_NOT_REF(value_ptr);
336  if (Z_TYPE_PP(value_ptr) == IS_STRING &&
337  !IS_INTERNED(Z_STRVAL_PP(value_ptr))) {
338  FREE(Z_STRVAL_PP(value_ptr));
339  }
340  ZVAL_EMPTY_STRING(*value_ptr);
341  ZVAL_STRINGL(*value_ptr, str, len, 1);
342 }
343 #else
344 static void *empty_php_string2(zval* value_ptr) {
345  if (Z_TYPE_P(value_ptr) == IS_STRING) {
346  zend_string_release(Z_STR_P(value_ptr));
347  }
348  ZVAL_EMPTY_STRING(value_ptr);
349  return value_ptr;
350 }
351 static void new_php_string(zval* value_ptr, const char* str, size_t len) {
352  if (Z_TYPE_P(value_ptr) == IS_STRING) {
353  zend_string_release(Z_STR_P(value_ptr));
354  }
355  ZVAL_NEW_STR(value_ptr, zend_string_init(str, len, 0));
356 }
357 #endif
358 
359 // Sets a non-repeated string/bytes field in a message.
360 static void* str_handler(void *closure,
361  const void *hd,
362  size_t size_hint) {
363  PHP_PROTO_UNUSED(hd);
364 
367  PHP_PROTO_ASSERT(frame != NULL);
368  frame->closure = closure;
369  stringsink_init(&frame->sink);
370 
371  return frame;
372 }
373 
374 static bool str_end_handler(void *closure, const void *hd) {
376  const size_t *ofs = hd;
377  MessageHeader* msg = (MessageHeader*)frame->closure;
378 
380  frame->sink.ptr, frame->sink.len);
381 
382  stringsink_uninit(&frame->sink);
383  free(frame);
384 
385  return true;
386 }
387 
388 static size_t stringdata_handler(void* closure, const void* hd,
389  const char* str, size_t len,
390  const upb_bufhandle* handle) {
392  return stringsink_string(&frame->sink, hd, str, len, handle);
393 }
394 
395 // Appends a submessage to a repeated field.
396 static void *appendsubmsg_handler(void *closure, const void *hd) {
397  zval* array = (zval*)closure;
398  TSRMLS_FETCH();
400 
401  const submsg_handlerdata_t *submsgdata = hd;
402  Descriptor* subdesc =
403  UNBOX_HASHTABLE_VALUE(Descriptor, get_def_obj((void*)submsgdata->md));
404  zend_class_entry* subklass = subdesc->klass;
405  MessageHeader* submsg;
406 
407 #if PHP_MAJOR_VERSION < 7
408  zval* val = NULL;
409  MAKE_STD_ZVAL(val);
410  ZVAL_OBJ(val, subklass->create_object(subklass TSRMLS_CC));
412  submsg = UNBOX(MessageHeader, val);
413 #else
414  zend_object* obj = subklass->create_object(subklass TSRMLS_CC);
416  submsg = (MessageHeader*)((char*)obj - XtOffsetOf(MessageHeader, std));
417 #endif
418  custom_data_init(subklass, submsg PHP_PROTO_TSRMLS_CC);
419 
420  return submsg;
421 }
422 
423 // Sets a non-repeated submessage field in a message.
424 static void *submsg_handler(void *closure, const void *hd) {
426  const submsg_handlerdata_t* submsgdata = hd;
427  TSRMLS_FETCH();
428  Descriptor* subdesc =
429  UNBOX_HASHTABLE_VALUE(Descriptor, get_def_obj((void*)submsgdata->md));
430  zend_class_entry* subklass = subdesc->klass;
431  zval* submsg_php;
432  MessageHeader* submsg;
433 
434  if (Z_TYPE_P(CACHED_PTR_TO_ZVAL_PTR(DEREF(message_data(msg), submsgdata->ofs,
435  CACHED_VALUE*))) == IS_NULL) {
436 #if PHP_MAJOR_VERSION < 7
437  zval val;
438  ZVAL_OBJ(&val, subklass->create_object(subklass TSRMLS_CC));
441  REPLACE_ZVAL_VALUE(DEREF(message_data(msg), submsgdata->ofs, zval**),
442  &val, 1);
443  zval_dtor(&val);
444 #else
445  zend_object* obj = subklass->create_object(subklass TSRMLS_CC);
446  ZVAL_OBJ(DEREF(message_data(msg), submsgdata->ofs, zval*), obj);
449 #endif
450  }
451 
452  submsg_php = CACHED_PTR_TO_ZVAL_PTR(
453  DEREF(message_data(msg), submsgdata->ofs, CACHED_VALUE*));
454 
455  submsg = UNBOX(MessageHeader, submsg_php);
456  return submsg;
457 }
458 
459 // Handler data for startmap/endmap handlers.
460 typedef struct {
461  size_t ofs;
465 
466 // Temporary frame for map parsing: at the beginning of a map entry message, a
467 // submsg handler allocates a frame to hold (i) a reference to the Map object
468 // into which this message will be inserted and (ii) storage slots to
469 // temporarily hold the key and value for this map entry until the end of the
470 // submessage. When the submessage ends, another handler is called to insert the
471 // value into the map.
472 typedef struct {
473  char key_storage[NATIVE_SLOT_MAX_SIZE];
474  char value_storage[NATIVE_SLOT_MAX_SIZE];
476 
478  map_parse_frame_data_t* data; // Place needs to be consistent with
479  // MessageHeader.
480  zval* map;
481  // In php7, we cannot allocate zval dynamically. So we need to add zval here
482  // to help decoding.
483  zval key_zval;
487 
488 static void map_slot_init(void* memory, upb_fieldtype_t type, zval* cache) {
489  switch (type) {
490  case UPB_TYPE_STRING:
491  case UPB_TYPE_BYTES: {
492 #if PHP_MAJOR_VERSION < 7
493  // Store zval** in memory in order to be consistent with the layout of
494  // singular fields.
495  zval** holder = ALLOC(zval*);
496  *(zval***)memory = holder;
497  zval* tmp;
498  MAKE_STD_ZVAL(tmp);
499  PHP_PROTO_ZVAL_STRINGL(tmp, "", 0, 1);
500  *holder = tmp;
501 #else
502  *(zval**)memory = cache;
503  PHP_PROTO_ZVAL_STRINGL(*(zval**)memory, "", 0, 1);
504 #endif
505  break;
506  }
507  case UPB_TYPE_MESSAGE: {
508 #if PHP_MAJOR_VERSION < 7
509  zval** holder = ALLOC(zval*);
510  zval* tmp;
511  MAKE_STD_ZVAL(tmp);
512  ZVAL_NULL(tmp);
513  *holder = tmp;
514  *(zval***)memory = holder;
515 #else
516  *(zval**)memory = cache;
517  ZVAL_NULL(*(zval**)memory);
518 #endif
519  break;
520  }
521  default:
522  native_slot_init(type, memory, NULL);
523  }
524 }
525 
526 static void map_slot_uninit(void* memory, upb_fieldtype_t type) {
527  switch (type) {
528  case UPB_TYPE_MESSAGE:
529  case UPB_TYPE_STRING:
530  case UPB_TYPE_BYTES: {
531 #if PHP_MAJOR_VERSION < 7
532  zval** holder = *(zval***)memory;
533  zval_ptr_dtor(holder);
534  FREE(holder);
535 #else
536  php_proto_zval_ptr_dtor(*(zval**)memory);
537 #endif
538  break;
539  }
540  default:
541  break;
542  }
543 }
544 
545 static void map_slot_key(upb_fieldtype_t type, const void* from,
546  const char** keyval,
547  size_t* length) {
548  if (type == UPB_TYPE_STRING) {
549 #if PHP_MAJOR_VERSION < 7
550  zval* key_php = **(zval***)from;
551 #else
552  zval* key_php = *(zval**)from;
553 #endif
554  *keyval = Z_STRVAL_P(key_php);
555  *length = Z_STRLEN_P(key_php);
556  } else {
557  *keyval = from;
559  }
560 }
561 
562 static void map_slot_value(upb_fieldtype_t type, const void* from,
563  upb_value* v) {
564  size_t len;
565  void* to = upb_value_memory(v);
566 #ifndef NDEBUG
567  v->ctype = UPB_CTYPE_UINT64;
568 #endif
569 
571 
572  switch (type) {
573 #if PHP_MAJOR_VERSION < 7
574  case UPB_TYPE_STRING:
575  case UPB_TYPE_BYTES:
576  case UPB_TYPE_MESSAGE: {
577  *(zval**)to = **(zval***)from;
578  Z_ADDREF_PP((zval**)to);
579  break;
580  }
581 #else
582  case UPB_TYPE_STRING:
583  case UPB_TYPE_BYTES:
584  *(zend_string**)to = Z_STR_P(*(zval**)from);
585  zend_string_addref(*(zend_string**)to);
586  break;
587  case UPB_TYPE_MESSAGE:
588  *(zend_object**)to = Z_OBJ_P(*(zval**)from);
589  GC_ADDREF(*(zend_object**)to);
590  break;
591 #endif
592  default:
594  memcpy(to, from, len);
595  }
596 }
597 
598 // Handler to begin a map entry: allocates a temporary frame. This is the
599 // 'startsubmsg' handler on the msgdef that contains the map field.
600 static void *startmapentry_handler(void *closure, const void *hd) {
602  const map_handlerdata_t* mapdata = hd;
603  zval* map = CACHED_PTR_TO_ZVAL_PTR(
604  DEREF(message_data(msg), mapdata->ofs, CACHED_VALUE*));
605 
608  frame->map = map;
609 
610  map_slot_init(&frame->data->key_storage, mapdata->key_field_type,
611  &frame->key_zval);
612  map_slot_init(&frame->data->value_storage, mapdata->value_field_type,
613  &frame->value_zval);
614 
615  return frame;
616 }
617 
618 // Handler to end a map entry: inserts the value defined during the message into
619 // the map. This is the 'endmsg' handler on the map entry msgdef.
620 static bool endmap_handler(void* closure, const void* hd, upb_status* s) {
622  const map_handlerdata_t* mapdata = hd;
623 
624  TSRMLS_FETCH();
625  Map *map = UNBOX(Map, frame->map);
626 
627  const char* keyval = NULL;
628  upb_value v;
629  size_t length;
630 
631  map_slot_key(map->key_type, &frame->data->key_storage, &keyval, &length);
632  map_slot_value(map->value_type, &frame->data->value_storage, &v);
633 
634  map_index_set(map, keyval, length, v);
635 
636  map_slot_uninit(&frame->data->key_storage, mapdata->key_field_type);
637  map_slot_uninit(&frame->data->value_storage, mapdata->value_field_type);
638  FREE(frame->data);
639  FREE(frame);
640 
641  return true;
642 }
643 
644 // Allocates a new map_handlerdata_t given the map entry message definition. If
645 // the offset of the field within the parent message is also given, that is
646 // added to the handler data as well. Note that this is called *twice* per map
647 // field: once in the parent message handler setup when setting the startsubmsg
648 // handler and once in the map entry message handler setup when setting the
649 // key/value and endmsg handlers. The reason is that there is no easy way to
650 // pass the handlerdata down to the sub-message handler setup.
652  size_t ofs,
653  const upb_msgdef* mapentry_def,
654  Descriptor* desc) {
655  const upb_fielddef* key_field;
656  const upb_fielddef* value_field;
657  // TODO(teboring): Use emalloc and efree.
658  map_handlerdata_t* hd =
659  (map_handlerdata_t*)malloc(sizeof(map_handlerdata_t));
660  PHP_PROTO_ASSERT(hd != NULL);
661  hd->ofs = ofs;
662  key_field = upb_msgdef_itof(mapentry_def, MAP_KEY_FIELD);
663  PHP_PROTO_ASSERT(key_field != NULL);
664  hd->key_field_type = upb_fielddef_type(key_field);
665  value_field = upb_msgdef_itof(mapentry_def, MAP_VALUE_FIELD);
666  PHP_PROTO_ASSERT(value_field != NULL);
667  hd->value_field_type = upb_fielddef_type(value_field);
668 
669  return hd;
670 }
671 
672 // Handlers that set primitive values in oneofs.
673 #define DEFINE_ONEOF_HANDLER(type, ctype) \
674  static bool oneof##type##_handler(void* closure, const void* hd, \
675  ctype val) { \
676  const oneof_handlerdata_t* oneofdata = hd; \
677  MessageHeader* msg = (MessageHeader*)closure; \
678  DEREF(message_data(closure), oneofdata->case_ofs, uint32_t) = \
679  oneofdata->oneof_case_num; \
680  DEREF(message_data(closure), oneofdata->ofs, ctype) = val; \
681  return true; \
682  }
683 
684 DEFINE_ONEOF_HANDLER(bool, bool)
687 DEFINE_ONEOF_HANDLER(float, float)
690 DEFINE_ONEOF_HANDLER(double, double)
691 
692 #undef DEFINE_ONEOF_HANDLER
693 
695  const oneof_handlerdata_t* oneofdata) {
696  uint32_t old_case_num =
697  DEREF(message_data(msg), oneofdata->case_ofs, uint32_t);
698  if (old_case_num == 0) {
699  return;
700  }
701 
702  const upb_fielddef* old_field =
703  upb_msgdef_itof(oneofdata->parent_md, old_case_num);
704  bool need_clean = false;
705 
706  switch (upb_fielddef_type(old_field)) {
707  case UPB_TYPE_STRING:
708  case UPB_TYPE_BYTES:
709  need_clean = true;
710  break;
711  case UPB_TYPE_MESSAGE:
712  if (oneofdata->oneof_case_num != old_case_num) {
713  need_clean = true;
714  }
715  break;
716  default:
717  break;
718  }
719 
720  if (need_clean) {
721 #if PHP_MAJOR_VERSION < 7
722  SEPARATE_ZVAL_IF_NOT_REF(
723  DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*));
725  *DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*));
726  MAKE_STD_ZVAL(*DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*));
727  ZVAL_NULL(*DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*));
728 #endif
729  }
730 }
731 
732 // Handlers for string/bytes in a oneof.
733 static void *oneofbytes_handler(void *closure,
734  const void *hd,
735  size_t size_hint) {
737  const oneof_handlerdata_t *oneofdata = hd;
738 
739  oneof_cleanup(msg, oneofdata);
740 
741  DEREF(message_data(msg), oneofdata->case_ofs, uint32_t) =
742  oneofdata->oneof_case_num;
743  DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*) =
744  OBJ_PROP(&msg->std, oneofdata->property_ofs);
745 
746  return empty_php_string(DEREF(
747  message_data(msg), oneofdata->ofs, CACHED_VALUE*));
748 }
749 static bool oneofstr_end_handler(void *closure, const void *hd) {
751  MessageHeader* msg = (MessageHeader*)frame->closure;
752  const oneof_handlerdata_t *oneofdata = hd;
753 
754  oneof_cleanup(msg, oneofdata);
755 
756  DEREF(message_data(msg), oneofdata->case_ofs, uint32_t) =
757  oneofdata->oneof_case_num;
758  DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*) =
759  OBJ_PROP(&msg->std, oneofdata->property_ofs);
760 
761  new_php_string(DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*),
762  frame->sink.ptr, frame->sink.len);
763 
764  stringsink_uninit(&frame->sink);
765  free(frame);
766 
767  return true;
768 }
769 
770 static void *oneofstr_handler(void *closure,
771  const void *hd,
772  size_t size_hint) {
773  PHP_PROTO_UNUSED(hd);
774 
777  PHP_PROTO_ASSERT(frame != NULL);
778  frame->closure = closure;
779  stringsink_init(&frame->sink);
780 
781  return frame;
782 }
783 
784 // Handler for a submessage field in a oneof.
785 static void* oneofsubmsg_handler(void* closure, const void* hd) {
787  const oneof_handlerdata_t *oneofdata = hd;
788  uint32_t oldcase = DEREF(message_data(msg), oneofdata->case_ofs, uint32_t);
789  TSRMLS_FETCH();
790  Descriptor* subdesc =
791  UNBOX_HASHTABLE_VALUE(Descriptor, get_def_obj((void*)oneofdata->md));
792  zend_class_entry* subklass = subdesc->klass;
793  zval* submsg_php;
794  MessageHeader* submsg;
795 
796  if (oldcase != oneofdata->oneof_case_num) {
797  oneof_cleanup(msg, oneofdata);
798 
799  // Create new message.
800  DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*) =
801  OBJ_PROP(&msg->std, oneofdata->property_ofs);
802 #if PHP_MAJOR_VERSION < 7
803  zval val;
804  ZVAL_OBJ(&val, subklass->create_object(subklass TSRMLS_CC));
805  REPLACE_ZVAL_VALUE(DEREF(message_data(msg), oneofdata->ofs, zval**),
806  &val, 1);
807  zval_dtor(&val);
808 #else
809  zend_object* obj = subklass->create_object(subklass TSRMLS_CC);
810  ZVAL_OBJ(DEREF(message_data(msg), oneofdata->ofs, zval*), obj);
811 #endif
812  }
813 
814  DEREF(message_data(msg), oneofdata->case_ofs, uint32_t) =
815  oneofdata->oneof_case_num;
816 
817  submsg_php = CACHED_PTR_TO_ZVAL_PTR(
818  DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*));
819  submsg = UNBOX(MessageHeader, submsg_php);
820  custom_data_init(subklass, submsg PHP_PROTO_TSRMLS_CC);
821  return submsg;
822 }
823 
824 // Set up handlers for a repeated field.
826  const upb_fielddef *f,
827  size_t offset) {
829  attr.handler_data = newhandlerdata(h, offset);
831 
832  switch (upb_fielddef_type(f)) {
833 
834 #define SET_HANDLER(utype, ltype) \
835  case utype: \
836  upb_handlers_set##ltype(h, f, append##ltype##_handler, NULL); \
837  break;
838 
839  SET_HANDLER(UPB_TYPE_BOOL, bool);
843  SET_HANDLER(UPB_TYPE_FLOAT, float);
846  SET_HANDLER(UPB_TYPE_DOUBLE, double);
847 
848 #undef SET_HANDLER
849 
850  case UPB_TYPE_STRING:
851  case UPB_TYPE_BYTES: {
855  break;
856  }
857  case UPB_TYPE_MESSAGE: {
859  attr.handler_data = newsubmsghandlerdata(h, 0, f);
861  break;
862  }
863  }
864 }
865 
866 // Set up handlers for a singular field.
868  const upb_fielddef *f,
869  size_t offset) {
870  switch (upb_fielddef_type(f)) {
871 #define SET_HANDLER(utype, ltype) \
872  case utype: { \
873  upb_handlerattr attr = UPB_HANDLERATTR_INIT; \
874  attr.handler_data = newhandlerdata(h, offset); \
875  upb_handlers_set##ltype(h, f, ltype##_handler, &attr); \
876  break; \
877  }
878 
879  SET_HANDLER(UPB_TYPE_BOOL, bool);
883  SET_HANDLER(UPB_TYPE_FLOAT, float);
886  SET_HANDLER(UPB_TYPE_DOUBLE, double);
887 
888 #undef SET_HANDLER
889 
890  case UPB_TYPE_STRING:
891  case UPB_TYPE_BYTES: {
893  attr.handler_data = newhandlerdata(h, offset);
897  break;
898  }
899  case UPB_TYPE_MESSAGE: {
901  attr.handler_data = newsubmsghandlerdata(h, offset, f);
903  break;
904  }
905  }
906 }
907 
908 // Adds handlers to a map field.
910  const upb_fielddef* fielddef,
911  size_t offset,
912  Descriptor* desc) {
913  const upb_msgdef* map_msgdef = upb_fielddef_msgsubdef(fielddef);
914  map_handlerdata_t* hd = new_map_handlerdata(offset, map_msgdef, desc);
916 
917  upb_handlers_addcleanup(h, hd, free);
918  attr.handler_data = hd;
920 }
921 
922 // Adds handlers to a map-entry msgdef.
924  Descriptor* desc) {
925  const upb_fielddef* key_field = map_entry_key(msgdef);
926  const upb_fielddef* value_field = map_entry_value(msgdef);
929 
930  upb_handlers_addcleanup(h, hd, free);
931  attr.handler_data = hd;
933 
934  add_handlers_for_singular_field(h, key_field,
935  offsetof(map_parse_frame_data_t,
936  key_storage));
937  add_handlers_for_singular_field(h, value_field,
938  offsetof(map_parse_frame_data_t,
939  value_storage));
940 }
941 
942 // Set up handlers for a oneof field.
944  const upb_msgdef *m,
945  const upb_fielddef *f,
946  size_t offset,
947  size_t oneof_case_offset,
948  int property_cache_offset) {
949 
951  attr.handler_data = newoneofhandlerdata(h, offset, oneof_case_offset,
952  property_cache_offset, m, f);
953 
954  switch (upb_fielddef_type(f)) {
955 
956 #define SET_HANDLER(utype, ltype) \
957  case utype: \
958  upb_handlers_set##ltype(h, f, oneof##ltype##_handler, &attr); \
959  break;
960 
961  SET_HANDLER(UPB_TYPE_BOOL, bool);
965  SET_HANDLER(UPB_TYPE_FLOAT, float);
968  SET_HANDLER(UPB_TYPE_DOUBLE, double);
969 
970 #undef SET_HANDLER
971 
972  case UPB_TYPE_STRING:
973  case UPB_TYPE_BYTES: {
977  break;
978  }
979  case UPB_TYPE_MESSAGE: {
981  break;
982  }
983  }
984 }
985 
986 static bool add_unknown_handler(void* closure, const void* hd, const char* buf,
987  size_t size) {
989  ((unknownfields_handlerdata_t*)hd)->handler;
990 
992  stringsink* unknown = DEREF(message_data(msg), 0, stringsink*);
993  if (unknown == NULL) {
995  unknown = DEREF(message_data(msg), 0, stringsink*);
996  stringsink_init(unknown);
997  }
998 
999  handler(unknown, NULL, buf, size, NULL);
1000 
1001  return true;
1002 }
1003 
1006  TSRMLS_FETCH();
1007  Descriptor* desc =
1010 
1011  // If this is a mapentry message type, set up a special set of handlers and
1012  // bail out of the normal (user-defined) message type handling.
1013  if (upb_msgdef_mapentry(msgdef)) {
1015  return;
1016  }
1017 
1018  // Ensure layout exists. We may be invoked to create handlers for a given
1019  // message if we are included as a submsg of another message type before our
1020  // class is actually built, so to work around this, we just create the layout
1021  // (and handlers, in the class-building function) on-demand.
1022  if (desc->layout == NULL) {
1023  desc->layout = create_layout(desc->msgdef);
1024  }
1025 
1027  attr.handler_data = newunknownfieldshandlerdata(h);
1029 
1030  for (upb_msg_field_begin(&i, desc->msgdef);
1031  !upb_msg_field_done(&i);
1032  upb_msg_field_next(&i)) {
1033  const upb_fielddef *f = upb_msg_iter_field(&i);
1034  size_t offset = desc->layout->fields[upb_fielddef_index(f)].offset;
1035 
1037  size_t oneof_case_offset =
1038  desc->layout->fields[upb_fielddef_index(f)].case_offset;
1039  int property_cache_index =
1040  desc->layout->fields[upb_fielddef_index(f)].cache_index;
1042  oneof_case_offset, property_cache_index);
1043  } else if (is_map_field(f)) {
1045  } else if (upb_fielddef_isseq(f)) {
1047  } else {
1049  }
1050  }
1051 }
1052 
1053 // Constructs the handlers for filling a message's data into an in-memory
1054 // object.
1056  return upb_handlercache_get(desc->pool->fill_handler_cache, desc->msgdef);
1057 }
1058 
1060  return upb_pbcodecache_get(desc->pool->fill_method_cache, desc->msgdef);
1061 }
1062 
1064  return upb_json_codecache_get(desc->pool->json_fill_method_cache, desc->msgdef);
1065 }
1066 
1067 // -----------------------------------------------------------------------------
1068 // Serializing.
1069 // -----------------------------------------------------------------------------
1070 
1071 static void putmsg(zval* msg, const Descriptor* desc, upb_sink sink,
1072  int depth, bool is_json TSRMLS_DC);
1073 static void putrawmsg(MessageHeader* msg, const Descriptor* desc,
1074  upb_sink sink, int depth, bool is_json,
1075  bool open_msg TSRMLS_DC);
1076 static void putjsonany(MessageHeader* msg, const Descriptor* desc,
1077  upb_sink sink, int depth TSRMLS_DC);
1078 static void putjsonlistvalue(
1079  MessageHeader* msg, const Descriptor* desc,
1080  upb_sink sink, int depth TSRMLS_DC);
1081 static void putjsonstruct(
1082  MessageHeader* msg, const Descriptor* desc,
1083  upb_sink sink, int depth TSRMLS_DC);
1084 
1085 static void putstr(zval* str, const upb_fielddef* f, upb_sink sink,
1086  bool force_default);
1087 
1088 static void putrawstr(const char* str, int len, const upb_fielddef* f,
1089  upb_sink sink, bool force_default);
1090 
1091 static void putsubmsg(zval* submsg, const upb_fielddef* f, upb_sink sink,
1092  int depth, bool is_json TSRMLS_DC);
1093 static void putrawsubmsg(MessageHeader* submsg, const upb_fielddef* f,
1094  upb_sink sink, int depth, bool is_json TSRMLS_DC);
1095 
1096 static void putarray(zval* array, const upb_fielddef* f, upb_sink sink,
1097  int depth, bool is_json TSRMLS_DC);
1098 static void putmap(zval* map, const upb_fielddef* f, upb_sink sink,
1099  int depth, bool is_json TSRMLS_DC);
1100 
1103  bool ok = upb_handlers_getselector(f, type, &ret);
1105  return ret;
1106 }
1107 
1108 static void put_optional_value(const void* memory, int len,
1109  const upb_fielddef* f,
1110  int depth, upb_sink sink,
1111  bool is_json TSRMLS_DC) {
1113 
1114  switch (upb_fielddef_type(f)) {
1115 #define T(upbtypeconst, upbtype, ctype, default_value) \
1116  case upbtypeconst: { \
1117  ctype value = DEREF(memory, 0, ctype); \
1118  if (is_json || value != default_value) { \
1119  upb_selector_t sel = getsel(f, upb_handlers_getprimitivehandlertype(f)); \
1120  upb_sink_put##upbtype(sink, sel, value); \
1121  } \
1122  } break;
1123 
1124  T(UPB_TYPE_FLOAT, float, float, 0.0)
1125  T(UPB_TYPE_DOUBLE, double, double, 0.0)
1126  T(UPB_TYPE_BOOL, bool, uint8_t, 0)
1132 
1133 #undef T
1134  case UPB_TYPE_STRING:
1135  case UPB_TYPE_BYTES:
1136  putrawstr(memory, len, f, sink, is_json);
1137  break;
1138  case UPB_TYPE_MESSAGE: {
1139 #if PHP_MAJOR_VERSION < 7
1140  MessageHeader *submsg = UNBOX(MessageHeader, *(zval**)memory);
1141 #else
1142  MessageHeader *submsg =
1143  (MessageHeader*)((char*)(*(zend_object**)memory) -
1144  XtOffsetOf(MessageHeader, std));
1145 #endif
1146  putrawsubmsg(submsg, f, sink, depth, is_json TSRMLS_CC);
1147  break;
1148  }
1149  default:
1150  PHP_PROTO_ASSERT(false);
1151  }
1152 }
1153 
1154 // Only string/bytes fields are stored as zval.
1155 static const char* raw_value(void* memory, const upb_fielddef* f) {
1156  switch (upb_fielddef_type(f)) {
1157  case UPB_TYPE_STRING:
1158  case UPB_TYPE_BYTES:
1159 #if PHP_MAJOR_VERSION < 7
1160  return Z_STRVAL_PP((zval**)memory);
1161 #else
1162  return ZSTR_VAL(*(zend_string**)memory);
1163 #endif
1164  break;
1165  default:
1166  return memory;
1167  }
1168 }
1169 
1170 static int raw_value_len(void* memory, int len, const upb_fielddef* f) {
1171  switch (upb_fielddef_type(f)) {
1172  case UPB_TYPE_STRING:
1173  case UPB_TYPE_BYTES:
1174 #if PHP_MAJOR_VERSION < 7
1175  return Z_STRLEN_PP((zval**)memory);
1176 #else
1177  return ZSTR_LEN(*(zend_string**)memory);
1178 #endif
1179  default:
1180  return len;
1181  }
1182 }
1183 
1184 static void putmap(zval* map, const upb_fielddef* f, upb_sink sink,
1185  int depth, bool is_json TSRMLS_DC) {
1186  upb_sink subsink;
1187  const upb_fielddef* key_field;
1188  const upb_fielddef* value_field;
1189  MapIter it;
1190  int len, size;
1191 
1192  PHP_PROTO_ASSERT(map != NULL);
1193  Map* intern = UNBOX(Map, map);
1194  size = upb_strtable_count(&intern->table);
1195  if (size == 0) return;
1196 
1198 
1200  key_field = map_field_key(f);
1201  value_field = map_field_value(f);
1202 
1203  for (map_begin(map, &it TSRMLS_CC); !map_done(&it); map_next(&it)) {
1205 
1206  upb_sink entry_sink;
1208  &entry_sink);
1209  upb_sink_startmsg(entry_sink);
1210 
1211  // Serialize key.
1212  const char *key = map_iter_key(&it, &len);
1213  put_optional_value(key, len, key_field, depth + 1,
1214  entry_sink, is_json TSRMLS_CC);
1215 
1216  // Serialize value.
1219  raw_value_len(upb_value_memory(&value), len, value_field),
1220  value_field, depth + 1, entry_sink, is_json TSRMLS_CC);
1221 
1222  upb_sink_endmsg(entry_sink, &status);
1224  }
1225 
1227 }
1228 
1229 static void putmsg(zval* msg_php, const Descriptor* desc, upb_sink sink,
1230  int depth, bool is_json TSRMLS_DC) {
1231  MessageHeader* msg = UNBOX(MessageHeader, msg_php);
1232  putrawmsg(msg, desc, sink, depth, is_json, true TSRMLS_CC);
1233 }
1234 
1236  Descriptor* desc, bool preserve_proto_fieldnames);
1237 
1239  upb_sink sink, int depth TSRMLS_DC) {
1241  const upb_fielddef* type_field = upb_msgdef_itof(desc->msgdef, UPB_ANY_TYPE);
1242  const upb_fielddef* value_field = upb_msgdef_itof(desc->msgdef, UPB_ANY_VALUE);
1243 
1244  uint32_t type_url_offset;
1245  zval* type_url_php_str;
1246  const upb_msgdef *payload_type = NULL;
1247 
1249 
1250  /* Handle type url */
1251  type_url_offset = desc->layout->fields[upb_fielddef_index(type_field)].offset;
1252  type_url_php_str = CACHED_PTR_TO_ZVAL_PTR(
1253  DEREF(message_data(msg), type_url_offset, CACHED_VALUE*));
1254  if (Z_STRLEN_P(type_url_php_str) > 0) {
1255  putstr(type_url_php_str, type_field, sink, false);
1256  }
1257 
1258  {
1259  const char* type_url_str = Z_STRVAL_P(type_url_php_str);
1260  size_t type_url_len = Z_STRLEN_P(type_url_php_str);
1261  if (type_url_len <= 20 ||
1262  strncmp(type_url_str, "type.googleapis.com/", 20) != 0) {
1263  zend_error(E_ERROR, "Invalid type url: %s", type_url_str);
1264  }
1265 
1266  /* Resolve type url */
1267  type_url_str += 20;
1268  type_url_len -= 20;
1269 
1270  payload_type = upb_symtab_lookupmsg2(
1271  generated_pool->symtab, type_url_str, type_url_len);
1272  if (payload_type == NULL) {
1273  zend_error(E_ERROR, "Unknown type: %s", type_url_str);
1274  return;
1275  }
1276  }
1277 
1278  {
1279  uint32_t value_offset;
1280  zval* value_php_str;
1281  const char* value_str;
1282  size_t value_len;
1283 
1284  value_offset = desc->layout->fields[upb_fielddef_index(value_field)].offset;
1285  value_php_str = CACHED_PTR_TO_ZVAL_PTR(
1286  DEREF(message_data(msg), value_offset, CACHED_VALUE*));
1287  value_str = Z_STRVAL_P(value_php_str);
1288  value_len = Z_STRLEN_P(value_php_str);
1289 
1290  if (value_len > 0) {
1291  Descriptor* payload_desc =
1292  UNBOX_HASHTABLE_VALUE(Descriptor, get_def_obj((void*)payload_type));
1293  zend_class_entry* payload_klass = payload_desc->klass;
1294  zval val;
1295  upb_sink subsink;
1296  bool is_wellknown;
1297 
1298  /* Create message of the payload type. */
1299  ZVAL_OBJ(&val, payload_klass->create_object(payload_klass TSRMLS_CC));
1302 
1303  merge_from_string(value_str, value_len, payload_desc, intern);
1304 
1305  is_wellknown =
1306  upb_msgdef_wellknowntype(payload_desc->msgdef) !=
1308  if (is_wellknown) {
1310  &subsink);
1311  }
1312 
1313  subsink.handlers =
1314  msgdef_json_serialize_handlers(payload_desc, true);
1315  subsink.closure = sink.closure;
1316  putrawmsg(intern, payload_desc, subsink, depth, true,
1317  is_wellknown TSRMLS_CC);
1318 
1319  zval_dtor(&val);
1320  }
1321  }
1322 
1324 }
1325 
1326 static void putjsonlistvalue(
1327  MessageHeader* msg, const Descriptor* desc,
1328  upb_sink sink, int depth TSRMLS_DC) {
1330  upb_sink subsink;
1331  const upb_fielddef* f = upb_msgdef_itof(desc->msgdef, 1);
1332  uint32_t offset = desc->layout->fields[upb_fielddef_index(f)].offset;
1333  zval* array;
1335  HashTable *ht;
1336  int size, i;
1337 
1339 
1343  ht = PHP_PROTO_HASH_OF(intern->array);
1344  size = zend_hash_num_elements(ht);
1345 
1346  if (size == 0) {
1349  } else {
1350  putarray(array, f, sink, depth, true TSRMLS_CC);
1351  }
1352 
1354 }
1355 
1356 static void putjsonstruct(
1357  MessageHeader* msg, const Descriptor* desc,
1358  upb_sink sink, int depth TSRMLS_DC) {
1360  upb_sink subsink;
1361  const upb_fielddef* f = upb_msgdef_itof(desc->msgdef, 1);
1362  uint32_t offset = desc->layout->fields[upb_fielddef_index(f)].offset;
1363  zval* map;
1364  Map* intern;
1365  int size;
1366 
1368 
1371  intern = UNBOX(Map, map);
1372  size = upb_strtable_count(&intern->table);
1373 
1374  if (size == 0) {
1377  } else {
1378  putmap(map, f, sink, depth, true TSRMLS_CC);
1379  }
1380 
1382 }
1383 
1385  upb_sink sink, int depth, bool is_json,
1386  bool open_msg TSRMLS_DC) {
1389 
1390  if (is_json &&
1392  putjsonany(msg, desc, sink, depth TSRMLS_CC);
1393  return;
1394  }
1395 
1396  if (is_json &&
1398  putjsonlistvalue(msg, desc, sink, depth TSRMLS_CC);
1399  return;
1400  }
1401 
1402  if (is_json &&
1404  putjsonstruct(msg, desc, sink, depth TSRMLS_CC);
1405  return;
1406  }
1407 
1408  if (open_msg) {
1410  }
1411 
1412  // Protect against cycles (possible because users may freely reassign message
1413  // and repeated fields) by imposing a maximum recursion depth.
1414  if (depth > ENCODE_MAX_NESTING) {
1415  zend_error(E_ERROR,
1416  "Maximum recursion depth exceeded during encoding.");
1417  }
1418 
1419  for (upb_msg_field_begin(&i, desc->msgdef); !upb_msg_field_done(&i);
1420  upb_msg_field_next(&i)) {
1422  uint32_t offset = desc->layout->fields[upb_fielddef_index(f)].offset;
1423  bool containing_oneof = false;
1424 
1426  uint32_t oneof_case_offset =
1427  desc->layout->fields[upb_fielddef_index(f)].case_offset;
1428  // For a oneof, check that this field is actually present -- skip all the
1429  // below if not.
1430  if (DEREF(message_data(msg), oneof_case_offset, uint32_t) !=
1432  continue;
1433  }
1434  // Otherwise, fall through to the appropriate singular-field handler
1435  // below.
1436  containing_oneof = true;
1437  }
1438 
1439  if (is_map_field(f)) {
1440  zval* map = CACHED_PTR_TO_ZVAL_PTR(
1442  if (map != NULL) {
1443  putmap(map, f, sink, depth, is_json TSRMLS_CC);
1444  }
1445  } else if (upb_fielddef_isseq(f)) {
1446  zval* array = CACHED_PTR_TO_ZVAL_PTR(
1448  if (array != NULL) {
1449  putarray(array, f, sink, depth, is_json TSRMLS_CC);
1450  }
1451  } else if (upb_fielddef_isstring(f)) {
1452  zval* str = CACHED_PTR_TO_ZVAL_PTR(
1454  if (containing_oneof || (is_json && is_wrapper_msg(desc->msgdef)) ||
1455  Z_STRLEN_P(str) > 0) {
1456  putstr(str, f, sink, is_json && is_wrapper_msg(desc->msgdef));
1457  }
1458  } else if (upb_fielddef_issubmsg(f)) {
1461  f, sink, depth, is_json TSRMLS_CC);
1462  } else {
1464 
1465 #define T(upbtypeconst, upbtype, ctype, default_value) \
1466  case upbtypeconst: { \
1467  ctype value = DEREF(message_data(msg), offset, ctype); \
1468  if (containing_oneof || \
1469  (is_json && is_wrapper_msg(desc->msgdef)) || \
1470  value != default_value) { \
1471  upb_sink_put##upbtype(sink, sel, value); \
1472  } \
1473  } break;
1474 
1475  switch (upb_fielddef_type(f)) {
1476  T(UPB_TYPE_FLOAT, float, float, 0.0)
1477  T(UPB_TYPE_DOUBLE, double, double, 0.0)
1478  T(UPB_TYPE_BOOL, bool, uint8_t, 0)
1479  case UPB_TYPE_ENUM:
1484 
1485  case UPB_TYPE_STRING:
1486  case UPB_TYPE_BYTES:
1487  case UPB_TYPE_MESSAGE:
1488  zend_error(E_ERROR, "Internal error.");
1489  }
1490 
1491 #undef T
1492  }
1493  }
1494 
1495  stringsink* unknown = DEREF(message_data(msg), 0, stringsink*);
1496  if (unknown != NULL) {
1497  upb_sink_putunknown(sink, unknown->ptr, unknown->len);
1498  }
1499 
1500  if (open_msg) {
1502  }
1503 }
1504 
1505 static void putstr(zval* str, const upb_fielddef *f,
1506  upb_sink sink, bool force_default) {
1507  upb_sink subsink;
1508 
1509  if (ZVAL_IS_NULL(str)) return;
1510 
1511  PHP_PROTO_ASSERT(Z_TYPE_P(str) == IS_STRING);
1512 
1514  &subsink);
1515 
1516  // For oneof string field, we may get here with string length is zero.
1517  if (Z_STRLEN_P(str) > 0 || force_default) {
1518  // Ensure that the string has the correct encoding. We also check at
1519  // field-set time, but the user may have mutated the string object since
1520  // then.
1522  !is_structurally_valid_utf8(Z_STRVAL_P(str), Z_STRLEN_P(str))) {
1523  zend_error(E_USER_ERROR, "Given string is not UTF8 encoded.");
1524  return;
1525  }
1526  upb_sink_putstring(subsink, getsel(f, UPB_HANDLER_STRING), Z_STRVAL_P(str),
1527  Z_STRLEN_P(str), NULL);
1528  }
1529 
1531 }
1532 
1533 static void putrawstr(const char* str, int len, const upb_fielddef* f,
1534  upb_sink sink, bool force_default) {
1535  upb_sink subsink;
1536 
1537  if (len == 0 && !force_default) return;
1538 
1539  // Ensure that the string has the correct encoding. We also check at field-set
1540  // time, but the user may have mutated the string object since then.
1543  zend_error(E_USER_ERROR, "Given string is not UTF8 encoded.");
1544  return;
1545  }
1546 
1548  upb_sink_putstring(subsink, getsel(f, UPB_HANDLER_STRING), str, len, NULL);
1550 }
1551 
1552 static void putsubmsg(zval* submsg_php, const upb_fielddef* f, upb_sink sink,
1553  int depth, bool is_json TSRMLS_DC) {
1554  if (Z_TYPE_P(submsg_php) == IS_NULL) return;
1555 
1556  MessageHeader *submsg = UNBOX(MessageHeader, submsg_php);
1557  putrawsubmsg(submsg, f, sink, depth, is_json TSRMLS_CC);
1558 }
1559 
1560 static void putrawsubmsg(MessageHeader* submsg, const upb_fielddef* f,
1561  upb_sink sink, int depth, bool is_json TSRMLS_DC) {
1562  upb_sink subsink;
1563 
1564  Descriptor* subdesc =
1566 
1568  putrawmsg(submsg, subdesc, subsink, depth + 1, is_json, true TSRMLS_CC);
1570 }
1571 
1572 static void putarray(zval* array, const upb_fielddef* f, upb_sink sink,
1573  int depth, bool is_json TSRMLS_DC) {
1574  upb_sink subsink;
1576  upb_selector_t sel = 0;
1577  int size, i;
1578 
1579  PHP_PROTO_ASSERT(array != NULL);
1581  HashTable *ht = PHP_PROTO_HASH_OF(intern->array);
1582  size = zend_hash_num_elements(ht);
1583  if (size == 0) return;
1584 
1586 
1587  if (upb_fielddef_isprimitive(f)) {
1589  }
1590 
1591  for (i = 0; i < size; i++) {
1592  void* memory = repeated_field_index_native(intern, i TSRMLS_CC);
1593  switch (type) {
1594 #define T(upbtypeconst, upbtype, ctype) \
1595  case upbtypeconst: \
1596  upb_sink_put##upbtype(subsink, sel, *((ctype*)memory)); \
1597  break;
1598 
1599  T(UPB_TYPE_FLOAT, float, float)
1600  T(UPB_TYPE_DOUBLE, double, double)
1601  T(UPB_TYPE_BOOL, bool, int8_t)
1602  case UPB_TYPE_ENUM:
1607 
1608  case UPB_TYPE_STRING:
1609  case UPB_TYPE_BYTES: {
1610 #if PHP_MAJOR_VERSION < 7
1611  const char* rawstr = Z_STRVAL_P(*(zval**)memory);
1612  int len = Z_STRLEN_P(*(zval**)memory);
1613 #else
1614  const char* rawstr = ZSTR_VAL(*(zend_string**)memory);
1615  int len = ZSTR_LEN(*(zend_string**)memory);
1616 #endif
1617  putrawstr(rawstr, len, f, subsink,
1619  break;
1620  }
1621  case UPB_TYPE_MESSAGE: {
1622 #if PHP_MAJOR_VERSION < 7
1623  MessageHeader *submsg = UNBOX(MessageHeader, *(zval**)memory);
1624 #else
1625  MessageHeader *submsg =
1626  (MessageHeader*)((char*)(Z_OBJ_P((zval*)memory)) -
1627  XtOffsetOf(MessageHeader, std));
1628 #endif
1629  putrawsubmsg(submsg, f, subsink, depth, is_json TSRMLS_CC);
1630  break;
1631  }
1632 
1633 #undef T
1634  }
1635  }
1637 }
1638 
1640  return upb_handlercache_get(desc->pool->pb_serialize_handler_cache,
1641  desc->msgdef);
1642 }
1643 
1645  Descriptor* desc, bool preserve_proto_fieldnames) {
1646  if (preserve_proto_fieldnames) {
1647  return upb_handlercache_get(
1648  desc->pool->json_serialize_handler_preserve_cache, desc->msgdef);
1649  } else {
1650  return upb_handlercache_get(desc->pool->json_serialize_handler_cache,
1651  desc->msgdef);
1652  }
1653 }
1654 
1655 // -----------------------------------------------------------------------------
1656 // PHP encode/decode methods
1657 // -----------------------------------------------------------------------------
1658 
1659 void serialize_to_string(zval* val, zval* return_value TSRMLS_DC) {
1660  Descriptor* desc =
1661  UNBOX_HASHTABLE_VALUE(Descriptor, get_ce_obj(Z_OBJCE_P(val)));
1662 
1663  stringsink sink;
1665 
1666  {
1667  const upb_handlers* serialize_handlers = msgdef_pb_serialize_handlers(desc);
1668 
1669  stackenv se;
1670  upb_pb_encoder* encoder;
1671 
1672  stackenv_init(&se, "Error occurred during encoding: %s");
1673  encoder = upb_pb_encoder_create(se.arena, serialize_handlers, sink.sink);
1674 
1675  putmsg(val, desc, upb_pb_encoder_input(encoder), 0, false TSRMLS_CC);
1676 
1677  PHP_PROTO_RETVAL_STRINGL(sink.ptr, sink.len, 1);
1678 
1679  stackenv_uninit(&se);
1681  }
1682 }
1683 
1684 PHP_METHOD(Message, serializeToString) {
1685  serialize_to_string(getThis(), return_value TSRMLS_CC);
1686 }
1687 
1688 void merge_from_string(const char* data, int data_len, Descriptor* desc,
1689  MessageHeader* msg) {
1692  stackenv se;
1693  upb_sink sink;
1694  upb_pbdecoder* decoder;
1695  stackenv_init(&se, "Error occurred during parsing: %s");
1696 
1697  upb_sink_reset(&sink, h, msg);
1698  decoder = upb_pbdecoder_create(se.arena, method, sink, &se.status);
1699  upb_bufsrc_putbuf(data, data_len, upb_pbdecoder_input(decoder));
1700 
1701  stackenv_uninit(&se);
1702 }
1703 
1704 PHP_METHOD(Message, mergeFromString) {
1705  Descriptor* desc =
1706  UNBOX_HASHTABLE_VALUE(Descriptor, get_ce_obj(Z_OBJCE_P(getThis())));
1707  MessageHeader* msg = UNBOX(MessageHeader, getThis());
1708 
1709  char *data = NULL;
1710  PHP_PROTO_SIZE data_len;
1711 
1712  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len) ==
1713  FAILURE) {
1714  return;
1715  }
1716 
1717  merge_from_string(data, data_len, desc, msg);
1718 }
1719 
1720 PHP_METHOD(Message, serializeToJsonString) {
1721  Descriptor* desc =
1722  UNBOX_HASHTABLE_VALUE(Descriptor, get_ce_obj(Z_OBJCE_P(getThis())));
1723 
1724  zend_bool preserve_proto_fieldnames = false;
1725  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b",
1726  &preserve_proto_fieldnames) == FAILURE) {
1727  return;
1728  }
1729 
1730  stringsink sink;
1732 
1733  {
1734  const upb_handlers* serialize_handlers =
1735  msgdef_json_serialize_handlers(desc, preserve_proto_fieldnames);
1736  upb_json_printer* printer;
1737  stackenv se;
1738 
1739  stackenv_init(&se, "Error occurred during encoding: %s");
1740  printer = upb_json_printer_create(se.arena, serialize_handlers, sink.sink);
1741 
1742  putmsg(getThis(), desc, upb_json_printer_input(printer), 0, true TSRMLS_CC);
1743 
1744  PHP_PROTO_RETVAL_STRINGL(sink.ptr, sink.len, 1);
1745 
1746  stackenv_uninit(&se);
1748  }
1749 }
1750 
1751 PHP_METHOD(Message, mergeFromJsonString) {
1752  Descriptor* desc =
1753  UNBOX_HASHTABLE_VALUE(Descriptor, get_ce_obj(Z_OBJCE_P(getThis())));
1754  MessageHeader* msg = UNBOX(MessageHeader, getThis());
1755 
1756  char *data = NULL;
1757  PHP_PROTO_SIZE data_len;
1758  zend_bool ignore_json_unknown = false;
1759 
1760  if (zend_parse_parameters(
1761  ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &data, &data_len,
1762  &ignore_json_unknown) ==
1763  FAILURE) {
1764  return;
1765  }
1766 
1767  // TODO(teboring): Check and respect string encoding. If not UTF-8, we need to
1768  // convert, because string handlers pass data directly to message string
1769  // fields.
1770 
1771  // TODO(teboring): Clear message.
1772 
1773  {
1775  stackenv se;
1776  upb_sink sink;
1778  stackenv_init(&se, "Error occurred during parsing: %s");
1779 
1782  sink, &se.status, ignore_json_unknown);
1784 
1785  stackenv_uninit(&se);
1786  }
1787 }
1788 
1789 // TODO(teboring): refactoring with putrawmsg
1792 
1793  stringsink* unknown = DEREF(message_data(msg), 0, stringsink*);
1794  if (unknown != NULL) {
1795  stringsink_uninit(unknown);
1796  FREE(unknown);
1797  DEREF(message_data(msg), 0, stringsink*) = NULL;
1798  }
1799 
1800  // Recursively discard unknown fields of submessages.
1801  Descriptor* desc = msg->descriptor;
1802  TSRMLS_FETCH();
1803  for (upb_msg_field_begin(&it, desc->msgdef);
1805  upb_msg_field_next(&it)) {
1807  uint32_t offset = desc->layout->fields[upb_fielddef_index(f)].offset;
1808  bool containing_oneof = false;
1809 
1811  uint32_t oneof_case_offset =
1812  desc->layout->fields[upb_fielddef_index(f)].case_offset;
1813  // For a oneof, check that this field is actually present -- skip all the
1814  // below if not.
1815  if (DEREF(message_data(msg), oneof_case_offset, uint32_t) !=
1817  continue;
1818  }
1819  // Otherwise, fall through to the appropriate singular-field handler
1820  // below.
1821  containing_oneof = true;
1822  }
1823 
1824  if (is_map_field(f)) {
1825  MapIter map_it;
1826  int len, size;
1827  const upb_fielddef* value_field;
1828 
1829  value_field = map_field_value(f);
1830  if (!upb_fielddef_issubmsg(value_field)) continue;
1831 
1832  zval* map_php = CACHED_PTR_TO_ZVAL_PTR(
1834  if (map_php == NULL) continue;
1835 
1836  Map* intern = UNBOX(Map, map_php);
1837  for (map_begin(map_php, &map_it TSRMLS_CC);
1838  !map_done(&map_it); map_next(&map_it)) {
1839  upb_value value = map_iter_value(&map_it, &len);
1840  const void* memory = raw_value(upb_value_memory(&value), value_field);
1841 #if PHP_MAJOR_VERSION < 7
1842  MessageHeader *submsg = UNBOX(MessageHeader, *(zval**)memory);
1843 #else
1844  MessageHeader *submsg =
1845  (MessageHeader*)((char*)(Z_OBJ_P((zval*)memory)) -
1846  XtOffsetOf(MessageHeader, std));
1847 #endif
1848  discard_unknown_fields(submsg);
1849  }
1850  } else if (upb_fielddef_isseq(f)) {
1851  if (!upb_fielddef_issubmsg(f)) continue;
1852 
1853  zval* array_php = CACHED_PTR_TO_ZVAL_PTR(
1855  if (array_php == NULL) continue;
1856 
1857  int size, i;
1858  RepeatedField* intern = UNBOX(RepeatedField, array_php);
1859  HashTable *ht = PHP_PROTO_HASH_OF(intern->array);
1860  size = zend_hash_num_elements(ht);
1861  if (size == 0) continue;
1862 
1863  for (i = 0; i < size; i++) {
1864  void* memory = repeated_field_index_native(intern, i TSRMLS_CC);
1865 #if PHP_MAJOR_VERSION < 7
1866  MessageHeader *submsg = UNBOX(MessageHeader, *(zval**)memory);
1867 #else
1868  MessageHeader *submsg =
1869  (MessageHeader*)((char*)(Z_OBJ_P((zval*)memory)) -
1870  XtOffsetOf(MessageHeader, std));
1871 #endif
1872  discard_unknown_fields(submsg);
1873  }
1874  } else if (upb_fielddef_issubmsg(f)) {
1875  zval* submsg_php = CACHED_PTR_TO_ZVAL_PTR(
1877  if (Z_TYPE_P(submsg_php) == IS_NULL) continue;
1878  MessageHeader* submsg = UNBOX(MessageHeader, submsg_php);
1879  discard_unknown_fields(submsg);
1880  }
1881  }
1882 }
1883 
1884 PHP_METHOD(Message, discardUnknownFields) {
1885  MessageHeader* msg = UNBOX(MessageHeader, getThis());
1887 }
is_wrapper_msg
static bool is_wrapper_msg(const upb_msgdef *msg)
Definition: php/ext/google/protobuf/encode_decode.c:126
xds_interop_client.str
str
Definition: xds_interop_client.py:487
map_parse_frame_data_t
Definition: php/ext/google/protobuf/encode_decode.c:472
putjsonlistvalue
static void putjsonlistvalue(MessageHeader *msg, const Descriptor *desc, upb_sink sink, int depth TSRMLS_DC)
Definition: php/ext/google/protobuf/encode_decode.c:1326
add_handlers_for_mapfield
static void add_handlers_for_mapfield(upb_handlers *h, const upb_fielddef *fielddef, size_t offset, Descriptor *desc)
Definition: php/ext/google/protobuf/encode_decode.c:909
ptr
char * ptr
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:45
upb_handlers_setendstr
bool upb_handlers_setendstr(upb_handlers *h, const upb_fielddef *f, upb_endfield_handlerfunc *func, const upb_handlerattr *attr)
upb_msgdef_file
const upb_filedef * upb_msgdef_file(const upb_msgdef *m)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3536
FREE
#define FREE(object)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1489
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: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:5584
upb_sink_startmsg
UPB_INLINE bool upb_sink_startmsg(upb_sink s)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:5609
custom_data_init
void custom_data_init(const zend_class_entry *ce, MessageHeader *intern PHP_PROTO_TSRMLS_DC)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/message.c:254
obj
OPENSSL_EXPORT const ASN1_OBJECT * obj
Definition: x509.h:1671
upb_json_printer_input
upb_sink upb_json_printer_input(upb_json_printer *p)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:13312
stackenv::status
upb_status status
Definition: php/ext/google/protobuf/encode_decode.c:94
UPB_TYPE_UINT64
@ UPB_TYPE_UINT64
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:487
upb_arena
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:2252
putmap
static void putmap(zval *map, const upb_fielddef *f, upb_sink sink, int depth, bool is_json TSRMLS_DC)
Definition: php/ext/google/protobuf/encode_decode.c:1184
regen-readme.it
it
Definition: regen-readme.py:15
upb_fielddef_label
upb_label_t upb_fielddef_label(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3347
upb_status_clear
void upb_status_clear(upb_status *status)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:2196
upb_msg_field_next
void upb_msg_field_next(upb_msg_field_iter *iter)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3626
data
map_parse_frame_data_t * data
Definition: php/ext/google/protobuf/encode_decode.c:478
const
#define const
Definition: bloaty/third_party/zlib/zconf.h:230
Map
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:451
UPB_TYPE_FLOAT
@ UPB_TYPE_FLOAT
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:476
msgdef_decodermethod
static const upb_pbdecodermethod * msgdef_decodermethod(Descriptor *desc)
Definition: php/ext/google/protobuf/encode_decode.c:1059
memset
return memset(p, 0, total)
upb_json_parsermethod
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:8761
stringsink_uninit_opaque
void stringsink_uninit_opaque(void *sink)
Definition: php/ext/google/protobuf/encode_decode.c:83
upb_status
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:197
raw_value_len
static int raw_value_len(void *memory, int len, const upb_fielddef *f)
Definition: php/ext/google/protobuf/encode_decode.c:1170
DEFINE_SINGULAR_HANDLER
#define DEFINE_SINGULAR_HANDLER(type, ctype)
Definition: php/ext/google/protobuf/encode_decode.c:286
map_handlerdata_t::value_field_type
upb_fieldtype_t value_field_type
Definition: php/ext/google/protobuf/encode_decode.c:463
str_end_handler
static bool str_end_handler(void *closure, const void *hd)
Definition: php/ext/google/protobuf/encode_decode.c:374
oneofstr_end_handler
static bool oneofstr_end_handler(void *closure, const void *hd)
Definition: php/ext/google/protobuf/encode_decode.c:749
upb_json_printer
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:11933
google::protobuf::int64
int64_t int64
Definition: third_party/bloaty/third_party/protobuf/src/google/protobuf/stubs/port.h:151
newoneofhandlerdata
static const void * newoneofhandlerdata(upb_handlers *h, uint32_t ofs, uint32_t case_ofs, int property_ofs, const upb_msgdef *m, const upb_fielddef *f)
Definition: php/ext/google/protobuf/encode_decode.c:191
upb_fielddef_issubmsg
bool upb_fielddef_issubmsg(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3486
map_field_key
const upb_fielddef * map_field_key(const upb_fielddef *field)
Definition: php/ext/google/protobuf/storage.c:530
upb_handlers_getprimitivehandlertype
upb_handlertype_t upb_handlers_getprimitivehandlertype(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:5201
UPB_ANY_TYPE
#define UPB_ANY_TYPE
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:3313
UPB_HANDLER_STARTSTR
@ UPB_HANDLER_STARTSTR
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:3923
UPB_HANDLER_ENDSEQ
@ UPB_HANDLER_ENDSEQ
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:3929
putrawstr
static void putrawstr(const char *str, int len, const upb_fielddef *f, upb_sink sink, bool force_default)
Definition: php/ext/google/protobuf/encode_decode.c:1533
str_handler
static void * str_handler(void *closure, const void *hd, size_t size_hint)
Definition: php/ext/google/protobuf/encode_decode.c:360
upb_pbdecoder
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:6436
MessageHeader
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:574
upb_value
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:681
merge_from_string
void merge_from_string(const char *data, int data_len, Descriptor *desc, MessageHeader *msg)
Definition: php/ext/google/protobuf/encode_decode.c:1688
discard_unknown_fields
static void discard_unknown_fields(MessageHeader *msg)
Definition: php/ext/google/protobuf/encode_decode.c:1790
DEREF
#define DEREF(msg, ofs, type)
Definition: php/ext/google/protobuf/encode_decode.c:131
upb_fieldtype_t
upb_fieldtype_t
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:472
putjsonstruct
static void putjsonstruct(MessageHeader *msg, const Descriptor *desc, upb_sink sink, int depth TSRMLS_DC)
Definition: php/ext/google/protobuf/encode_decode.c:1356
upb_arena_free
void upb_arena_free(upb_arena *a)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:2391
CACHED_PTR_TO_ZVAL_PTR
#define CACHED_PTR_TO_ZVAL_PTR(VALUE)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:203
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
stackenv_init
static void stackenv_init(stackenv *se, const char *errmsg)
Definition: php/ext/google/protobuf/encode_decode.c:103
msgdef_json_serialize_handlers
static const upb_handlers * msgdef_json_serialize_handlers(Descriptor *desc, bool preserve_proto_fieldnames)
Definition: php/ext/google/protobuf/encode_decode.c:1644
array
PHP_PROTO_OBJECT_FREE_END PHP_PROTO_OBJECT_DTOR_END intern array
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/array.c:111
upb_handlers_setstring
bool upb_handlers_setstring(upb_handlers *h, const upb_fielddef *f, upb_string_handlerfunc *func, const upb_handlerattr *attr)
putarray
static void putarray(zval *array, const upb_fielddef *f, upb_sink sink, int depth, bool is_json TSRMLS_DC)
Definition: php/ext/google/protobuf/encode_decode.c:1572
UPB_WELLKNOWN_UNSPECIFIED
@ UPB_WELLKNOWN_UNSPECIFIED
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:2981
binary_size.new_size
def new_size
Definition: binary_size.py:124
Descriptor::msgdef
const upb_msgdef * msgdef
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:122
upb_handlers_setstartsubmsg
bool upb_handlers_setstartsubmsg(upb_handlers *h, const upb_fielddef *f, upb_startfield_handlerfunc *func, const upb_handlerattr *attr)
upb_msg_iter_field
upb_fielddef * upb_msg_iter_field(const upb_msg_field_iter *iter)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3632
google::protobuf::uint32
uint32_t uint32
Definition: third_party/bloaty/third_party/protobuf/src/google/protobuf/stubs/port.h:155
add_handlers_for_message
void add_handlers_for_message(const void *closure, upb_handlers *h)
Definition: php/ext/google/protobuf/encode_decode.c:1004
stringsink_string
size_t stringsink_string(void *_sink, const void *hd, const char *ptr, size_t len, const upb_bufhandle *handle)
Definition: php/ext/google/protobuf/encode_decode.c:45
upb_byteshandler_setstartstr
bool upb_byteshandler_setstartstr(upb_byteshandler *h, upb_startstr_handlerfunc *func, void *d)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:5360
ENCODE_MAX_NESTING
#define ENCODE_MAX_NESTING
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:978
status
absl::Status status
Definition: rls.cc:251
UPB_TYPE_UINT32
@ UPB_TYPE_UINT32
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:478
DEFINE_ONEOF_HANDLER
#define DEFINE_ONEOF_HANDLER(type, ctype)
Definition: php/ext/google/protobuf/encode_decode.c:673
upb_pbdecoder_create
upb_pbdecoder * upb_pbdecoder_create(upb_arena *a, const upb_pbdecodermethod *m, upb_sink sink, upb_status *status)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:7408
upb_bufsrc_putbuf
bool upb_bufsrc_putbuf(const char *buf, size_t len, upb_bytessink sink)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:5477
PHP_PROTO_TSRMLS_CC
#define PHP_PROTO_TSRMLS_CC
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:74
to
size_t to
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1385
add_handlers_for_repeated_field
static void add_handlers_for_repeated_field(upb_handlers *h, const upb_fielddef *f, size_t offset)
Definition: php/ext/google/protobuf/encode_decode.c:825
stringfields_parseframe_t::sink
stringsink sink
Definition: php/ext/google/protobuf/encode_decode.c:144
empty_php_string2
static void * empty_php_string2(zval **value_ptr)
Definition: php/ext/google/protobuf/encode_decode.c:325
msgdef_pb_serialize_handlers
static const upb_handlers * msgdef_pb_serialize_handlers(Descriptor *desc)
Definition: php/ext/google/protobuf/encode_decode.c:1639
MapIter
struct MapIter MapIter
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:656
repeated_field_index_native
void * repeated_field_index_native(RepeatedField *intern, int index TSRMLS_DC)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/array.c:231
NATIVE_SLOT_MAX_SIZE
#define NATIVE_SLOT_MAX_SIZE
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1030
ZVAL_OBJ
#define ZVAL_OBJ(zval_ptr, call_create)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:238
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
upb_fielddef_isprimitive
bool upb_fielddef_isprimitive(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3499
map
zval * map
Definition: php/ext/google/protobuf/encode_decode.c:480
upb_sink_startseq
UPB_INLINE bool upb_sink_startseq(upb_sink s, upb_selector_t sel, upb_sink *sub)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:5633
map_iter_value
upb_value map_iter_value(MapIter *iter, int *len)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/map.c:513
upb_handlers_setunknown
bool upb_handlers_setunknown(upb_handlers *h, upb_unknown_handlerfunc *func, const upb_handlerattr *attr)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:5136
putrawmsg
static void putrawmsg(MessageHeader *msg, const Descriptor *desc, upb_sink sink, int depth, bool is_json, bool open_msg TSRMLS_DC)
Definition: php/ext/google/protobuf/encode_decode.c:1384
endmap_handler
static bool endmap_handler(void *closure, const void *hd, upb_status *s)
Definition: php/ext/google/protobuf/encode_decode.c:620
T
#define T(upbtypeconst, upbtype, ctype, default_value)
upb_sink::handlers
const upb_handlers * handlers
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:5554
gen_build_yaml.struct
def struct(**kwargs)
Definition: test/core/end2end/gen_build_yaml.py:30
map_parse_frame_t
Definition: ruby/ext/google/protobuf_c/encode_decode.c:315
Descriptor
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:121
get_def_obj
PHP_PROTO_HASHTABLE_VALUE get_def_obj(const void *def)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.c:112
upb_fielddef_msgsubdef
const upb_msgdef * upb_fielddef_msgsubdef(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3476
upb_handlercache_get
const upb_handlers * upb_handlercache_get(upb_handlercache *c, const upb_msgdef *md)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:5288
upb_handlertype_t
upb_handlertype_t
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:3915
upb_symtab_lookupmsg2
const upb_msgdef * upb_symtab_lookupmsg2(const upb_symtab *s, const char *sym, size_t len)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:4571
upb_bytessink_reset
UPB_INLINE void upb_bytessink_reset(upb_bytessink *s, const upb_byteshandler *h, void *closure)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:5916
empty_php_string
static void * empty_php_string(zval **value_ptr)
Definition: php/ext/google/protobuf/encode_decode.c:306
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
get_fill_handlers
const upb_handlers * get_fill_handlers(Descriptor *desc)
Definition: php/ext/google/protobuf/encode_decode.c:1055
map_done
bool map_done(MapIter *iter)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/map.c:504
from
size_t from
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1384
UPB_TYPE_BYTES
@ UPB_TYPE_BYTES
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:482
upb_msg_field_done
bool upb_msg_field_done(const upb_msg_field_iter *iter)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3628
upb_handlers_getselector
bool upb_handlers_getselector(const upb_fielddef *f, upb_handlertype_t type, upb_selector_t *s)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:5215
UPB_TYPE_ENUM
@ UPB_TYPE_ENUM
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:479
DEFINE_APPEND_HANDLER
#define DEFINE_APPEND_HANDLER(type, ctype)
Definition: php/ext/google/protobuf/encode_decode.c:229
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
appendstr_end_handler
static bool appendstr_end_handler(void *closure, const void *hd)
Definition: php/ext/google/protobuf/encode_decode.c:262
oneof_handlerdata_t
Definition: php/ext/google/protobuf/encode_decode.c:182
google::protobuf::int32
int32_t int32
Definition: third_party/bloaty/third_party/protobuf/src/google/protobuf/stubs/port.h:150
newhandlerdata
static const void * newhandlerdata(upb_handlers *h, uint32_t ofs)
Definition: php/ext/google/protobuf/encode_decode.c:134
upb_selector_t
int32_t upb_selector_t
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:3942
autogen_x86imm.f
f
Definition: autogen_x86imm.py:9
asyncio_get_stats.parser
parser
Definition: asyncio_get_stats.py:34
upb_sink_endsubmsg
UPB_INLINE bool upb_sink_endsubmsg(upb_sink s, upb_selector_t sel)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:5703
unknownfields_handlerdata_t::handler
encodeunknown_handlerfunc handler
Definition: php/ext/google/protobuf/encode_decode.c:152
upb_bufhandle
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:3975
upb_filedef_name
const char * upb_filedef_name(const upb_filedef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:4496
array
Definition: undname.c:101
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
startmapentry_handler
static void * startmapentry_handler(void *closure, const void *hd)
Definition: php/ext/google/protobuf/encode_decode.c:600
upb_status_errmsg
const char * upb_status_errmsg(const upb_status *status)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:2204
PHP_PROTO_UNUSED
#define PHP_PROTO_UNUSED(var)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:49
put_optional_value
static void put_optional_value(const void *memory, int len, const upb_fielddef *f, int depth, upb_sink sink, bool is_json TSRMLS_DC)
Definition: php/ext/google/protobuf/encode_decode.c:1108
map_handlerdata_t::key_field_type
upb_fieldtype_t key_field_type
Definition: php/ext/google/protobuf/encode_decode.c:462
serialize_to_string
void serialize_to_string(zval *val, zval *return_value TSRMLS_DC)
Definition: php/ext/google/protobuf/encode_decode.c:1659
setup.v
v
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:42
upb_inttable_iter
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:1113
UPB_HANDLER_ENDSTR
@ UPB_HANDLER_ENDSTR
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:3925
stringsink::len
size_t len
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1473
upb_pbdecoder_input
upb_bytessink upb_pbdecoder_input(upb_pbdecoder *d)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:7453
closure
grpc_closure closure
Definition: src/core/lib/surface/server.cc:466
SET_HANDLER
#define SET_HANDLER(utype, ltype)
add_unknown_handler
static bool add_unknown_handler(void *closure, const void *hd, const char *buf, size_t size)
Definition: php/ext/google/protobuf/encode_decode.c:986
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
upb_fielddef_number
uint32_t upb_fielddef_number(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3351
upb_sink_endmsg
UPB_INLINE bool upb_sink_endmsg(upb_sink s, upb_status *status)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:5621
upb_handlers_addcleanup
bool upb_handlers_addcleanup(upb_handlers *h, void *p, upb_handlerfree *func)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:5197
upb_fielddef_isstring
bool upb_fielddef_isstring(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3490
oneof_handlerdata_t::md
const upb_msgdef * md
Definition: php/ext/google/protobuf/encode_decode.c:187
Z_OBJ_P
#define Z_OBJ_P(zval_p)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1497
new_php_string
static void new_php_string(zval **value_ptr, const char *str, size_t len)
Definition: php/ext/google/protobuf/encode_decode.c:334
UPB_LABEL_OPTIONAL
@ UPB_LABEL_OPTIONAL
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:492
upb_arena_new
UPB_INLINE upb_arena * upb_arena_new(void)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:392
UPB_ANY_VALUE
#define UPB_ANY_VALUE
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:3314
STACK_ENV_STACKBYTES
#define STACK_ENV_STACKBYTES
Definition: php/ext/google/protobuf/encode_decode.c:91
google::protobuf::uint64
uint64_t uint64
Definition: third_party/bloaty/third_party/protobuf/src/google/protobuf/stubs/port.h:156
generated_pool
InternalDescriptorPool * generated_pool
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/def.c:582
oneof_handlerdata_t::oneof_case_num
uint32_t oneof_case_num
Definition: php/ext/google/protobuf/encode_decode.c:186
upb_pbcodecache_get
const upb_pbdecodermethod * upb_pbcodecache_get(upb_pbcodecache *c, const upb_msgdef *md)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:6400
stackenv
Definition: php/ext/google/protobuf/encode_decode.c:92
upb_fielddef
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:2934
map_slot_value
static void map_slot_value(upb_fieldtype_t type, const void *from, upb_value *v)
Definition: php/ext/google/protobuf/encode_decode.c:562
startseq_handler
static void * startseq_handler(void *closure, const void *hd)
Definition: php/ext/google/protobuf/encode_decode.c:222
map_field_value
const upb_fielddef * map_field_value(const upb_fielddef *field)
Definition: php/ext/google/protobuf/storage.c:535
upb_fielddef_containingtype
const upb_msgdef * upb_fielddef_containingtype(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3414
upb_pb_encoder
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:7583
map_handlerdata_t::ofs
size_t ofs
Definition: php/ext/google/protobuf/encode_decode.c:461
encodeunknown_handlerfunc
size_t(* encodeunknown_handlerfunc)(void *_sink, const void *hd, const char *ptr, size_t len, const upb_bufhandle *handle)
Definition: php/ext/google/protobuf/encode_decode.c:147
putjsonany
static void putjsonany(MessageHeader *msg, const Descriptor *desc, upb_sink sink, int depth TSRMLS_DC)
Definition: php/ext/google/protobuf/encode_decode.c:1238
key_zval
zval key_zval
Definition: php/ext/google/protobuf/encode_decode.c:483
UPB_TYPE_INT32
@ UPB_TYPE_INT32
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:477
upb_msgdef_itof
const upb_fielddef * upb_msgdef_itof(const upb_msgdef *m, uint32_t i)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3556
upb_ok
bool upb_ok(const upb_status *status)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:2202
newunknownfieldshandlerdata
static const void * newunknownfieldshandlerdata(upb_handlers *h)
Definition: php/ext/google/protobuf/encode_decode.c:156
UPB_HANDLER_STRING
@ UPB_HANDLER_STRING
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:3924
msg
std::string msg
Definition: client_interceptors_end2end_test.cc:372
UPB_HANDLER_STARTSUBMSG
@ UPB_HANDLER_STARTSUBMSG
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:3926
appendsubmsg_handler
static void * appendsubmsg_handler(void *closure, const void *hd)
Definition: php/ext/google/protobuf/encode_decode.c:396
stringsink::ptr
char * ptr
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1472
add_handlers_for_singular_field
static void add_handlers_for_singular_field(upb_handlers *h, const upb_fielddef *f, size_t offset)
Definition: php/ext/google/protobuf/encode_decode.c:867
CACHED_VALUE
#define CACHED_VALUE
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:201
message_data
void * message_data(MessageHeader *msg)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/message.c:250
MAP_VALUE_FIELD
#define MAP_VALUE_FIELD
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1103
stringsink_uninit
void stringsink_uninit(stringsink *sink)
Definition: php/ext/google/protobuf/encode_decode.c:81
msgdef_jsonparsermethod
static const upb_json_parsermethod * msgdef_jsonparsermethod(Descriptor *desc)
Definition: php/ext/google/protobuf/encode_decode.c:1063
value
const char * value
Definition: hpack_parser_table.cc:165
upb_fielddef_index
uint32_t upb_fielddef_index(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3343
upb_pb_encoder_input
upb_sink upb_pb_encoder_input(upb_pb_encoder *e)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:8059
upb_json_parser
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:8702
putrawsubmsg
static void putrawsubmsg(MessageHeader *submsg, const upb_fielddef *f, upb_sink sink, int depth, bool is_json TSRMLS_DC)
Definition: php/ext/google/protobuf/encode_decode.c:1560
upb_sink
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:5553
get_ce_obj
PHP_PROTO_HASHTABLE_VALUE get_ce_obj(const void *ce)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.c:125
map_slot_init
static void map_slot_init(void *memory, upb_fieldtype_t type, zval *cache)
Definition: php/ext/google/protobuf/encode_decode.c:488
attr
OPENSSL_EXPORT X509_ATTRIBUTE * attr
Definition: x509.h:1666
is_structurally_valid_utf8
bool is_structurally_valid_utf8(const char *buf, int len)
Definition: utf8.c:50
upb_value_memory
void * upb_value_memory(upb_value *v)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/map.c:52
upb_sink_endstr
UPB_INLINE bool upb_sink_endstr(upb_sink s, upb_selector_t sel)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:5674
add_handlers_for_oneof_field
static void add_handlers_for_oneof_field(upb_handlers *h, const upb_msgdef *m, const upb_fielddef *f, size_t offset, size_t oneof_case_offset, int property_cache_offset)
Definition: php/ext/google/protobuf/encode_decode.c:943
upb_sink_putunknown
UPB_INLINE bool upb_sink_putunknown(upb_sink s, const char *buf, size_t n)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:5597
submsg_handlerdata_t::md
const upb_msgdef * md
Definition: php/ext/google/protobuf/encode_decode.c:167
map_begin
void map_begin(zval *map_php, MapIter *iter TSRMLS_DC)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/map.c:495
key
const char * key
Definition: hpack_parser_table.cc:164
UPB_TYPE_STRING
@ UPB_TYPE_STRING
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:481
PHP_METHOD
PHP_METHOD(Message, serializeToString)
Definition: php/ext/google/protobuf/encode_decode.c:1684
upb_sink_startstr
UPB_INLINE bool upb_sink_startstr(upb_sink s, upb_selector_t sel, size_t size_hint, upb_sink *sub)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:5659
PHP_PROTO_HASH_OF
#define PHP_PROTO_HASH_OF(array)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:93
sink
FormatSinkImpl * sink
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:450
ALLOC
#define ALLOC(class_name)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1486
client.handler
handler
Definition: examples/python/multiprocessing/client.py:87
upb_msg_field_begin
void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3622
intern
upb_strtable_uninit & intern
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/map.c:222
map_next
void map_next(MapIter *iter)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/map.c:500
protobuf.h
map_entry_value
const upb_fielddef * map_entry_value(const upb_msgdef *msgdef)
Definition: php/ext/google/protobuf/storage.c:546
unknownfields_handlerdata_t
Definition: php/ext/google/protobuf/encode_decode.c:151
upb_byteshandler_init
UPB_INLINE void upb_byteshandler_init(upb_byteshandler *handler)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:4535
phone_pb2.containing_oneof
containing_oneof
Definition: phone_pb2.py:204
php_proto_zval_ptr_dtor
php_proto_zval_ptr_dtor(intern->array)
ret
UniquePtr< SSL_SESSION > ret
Definition: ssl_x509.cc:1029
map_handlerdata_t
Definition: php/ext/google/protobuf/encode_decode.c:460
GC_ADDREF
#define GC_ADDREF(h)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:63
MAP_KEY_FIELD
#define MAP_KEY_FIELD
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1102
upb_json_printer_create
upb_json_printer * upb_json_printer_create(upb_arena *a, const upb_handlers *h, upb_bytessink output)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:13291
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
stringfields_parseframe_t
Definition: php/ext/google/protobuf/encode_decode.c:142
msgdef
const upb_msgdef * msgdef
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:808
oneof_handlerdata_t::case_ofs
size_t case_ofs
Definition: php/ext/google/protobuf/encode_decode.c:184
map_slot_key
static void map_slot_key(upb_fieldtype_t type, const void *from, const char **keyval, size_t *length)
Definition: php/ext/google/protobuf/encode_decode.c:545
UPB_HANDLERATTR_INIT
#define UPB_HANDLERATTR_INIT
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:3972
native_slot_size
size_t native_slot_size(upb_fieldtype_t type)
Definition: php/ext/google/protobuf/storage.c:43
map_slot_uninit
static void map_slot_uninit(void *memory, upb_fieldtype_t type)
Definition: php/ext/google/protobuf/encode_decode.c:526
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_json_parser_input
upb_bytessink upb_json_parser_input(upb_json_parser *p)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:11858
OBJ_PROP
#define OBJ_PROP(OBJECT, OFFSET)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:216
oneof_handlerdata_t::property_ofs
int property_ofs
Definition: php/ext/google/protobuf/encode_decode.c:185
upb_sink_reset
UPB_INLINE void upb_sink_reset(upb_sink *s, const upb_handlers *h, void *c)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:5579
ok
bool ok
Definition: async_end2end_test.cc:197
frame
static void frame(frame_handler *handler, unsigned char *payload, size_t payload_length, size_t write_length)
Definition: frame_handler_test.cc:65
desc
#define desc
Definition: bloaty/third_party/protobuf/src/google/protobuf/extension_set.h:338
putmsg
static void putmsg(zval *msg, const Descriptor *desc, upb_sink sink, int depth, bool is_json TSRMLS_DC)
Definition: php/ext/google/protobuf/encode_decode.c:1229
UPB_HANDLER_ENDSUBMSG
@ UPB_HANDLER_ENDSUBMSG
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:3927
utf8.h
closure
Definition: proxy.cc:59
UPB_TYPE_MESSAGE
@ UPB_TYPE_MESSAGE
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:483
stackenv_uninit
static void stackenv_uninit(stackenv *se)
Definition: php/ext/google/protobuf/encode_decode.c:109
upb_msgdef_wellknowntype
upb_wellknowntype_t upb_msgdef_wellknowntype(const upb_msgdef *m)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3612
stringsink_init
void stringsink_init(stringsink *sink)
Definition: php/ext/google/protobuf/encode_decode.c:68
PHP_PROTO_SIZE
#define PHP_PROTO_SIZE
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:71
upb_pb_encoder_create
upb_pb_encoder * upb_pb_encoder_create(upb_arena *arena, const upb_handlers *h, upb_bytessink output)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:8020
upb_handlerattr
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:3965
PHP_PROTO_ZVAL_STRINGL
#define PHP_PROTO_ZVAL_STRINGL(zval_ptr, s, len, copy)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:80
PHP_PROTO_WRAP_OBJECT_START
#define PHP_PROTO_WRAP_OBJECT_START(name)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:137
upb_fielddef_containingoneof
const upb_oneofdef * upb_fielddef_containingoneof(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3418
PHP_PROTO_RETVAL_STRINGL
#define PHP_PROTO_RETVAL_STRINGL(s, len, copy)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:84
upb_sink_endseq
UPB_INLINE bool upb_sink_endseq(upb_sink s, upb_selector_t sel)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:5648
stackenv::arena
upb_arena * arena
Definition: php/ext/google/protobuf/encode_decode.c:93
upb_msgdef_mapentry
bool upb_msgdef_mapentry(const upb_msgdef *m)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3608
UPB_WELLKNOWN_STRUCT
@ UPB_WELLKNOWN_STRUCT
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:2999
handle
static csh handle
Definition: test_arm_regression.c:16
submsg_handlerdata_t::ofs
size_t ofs
Definition: php/ext/google/protobuf/encode_decode.c:166
UPB_HANDLER_STARTSEQ
@ UPB_HANDLER_STARTSEQ
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:3928
upb_handlers_setendmsg
bool upb_handlers_setendmsg(upb_handlers *h, upb_endmsg_handlerfunc *func, const upb_handlerattr *attr)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:5148
newsubmsghandlerdata
static const void * newsubmsghandlerdata(upb_handlers *h, uint32_t ofs, const upb_fielddef *f)
Definition: php/ext/google/protobuf/encode_decode.c:171
stringsink_start
static void * stringsink_start(void *_sink, const void *hd, size_t size_hint)
Definition: php/ext/google/protobuf/encode_decode.c:39
UNBOX_HASHTABLE_VALUE
#define UNBOX_HASHTABLE_VALUE(class_name, val)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:245
int8_t
signed char int8_t
Definition: stdint-msvc2008.h:75
PHP_PROTO_WRAP_OBJECT_END
#define PHP_PROTO_WRAP_OBJECT_END
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:140
upb_handlers_msgdef
const upb_msgdef * upb_handlers_msgdef(const upb_handlers *h)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:5195
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
map_entry_key
const upb_fielddef * map_entry_key(const upb_msgdef *msgdef)
Definition: php/ext/google/protobuf/storage.c:540
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
autogen_x86imm.tmp
tmp
Definition: autogen_x86imm.py:12
stringdata_handler
static size_t stringdata_handler(void *closure, const void *hd, const char *str, size_t len, const upb_bufhandle *handle)
Definition: php/ext/google/protobuf/encode_decode.c:388
add_handlers_for_mapentry
static void add_handlers_for_mapentry(const upb_msgdef *msgdef, upb_handlers *h, Descriptor *desc)
Definition: php/ext/google/protobuf/encode_decode.c:923
upb_handlers_setstartseq
bool upb_handlers_setstartseq(upb_handlers *h, const upb_fielddef *f, upb_startfield_handlerfunc *func, const upb_handlerattr *attr)
repeated_field_push_native
void repeated_field_push_native(RepeatedField *intern, void *value)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/array.c:252
value_zval
zval value_zval
Definition: php/ext/google/protobuf/encode_decode.c:484
upb_sink::closure
void * closure
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:5555
Descriptor::klass
VALUE klass
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:124
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
putsubmsg
static void putsubmsg(zval *submsg, const upb_fielddef *f, upb_sink sink, int depth, bool is_json TSRMLS_DC)
Definition: php/ext/google/protobuf/encode_decode.c:1552
new_map_handlerdata
static map_handlerdata_t * new_map_handlerdata(size_t ofs, const upb_msgdef *mapentry_def, Descriptor *desc)
Definition: php/ext/google/protobuf/encode_decode.c:651
length
std::size_t length
Definition: abseil-cpp/absl/time/internal/test_util.cc:57
map_index_set
bool map_index_set(Map *intern, const char *keyval, int length, upb_value v)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/map.c:330
fielddef
const upb_fielddef * fielddef
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:825
mkowners.depth
depth
Definition: mkowners.py:114
regress.m
m
Definition: regress/regress.py:25
method
NSString * method
Definition: ProtoMethod.h:28
int32_t
signed int int32_t
Definition: stdint-msvc2008.h:77
upb_fielddef_isseq
bool upb_fielddef_isseq(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3495
stackenv::php_error_template
const char * php_error_template
Definition: php/ext/google/protobuf/encode_decode.c:95
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: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:11816
raw_value
static const char * raw_value(void *memory, const upb_fielddef *f)
Definition: php/ext/google/protobuf/encode_decode.c:1155
upb_handlers_setstartstr
bool upb_handlers_setstartstr(upb_handlers *h, const upb_fielddef *f, upb_startstr_handlerfunc *func, const upb_handlerattr *attr)
PHP_PROTO_ASSERT
#define PHP_PROTO_ASSERT(expr)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:55
UPB_CTYPE_UINT64
@ UPB_CTYPE_UINT64
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:671
oneofbytes_handler
static void * oneofbytes_handler(void *closure, const void *hd, size_t size_hint)
Definition: php/ext/google/protobuf/encode_decode.c:733
appendstr_handler
static void * appendstr_handler(void *closure, const void *hd, size_t size_hint)
Definition: php/ext/google/protobuf/encode_decode.c:248
oneof_handlerdata_t::parent_md
const upb_msgdef * parent_md
Definition: php/ext/google/protobuf/encode_decode.c:188
upb_handlers
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:4921
getsel
static upb_selector_t getsel(const upb_fielddef *f, upb_handlertype_t type)
Definition: php/ext/google/protobuf/encode_decode.c:1101
submsg_handlerdata_t
Definition: php/ext/google/protobuf/encode_decode.c:165
UPB_TYPE_DOUBLE
@ UPB_TYPE_DOUBLE
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:485
oneof_cleanup
static void oneof_cleanup(MessageHeader *msg, const oneof_handlerdata_t *oneofdata)
Definition: php/ext/google/protobuf/encode_decode.c:694
upb_json_codecache_get
const upb_json_parsermethod * upb_json_codecache_get(upb_json_codecache *c, const upb_msgdef *md)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:11886
map_iter_key
const char * map_iter_key(MapIter *iter, int *len)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/map.c:508
create_layout
PHP_PROTO_WRAP_OBJECT_END MessageLayout * create_layout(const upb_msgdef *msgdef)
Definition: php/ext/google/protobuf/storage.c:591
UPB_TYPE_BOOL
@ UPB_TYPE_BOOL
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:474
is_map_field
bool is_map_field(const upb_fielddef *field)
Definition: php/ext/google/protobuf/storage.c:526
UPB_TYPE_INT64
@ UPB_TYPE_INT64
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:486
upb_pbdecodermethod_desthandlers
const upb_handlers * upb_pbdecodermethod_desthandlers(const upb_pbdecodermethod *m)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:5529
upb_msgdef
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:2962
upb_strtable_count
UPB_INLINE size_t upb_strtable_count(const upb_strtable *t)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:919
Message
Definition: protobuf/php/ext/google/protobuf/message.c:53
putstr
static void putstr(zval *str, const upb_fielddef *f, upb_sink sink, bool force_default)
Definition: php/ext/google/protobuf/encode_decode.c:1505
UNBOX
#define UNBOX(class_name, val)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:242
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
UPB_WELLKNOWN_LISTVALUE
@ UPB_WELLKNOWN_LISTVALUE
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:2998
offset
voidpf uLong offset
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:142
upb_fielddef_type
upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:3304
UPB_WELLKNOWN_ANY
@ UPB_WELLKNOWN_ANY
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:2982
upb_sink_startsubmsg
UPB_INLINE bool upb_sink_startsubmsg(upb_sink s, upb_selector_t sel, upb_sink *sub)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:5685
stringsink
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1469
stringfields_parseframe_t::closure
void * closure
Definition: php/ext/google/protobuf/encode_decode.c:143
submsg_handler
static void * submsg_handler(void *closure, const void *hd)
Definition: php/ext/google/protobuf/encode_decode.c:424
oneof_handlerdata_t::ofs
size_t ofs
Definition: php/ext/google/protobuf/encode_decode.c:183
oneofsubmsg_handler
static void * oneofsubmsg_handler(void *closure, const void *hd)
Definition: php/ext/google/protobuf/encode_decode.c:785
upb_pbdecodermethod
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:6410
oneofstr_handler
static void * oneofstr_handler(void *closure, const void *hd, size_t size_hint)
Definition: php/ext/google/protobuf/encode_decode.c:770
RepeatedField
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h:403
upb_byteshandler_setstring
bool upb_byteshandler_setstring(upb_byteshandler *h, upb_string_handlerfunc *func, void *d)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:5367


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:15