encode.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 /* We encode backwards, to avoid pre-computing lengths (one-pass encode). */
29 
30 #include "upb/encode.h"
31 
32 #include <setjmp.h>
33 #include <string.h>
34 
35 #include "upb/msg_internal.h"
36 #include "upb/upb.h"
37 
38 /* Must be last. */
39 #include "upb/port_def.inc"
40 
41 #define UPB_PB_VARINT_MAX_LEN 10
42 
44 static size_t encode_varint64(uint64_t val, char* buf) {
45  size_t i = 0;
46  do {
47  uint8_t byte = val & 0x7fU;
48  val >>= 7;
49  if (val) byte |= 0x80U;
50  buf[i++] = byte;
51  } while (val);
52  return i;
53 }
54 
56  return ((uint32_t)n << 1) ^ (n >> 31);
57 }
59  return ((uint64_t)n << 1) ^ (n >> 63);
60 }
61 
62 typedef struct {
63  jmp_buf err;
65  char *buf, *ptr, *limit;
66  int options;
67  int depth;
68  _upb_mapsorter sorter;
69 } upb_encstate;
70 
71 static size_t upb_roundup_pow2(size_t bytes) {
72  size_t ret = 128;
73  while (ret < bytes) {
74  ret *= 2;
75  }
76  return ret;
77 }
78 
79 UPB_NORETURN static void encode_err(upb_encstate* e) { UPB_LONGJMP(e->err, 1); }
80 
82 static void encode_growbuffer(upb_encstate* e, size_t bytes) {
83  size_t old_size = e->limit - e->buf;
84  size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr));
85  char* new_buf = upb_realloc(e->alloc, e->buf, old_size, new_size);
86 
87  if (!new_buf) encode_err(e);
88 
89  /* We want previous data at the end, realloc() put it at the beginning. */
90  if (old_size > 0) {
91  memmove(new_buf + new_size - old_size, e->buf, old_size);
92  }
93 
94  e->ptr = new_buf + new_size - (e->limit - e->ptr);
95  e->limit = new_buf + new_size;
96  e->buf = new_buf;
97 
98  e->ptr -= bytes;
99 }
100 
101 /* Call to ensure that at least "bytes" bytes are available for writing at
102  * e->ptr. Returns false if the bytes could not be allocated. */
104 static void encode_reserve(upb_encstate* e, size_t bytes) {
105  if ((size_t)(e->ptr - e->buf) < bytes) {
107  return;
108  }
109 
110  e->ptr -= bytes;
111 }
112 
113 /* Writes the given bytes to the buffer, handling reserve/advance. */
114 static void encode_bytes(upb_encstate* e, const void* data, size_t len) {
115  if (len == 0) return; /* memcpy() with zero size is UB */
116  encode_reserve(e, len);
117  memcpy(e->ptr, data, len);
118 }
119 
120 static void encode_fixed64(upb_encstate* e, uint64_t val) {
121  val = _upb_BigEndian_Swap64(val);
122  encode_bytes(e, &val, sizeof(uint64_t));
123 }
124 
125 static void encode_fixed32(upb_encstate* e, uint32_t val) {
126  val = _upb_BigEndian_Swap32(val);
127  encode_bytes(e, &val, sizeof(uint32_t));
128 }
129 
132  size_t len;
133  char* start;
134 
136  len = encode_varint64(val, e->ptr);
137  start = e->ptr + UPB_PB_VARINT_MAX_LEN - len;
138  memmove(start, e->ptr, len);
139  e->ptr = start;
140 }
141 
143 static void encode_varint(upb_encstate* e, uint64_t val) {
144  if (val < 128 && e->ptr != e->buf) {
145  --e->ptr;
146  *e->ptr = val;
147  } else {
148  encode_longvarint(e, val);
149  }
150 }
151 
152 static void encode_double(upb_encstate* e, double d) {
153  uint64_t u64;
154  UPB_ASSERT(sizeof(double) == sizeof(uint64_t));
155  memcpy(&u64, &d, sizeof(uint64_t));
156  encode_fixed64(e, u64);
157 }
158 
159 static void encode_float(upb_encstate* e, float d) {
160  uint32_t u32;
161  UPB_ASSERT(sizeof(float) == sizeof(uint32_t));
162  memcpy(&u32, &d, sizeof(uint32_t));
163  encode_fixed32(e, u32);
164 }
165 
166 static void encode_tag(upb_encstate* e, uint32_t field_number,
167  uint8_t wire_type) {
168  encode_varint(e, (field_number << 3) | wire_type);
169 }
170 
171 static void encode_fixedarray(upb_encstate* e, const upb_Array* arr,
172  size_t elem_size, uint32_t tag) {
173  size_t bytes = arr->len * elem_size;
174  const char* data = _upb_array_constptr(arr);
175  const char* ptr = data + bytes - elem_size;
176 
177  if (tag || !_upb_IsLittleEndian()) {
178  while (true) {
179  if (elem_size == 4) {
180  uint32_t val;
181  memcpy(&val, ptr, sizeof(val));
182  val = _upb_BigEndian_Swap32(val);
183  encode_bytes(e, &val, elem_size);
184  } else {
185  UPB_ASSERT(elem_size == 8);
186  uint64_t val;
187  memcpy(&val, ptr, sizeof(val));
188  val = _upb_BigEndian_Swap64(val);
189  encode_bytes(e, &val, elem_size);
190  }
191 
192  if (tag) encode_varint(e, tag);
193  if (ptr == data) break;
194  ptr -= elem_size;
195  }
196  } else {
197  encode_bytes(e, data, bytes);
198  }
199 }
200 
201 static void encode_message(upb_encstate* e, const upb_Message* msg,
202  const upb_MiniTable* m, size_t* size);
203 
204 static void encode_scalar(upb_encstate* e, const void* _field_mem,
205  const upb_MiniTable_Sub* subs,
206  const upb_MiniTable_Field* f) {
207  const char* field_mem = _field_mem;
208  int wire_type;
209 
210 #define CASE(ctype, type, wtype, encodeval) \
211  { \
212  ctype val = *(ctype*)field_mem; \
213  encode_##type(e, encodeval); \
214  wire_type = wtype; \
215  break; \
216  }
217 
218  switch (f->descriptortype) {
220  CASE(double, double, kUpb_WireType_64Bit, val);
222  CASE(float, float, kUpb_WireType_32Bit, val);
225  CASE(uint64_t, varint, kUpb_WireType_Varint, val);
227  CASE(uint32_t, varint, kUpb_WireType_Varint, val);
229  case kUpb_FieldType_Enum:
230  CASE(int32_t, varint, kUpb_WireType_Varint, (int64_t)val);
233  CASE(uint64_t, fixed64, kUpb_WireType_64Bit, val);
236  CASE(uint32_t, fixed32, kUpb_WireType_32Bit, val);
237  case kUpb_FieldType_Bool:
238  CASE(bool, varint, kUpb_WireType_Varint, val);
244  case kUpb_FieldType_Bytes: {
245  upb_StringView view = *(upb_StringView*)field_mem;
246  encode_bytes(e, view.data, view.size);
247  encode_varint(e, view.size);
248  wire_type = kUpb_WireType_Delimited;
249  break;
250  }
251  case kUpb_FieldType_Group: {
252  size_t size;
253  void* submsg = *(void**)field_mem;
254  const upb_MiniTable* subm = subs[f->submsg_index].submsg;
255  if (submsg == NULL) {
256  return;
257  }
258  if (--e->depth == 0) encode_err(e);
259  encode_tag(e, f->number, kUpb_WireType_EndGroup);
260  encode_message(e, submsg, subm, &size);
261  wire_type = kUpb_WireType_StartGroup;
262  e->depth++;
263  break;
264  }
265  case kUpb_FieldType_Message: {
266  size_t size;
267  void* submsg = *(void**)field_mem;
268  const upb_MiniTable* subm = subs[f->submsg_index].submsg;
269  if (submsg == NULL) {
270  return;
271  }
272  if (--e->depth == 0) encode_err(e);
273  encode_message(e, submsg, subm, &size);
274  encode_varint(e, size);
275  wire_type = kUpb_WireType_Delimited;
276  e->depth++;
277  break;
278  }
279  default:
280  UPB_UNREACHABLE();
281  }
282 #undef CASE
283 
284  encode_tag(e, f->number, wire_type);
285 }
286 
287 static void encode_array(upb_encstate* e, const upb_Message* msg,
288  const upb_MiniTable_Sub* subs,
289  const upb_MiniTable_Field* f) {
290  const upb_Array* arr = *UPB_PTR_AT(msg, f->offset, upb_Array*);
291  bool packed = f->mode & kUpb_LabelFlags_IsPacked;
292  size_t pre_len = e->limit - e->ptr;
293 
294  if (arr == NULL || arr->len == 0) {
295  return;
296  }
297 
298 #define VARINT_CASE(ctype, encode) \
299  { \
300  const ctype* start = _upb_array_constptr(arr); \
301  const ctype* ptr = start + arr->len; \
302  uint32_t tag = packed ? 0 : (f->number << 3) | kUpb_WireType_Varint; \
303  do { \
304  ptr--; \
305  encode_varint(e, encode); \
306  if (tag) encode_varint(e, tag); \
307  } while (ptr != start); \
308  } \
309  break;
310 
311 #define TAG(wire_type) (packed ? 0 : (f->number << 3 | wire_type))
312 
313  switch (f->descriptortype) {
315  encode_fixedarray(e, arr, sizeof(double), TAG(kUpb_WireType_64Bit));
316  break;
318  encode_fixedarray(e, arr, sizeof(float), TAG(kUpb_WireType_32Bit));
319  break;
323  break;
327  break;
334  case kUpb_FieldType_Enum:
336  case kUpb_FieldType_Bool:
337  VARINT_CASE(bool, *ptr);
343  case kUpb_FieldType_Bytes: {
345  const upb_StringView* ptr = start + arr->len;
346  do {
347  ptr--;
348  encode_bytes(e, ptr->data, ptr->size);
349  encode_varint(e, ptr->size);
350  encode_tag(e, f->number, kUpb_WireType_Delimited);
351  } while (ptr != start);
352  return;
353  }
354  case kUpb_FieldType_Group: {
355  const void* const* start = _upb_array_constptr(arr);
356  const void* const* ptr = start + arr->len;
357  const upb_MiniTable* subm = subs[f->submsg_index].submsg;
358  if (--e->depth == 0) encode_err(e);
359  do {
360  size_t size;
361  ptr--;
362  encode_tag(e, f->number, kUpb_WireType_EndGroup);
363  encode_message(e, *ptr, subm, &size);
365  } while (ptr != start);
366  e->depth++;
367  return;
368  }
369  case kUpb_FieldType_Message: {
370  const void* const* start = _upb_array_constptr(arr);
371  const void* const* ptr = start + arr->len;
372  const upb_MiniTable* subm = subs[f->submsg_index].submsg;
373  if (--e->depth == 0) encode_err(e);
374  do {
375  size_t size;
376  ptr--;
377  encode_message(e, *ptr, subm, &size);
378  encode_varint(e, size);
379  encode_tag(e, f->number, kUpb_WireType_Delimited);
380  } while (ptr != start);
381  e->depth++;
382  return;
383  }
384  }
385 #undef VARINT_CASE
386 
387  if (packed) {
388  encode_varint(e, e->limit - e->ptr - pre_len);
389  encode_tag(e, f->number, kUpb_WireType_Delimited);
390  }
391 }
392 
394  const upb_MiniTable* layout,
395  const upb_MapEntry* ent) {
396  const upb_MiniTable_Field* key_field = &layout->fields[0];
397  const upb_MiniTable_Field* val_field = &layout->fields[1];
398  size_t pre_len = e->limit - e->ptr;
399  size_t size;
400  encode_scalar(e, &ent->v, layout->subs, val_field);
401  encode_scalar(e, &ent->k, layout->subs, key_field);
402  size = (e->limit - e->ptr) - pre_len;
403  encode_varint(e, size);
405 }
406 
407 static void encode_map(upb_encstate* e, const upb_Message* msg,
408  const upb_MiniTable_Sub* subs,
409  const upb_MiniTable_Field* f) {
410  const upb_Map* map = *UPB_PTR_AT(msg, f->offset, const upb_Map*);
411  const upb_MiniTable* layout = subs[f->submsg_index].submsg;
412  UPB_ASSERT(layout->field_count == 2);
413 
414  if (map == NULL) return;
415 
416  if (e->options & kUpb_Encode_Deterministic) {
417  _upb_sortedmap sorted;
418  _upb_mapsorter_pushmap(&e->sorter, layout->fields[0].descriptortype, map,
419  &sorted);
420  upb_MapEntry ent;
421  while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) {
422  encode_mapentry(e, f->number, layout, &ent);
423  }
424  _upb_mapsorter_popmap(&e->sorter, &sorted);
425  } else {
427  upb_strtable_begin(&i, &map->table);
428  for (; !upb_strtable_done(&i); upb_strtable_next(&i)) {
430  const upb_value val = upb_strtable_iter_value(&i);
431  upb_MapEntry ent;
432  _upb_map_fromkey(key, &ent.k, map->key_size);
433  _upb_map_fromvalue(val, &ent.v, map->val_size);
434  encode_mapentry(e, f->number, layout, &ent);
435  }
436  }
437 }
438 
440  const upb_MiniTable_Sub* subs,
441  const upb_MiniTable_Field* f) {
442  if (f->presence == 0) {
443  /* Proto3 presence or map/array. */
444  const void* mem = UPB_PTR_AT(msg, f->offset, void);
445  switch (f->mode >> kUpb_FieldRep_Shift) {
446  case kUpb_FieldRep_1Byte: {
447  char ch;
448  memcpy(&ch, mem, 1);
449  return ch != 0;
450  }
451 #if UINTPTR_MAX == 0xffffffff
453 #endif
454  case kUpb_FieldRep_4Byte: {
455  uint32_t u32;
456  memcpy(&u32, mem, 4);
457  return u32 != 0;
458  }
459 #if UINTPTR_MAX != 0xffffffff
461 #endif
462  case kUpb_FieldRep_8Byte: {
463  uint64_t u64;
464  memcpy(&u64, mem, 8);
465  return u64 != 0;
466  }
468  const upb_StringView* str = (const upb_StringView*)mem;
469  return str->size != 0;
470  }
471  default:
472  UPB_UNREACHABLE();
473  }
474  } else if (f->presence > 0) {
475  /* Proto2 presence: hasbit. */
476  return _upb_hasbit_field(msg, f);
477  } else {
478  /* Field is in a oneof. */
479  return _upb_getoneofcase_field(msg, f) == f->number;
480  }
481 }
482 
483 static void encode_field(upb_encstate* e, const upb_Message* msg,
484  const upb_MiniTable_Sub* subs,
485  const upb_MiniTable_Field* field) {
486  switch (upb_FieldMode_Get(field)) {
488  encode_array(e, msg, subs, field);
489  break;
490  case kUpb_FieldMode_Map:
491  encode_map(e, msg, subs, field);
492  break;
494  encode_scalar(e, UPB_PTR_AT(msg, field->offset, void), subs, field);
495  break;
496  default:
497  UPB_UNREACHABLE();
498  }
499 }
500 
501 /* message MessageSet {
502  * repeated group Item = 1 {
503  * required int32 type_id = 2;
504  * required string message = 3;
505  * }
506  * } */
508  const upb_Message_Extension* ext) {
509  size_t size;
511  encode_message(e, ext->data.ptr, ext->ext->sub.submsg, &size);
512  encode_varint(e, size);
514  encode_varint(e, ext->ext->field.number);
517 }
518 
520  const upb_MiniTable* m, size_t* size) {
521  size_t pre_len = e->limit - e->ptr;
522 
523  if ((e->options & kUpb_Encode_CheckRequired) && m->required_count) {
524  uint64_t msg_head;
525  memcpy(&msg_head, msg, 8);
526  msg_head = _upb_BigEndian_Swap64(msg_head);
527  if (upb_MiniTable_requiredmask(m) & ~msg_head) {
528  encode_err(e);
529  }
530  }
531 
532  if ((e->options & kUpb_Encode_SkipUnknown) == 0) {
533  size_t unknown_size;
534  const char* unknown = upb_Message_GetUnknown(msg, &unknown_size);
535 
536  if (unknown) {
537  encode_bytes(e, unknown, unknown_size);
538  }
539  }
540 
541  if (m->ext != kUpb_ExtMode_NonExtendable) {
542  /* Encode all extensions together. Unlike C++, we do not attempt to keep
543  * these in field number order relative to normal fields or even to each
544  * other. */
545  size_t ext_count;
546  const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &ext_count);
547  if (ext_count) {
548  const upb_Message_Extension* end = ext + ext_count;
549  for (; ext != end; ext++) {
552  } else {
553  encode_field(e, &ext->data, &ext->ext->sub, &ext->ext->field);
554  }
555  }
556  }
557  }
558 
559  if (m->field_count) {
560  const upb_MiniTable_Field* f = &m->fields[m->field_count];
561  const upb_MiniTable_Field* first = &m->fields[0];
562  while (f != first) {
563  f--;
564  if (encode_shouldencode(e, msg, m->subs, f)) {
565  encode_field(e, msg, m->subs, f);
566  }
567  }
568  }
569 
570  *size = (e->limit - e->ptr) - pre_len;
571 }
572 
573 char* upb_Encode(const void* msg, const upb_MiniTable* l, int options,
574  upb_Arena* arena, size_t* size) {
575  upb_encstate e;
576  unsigned depth = (unsigned)options >> 16;
577 
578  e.alloc = upb_Arena_Alloc(arena);
579  e.buf = NULL;
580  e.limit = NULL;
581  e.ptr = NULL;
582  e.depth = depth ? depth : 64;
583  e.options = options;
584  _upb_mapsorter_init(&e.sorter);
585  char* ret = NULL;
586 
587  if (UPB_SETJMP(e.err)) {
588  *size = 0;
589  ret = NULL;
590  } else {
591  encode_message(&e, msg, l, size);
592  *size = e.limit - e.ptr;
593  if (*size == 0) {
594  static char ch;
595  ret = &ch;
596  } else {
597  UPB_ASSERT(e.ptr);
598  ret = e.ptr;
599  }
600  }
601 
602  _upb_mapsorter_destroy(&e.sorter);
603  return ret;
604 }
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
kUpb_WireType_Delimited
@ kUpb_WireType_Delimited
Definition: upb/upb/upb.h:277
kUpb_FieldRep_4Byte
@ kUpb_FieldRep_4Byte
Definition: msg_internal.h:101
kUpb_FieldType_SInt64
@ kUpb_FieldType_SInt64
Definition: upb/upb/upb.h:326
kUpb_FieldType_SFixed64
@ kUpb_FieldType_SFixed64
Definition: upb/upb/upb.h:324
encode_field
static void encode_field(upb_encstate *e, const upb_Message *msg, const upb_MiniTable_Sub *subs, const upb_MiniTable_Field *field)
Definition: encode.c:483
upb_MiniTable_Sub
Definition: msg_internal.h:154
upb_strtable_done
bool upb_strtable_done(const upb_strtable_iter *i)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:1645
kUpb_FieldType_SInt32
@ kUpb_FieldType_SInt32
Definition: upb/upb/upb.h:325
encode_longvarint
static UPB_NOINLINE void encode_longvarint(upb_encstate *e, uint64_t val)
Definition: encode.c:131
encode_map
static void encode_map(upb_encstate *e, const upb_Message *msg, const upb_MiniTable_Sub *subs, const upb_MiniTable_Field *f)
Definition: encode.c:407
encode_fixedarray
static void encode_fixedarray(upb_encstate *e, const upb_Array *arr, size_t elem_size, uint32_t tag)
Definition: encode.c:171
kUpb_Encode_Deterministic
@ kUpb_Encode_Deterministic
Definition: encode.h:51
UPB_UNLIKELY
#define UPB_UNLIKELY(x)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:62
kUpb_Encode_CheckRequired
@ kUpb_Encode_CheckRequired
Definition: encode.h:57
upb_MiniTable_Field
Definition: msg_internal.h:71
kUpb_Encode_SkipUnknown
@ kUpb_Encode_SkipUnknown
Definition: encode.h:54
encode_shouldencode
static bool encode_shouldencode(upb_encstate *e, const upb_Message *msg, const upb_MiniTable_Sub *subs, const upb_MiniTable_Field *f)
Definition: encode.c:439
kUpb_FieldType_UInt64
@ kUpb_FieldType_UInt64
Definition: upb/upb/upb.h:312
kUpb_LabelFlags_IsPacked
@ kUpb_LabelFlags_IsPacked
Definition: msg_internal.h:94
encode.h
upb_StringView::data
const char * data
Definition: upb/upb/upb.h:73
upb_value
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:681
ext
void * ext
Definition: x509v3.h:87
_upb_mapsorter
Definition: php-upb.h:1688
string.h
options
double_dict options[]
Definition: capstone_test.c:55
encode_mapentry
static void encode_mapentry(upb_encstate *e, uint32_t number, const upb_MiniTable *layout, const upb_MapEntry *ent)
Definition: encode.c:393
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
encode_fixed64
static void encode_fixed64(upb_encstate *e, uint64_t val)
Definition: encode.c:120
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
binary_size.new_size
def new_size
Definition: binary_size.py:124
error_ref_leak.err
err
Definition: error_ref_leak.py:35
UPB_SETJMP
#define UPB_SETJMP(buf)
Definition: php-upb.c:163
kUpb_FieldType_SFixed32
@ kUpb_FieldType_SFixed32
Definition: upb/upb/upb.h:323
encode_growbuffer
static UPB_NOINLINE void encode_growbuffer(upb_encstate *e, size_t bytes)
Definition: encode.c:82
upb_MiniTable
Definition: msg_internal.h:185
encode_array
static void encode_array(upb_encstate *e, const upb_Message *msg, const upb_MiniTable_Sub *subs, const upb_MiniTable_Field *f)
Definition: encode.c:287
encode_zz32
static uint32_t encode_zz32(int32_t n)
Definition: encode.c:55
_upb_mapsorter_pushmap
bool _upb_mapsorter_pushmap(_upb_mapsorter *s, upb_descriptortype_t key_type, const upb_map *map, _upb_sortedmap *sorted)
Definition: php-upb.c:1725
UPB_PTR_AT
#define UPB_PTR_AT(msg, ofs, type)
Definition: php-upb.c:71
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
map
zval * map
Definition: php/ext/google/protobuf/encode_decode.c:480
_upb_getoneofcase_field
UPB_INLINE uint32_t _upb_getoneofcase_field(const upb_msg *msg, const upb_msglayout_field *f)
Definition: php-upb.h:1321
upb_strtable_iter_key
const char * upb_strtable_iter_key(const upb_strtable_iter *i)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:1651
arena
grpc_core::ScopedArenaPtr arena
Definition: binder_transport_test.cc:237
upb_MapEntry::k
union upb_MapEntry::@708 k
kUpb_FieldType_Double
@ kUpb_FieldType_Double
Definition: upb/upb/upb.h:309
kUpb_FieldType_Bool
@ kUpb_FieldType_Bool
Definition: upb/upb/upb.h:316
kUpb_ExtMode_NonExtendable
@ kUpb_ExtMode_NonExtendable
Definition: msg_internal.h:160
upb_encstate
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:782
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
kUpb_FieldType_Float
@ kUpb_FieldType_Float
Definition: upb/upb/upb.h:310
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
start
static uint64_t start
Definition: benchmark-pound.c:74
kUpb_FieldType_UInt32
@ kUpb_FieldType_UInt32
Definition: upb/upb/upb.h:321
_upb_Message_Getexts
const upb_Message_Extension * _upb_Message_Getexts(const upb_Message *msg, size_t *count)
Definition: msg.c:112
upb_strtable_begin
void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:1636
kUpb_WireType_EndGroup
@ kUpb_WireType_EndGroup
Definition: upb/upb/upb.h:279
kUpb_FieldRep_8Byte
@ kUpb_FieldRep_8Byte
Definition: msg_internal.h:104
autogen_x86imm.f
f
Definition: autogen_x86imm.py:9
encode_varint64
static UPB_NOINLINE size_t encode_varint64(uint64_t val, char *buf)
Definition: encode.c:44
end
char * end
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1008
kUpb_FieldType_String
@ kUpb_FieldType_String
Definition: upb/upb/upb.h:317
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
upb_realloc
UPB_INLINE void * upb_realloc(upb_alloc *alloc, void *ptr, size_t oldsize, size_t size)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:308
tag
static void * tag(intptr_t t)
Definition: bad_client.cc:318
upb_StringView::size
size_t size
Definition: upb/upb/upb.h:74
upb_Message_Extension
Definition: msg_internal.h:327
upb.h
kUpb_FieldType_Enum
@ kUpb_FieldType_Enum
Definition: upb/upb/upb.h:322
upb_Array
Definition: msg_internal.h:424
kUpb_FieldType_Fixed32
@ kUpb_FieldType_Fixed32
Definition: upb/upb/upb.h:315
encode_varint
static UPB_FORCEINLINE void encode_varint(upb_encstate *e, uint64_t val)
Definition: encode.c:143
_upb_map_fromvalue
UPB_INLINE void _upb_map_fromvalue(upb_value val, void *out, size_t size)
Definition: php-upb.h:1552
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
encode_float
static void encode_float(upb_encstate *e, float d)
Definition: encode.c:159
encode_msgset_item
static void encode_msgset_item(upb_encstate *e, const upb_Message_Extension *ext)
Definition: encode.c:507
number
int32_t number
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:850
kUpb_FieldRep_Shift
@ kUpb_FieldRep_Shift
Definition: msg_internal.h:106
encode_scalar
static void encode_scalar(upb_encstate *e, const void *_field_mem, const upb_MiniTable_Sub *subs, const upb_MiniTable_Field *f)
Definition: encode.c:204
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
upb_strtable_next
void upb_strtable_next(upb_strtable_iter *i)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:1641
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
_upb_BigEndian_Swap64
UPB_INLINE uint64_t _upb_BigEndian_Swap64(uint64_t val)
Definition: upb/upb/upb.h:345
_upb_IsLittleEndian
UPB_INLINE bool _upb_IsLittleEndian(void)
Definition: upb/upb/upb.h:331
_upb_sortedmap_next
UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter *s, const upb_map *map, _upb_sortedmap *sorted, upb_map_entry *ent)
Definition: php-upb.h:1717
layout
MessageLayout * layout
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:809
_upb_mapsorter_popmap
UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter *s, _upb_sortedmap *sorted)
Definition: php-upb.h:1713
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
_upb_hasbit_field
UPB_INLINE bool _upb_hasbit_field(const upb_msg *msg, const upb_msglayout_field *f)
Definition: php-upb.h:1286
_upb_mapsorter_destroy
UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter *s)
Definition: php-upb.h:1706
encode_tag
static void encode_tag(upb_encstate *e, uint32_t field_number, uint8_t wire_type)
Definition: encode.c:166
msg
std::string msg
Definition: client_interceptors_end2end_test.cc:372
upb_Arena_Alloc
UPB_INLINE upb_alloc * upb_Arena_Alloc(upb_Arena *a)
Definition: upb/upb/upb.h:192
mem
void * mem
Definition: libc.cpp:91
kUpb_FieldType_Fixed64
@ kUpb_FieldType_Fixed64
Definition: upb/upb/upb.h:314
TAG
#define TAG(wire_type)
ares::byte
unsigned char byte
Definition: ares-test.h:33
encode_zz64
static uint64_t encode_zz64(int64_t n)
Definition: encode.c:58
upb_Encode
char * upb_Encode(const void *msg, const upb_MiniTable *l, int options, upb_Arena *arena, size_t *size)
Definition: encode.c:573
kUpb_FieldMode_Scalar
@ kUpb_FieldMode_Scalar
Definition: msg_internal.h:86
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
key
const char * key
Definition: hpack_parser_table.cc:164
upb_StringView
Definition: upb/upb/upb.h:72
bytes
uint8 bytes[10]
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/coded_stream_unittest.cc:153
_upb_mapsorter_init
UPB_INLINE void _upb_mapsorter_init(_upb_mapsorter *s)
Definition: php-upb.h:1700
CASE
#define CASE(ctype, type, wtype, encodeval)
encode_bytes
static void encode_bytes(upb_encstate *e, const void *data, size_t len)
Definition: encode.c:114
ret
UniquePtr< SSL_SESSION > ret
Definition: ssl_x509.cc:1029
kUpb_FieldType_Group
@ kUpb_FieldType_Group
Definition: upb/upb/upb.h:318
encode_message
static void encode_message(upb_encstate *e, const upb_Message *msg, const upb_MiniTable *m, size_t *size)
Definition: encode.c:519
upb_Array::len
size_t len
Definition: msg_internal.h:426
first
StrT first
Definition: cxa_demangle.cpp:4884
kUpb_ExtMode_IsMessageSet
@ kUpb_ExtMode_IsMessageSet
Definition: msg_internal.h:162
VARINT_CASE
#define VARINT_CASE(ctype, encode)
encode_fixed32
static void encode_fixed32(upb_encstate *e, uint32_t val)
Definition: encode.c:125
UPB_NORETURN
#define UPB_NORETURN
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:79
encode_err
static UPB_NORETURN void encode_err(upb_encstate *e)
Definition: encode.c:79
upb_strtable_iter_value
upb_value upb_strtable_iter_value(const upb_strtable_iter *i)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:1663
UPB_PB_VARINT_MAX_LEN
#define UPB_PB_VARINT_MAX_LEN
Definition: encode.c:41
_upb_BigEndian_Swap32
UPB_INLINE uint32_t _upb_BigEndian_Swap32(uint32_t val)
Definition: upb/upb/upb.h:336
_upb_array_constptr
const UPB_INLINE void * _upb_array_constptr(const upb_array *arr)
Definition: php-upb.h:1340
kUpb_FieldType_Message
@ kUpb_FieldType_Message
Definition: upb/upb/upb.h:319
encode_double
static void encode_double(upb_encstate *e, double d)
Definition: encode.c:152
encode_reserve
static UPB_FORCEINLINE void encode_reserve(upb_encstate *e, size_t bytes)
Definition: encode.c:104
upb_Map
Definition: msg_internal.h:581
_upb_sortedmap
Definition: php-upb.h:1694
ch
char ch
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3621
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
kUpb_FieldRep_Pointer
@ kUpb_FieldRep_Pointer
Definition: msg_internal.h:103
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
upb_strtable_iter
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:1086
kUpb_FieldRep_1Byte
@ kUpb_FieldRep_1Byte
Definition: msg_internal.h:100
kUpb_FieldRep_StringView
@ kUpb_FieldRep_StringView
Definition: msg_internal.h:102
regress.m
m
Definition: regress/regress.py:25
mkowners.depth
depth
Definition: mkowners.py:114
int32_t
signed int int32_t
Definition: stdint-msvc2008.h:77
upb_alloc
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.h:299
_upb_map_fromkey
UPB_INLINE void _upb_map_fromkey(upb_strview key, void *out, size_t size)
Definition: php-upb.h:1531
kUpb_FieldMode_Array
@ kUpb_FieldMode_Array
Definition: msg_internal.h:85
kUpb_FieldType_Int64
@ kUpb_FieldType_Int64
Definition: upb/upb/upb.h:311
subs
template_param_type subs
Definition: cxa_demangle.cpp:4906
UPB_FORCEINLINE
#define UPB_FORCEINLINE
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:77
msg_internal.h
upb_Arena
Definition: upb_internal.h:36
UPB_NOINLINE
#define UPB_NOINLINE
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:78
binary_size.old_size
old_size
Definition: binary_size.py:125
alloc
std::allocator< int > alloc
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:87
upb_roundup_pow2
static size_t upb_roundup_pow2(size_t bytes)
Definition: encode.c:71
UPB_LONGJMP
#define UPB_LONGJMP(buf, val)
Definition: php-upb.c:164
kUpb_WireType_64Bit
@ kUpb_WireType_64Bit
Definition: upb/upb/upb.h:276
kUpb_WireType_StartGroup
@ kUpb_WireType_StartGroup
Definition: upb/upb/upb.h:278
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
kUpb_FieldType_Bytes
@ kUpb_FieldType_Bytes
Definition: upb/upb/upb.h:320


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