decode.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2021, Google LLC
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of Google LLC nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include "upb/decode.h"
29 
30 #include <setjmp.h>
31 #include <string.h>
32 
33 #include "upb/decode_internal.h"
34 #include "upb/upb.h"
35 #include "upb/upb_internal.h"
36 
37 /* Must be last. */
38 #include "upb/port_def.inc"
39 
40 /* Maps descriptor type -> elem_size_lg2. */
42  -1, /* invalid descriptor type */
43  3, /* DOUBLE */
44  2, /* FLOAT */
45  3, /* INT64 */
46  3, /* UINT64 */
47  2, /* INT32 */
48  3, /* FIXED64 */
49  2, /* FIXED32 */
50  0, /* BOOL */
51  UPB_SIZE(3, 4), /* STRING */
52  UPB_SIZE(2, 3), /* GROUP */
53  UPB_SIZE(2, 3), /* MESSAGE */
54  UPB_SIZE(3, 4), /* BYTES */
55  2, /* UINT32 */
56  2, /* ENUM */
57  2, /* SFIXED32 */
58  3, /* SFIXED64 */
59  2, /* SINT32 */
60  3, /* SINT64 */
61 };
62 
63 /* Maps descriptor type -> upb map size. */
64 static const uint8_t desctype_to_mapsize[] = {
65  -1, /* invalid descriptor type */
66  8, /* DOUBLE */
67  4, /* FLOAT */
68  8, /* INT64 */
69  8, /* UINT64 */
70  4, /* INT32 */
71  8, /* FIXED64 */
72  4, /* FIXED32 */
73  1, /* BOOL */
74  UPB_MAPTYPE_STRING, /* STRING */
75  sizeof(void*), /* GROUP */
76  sizeof(void*), /* MESSAGE */
77  UPB_MAPTYPE_STRING, /* BYTES */
78  4, /* UINT32 */
79  4, /* ENUM */
80  4, /* SFIXED32 */
81  8, /* SFIXED64 */
82  4, /* SINT32 */
83  8, /* SINT64 */
84 };
85 
86 static const unsigned FIXED32_OK_MASK = (1 << kUpb_FieldType_Float) |
87  (1 << kUpb_FieldType_Fixed32) |
89 
90 static const unsigned FIXED64_OK_MASK = (1 << kUpb_FieldType_Double) |
91  (1 << kUpb_FieldType_Fixed64) |
93 
94 /* Three fake field types for MessageSet. */
95 #define TYPE_MSGSET_ITEM 19
96 #define TYPE_MSGSET_TYPE_ID 20
97 #define TYPE_COUNT 20
98 
99 /* Op: an action to be performed for a wire-type/field-type combination. */
100 #define OP_UNKNOWN -1 /* Unknown field. */
101 #define OP_MSGSET_ITEM -2
102 #define OP_MSGSET_TYPEID -3
103 #define OP_SCALAR_LG2(n) (n) /* n in [0, 2, 3] => op in [0, 2, 3] */
104 #define OP_ENUM 1
105 #define OP_STRING 4
106 #define OP_BYTES 5
107 #define OP_SUBMSG 6
108 /* Scalar fields use only ops above. Repeated fields can use any op. */
109 #define OP_FIXPCK_LG2(n) (n + 5) /* n in [2, 3] => op in [7, 8] */
110 #define OP_VARPCK_LG2(n) (n + 9) /* n in [0, 2, 3] => op in [9, 11, 12] */
111 #define OP_PACKED_ENUM 13
112 
113 static const int8_t varint_ops[] = {
114  OP_UNKNOWN, /* field not found */
115  OP_UNKNOWN, /* DOUBLE */
116  OP_UNKNOWN, /* FLOAT */
117  OP_SCALAR_LG2(3), /* INT64 */
118  OP_SCALAR_LG2(3), /* UINT64 */
119  OP_SCALAR_LG2(2), /* INT32 */
120  OP_UNKNOWN, /* FIXED64 */
121  OP_UNKNOWN, /* FIXED32 */
122  OP_SCALAR_LG2(0), /* BOOL */
123  OP_UNKNOWN, /* STRING */
124  OP_UNKNOWN, /* GROUP */
125  OP_UNKNOWN, /* MESSAGE */
126  OP_UNKNOWN, /* BYTES */
127  OP_SCALAR_LG2(2), /* UINT32 */
128  OP_ENUM, /* ENUM */
129  OP_UNKNOWN, /* SFIXED32 */
130  OP_UNKNOWN, /* SFIXED64 */
131  OP_SCALAR_LG2(2), /* SINT32 */
132  OP_SCALAR_LG2(3), /* SINT64 */
133  OP_UNKNOWN, /* MSGSET_ITEM */
134  OP_MSGSET_TYPEID, /* MSGSET TYPEID */
135 };
136 
137 static const int8_t delim_ops[] = {
138  /* For non-repeated field type. */
139  OP_UNKNOWN, /* field not found */
140  OP_UNKNOWN, /* DOUBLE */
141  OP_UNKNOWN, /* FLOAT */
142  OP_UNKNOWN, /* INT64 */
143  OP_UNKNOWN, /* UINT64 */
144  OP_UNKNOWN, /* INT32 */
145  OP_UNKNOWN, /* FIXED64 */
146  OP_UNKNOWN, /* FIXED32 */
147  OP_UNKNOWN, /* BOOL */
148  OP_STRING, /* STRING */
149  OP_UNKNOWN, /* GROUP */
150  OP_SUBMSG, /* MESSAGE */
151  OP_BYTES, /* BYTES */
152  OP_UNKNOWN, /* UINT32 */
153  OP_UNKNOWN, /* ENUM */
154  OP_UNKNOWN, /* SFIXED32 */
155  OP_UNKNOWN, /* SFIXED64 */
156  OP_UNKNOWN, /* SINT32 */
157  OP_UNKNOWN, /* SINT64 */
158  OP_UNKNOWN, /* MSGSET_ITEM */
159  OP_UNKNOWN, /* MSGSET TYPEID */
160  /* For repeated field type. */
161  OP_FIXPCK_LG2(3), /* REPEATED DOUBLE */
162  OP_FIXPCK_LG2(2), /* REPEATED FLOAT */
163  OP_VARPCK_LG2(3), /* REPEATED INT64 */
164  OP_VARPCK_LG2(3), /* REPEATED UINT64 */
165  OP_VARPCK_LG2(2), /* REPEATED INT32 */
166  OP_FIXPCK_LG2(3), /* REPEATED FIXED64 */
167  OP_FIXPCK_LG2(2), /* REPEATED FIXED32 */
168  OP_VARPCK_LG2(0), /* REPEATED BOOL */
169  OP_STRING, /* REPEATED STRING */
170  OP_SUBMSG, /* REPEATED GROUP */
171  OP_SUBMSG, /* REPEATED MESSAGE */
172  OP_BYTES, /* REPEATED BYTES */
173  OP_VARPCK_LG2(2), /* REPEATED UINT32 */
174  OP_PACKED_ENUM, /* REPEATED ENUM */
175  OP_FIXPCK_LG2(2), /* REPEATED SFIXED32 */
176  OP_FIXPCK_LG2(3), /* REPEATED SFIXED64 */
177  OP_VARPCK_LG2(2), /* REPEATED SINT32 */
178  OP_VARPCK_LG2(3), /* REPEATED SINT64 */
179  /* Omitting MSGSET_*, because we never emit a repeated msgset type */
180 };
181 
182 typedef union {
183  bool bool_val;
184  uint32_t uint32_val;
185  uint64_t uint64_val;
186  uint32_t size;
187 } wireval;
188 
189 static const char* decode_msg(upb_Decoder* d, const char* ptr, upb_Message* msg,
190  const upb_MiniTable* layout);
191 
193  assert(status != kUpb_DecodeStatus_Ok);
194  UPB_LONGJMP(d->err, status);
195 }
196 
197 const char* fastdecode_err(upb_Decoder* d, int status) {
198  assert(status != kUpb_DecodeStatus_Ok);
199  UPB_LONGJMP(d->err, status);
200  return NULL;
201 }
202 static void decode_verifyutf8(upb_Decoder* d, const char* buf, int len) {
205 }
206 
207 static bool decode_reserve(upb_Decoder* d, upb_Array* arr, size_t elem) {
208  bool need_realloc = arr->size - arr->len < elem;
209  if (need_realloc && !_upb_array_realloc(arr, arr->len + elem, &d->arena)) {
211  }
212  return need_realloc;
213 }
214 
215 typedef struct {
216  const char* ptr;
217  uint64_t val;
218 } decode_vret;
219 
221 static decode_vret decode_longvarint64(const char* ptr, uint64_t val) {
222  decode_vret ret = {NULL, 0};
223  uint64_t byte;
224  int i;
225  for (i = 1; i < 10; i++) {
226  byte = (uint8_t)ptr[i];
227  val += (byte - 1) << (i * 7);
228  if (!(byte & 0x80)) {
229  ret.ptr = ptr + i + 1;
230  ret.val = val;
231  return ret;
232  }
233  }
234  return ret;
235 }
236 
238 static const char* decode_varint64(upb_Decoder* d, const char* ptr,
239  uint64_t* val) {
240  uint64_t byte = (uint8_t)*ptr;
241  if (UPB_LIKELY((byte & 0x80) == 0)) {
242  *val = byte;
243  return ptr + 1;
244  } else {
245  decode_vret res = decode_longvarint64(ptr, byte);
246  if (!res.ptr) return decode_err(d, kUpb_DecodeStatus_Malformed);
247  *val = res.val;
248  return res.ptr;
249  }
250 }
251 
253 static const char* decode_tag(upb_Decoder* d, const char* ptr, uint32_t* val) {
254  uint64_t byte = (uint8_t)*ptr;
255  if (UPB_LIKELY((byte & 0x80) == 0)) {
256  *val = byte;
257  return ptr + 1;
258  } else {
259  const char* start = ptr;
260  decode_vret res = decode_longvarint64(ptr, byte);
261  if (!res.ptr || res.ptr - start > 5 || res.val > UINT32_MAX) {
263  }
264  *val = res.val;
265  return res.ptr;
266  }
267 }
268 
269 static void decode_munge_int32(wireval* val) {
270  if (!_upb_IsLittleEndian()) {
271  /* The next stage will memcpy(dst, &val, 4) */
272  val->uint32_val = val->uint64_val;
273  }
274 }
275 
276 static void decode_munge(int type, wireval* val) {
277  switch (type) {
278  case kUpb_FieldType_Bool:
279  val->bool_val = val->uint64_val != 0;
280  break;
281  case kUpb_FieldType_SInt32: {
282  uint32_t n = val->uint64_val;
283  val->uint32_val = (n >> 1) ^ -(int32_t)(n & 1);
284  break;
285  }
286  case kUpb_FieldType_SInt64: {
287  uint64_t n = val->uint64_val;
288  val->uint64_val = (n >> 1) ^ -(int64_t)(n & 1);
289  break;
290  }
293  case kUpb_FieldType_Enum:
294  decode_munge_int32(val);
295  break;
296  }
297 }
298 
300  const upb_MiniTable_Sub* subs,
301  const upb_MiniTable_Field* field) {
302  const upb_MiniTable* subl = subs[field->submsg_index].submsg;
303  return _upb_Message_New_inl(subl, &d->arena);
304 }
305 
307 const char* decode_isdonefallback(upb_Decoder* d, const char* ptr,
308  int overrun) {
309  int status;
310  ptr = decode_isdonefallback_inl(d, ptr, overrun, &status);
311  if (ptr == NULL) {
312  return decode_err(d, status);
313  }
314  return ptr;
315 }
316 
317 static const char* decode_readstr(upb_Decoder* d, const char* ptr, int size,
318  upb_StringView* str) {
319  if (d->options & kUpb_DecodeOption_AliasString) {
320  str->data = ptr;
321  } else {
322  char* data = upb_Arena_Malloc(&d->arena, size);
324  memcpy(data, ptr, size);
325  str->data = data;
326  }
327  str->size = size;
328  return ptr + size;
329 }
330 
332 static const char* decode_tosubmsg2(upb_Decoder* d, const char* ptr,
333  upb_Message* submsg,
334  const upb_MiniTable* subl, int size) {
335  int saved_delta = decode_pushlimit(d, ptr, size);
336  if (--d->depth < 0) return decode_err(d, kUpb_DecodeStatus_MaxDepthExceeded);
337  ptr = decode_msg(d, ptr, submsg, subl);
338  if (d->end_group != DECODE_NOGROUP)
340  decode_poplimit(d, ptr, saved_delta);
341  d->depth++;
342  return ptr;
343 }
344 
346 static const char* decode_tosubmsg(upb_Decoder* d, const char* ptr,
347  upb_Message* submsg,
348  const upb_MiniTable_Sub* subs,
349  const upb_MiniTable_Field* field, int size) {
350  return decode_tosubmsg2(d, ptr, submsg, subs[field->submsg_index].submsg,
351  size);
352 }
353 
355 static const char* decode_group(upb_Decoder* d, const char* ptr,
356  upb_Message* submsg, const upb_MiniTable* subl,
357  uint32_t number) {
358  if (--d->depth < 0) return decode_err(d, kUpb_DecodeStatus_MaxDepthExceeded);
359  if (decode_isdone(d, &ptr)) {
361  }
362  ptr = decode_msg(d, ptr, submsg, subl);
363  if (d->end_group != number) return decode_err(d, kUpb_DecodeStatus_Malformed);
364  d->end_group = DECODE_NOGROUP;
365  d->depth++;
366  return ptr;
367 }
368 
370 static const char* decode_togroup(upb_Decoder* d, const char* ptr,
371  upb_Message* submsg,
372  const upb_MiniTable_Sub* subs,
373  const upb_MiniTable_Field* field) {
374  const upb_MiniTable* subl = subs[field->submsg_index].submsg;
375  return decode_group(d, ptr, submsg, subl, field->number);
376 }
377 
378 static char* encode_varint32(uint32_t val, char* ptr) {
379  do {
380  uint8_t byte = val & 0x7fU;
381  val >>= 7;
382  if (val) byte |= 0x80U;
383  *(ptr++) = byte;
384  } while (val);
385  return ptr;
386 }
387 
390  char buf[20];
391  char* end = buf;
394 
395  if (!_upb_Message_AddUnknown(msg, buf, end - buf, &d->arena)) {
397  }
398 }
399 
401 static bool decode_checkenum_slow(upb_Decoder* d, const char* ptr,
403  const upb_MiniTable_Field* field,
404  uint32_t v) {
405  // OPT: binary search long lists?
406  int n = e->value_count;
407  for (int i = 0; i < n; i++) {
408  if ((uint32_t)e->values[i] == v) return true;
409  }
410 
411  // Unrecognized enum goes into unknown fields.
412  // For packed fields the tag could be arbitrarily far in the past, so we
413  // just re-encode the tag and value here.
414  uint32_t tag = ((uint32_t)field->number << 3) | kUpb_WireType_Varint;
416  return false;
417 }
418 
420 static bool decode_checkenum(upb_Decoder* d, const char* ptr, upb_Message* msg,
421  const upb_MiniTable_Enum* e,
422  const upb_MiniTable_Field* field, wireval* val) {
423  uint32_t v = val->uint32_val;
424 
425  if (UPB_LIKELY(v < 64) && UPB_LIKELY(((1ULL << v) & e->mask))) return true;
426 
427  return decode_checkenum_slow(d, ptr, msg, e, field, v);
428 }
429 
431 static const char* decode_enum_toarray(upb_Decoder* d, const char* ptr,
432  upb_Message* msg, upb_Array* arr,
433  const upb_MiniTable_Sub* subs,
434  const upb_MiniTable_Field* field,
435  wireval* val) {
436  const upb_MiniTable_Enum* e = subs[field->submsg_index].subenum;
437  if (!decode_checkenum(d, ptr, msg, e, field, val)) return ptr;
438  void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len * 4, void);
439  arr->len++;
440  memcpy(mem, val, 4);
441  return ptr;
442 }
443 
445 static const char* decode_fixed_packed(upb_Decoder* d, const char* ptr,
446  upb_Array* arr, wireval* val,
447  const upb_MiniTable_Field* field,
448  int lg2) {
449  int mask = (1 << lg2) - 1;
450  size_t count = val->size >> lg2;
451  if ((val->size & mask) != 0) {
452  // Length isn't a round multiple of elem size.
454  }
455  decode_reserve(d, arr, count);
456  void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void);
457  arr->len += count;
458  // Note: if/when the decoder supports multi-buffer input, we will need to
459  // handle buffer seams here.
460  if (_upb_IsLittleEndian()) {
461  memcpy(mem, ptr, val->size);
462  ptr += val->size;
463  } else {
464  const char* end = ptr + val->size;
465  char* dst = mem;
466  while (ptr < end) {
467  if (lg2 == 2) {
468  uint32_t val;
469  memcpy(&val, ptr, sizeof(val));
470  val = _upb_BigEndian_Swap32(val);
471  memcpy(dst, &val, sizeof(val));
472  } else {
473  UPB_ASSERT(lg2 == 3);
474  uint64_t val;
475  memcpy(&val, ptr, sizeof(val));
476  val = _upb_BigEndian_Swap64(val);
477  memcpy(dst, &val, sizeof(val));
478  }
479  ptr += 1 << lg2;
480  dst += 1 << lg2;
481  }
482  }
483 
484  return ptr;
485 }
486 
488 static const char* decode_varint_packed(upb_Decoder* d, const char* ptr,
489  upb_Array* arr, wireval* val,
490  const upb_MiniTable_Field* field,
491  int lg2) {
492  int scale = 1 << lg2;
493  int saved_limit = decode_pushlimit(d, ptr, val->size);
494  char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void);
495  while (!decode_isdone(d, &ptr)) {
496  wireval elem;
497  ptr = decode_varint64(d, ptr, &elem.uint64_val);
498  decode_munge(field->descriptortype, &elem);
499  if (decode_reserve(d, arr, 1)) {
500  out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void);
501  }
502  arr->len++;
503  memcpy(out, &elem, scale);
504  out += scale;
505  }
506  decode_poplimit(d, ptr, saved_limit);
507  return ptr;
508 }
509 
511 static const char* decode_enum_packed(upb_Decoder* d, const char* ptr,
512  upb_Message* msg, upb_Array* arr,
513  const upb_MiniTable_Sub* subs,
514  const upb_MiniTable_Field* field,
515  wireval* val) {
516  const upb_MiniTable_Enum* e = subs[field->submsg_index].subenum;
517  int saved_limit = decode_pushlimit(d, ptr, val->size);
518  char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len * 4, void);
519  while (!decode_isdone(d, &ptr)) {
520  wireval elem;
521  ptr = decode_varint64(d, ptr, &elem.uint64_val);
523  if (!decode_checkenum(d, ptr, msg, e, field, &elem)) {
524  continue;
525  }
526  if (decode_reserve(d, arr, 1)) {
527  out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len * 4, void);
528  }
529  arr->len++;
530  memcpy(out, &elem, 4);
531  out += 4;
532  }
533  decode_poplimit(d, ptr, saved_limit);
534  return ptr;
535 }
536 
537 static const char* decode_toarray(upb_Decoder* d, const char* ptr,
538  upb_Message* msg,
539  const upb_MiniTable_Sub* subs,
540  const upb_MiniTable_Field* field,
541  wireval* val, int op) {
542  upb_Array** arrp = UPB_PTR_AT(msg, field->offset, void);
543  upb_Array* arr = *arrp;
544  void* mem;
545 
546  if (arr) {
547  decode_reserve(d, arr, 1);
548  } else {
549  size_t lg2 = desctype_to_elem_size_lg2[field->descriptortype];
550  arr = _upb_Array_New(&d->arena, 4, lg2);
551  if (!arr) return decode_err(d, kUpb_DecodeStatus_OutOfMemory);
552  *arrp = arr;
553  }
554 
555  switch (op) {
556  case OP_SCALAR_LG2(0):
557  case OP_SCALAR_LG2(2):
558  case OP_SCALAR_LG2(3):
559  /* Append scalar value. */
560  mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << op, void);
561  arr->len++;
562  memcpy(mem, val, 1 << op);
563  return ptr;
564  case OP_STRING:
565  decode_verifyutf8(d, ptr, val->size);
566  /* Fallthrough. */
567  case OP_BYTES: {
568  /* Append bytes. */
570  arr->len++;
571  return decode_readstr(d, ptr, val->size, str);
572  }
573  case OP_SUBMSG: {
574  /* Append submessage / group. */
575  upb_Message* submsg = decode_newsubmsg(d, subs, field);
576  *UPB_PTR_AT(_upb_array_ptr(arr), arr->len * sizeof(void*), upb_Message*) =
577  submsg;
578  arr->len++;
579  if (UPB_UNLIKELY(field->descriptortype == kUpb_FieldType_Group)) {
580  return decode_togroup(d, ptr, submsg, subs, field);
581  } else {
582  return decode_tosubmsg(d, ptr, submsg, subs, field, val->size);
583  }
584  }
585  case OP_FIXPCK_LG2(2):
586  case OP_FIXPCK_LG2(3):
587  return decode_fixed_packed(d, ptr, arr, val, field,
588  op - OP_FIXPCK_LG2(0));
589  case OP_VARPCK_LG2(0):
590  case OP_VARPCK_LG2(2):
591  case OP_VARPCK_LG2(3):
592  return decode_varint_packed(d, ptr, arr, val, field,
593  op - OP_VARPCK_LG2(0));
594  case OP_ENUM:
595  return decode_enum_toarray(d, ptr, msg, arr, subs, field, val);
596  case OP_PACKED_ENUM:
597  return decode_enum_packed(d, ptr, msg, arr, subs, field, val);
598  default:
599  UPB_UNREACHABLE();
600  }
601 }
602 
603 static const char* decode_tomap(upb_Decoder* d, const char* ptr,
605  const upb_MiniTable_Field* field,
606  wireval* val) {
607  upb_Map** map_p = UPB_PTR_AT(msg, field->offset, upb_Map*);
608  upb_Map* map = *map_p;
609  upb_MapEntry ent;
610  const upb_MiniTable* entry = subs[field->submsg_index].submsg;
611 
612  if (!map) {
613  /* Lazily create map. */
614  const upb_MiniTable_Field* key_field = &entry->fields[0];
615  const upb_MiniTable_Field* val_field = &entry->fields[1];
616  char key_size = desctype_to_mapsize[key_field->descriptortype];
617  char val_size = desctype_to_mapsize[val_field->descriptortype];
618  UPB_ASSERT(key_field->offset == 0);
619  UPB_ASSERT(val_field->offset == sizeof(upb_StringView));
620  map = _upb_Map_New(&d->arena, key_size, val_size);
621  *map_p = map;
622  }
623 
624  /* Parse map entry. */
625  memset(&ent, 0, sizeof(ent));
626 
627  if (entry->fields[1].descriptortype == kUpb_FieldType_Message ||
629  /* Create proactively to handle the case where it doesn't appear. */
630  ent.v.val =
631  upb_value_ptr(_upb_Message_New(entry->subs[0].submsg, &d->arena));
632  }
633 
634  const char* start = ptr;
635  ptr = decode_tosubmsg(d, ptr, &ent.k, subs, field, val->size);
636  // check if ent had any unknown fields
637  size_t size;
638  upb_Message_GetUnknown(&ent.k, &size);
639  if (size != 0) {
640  uint32_t tag = ((uint32_t)field->number << 3) | kUpb_WireType_Delimited;
642  if (!_upb_Message_AddUnknown(msg, start, ptr - start, &d->arena)) {
644  }
645  } else {
646  _upb_Map_Set(map, &ent.k, map->key_size, &ent.v, map->val_size, &d->arena);
647  }
648  return ptr;
649 }
650 
651 static const char* decode_tomsg(upb_Decoder* d, const char* ptr,
653  const upb_MiniTable_Field* field, wireval* val,
654  int op) {
655  void* mem = UPB_PTR_AT(msg, field->offset, void);
656  int type = field->descriptortype;
657 
658  if (UPB_UNLIKELY(op == OP_ENUM) &&
659  !decode_checkenum(d, ptr, msg, subs[field->submsg_index].subenum, field,
660  val)) {
661  return ptr;
662  }
663 
664  /* Set presence if necessary. */
665  if (field->presence > 0) {
667  } else if (field->presence < 0) {
668  /* Oneof case */
669  uint32_t* oneof_case = _upb_oneofcase_field(msg, field);
670  if (op == OP_SUBMSG && *oneof_case != field->number) {
671  memset(mem, 0, sizeof(void*));
672  }
673  *oneof_case = field->number;
674  }
675 
676  /* Store into message. */
677  switch (op) {
678  case OP_SUBMSG: {
679  upb_Message** submsgp = mem;
680  upb_Message* submsg = *submsgp;
681  if (!submsg) {
682  submsg = decode_newsubmsg(d, subs, field);
683  *submsgp = submsg;
684  }
686  ptr = decode_togroup(d, ptr, submsg, subs, field);
687  } else {
688  ptr = decode_tosubmsg(d, ptr, submsg, subs, field, val->size);
689  }
690  break;
691  }
692  case OP_STRING:
693  decode_verifyutf8(d, ptr, val->size);
694  /* Fallthrough. */
695  case OP_BYTES:
696  return decode_readstr(d, ptr, val->size, mem);
697  case OP_SCALAR_LG2(3):
698  memcpy(mem, val, 8);
699  break;
700  case OP_ENUM:
701  case OP_SCALAR_LG2(2):
702  memcpy(mem, val, 4);
703  break;
704  case OP_SCALAR_LG2(0):
705  memcpy(mem, val, 1);
706  break;
707  default:
708  UPB_UNREACHABLE();
709  }
710 
711  return ptr;
712 }
713 
715 const char* decode_checkrequired(upb_Decoder* d, const char* ptr,
716  const upb_Message* msg,
717  const upb_MiniTable* l) {
718  assert(l->required_count);
719  if (UPB_LIKELY((d->options & kUpb_DecodeOption_CheckRequired) == 0)) {
720  return ptr;
721  }
722  uint64_t msg_head;
723  memcpy(&msg_head, msg, 8);
724  msg_head = _upb_BigEndian_Swap64(msg_head);
725  if (upb_MiniTable_requiredmask(l) & ~msg_head) {
726  d->missing_required = true;
727  }
728  return ptr;
729 }
730 
732 static bool decode_tryfastdispatch(upb_Decoder* d, const char** ptr,
733  upb_Message* msg,
734  const upb_MiniTable* layout) {
735 #if UPB_FASTTABLE
736  if (layout && layout->table_mask != (unsigned char)-1) {
739  *ptr = fastdecode_tagdispatch(d, *ptr, msg, table, 0, tag);
740  return true;
741  }
742 #endif
743  return false;
744 }
745 
746 static const char* decode_msgset(upb_Decoder* d, const char* ptr,
747  upb_Message* msg,
748  const upb_MiniTable* layout) {
749  // We create a temporary upb_MiniTable here and abuse its fields as temporary
750  // storage, to avoid creating lots of MessageSet-specific parsing code-paths:
751  // 1. We store 'layout' in item_layout.subs. We will need this later as
752  // a key to look up extensions for this MessageSet.
753  // 2. We use item_layout.fields as temporary storage to store the extension
754  // we
755  // found when parsing the type id.
756  upb_MiniTable item_layout = {
757  .subs = (const upb_MiniTable_Sub[]){{.submsg = layout}},
758  .fields = NULL,
759  .size = 0,
760  .field_count = 0,
762  .dense_below = 0,
763  .table_mask = -1};
764  return decode_group(d, ptr, msg, &item_layout, 1);
765 }
766 
768  const upb_MiniTable* l,
769  uint32_t field_number,
770  int* last_field_index) {
771  static upb_MiniTable_Field none = {0, 0, 0, 0, 0, 0};
772  if (l == NULL) return &none;
773 
774  size_t idx = ((size_t)field_number) - 1; // 0 wraps to SIZE_MAX
775  if (idx < l->dense_below) {
776  /* Fastest case: index into dense fields. */
777  goto found;
778  }
779 
780  if (l->dense_below < l->field_count) {
781  /* Linear search non-dense fields. Resume scanning from last_field_index
782  * since fields are usually in order. */
783  int last = *last_field_index;
784  for (idx = last; idx < l->field_count; idx++) {
785  if (l->fields[idx].number == field_number) {
786  goto found;
787  }
788  }
789 
790  for (idx = l->dense_below; idx < last; idx++) {
791  if (l->fields[idx].number == field_number) {
792  goto found;
793  }
794  }
795  }
796 
797  if (d->extreg) {
798  switch (l->ext) {
801  _upb_extreg_get(d->extreg, l, field_number);
802  if (ext) return &ext->field;
803  break;
804  }
806  if (field_number == _UPB_MSGSET_ITEM) {
807  static upb_MiniTable_Field item = {0, 0, 0, 0, TYPE_MSGSET_ITEM, 0};
808  return &item;
809  }
810  break;
812  switch (field_number) {
813  case _UPB_MSGSET_TYPEID: {
814  static upb_MiniTable_Field type_id = {
815  0, 0, 0, 0, TYPE_MSGSET_TYPE_ID, 0};
816  return &type_id;
817  }
818  case _UPB_MSGSET_MESSAGE:
819  if (l->fields) {
820  // We saw type_id previously and succeeded in looking up msg.
821  return l->fields;
822  } else {
823  // TODO: out of order MessageSet.
824  // This is a very rare case: all serializers will emit in-order
825  // MessageSets. To hit this case there has to be some kind of
826  // re-ordering proxy. We should eventually handle this case, but
827  // not today.
828  }
829  break;
830  }
831  }
832  }
833 
834  return &none; /* Unknown field. */
835 
836 found:
837  UPB_ASSERT(l->fields[idx].number == field_number);
838  *last_field_index = idx;
839  return &l->fields[idx];
840 }
841 
843 static const char* decode_wireval(upb_Decoder* d, const char* ptr,
844  const upb_MiniTable_Field* field,
845  int wire_type, wireval* val, int* op) {
846  switch (wire_type) {
848  ptr = decode_varint64(d, ptr, &val->uint64_val);
849  *op = varint_ops[field->descriptortype];
850  decode_munge(field->descriptortype, val);
851  return ptr;
852  case kUpb_WireType_32Bit:
853  memcpy(&val->uint32_val, ptr, 4);
855  *op = OP_SCALAR_LG2(2);
856  if (((1 << field->descriptortype) & FIXED32_OK_MASK) == 0) {
857  *op = OP_UNKNOWN;
858  }
859  return ptr + 4;
860  case kUpb_WireType_64Bit:
861  memcpy(&val->uint64_val, ptr, 8);
863  *op = OP_SCALAR_LG2(3);
864  if (((1 << field->descriptortype) & FIXED64_OK_MASK) == 0) {
865  *op = OP_UNKNOWN;
866  }
867  return ptr + 8;
869  int ndx = field->descriptortype;
870  uint64_t size;
872  ptr = decode_varint64(d, ptr, &size);
873  if (size >= INT32_MAX || ptr - d->end + (int32_t)size > d->limit) {
874  break; /* Length overflow. */
875  }
876  *op = delim_ops[ndx];
877  val->size = size;
878  return ptr;
879  }
881  val->uint32_val = field->number;
882  if (field->descriptortype == kUpb_FieldType_Group) {
883  *op = OP_SUBMSG;
884  } else if (field->descriptortype == TYPE_MSGSET_ITEM) {
885  *op = OP_MSGSET_ITEM;
886  } else {
887  *op = OP_UNKNOWN;
888  }
889  return ptr;
890  default:
891  break;
892  }
894 }
895 
897 static const char* decode_known(upb_Decoder* d, const char* ptr,
899  const upb_MiniTable_Field* field, int op,
900  wireval* val) {
901  const upb_MiniTable_Sub* subs = layout->subs;
902  uint8_t mode = field->mode;
903 
905  const upb_MiniTable_Extension* ext_layout =
908  _upb_Message_Getorcreateext(msg, ext_layout, &d->arena);
910  msg = &ext->data;
911  subs = &ext->ext->sub;
912  }
913 
914  switch (mode & kUpb_FieldMode_Mask) {
916  return decode_toarray(d, ptr, msg, subs, field, val, op);
917  case kUpb_FieldMode_Map:
918  return decode_tomap(d, ptr, msg, subs, field, val);
920  return decode_tomsg(d, ptr, msg, subs, field, val, op);
921  default:
922  UPB_UNREACHABLE();
923  }
924 }
925 
926 static const char* decode_reverse_skip_varint(const char* ptr, uint32_t val) {
927  uint32_t seen = 0;
928  do {
929  ptr--;
930  seen <<= 7;
931  seen |= *ptr & 0x7f;
932  } while (seen != val);
933  return ptr;
934 }
935 
936 static const char* decode_unknown(upb_Decoder* d, const char* ptr,
937  upb_Message* msg, int field_number,
938  int wire_type, wireval val) {
939  if (field_number == 0) return decode_err(d, kUpb_DecodeStatus_Malformed);
940 
941  // Since unknown fields are the uncommon case, we do a little extra work here
942  // to walk backwards through the buffer to find the field start. This frees
943  // up a register in the fast paths (when the field is known), which leads to
944  // significant speedups in benchmarks.
945  const char* start = ptr;
946 
947  if (wire_type == kUpb_WireType_Delimited) ptr += val.size;
948  if (msg) {
949  switch (wire_type) {
952  start--;
953  while (start[-1] & 0x80) start--;
954  break;
955  case kUpb_WireType_32Bit:
956  start -= 4;
957  break;
958  case kUpb_WireType_64Bit:
959  start -= 8;
960  break;
961  default:
962  break;
963  }
964 
965  assert(start == d->debug_valstart);
966  uint32_t tag = ((uint32_t)field_number << 3) | wire_type;
968  assert(start == d->debug_tagstart);
969 
970  if (wire_type == kUpb_WireType_StartGroup) {
971  d->unknown = start;
972  d->unknown_msg = msg;
973  ptr = decode_group(d, ptr, NULL, NULL, field_number);
974  start = d->unknown;
975  d->unknown_msg = NULL;
976  d->unknown = NULL;
977  }
978  if (!_upb_Message_AddUnknown(msg, start, ptr - start, &d->arena)) {
980  }
981  } else if (wire_type == kUpb_WireType_StartGroup) {
982  ptr = decode_group(d, ptr, NULL, NULL, field_number);
983  }
984  return ptr;
985 }
986 
988 static const char* decode_msg(upb_Decoder* d, const char* ptr, upb_Message* msg,
989  const upb_MiniTable* layout) {
990  int last_field_index = 0;
991 
992 #if UPB_FASTTABLE
993  // The first time we want to skip fast dispatch, because we may have just been
994  // invoked by the fast parser to handle a case that it bailed on.
995  if (!decode_isdone(d, &ptr)) goto nofast;
996 #endif
997 
998  while (!decode_isdone(d, &ptr)) {
999  uint32_t tag;
1000  const upb_MiniTable_Field* field;
1001  int field_number;
1002  int wire_type;
1003  wireval val;
1004  int op;
1005 
1006  if (decode_tryfastdispatch(d, &ptr, msg, layout)) break;
1007 
1008 #if UPB_FASTTABLE
1009  nofast:
1010 #endif
1011 
1012 #ifndef NDEBUG
1013  d->debug_tagstart = ptr;
1014 #endif
1015 
1016  UPB_ASSERT(ptr < d->limit_ptr);
1017  ptr = decode_tag(d, ptr, &tag);
1018  field_number = tag >> 3;
1019  wire_type = tag & 7;
1020 
1021 #ifndef NDEBUG
1022  d->debug_valstart = ptr;
1023 #endif
1024 
1025  if (wire_type == kUpb_WireType_EndGroup) {
1026  d->end_group = field_number;
1027  return ptr;
1028  }
1029 
1030  field = decode_findfield(d, layout, field_number, &last_field_index);
1031  ptr = decode_wireval(d, ptr, field, wire_type, &val, &op);
1032 
1033  if (op >= 0) {
1034  ptr = decode_known(d, ptr, msg, layout, field, op, &val);
1035  } else {
1036  switch (op) {
1037  case OP_UNKNOWN:
1038  ptr = decode_unknown(d, ptr, msg, field_number, wire_type, val);
1039  break;
1040  case OP_MSGSET_ITEM:
1041  ptr = decode_msgset(d, ptr, msg, layout);
1042  break;
1043  case OP_MSGSET_TYPEID: {
1045  d->extreg, layout->subs[0].submsg, val.uint64_val);
1046  if (ext) ((upb_MiniTable*)layout)->fields = &ext->field;
1047  break;
1048  }
1049  }
1050  }
1051  }
1052 
1053  return UPB_UNLIKELY(layout && layout->required_count)
1055  : ptr;
1056 }
1057 
1058 const char* fastdecode_generic(struct upb_Decoder* d, const char* ptr,
1060  uint64_t hasbits, uint64_t data) {
1061  (void)data;
1062  *(uint32_t*)msg |= hasbits;
1063  return decode_msg(d, ptr, msg, decode_totablep(table));
1064 }
1065 
1066 static upb_DecodeStatus decode_top(struct upb_Decoder* d, const char* buf,
1067  void* msg, const upb_MiniTable* l) {
1068  if (!decode_tryfastdispatch(d, &buf, msg, l)) {
1069  decode_msg(d, buf, msg, l);
1070  }
1071  if (d->end_group != DECODE_NOGROUP) return kUpb_DecodeStatus_Malformed;
1072  if (d->missing_required) return kUpb_DecodeStatus_MissingRequired;
1073  return kUpb_DecodeStatus_Ok;
1074 }
1075 
1076 upb_DecodeStatus upb_Decode(const char* buf, size_t size, void* msg,
1077  const upb_MiniTable* l,
1078  const upb_ExtensionRegistry* extreg, int options,
1079  upb_Arena* arena) {
1081  unsigned depth = (unsigned)options >> 16;
1082 
1083  if (size <= 16) {
1084  memset(&state.patch, 0, 32);
1085  if (size) memcpy(&state.patch, buf, size);
1086  buf = state.patch;
1087  state.end = buf + size;
1088  state.limit = 0;
1089  options &= ~kUpb_DecodeOption_AliasString; // Can't alias patch buf.
1090  } else {
1091  state.end = buf + size - 16;
1092  state.limit = 16;
1093  }
1094 
1095  state.extreg = extreg;
1096  state.limit_ptr = state.end;
1097  state.unknown_msg = NULL;
1098  state.depth = depth ? depth : 64;
1099  state.end_group = DECODE_NOGROUP;
1100  state.options = (uint16_t)options;
1101  state.missing_required = false;
1102  state.arena.head = arena->head;
1103  state.arena.last_size = arena->last_size;
1104  state.arena.cleanup_metadata = arena->cleanup_metadata;
1105  state.arena.parent = arena;
1106 
1109  status = decode_top(&state, buf, msg, l);
1110  }
1111 
1112  arena->head.ptr = state.arena.head.ptr;
1113  arena->head.end = state.arena.head.end;
1114  arena->cleanup_metadata = state.arena.cleanup_metadata;
1115  return status;
1116 }
1117 
1118 #undef OP_UNKNOWN
1119 #undef OP_SKIP
1120 #undef OP_SCALAR_LG2
1121 #undef OP_FIXPCK_LG2
1122 #undef OP_VARPCK_LG2
1123 #undef OP_STRING
1124 #undef OP_BYTES
1125 #undef OP_SUBMSG
xds_interop_client.str
str
Definition: xds_interop_client.py:487
upb_MiniTable_requiredmask
UPB_INLINE uint64_t upb_MiniTable_requiredmask(const upb_MiniTable *l)
Definition: msg_internal.h:223
ptr
char * ptr
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:45
upb_Array::size
size_t size
Definition: msg_internal.h:427
decode_wireval
static const UPB_FORCEINLINE char * decode_wireval(upb_Decoder *d, const char *ptr, const upb_MiniTable_Field *field, int wire_type, wireval *val, int *op)
Definition: decode.c:843
wireval::uint64_val
uint64_t uint64_val
Definition: php-upb.c:395
upb_internal.h
kUpb_WireType_Delimited
@ kUpb_WireType_Delimited
Definition: upb/upb/upb.h:277
kUpb_DecodeStatus_MissingRequired
@ kUpb_DecodeStatus_MissingRequired
Definition: decode.h:80
grpc::testing::val1
const char val1[]
Definition: client_context_test_peer_test.cc:34
kUpb_FieldType_SInt64
@ kUpb_FieldType_SInt64
Definition: upb/upb/upb.h:326
kUpb_FieldType_SFixed64
@ kUpb_FieldType_SFixed64
Definition: upb/upb/upb.h:324
dst
static const char dst[]
Definition: test-fs-copyfile.c:37
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
desctype_to_mapsize
static const uint8_t desctype_to_mapsize[]
Definition: decode.c:64
_UPB_MSGSET_TYPEID
@ _UPB_MSGSET_TYPEID
Definition: msg_internal.h:181
upb_MiniTable_Sub
Definition: msg_internal.h:154
kUpb_FieldType_SInt32
@ kUpb_FieldType_SInt32
Definition: upb/upb/upb.h:325
FIXED64_OK_MASK
static const unsigned FIXED64_OK_MASK
Definition: decode.c:90
decode_internal.h
memset
return memset(p, 0, total)
upb_Decoder
Definition: decode_internal.h:48
OP_MSGSET_TYPEID
#define OP_MSGSET_TYPEID
Definition: decode.c:102
OP_STRING
#define OP_STRING
Definition: decode.c:105
UPB_UNLIKELY
#define UPB_UNLIKELY(x)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:62
upb_MiniTable::fields
const upb_MiniTable_Field * fields
Definition: msg_internal.h:187
kUpb_FieldMode_Mask
#define kUpb_FieldMode_Mask
Definition: msg_internal.h:90
upb_MiniTable_Enum
Definition: msg_internal.h:136
upb_MiniTable_Field
Definition: msg_internal.h:71
uint16_t
unsigned short uint16_t
Definition: stdint-msvc2008.h:79
DECODE_NOGROUP
#define DECODE_NOGROUP
Definition: php-upb.h:1770
decode_poplimit
UPB_INLINE void decode_poplimit(upb_decstate *d, const char *ptr, int saved_delta)
Definition: php-upb.h:1908
decode_vret
Definition: php-upb.c:447
upb_Decode
upb_DecodeStatus upb_Decode(const char *buf, size_t size, void *msg, const upb_MiniTable *l, const upb_ExtensionRegistry *extreg, int options, upb_Arena *arena)
Definition: decode.c:1076
kUpb_DecodeStatus_BadUtf8
@ kUpb_DecodeStatus_BadUtf8
Definition: decode.h:75
ext
void * ext
Definition: x509v3.h:87
OP_ENUM
#define OP_ENUM
Definition: decode.c:104
decode_munge_int32
static void decode_munge_int32(wireval *val)
Definition: decode.c:269
string.h
upb_MiniTable_Sub::submsg
const struct upb_MiniTable * submsg
Definition: msg_internal.h:155
options
double_dict options[]
Definition: capstone_test.c:55
desctype_to_elem_size_lg2
static const uint8_t desctype_to_elem_size_lg2[]
Definition: decode.c:41
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
decode_isdonefallback
const UPB_NOINLINE char * decode_isdonefallback(upb_Decoder *d, const char *ptr, int overrun)
Definition: decode.c:307
upb_MiniTable_Extension
Definition: msg_internal.h:202
_upb_Message_New_inl
UPB_INLINE upb_Message * _upb_Message_New_inl(const upb_MiniTable *l, upb_Arena *a)
Definition: msg_internal.h:287
elem
Timer elem
Definition: event_engine/iomgr_event_engine/timer_heap_test.cc:109
kUpb_DecodeStatus_Ok
@ kUpb_DecodeStatus_Ok
Definition: decode.h:72
_upb_sethas_field
UPB_INLINE void _upb_sethas_field(const upb_msg *msg, const upb_msglayout_field *f)
Definition: php-upb.h:1291
upb_Message_GetUnknown
const char * upb_Message_GetUnknown(const upb_Message *msg, size_t *len)
Definition: msg.c:101
UPB_UNREACHABLE
#define UPB_UNREACHABLE()
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:145
decode_enum_toarray
static const UPB_NOINLINE char * decode_enum_toarray(upb_Decoder *d, const char *ptr, upb_Message *msg, upb_Array *arr, const upb_MiniTable_Sub *subs, const upb_MiniTable_Field *field, wireval *val)
Definition: decode.c:431
UINT32_MAX
#define UINT32_MAX
Definition: stdint-msvc2008.h:142
UPB_SETJMP
#define UPB_SETJMP(buf)
Definition: php-upb.c:163
decode_varint_packed
static const UPB_FORCEINLINE char * decode_varint_packed(upb_Decoder *d, const char *ptr, upb_Array *arr, wireval *val, const upb_MiniTable_Field *field, int lg2)
Definition: decode.c:488
_upb_Message_Getorcreateext
upb_Message_Extension * _upb_Message_Getorcreateext(upb_Message *msg, const upb_MiniTable_Extension *e, upb_Arena *arena)
Definition: msg.c:156
status
absl::Status status
Definition: rls.cc:251
kUpb_FieldType_SFixed32
@ kUpb_FieldType_SFixed32
Definition: upb/upb/upb.h:323
upb_MiniTable
Definition: msg_internal.h:185
decode_known
static const UPB_FORCEINLINE char * decode_known(upb_Decoder *d, const char *ptr, upb_Message *msg, const upb_MiniTable *layout, const upb_MiniTable_Field *field, int op, wireval *val)
Definition: decode.c:897
mode
const char int mode
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:135
kUpb_DecodeStatus_MaxDepthExceeded
@ kUpb_DecodeStatus_MaxDepthExceeded
Definition: decode.h:76
kUpb_DecodeStatus_Malformed
@ kUpb_DecodeStatus_Malformed
Definition: decode.h:73
decode_totable
UPB_INLINE intptr_t decode_totable(const upb_msglayout *tablep)
Definition: php-upb.h:1820
_upb_Map_Set
UPB_INLINE bool _upb_Map_Set(upb_Map *map, const void *key, size_t key_size, void *val, size_t val_size, upb_Arena *a)
Definition: msg_internal.h:682
decode_totablep
const UPB_INLINE upb_msglayout * decode_totablep(intptr_t table)
Definition: php-upb.h:1824
decode_longvarint64
static UPB_NOINLINE decode_vret decode_longvarint64(const char *ptr, uint64_t val)
Definition: decode.c:221
UPB_PTR_AT
#define UPB_PTR_AT(msg, ofs, type)
Definition: php-upb.c:71
decode_newsubmsg
static upb_Message * decode_newsubmsg(upb_Decoder *d, const upb_MiniTable_Sub *subs, const upb_MiniTable_Field *field)
Definition: decode.c:299
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
map
zval * map
Definition: php/ext/google/protobuf/encode_decode.c:480
decode_toarray
static const char * decode_toarray(upb_Decoder *d, const char *ptr, upb_Message *msg, const upb_MiniTable_Sub *subs, const upb_MiniTable_Field *field, wireval *val, int op)
Definition: decode.c:537
arena
grpc_core::ScopedArenaPtr arena
Definition: binder_transport_test.cc:237
kUpb_LabelFlags_IsExtension
@ kUpb_LabelFlags_IsExtension
Definition: msg_internal.h:95
decode_msgset
static const char * decode_msgset(upb_Decoder *d, const char *ptr, upb_Message *msg, const upb_MiniTable *layout)
Definition: decode.c:746
upb_MapEntry::k
union upb_MapEntry::@708 k
_UPB_MSGSET_ITEM
@ _UPB_MSGSET_ITEM
Definition: msg_internal.h:180
kUpb_FieldType_Double
@ kUpb_FieldType_Double
Definition: upb/upb/upb.h:309
kUpb_FieldType_Bool
@ kUpb_FieldType_Bool
Definition: upb/upb/upb.h:316
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
decode_verifyutf8
static void decode_verifyutf8(upb_Decoder *d, const char *buf, int len)
Definition: decode.c:202
kUpb_FieldType_Float
@ kUpb_FieldType_Float
Definition: upb/upb/upb.h:310
ULL
#define ULL(x)
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/coded_stream_unittest.cc:57
_upb_array_ptr
UPB_INLINE void * _upb_array_ptr(upb_array *arr)
Definition: php-upb.h:1350
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
OP_UNKNOWN
#define OP_UNKNOWN
Definition: decode.c:100
start
static uint64_t start
Definition: benchmark-pound.c:74
kUpb_FieldType_UInt32
@ kUpb_FieldType_UInt32
Definition: upb/upb/upb.h:321
_upb_Message_New
upb_Message * _upb_Message_New(const upb_MiniTable *l, upb_Arena *a)
Definition: msg.c:44
kUpb_WireType_EndGroup
@ kUpb_WireType_EndGroup
Definition: upb/upb/upb.h:279
upb_MiniTable::subs
const upb_MiniTable_Sub * subs
Definition: msg_internal.h:186
decode_tomsg
static const char * decode_tomsg(upb_Decoder *d, const char *ptr, upb_Message *msg, const upb_MiniTable_Sub *subs, const upb_MiniTable_Field *field, wireval *val, int op)
Definition: decode.c:651
end
char * end
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1008
decode.h
TYPE_MSGSET_ITEM
#define TYPE_MSGSET_ITEM
Definition: decode.c:95
decode_vret::ptr
const char * ptr
Definition: php-upb.c:448
gen_stats_data.found
bool found
Definition: gen_stats_data.py:61
decode_group
static const UPB_FORCEINLINE char * decode_group(upb_Decoder *d, const char *ptr, upb_Message *submsg, const upb_MiniTable *subl, uint32_t number)
Definition: decode.c:355
decode_reverse_skip_varint
static const char * decode_reverse_skip_varint(const char *ptr, uint32_t val)
Definition: decode.c:926
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
tag
static void * tag(intptr_t t)
Definition: bad_client.cc:318
wireval::size
uint32_t size
Definition: php-upb.c:396
decode_checkrequired
const UPB_NOINLINE char * decode_checkrequired(upb_Decoder *d, const char *ptr, const upb_Message *msg, const upb_MiniTable *l)
Definition: decode.c:715
decode_msg
static const char * decode_msg(upb_Decoder *d, const char *ptr, upb_Message *msg, const upb_MiniTable *layout)
Definition: decode.c:988
_upb_array_realloc
bool _upb_array_realloc(upb_array *arr, size_t min_size, upb_arena *arena)
Definition: php-upb.c:1604
decode_verifyutf8_inl
UPB_INLINE bool decode_verifyutf8_inl(const char *buf, int len)
Definition: php-upb.h:1798
upb_Message_Extension
Definition: msg_internal.h:327
upb.h
setup.v
v
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:42
kUpb_FieldType_Enum
@ kUpb_FieldType_Enum
Definition: upb/upb/upb.h:322
upb_Array
Definition: msg_internal.h:424
UPB_SIZE
#define UPB_SIZE(size32, size64)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:32
upb_Arena_Malloc
UPB_INLINE void * upb_Arena_Malloc(upb_Arena *a, size_t size)
Definition: upb/upb/upb.h:222
OP_VARPCK_LG2
#define OP_VARPCK_LG2(n)
Definition: decode.c:110
decode_munge
static void decode_munge(int type, wireval *val)
Definition: decode.c:276
kUpb_FieldType_Fixed32
@ kUpb_FieldType_Fixed32
Definition: upb/upb/upb.h:315
grpc::testing::val2
const char val2[]
Definition: client_context_test_peer_test.cc:35
MessageLayout::fields
MessageField * fields
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:938
kUpb_WireType_Varint
@ kUpb_WireType_Varint
Definition: upb/upb/upb.h:275
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
upb_MapEntry::v
union upb_MapEntry::@709 v
upb_FieldMode_Get
UPB_INLINE upb_FieldMode upb_FieldMode_Get(const upb_MiniTable_Field *field)
Definition: msg_internal.h:110
decode_findfield
static const upb_MiniTable_Field * decode_findfield(upb_Decoder *d, const upb_MiniTable *l, uint32_t field_number, int *last_field_index)
Definition: decode.c:767
kUpb_DecodeOption_AliasString
@ kUpb_DecodeOption_AliasString
Definition: decode.h:47
number
int32_t number
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:850
_upb_Message_AddUnknown
bool _upb_Message_AddUnknown(upb_Message *msg, const char *data, size_t len, upb_Arena *arena)
Definition: msg.c:85
TYPE_COUNT
#define TYPE_COUNT
Definition: decode.c:97
fastdecode_loadtag
UPB_INLINE uint32_t fastdecode_loadtag(const char *ptr)
Definition: php-upb.h:1888
fastdecode_err
const char * fastdecode_err(upb_Decoder *d, int status)
Definition: decode.c:197
_upb_Map_New
upb_Map * _upb_Map_New(upb_Arena *a, size_t key_size, size_t value_size)
Definition: msg.c:236
intptr_t
_W64 signed int intptr_t
Definition: stdint-msvc2008.h:118
UPB_ASSERT
#define UPB_ASSERT(expr)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:135
kUpb_FieldMode_Map
@ kUpb_FieldMode_Map
Definition: msg_internal.h:84
decode_unknown
static const char * decode_unknown(upb_Decoder *d, const char *ptr, upb_Message *msg, int field_number, int wire_type, wireval val)
Definition: decode.c:936
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
upb_MiniTable_Field::offset
uint16_t offset
Definition: msg_internal.h:73
_upb_BigEndian_Swap64
UPB_INLINE uint64_t _upb_BigEndian_Swap64(uint64_t val)
Definition: upb/upb/upb.h:345
bm_speedup.scale
def scale(a, mul)
Definition: bm_speedup.py:24
_upb_IsLittleEndian
UPB_INLINE bool _upb_IsLittleEndian(void)
Definition: upb/upb/upb.h:331
layout
MessageLayout * layout
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:809
kUpb_ExtMode_Extendable
@ kUpb_ExtMode_Extendable
Definition: msg_internal.h:161
d
static const fe d
Definition: curve25519_tables.h:19
upb_MapEntry
Definition: msg_internal.h:593
upb_Message
void upb_Message
Definition: msg.h:49
n
int n
Definition: abseil-cpp/absl/container/btree_test.cc:1080
setup.idx
idx
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:197
msg
std::string msg
Definition: client_interceptors_end2end_test.cc:372
OP_FIXPCK_LG2
#define OP_FIXPCK_LG2(n)
Definition: decode.c:109
upb_Decode_AddUnknownVarints
static void upb_Decode_AddUnknownVarints(upb_Decoder *d, upb_Message *msg, uint32_t val1, uint32_t val2)
Definition: decode.c:388
upb_DecodeStatus
upb_DecodeStatus
Definition: decode.h:71
OP_BYTES
#define OP_BYTES
Definition: decode.c:106
upb_MapEntry::val
upb_value val
Definition: msg_internal.h:597
OP_SUBMSG
#define OP_SUBMSG
Definition: decode.c:107
mem
void * mem
Definition: libc.cpp:91
upb_MiniTable_Field::descriptortype
uint8_t descriptortype
Definition: msg_internal.h:76
decode_tryfastdispatch
static UPB_FORCEINLINE bool decode_tryfastdispatch(upb_Decoder *d, const char **ptr, upb_Message *msg, const upb_MiniTable *layout)
Definition: decode.c:732
kUpb_FieldType_Fixed64
@ kUpb_FieldType_Fixed64
Definition: upb/upb/upb.h:314
decode_checkenum
static UPB_FORCEINLINE bool decode_checkenum(upb_Decoder *d, const char *ptr, upb_Message *msg, const upb_MiniTable_Enum *e, const upb_MiniTable_Field *field, wireval *val)
Definition: decode.c:420
ares::byte
unsigned char byte
Definition: ares-test.h:33
decode_isdonefallback_inl
const UPB_INLINE char * decode_isdonefallback_inl(upb_decstate *d, const char *ptr, int overrun)
Definition: php-upb.h:1829
decode_varint64
static const UPB_FORCEINLINE char * decode_varint64(upb_Decoder *d, const char *ptr, uint64_t *val)
Definition: decode.c:238
decode_enum_packed
static const UPB_NOINLINE char * decode_enum_packed(upb_Decoder *d, const char *ptr, upb_Message *msg, upb_Array *arr, const upb_MiniTable_Sub *subs, const upb_MiniTable_Field *field, wireval *val)
Definition: decode.c:511
kUpb_FieldMode_Scalar
@ kUpb_FieldMode_Scalar
Definition: msg_internal.h:86
UPB_MAPTYPE_STRING
#define UPB_MAPTYPE_STRING
Definition: php-upb.c:82
field
const FieldDescriptor * field
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/parser_unittest.cc:2692
kUpb_WireType_32Bit
@ kUpb_WireType_32Bit
Definition: upb/upb/upb.h:280
kUpb_ExtMode_IsMessageSet_ITEM
@ kUpb_ExtMode_IsMessageSet_ITEM
Definition: msg_internal.h:163
upb_StringView
Definition: upb/upb/upb.h:72
encode_varint32
static char * encode_varint32(uint32_t val, char *ptr)
Definition: decode.c:378
wireval::uint32_val
uint32_t uint32_val
Definition: php-upb.c:394
UPB_LIKELY
#define UPB_LIKELY(x)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:61
count
int * count
Definition: bloaty/third_party/googletest/googlemock/test/gmock_stress_test.cc:96
decode_tosubmsg
static const UPB_FORCEINLINE char * decode_tosubmsg(upb_Decoder *d, const char *ptr, upb_Message *submsg, const upb_MiniTable_Sub *subs, const upb_MiniTable_Field *field, int size)
Definition: decode.c:346
decode_readstr
static const char * decode_readstr(upb_Decoder *d, const char *ptr, int size, upb_StringView *str)
Definition: decode.c:317
OP_SCALAR_LG2
#define OP_SCALAR_LG2(n)
Definition: decode.c:103
ret
UniquePtr< SSL_SESSION > ret
Definition: ssl_x509.cc:1029
kUpb_FieldType_Group
@ kUpb_FieldType_Group
Definition: upb/upb/upb.h:318
kUpb_DecodeOption_CheckRequired
@ kUpb_DecodeOption_CheckRequired
Definition: decode.h:66
upb_Array::len
size_t len
Definition: msg_internal.h:426
decode_top
static upb_DecodeStatus decode_top(struct upb_Decoder *d, const char *buf, void *msg, const upb_MiniTable *l)
Definition: decode.c:1066
kUpb_ExtMode_IsMessageSet
@ kUpb_ExtMode_IsMessageSet
Definition: msg_internal.h:162
decode_tosubmsg2
static const UPB_FORCEINLINE char * decode_tosubmsg2(upb_Decoder *d, const char *ptr, upb_Message *submsg, const upb_MiniTable *subl, int size)
Definition: decode.c:332
_upb_Array_New
UPB_INLINE upb_Array * _upb_Array_New(upb_Arena *a, size_t init_size, int elem_size_lg2)
Definition: msg_internal.h:451
fastdecode_generic
const char * fastdecode_generic(struct upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, uint64_t hasbits, uint64_t data)
Definition: decode.c:1058
decode_isdone
UPB_INLINE bool decode_isdone(upb_decstate *d, const char **ptr)
Definition: php-upb.h:1859
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
UPB_NORETURN
#define UPB_NORETURN
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:79
kUpb_DecodeStatus_OutOfMemory
@ kUpb_DecodeStatus_OutOfMemory
Definition: decode.h:74
decode_tag
static const UPB_FORCEINLINE char * decode_tag(upb_Decoder *d, const char *ptr, uint32_t *val)
Definition: decode.c:253
varint_ops
static const int8_t varint_ops[]
Definition: decode.c:113
_upb_BigEndian_Swap32
UPB_INLINE uint32_t _upb_BigEndian_Swap32(uint32_t val)
Definition: upb/upb/upb.h:336
decode_err
static UPB_NORETURN void * decode_err(upb_Decoder *d, upb_DecodeStatus status)
Definition: decode.c:192
kUpb_FieldType_Message
@ kUpb_FieldType_Message
Definition: upb/upb/upb.h:319
upb_Map
Definition: msg_internal.h:581
_UPB_MSGSET_MESSAGE
@ _UPB_MSGSET_MESSAGE
Definition: msg_internal.h:182
table
uint8_t table[256]
Definition: hpack_parser.cc:456
_upb_extreg_get
const upb_msglayout_field * _upb_extreg_get(const upb_extreg *r, const upb_msglayout *l, uint32_t num)
Definition: php-upb.c:1835
int8_t
signed char int8_t
Definition: stdint-msvc2008.h:75
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
decode_pushlimit
UPB_INLINE int decode_pushlimit(upb_decstate *d, const char *ptr, int size)
Definition: php-upb.h:1898
run_grpclb_interop_tests.l
dictionary l
Definition: run_grpclb_interop_tests.py:410
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
kUpb_FieldType_Int32
@ kUpb_FieldType_Int32
Definition: upb/upb/upb.h:313
INT32_MAX
#define INT32_MAX
Definition: stdint-msvc2008.h:137
mkowners.depth
depth
Definition: mkowners.py:114
int32_t
signed int int32_t
Definition: stdint-msvc2008.h:77
seen
bool * seen
Definition: async_end2end_test.cc:198
TYPE_MSGSET_TYPE_ID
#define TYPE_MSGSET_TYPE_ID
Definition: decode.c:96
kUpb_FieldMode_Array
@ kUpb_FieldMode_Array
Definition: msg_internal.h:85
subs
template_param_type subs
Definition: cxa_demangle.cpp:4906
FIXED32_OK_MASK
static const unsigned FIXED32_OK_MASK
Definition: decode.c:86
op
static grpc_op * op
Definition: test/core/fling/client.cc:47
UPB_FORCEINLINE
#define UPB_FORCEINLINE
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:77
OP_MSGSET_ITEM
#define OP_MSGSET_ITEM
Definition: decode.c:101
decode_tomap
static const char * decode_tomap(upb_Decoder *d, const char *ptr, upb_Message *msg, const upb_MiniTable_Sub *subs, const upb_MiniTable_Field *field, wireval *val)
Definition: decode.c:603
upb_Arena
Definition: upb_internal.h:36
decode_togroup
static const UPB_FORCEINLINE char * decode_togroup(upb_Decoder *d, const char *ptr, upb_Message *submsg, const upb_MiniTable_Sub *subs, const upb_MiniTable_Field *field)
Definition: decode.c:370
decode_reserve
static bool decode_reserve(upb_Decoder *d, upb_Array *arr, size_t elem)
Definition: decode.c:207
UPB_NOINLINE
#define UPB_NOINLINE
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:78
_upb_oneofcase_field
UPB_INLINE uint32_t * _upb_oneofcase_field(upb_msg *msg, const upb_msglayout_field *f)
Definition: php-upb.h:1316
UPB_LONGJMP
#define UPB_LONGJMP(buf, val)
Definition: php-upb.c:164
upb_ExtensionRegistry
Definition: msg.c:372
OP_PACKED_ENUM
#define OP_PACKED_ENUM
Definition: decode.c:111
decode_fixed_packed
static const UPB_FORCEINLINE char * decode_fixed_packed(upb_Decoder *d, const char *ptr, upb_Array *arr, wireval *val, const upb_MiniTable_Field *field, int lg2)
Definition: decode.c:445
kUpb_WireType_64Bit
@ kUpb_WireType_64Bit
Definition: upb/upb/upb.h:276
kUpb_WireType_StartGroup
@ kUpb_WireType_StartGroup
Definition: upb/upb/upb.h:278
wireval
Definition: php-upb.c:392
wireval::bool_val
bool bool_val
Definition: php-upb.c:393
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
state
static struct rpc_state state
Definition: bad_server_response_test.cc:87
delim_ops
static const int8_t delim_ops[]
Definition: decode.c:137
decode_checkenum_slow
static UPB_NOINLINE bool decode_checkenum_slow(upb_Decoder *d, const char *ptr, upb_Message *msg, const upb_MiniTable_Enum *e, const upb_MiniTable_Field *field, uint32_t v)
Definition: decode.c:401
decode_vret::val
uint64_t val
Definition: php-upb.c:449


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