• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Amalgamated source file */
2 
3 // php.h intentionally defined NDEBUG. We have to define this macro in order to
4 // be used together with php.h
5 #ifndef NDEBUG
6 #define NDEBUG
7 #endif
8 
9 #include <stdint.h>
10 #ifndef UINTPTR_MAX
11 #error must include stdint.h first
12 #endif
13 
14 #if UINTPTR_MAX == 0xffffffff
15 #define UPB_SIZE(size32, size64) size32
16 #else
17 #define UPB_SIZE(size32, size64) size64
18 #endif
19 
20 #define UPB_FIELD_AT(msg, fieldtype, offset) \
21   *(fieldtype*)((const char*)(msg) + offset)
22 
23 #define UPB_READ_ONEOF(msg, fieldtype, offset, case_offset, case_val, default) \
24   UPB_FIELD_AT(msg, int, case_offset) == case_val                              \
25       ? UPB_FIELD_AT(msg, fieldtype, offset)                                   \
26       : default
27 
28 #define UPB_WRITE_ONEOF(msg, fieldtype, offset, value, case_offset, case_val) \
29   UPB_FIELD_AT(msg, int, case_offset) = case_val;                             \
30   UPB_FIELD_AT(msg, fieldtype, offset) = value;
31 /*
32 ** upb::Message is a representation for protobuf messages.
33 **
34 ** However it differs from other common representations like
35 ** google::protobuf::Message in one key way: it does not prescribe any
36 ** ownership between messages and submessages, and it relies on the
37 ** client to ensure that each submessage/array/map outlives its parent.
38 **
39 ** All messages, arrays, and maps live in an Arena.  If the entire message
40 ** tree is in the same arena, ensuring proper lifetimes is simple.  However
41 ** the client can mix arenas as long as they ensure that there are no
42 ** dangling pointers.
43 **
44 ** A client can access a upb::Message without knowing anything about
45 ** ownership semantics, but to create or mutate a message a user needs
46 ** to implement the memory management themselves.
47 **
48 ** TODO: UTF-8 checking?
49 **/
50 
51 #ifndef UPB_MSG_H_
52 #define UPB_MSG_H_
53 
54 #include <stdint.h>
55 #include <string.h>
56 /*
57 ** This file contains shared definitions that are widely used across upb.
58 **
59 ** This is a mixed C/C++ interface that offers a full API to both languages.
60 ** See the top-level README for more information.
61 */
62 
63 #ifndef UPB_H_
64 #define UPB_H_
65 
66 #include <assert.h>
67 #include <stdarg.h>
68 #include <stdbool.h>
69 #include <stddef.h>
70 #include <stdint.h>
71 
72 #ifdef __cplusplus
73 #include <memory>
74 namespace upb {
75 class Arena;
76 class Status;
77 template <int N> class InlinedArena;
78 }
79 #endif
80 
81 /* UPB_INLINE: inline if possible, emit standalone code if required. */
82 #ifdef __cplusplus
83 #define UPB_INLINE inline
84 #elif defined (__GNUC__)
85 #define UPB_INLINE static __inline__
86 #else
87 #define UPB_INLINE static
88 #endif
89 
90 /* Hints to the compiler about likely/unlikely branches. */
91 #define UPB_LIKELY(x) __builtin_expect((x),1)
92 
93 /* Define UPB_BIG_ENDIAN manually if you're on big endian and your compiler
94  * doesn't provide these preprocessor symbols. */
95 #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
96 #define UPB_BIG_ENDIAN
97 #endif
98 
99 /* Macros for function attributes on compilers that support them. */
100 #ifdef __GNUC__
101 #define UPB_FORCEINLINE __inline__ __attribute__((always_inline))
102 #define UPB_NOINLINE __attribute__((noinline))
103 #define UPB_NORETURN __attribute__((__noreturn__))
104 #else  /* !defined(__GNUC__) */
105 #define UPB_FORCEINLINE
106 #define UPB_NOINLINE
107 #define UPB_NORETURN
108 #endif
109 
110 #if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L
111 /* C99/C++11 versions. */
112 #include <stdio.h>
113 #define _upb_snprintf snprintf
114 #define _upb_vsnprintf vsnprintf
115 #define _upb_va_copy(a, b) va_copy(a, b)
116 #elif defined __GNUC__
117 /* A few hacky workarounds for functions not in C89.
118  * For internal use only!
119  * TODO(haberman): fix these by including our own implementations, or finding
120  * another workaround.
121  */
122 #define _upb_snprintf __builtin_snprintf
123 #define _upb_vsnprintf __builtin_vsnprintf
124 #define _upb_va_copy(a, b) __va_copy(a, b)
125 #else
126 #error Need implementations of [v]snprintf and va_copy
127 #endif
128 
129 #ifdef __cplusplus
130 #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || \
131     (defined(_MSC_VER) && _MSC_VER >= 1900)
132 // C++11 is present
133 #else
134 #error upb requires C++11 for C++ support
135 #endif
136 #endif
137 
138 #define UPB_MAX(x, y) ((x) > (y) ? (x) : (y))
139 #define UPB_MIN(x, y) ((x) < (y) ? (x) : (y))
140 
141 #define UPB_UNUSED(var) (void)var
142 
143 /* UPB_ASSERT(): in release mode, we use the expression without letting it be
144  * evaluated.  This prevents "unused variable" warnings. */
145 #ifdef NDEBUG
146 #define UPB_ASSERT(expr) do {} while (false && (expr))
147 #else
148 #define UPB_ASSERT(expr) assert(expr)
149 #endif
150 
151 /* UPB_ASSERT_DEBUGVAR(): assert that uses functions or variables that only
152  * exist in debug mode.  This turns into regular assert. */
153 #define UPB_ASSERT_DEBUGVAR(expr) assert(expr)
154 
155 #ifdef __GNUC__
156 #define UPB_UNREACHABLE() do { assert(0); __builtin_unreachable(); } while(0)
157 #else
158 #define UPB_UNREACHABLE() do { assert(0); } while(0)
159 #endif
160 
161 /* upb_status *****************************************************************/
162 
163 /* upb_status represents a success or failure status and error message.
164  * It owns no resources and allocates no memory, so it should work
165  * even in OOM situations. */
166 
167 /* The maximum length of an error message before it will get truncated. */
168 #define UPB_STATUS_MAX_MESSAGE 127
169 
170 typedef struct {
171   bool ok;
172   char msg[UPB_STATUS_MAX_MESSAGE];  /* Error message; NULL-terminated. */
173 } upb_status;
174 
175 #ifdef __cplusplus
176 extern "C" {
177 #endif
178 
179 const char *upb_status_errmsg(const upb_status *status);
180 bool upb_ok(const upb_status *status);
181 
182 /* Any of the functions that write to a status object allow status to be NULL,
183  * to support use cases where the function's caller does not care about the
184  * status message. */
185 void upb_status_clear(upb_status *status);
186 void upb_status_seterrmsg(upb_status *status, const char *msg);
187 void upb_status_seterrf(upb_status *status, const char *fmt, ...);
188 void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args);
189 
upb_status_setoom(upb_status * status)190 UPB_INLINE void upb_status_setoom(upb_status *status) {
191   upb_status_seterrmsg(status, "out of memory");
192 }
193 
194 #ifdef __cplusplus
195 }  /* extern "C" */
196 
197 class upb::Status {
198  public:
Status()199   Status() { upb_status_clear(&status_); }
200 
ptr()201   upb_status* ptr() { return &status_; }
202 
203   /* Returns true if there is no error. */
ok()204   bool ok() const { return upb_ok(&status_); }
205 
206   /* Guaranteed to be NULL-terminated. */
error_message()207   const char *error_message() const { return upb_status_errmsg(&status_); }
208 
209   /* The error message will be truncated if it is longer than
210    * UPB_STATUS_MAX_MESSAGE-4. */
SetErrorMessage(const char * msg)211   void SetErrorMessage(const char *msg) { upb_status_seterrmsg(&status_, msg); }
SetFormattedErrorMessage(const char * fmt,...)212   void SetFormattedErrorMessage(const char *fmt, ...) {
213     va_list args;
214     va_start(args, fmt);
215     upb_status_vseterrf(&status_, fmt, args);
216     va_end(args);
217   }
218 
219   /* Resets the status to a successful state with no message. */
Clear()220   void Clear() { upb_status_clear(&status_); }
221 
222  private:
223   upb_status status_;
224 };
225 
226 #endif  /* __cplusplus */
227 
228 /** upb_alloc *****************************************************************/
229 
230 /* A upb_alloc is a possibly-stateful allocator object.
231  *
232  * It could either be an arena allocator (which doesn't require individual
233  * free() calls) or a regular malloc() (which does).  The client must therefore
234  * free memory unless it knows that the allocator is an arena allocator. */
235 
236 struct upb_alloc;
237 typedef struct upb_alloc upb_alloc;
238 
239 /* A malloc()/free() function.
240  * If "size" is 0 then the function acts like free(), otherwise it acts like
241  * realloc().  Only "oldsize" bytes from a previous allocation are preserved. */
242 typedef void *upb_alloc_func(upb_alloc *alloc, void *ptr, size_t oldsize,
243                              size_t size);
244 
245 struct upb_alloc {
246   upb_alloc_func *func;
247 };
248 
upb_malloc(upb_alloc * alloc,size_t size)249 UPB_INLINE void *upb_malloc(upb_alloc *alloc, size_t size) {
250   UPB_ASSERT(alloc);
251   return alloc->func(alloc, NULL, 0, size);
252 }
253 
upb_realloc(upb_alloc * alloc,void * ptr,size_t oldsize,size_t size)254 UPB_INLINE void *upb_realloc(upb_alloc *alloc, void *ptr, size_t oldsize,
255                              size_t size) {
256   UPB_ASSERT(alloc);
257   return alloc->func(alloc, ptr, oldsize, size);
258 }
259 
upb_free(upb_alloc * alloc,void * ptr)260 UPB_INLINE void upb_free(upb_alloc *alloc, void *ptr) {
261   assert(alloc);
262   alloc->func(alloc, ptr, 0, 0);
263 }
264 
265 /* The global allocator used by upb.  Uses the standard malloc()/free(). */
266 
267 extern upb_alloc upb_alloc_global;
268 
269 /* Functions that hard-code the global malloc.
270  *
271  * We still get benefit because we can put custom logic into our global
272  * allocator, like injecting out-of-memory faults in debug/testing builds. */
273 
upb_gmalloc(size_t size)274 UPB_INLINE void *upb_gmalloc(size_t size) {
275   return upb_malloc(&upb_alloc_global, size);
276 }
277 
upb_grealloc(void * ptr,size_t oldsize,size_t size)278 UPB_INLINE void *upb_grealloc(void *ptr, size_t oldsize, size_t size) {
279   return upb_realloc(&upb_alloc_global, ptr, oldsize, size);
280 }
281 
upb_gfree(void * ptr)282 UPB_INLINE void upb_gfree(void *ptr) {
283   upb_free(&upb_alloc_global, ptr);
284 }
285 
286 /* upb_arena ******************************************************************/
287 
288 /* upb_arena is a specific allocator implementation that uses arena allocation.
289  * The user provides an allocator that will be used to allocate the underlying
290  * arena blocks.  Arenas by nature do not require the individual allocations
291  * to be freed.  However the Arena does allow users to register cleanup
292  * functions that will run when the arena is destroyed.
293  *
294  * A upb_arena is *not* thread-safe.
295  *
296  * You could write a thread-safe arena allocator that satisfies the
297  * upb_alloc interface, but it would not be as efficient for the
298  * single-threaded case. */
299 
300 typedef void upb_cleanup_func(void *ud);
301 
302 struct upb_arena;
303 typedef struct upb_arena upb_arena;
304 
305 #ifdef __cplusplus
306 extern "C" {
307 #endif
308 
309 /* Creates an arena from the given initial block (if any -- n may be 0).
310  * Additional blocks will be allocated from |alloc|.  If |alloc| is NULL, this
311  * is a fixed-size arena and cannot grow. */
312 upb_arena *upb_arena_init(void *mem, size_t n, upb_alloc *alloc);
313 void upb_arena_free(upb_arena *a);
314 bool upb_arena_addcleanup(upb_arena *a, void *ud, upb_cleanup_func *func);
315 size_t upb_arena_bytesallocated(const upb_arena *a);
316 
upb_arena_alloc(upb_arena * a)317 UPB_INLINE upb_alloc *upb_arena_alloc(upb_arena *a) { return (upb_alloc*)a; }
318 
319 /* Convenience wrappers around upb_alloc functions. */
320 
upb_arena_malloc(upb_arena * a,size_t size)321 UPB_INLINE void *upb_arena_malloc(upb_arena *a, size_t size) {
322   return upb_malloc(upb_arena_alloc(a), size);
323 }
324 
upb_arena_realloc(upb_arena * a,void * ptr,size_t oldsize,size_t size)325 UPB_INLINE void *upb_arena_realloc(upb_arena *a, void *ptr, size_t oldsize,
326                                    size_t size) {
327   return upb_realloc(upb_arena_alloc(a), ptr, oldsize, size);
328 }
329 
upb_arena_new()330 UPB_INLINE upb_arena *upb_arena_new() {
331   return upb_arena_init(NULL, 0, &upb_alloc_global);
332 }
333 
334 #ifdef __cplusplus
335 }  /* extern "C" */
336 
337 class upb::Arena {
338  public:
339   /* A simple arena with no initial memory block and the default allocator. */
Arena()340   Arena() : ptr_(upb_arena_new(), upb_arena_free) {}
341 
ptr()342   upb_arena* ptr() { return ptr_.get(); }
343 
344   /* Allows this arena to be used as a generic allocator.
345    *
346    * The arena does not need free() calls so when using Arena as an allocator
347    * it is safe to skip them.  However they are no-ops so there is no harm in
348    * calling free() either. */
allocator()349   upb_alloc *allocator() { return upb_arena_alloc(ptr_.get()); }
350 
351   /* Add a cleanup function to run when the arena is destroyed.
352    * Returns false on out-of-memory. */
AddCleanup(void * ud,upb_cleanup_func * func)353   bool AddCleanup(void *ud, upb_cleanup_func* func) {
354     return upb_arena_addcleanup(ptr_.get(), ud, func);
355   }
356 
357   /* Total number of bytes that have been allocated.  It is undefined what
358    * Realloc() does to &arena_ counter. */
BytesAllocated()359   size_t BytesAllocated() const { return upb_arena_bytesallocated(ptr_.get()); }
360 
361  private:
362   std::unique_ptr<upb_arena, decltype(&upb_arena_free)> ptr_;
363 };
364 
365 #endif
366 
367 /* upb::InlinedArena **********************************************************/
368 
369 /* upb::InlinedArena seeds the arenas with a predefined amount of memory.  No
370  * heap memory will be allocated until the initial block is exceeded.
371  *
372  * These types only exist in C++ */
373 
374 #ifdef __cplusplus
375 
376 template <int N> class upb::InlinedArena : public upb::Arena {
377  public:
InlinedArena()378   InlinedArena() : ptr_(upb_arena_new(&initial_block_, N, &upb_alloc_global)) {}
379 
ptr()380   upb_arena* ptr() { return ptr_.get(); }
381 
382  private:
383   InlinedArena(const InlinedArena*) = delete;
384   InlinedArena& operator=(const InlinedArena*) = delete;
385 
386   std::unique_ptr<upb_arena, decltype(&upb_arena_free)> ptr_;
387   char initial_block_[N];
388 };
389 
390 #endif  /* __cplusplus */
391 
392 /* Constants ******************************************************************/
393 
394 /* Generic function type. */
395 typedef void upb_func();
396 
397 /* A list of types as they are encoded on-the-wire. */
398 typedef enum {
399   UPB_WIRE_TYPE_VARINT      = 0,
400   UPB_WIRE_TYPE_64BIT       = 1,
401   UPB_WIRE_TYPE_DELIMITED   = 2,
402   UPB_WIRE_TYPE_START_GROUP = 3,
403   UPB_WIRE_TYPE_END_GROUP   = 4,
404   UPB_WIRE_TYPE_32BIT       = 5
405 } upb_wiretype_t;
406 
407 /* The types a field can have.  Note that this list is not identical to the
408  * types defined in descriptor.proto, which gives INT32 and SINT32 separate
409  * types (we distinguish the two with the "integer encoding" enum below). */
410 typedef enum {
411   /* Types stored in 1 byte. */
412   UPB_TYPE_BOOL     = 1,
413   /* Types stored in 4 bytes. */
414   UPB_TYPE_FLOAT    = 2,
415   UPB_TYPE_INT32    = 3,
416   UPB_TYPE_UINT32   = 4,
417   UPB_TYPE_ENUM     = 5,  /* Enum values are int32. */
418   /* Types stored as pointers (probably 4 or 8 bytes). */
419   UPB_TYPE_STRING   = 6,
420   UPB_TYPE_BYTES    = 7,
421   UPB_TYPE_MESSAGE  = 8,
422   /* Types stored as 8 bytes. */
423   UPB_TYPE_DOUBLE   = 9,
424   UPB_TYPE_INT64    = 10,
425   UPB_TYPE_UINT64   = 11
426 } upb_fieldtype_t;
427 
428 /* The repeated-ness of each field; this matches descriptor.proto. */
429 typedef enum {
430   UPB_LABEL_OPTIONAL = 1,
431   UPB_LABEL_REQUIRED = 2,
432   UPB_LABEL_REPEATED = 3
433 } upb_label_t;
434 
435 /* Descriptor types, as defined in descriptor.proto. */
436 typedef enum {
437   UPB_DESCRIPTOR_TYPE_DOUBLE   = 1,
438   UPB_DESCRIPTOR_TYPE_FLOAT    = 2,
439   UPB_DESCRIPTOR_TYPE_INT64    = 3,
440   UPB_DESCRIPTOR_TYPE_UINT64   = 4,
441   UPB_DESCRIPTOR_TYPE_INT32    = 5,
442   UPB_DESCRIPTOR_TYPE_FIXED64  = 6,
443   UPB_DESCRIPTOR_TYPE_FIXED32  = 7,
444   UPB_DESCRIPTOR_TYPE_BOOL     = 8,
445   UPB_DESCRIPTOR_TYPE_STRING   = 9,
446   UPB_DESCRIPTOR_TYPE_GROUP    = 10,
447   UPB_DESCRIPTOR_TYPE_MESSAGE  = 11,
448   UPB_DESCRIPTOR_TYPE_BYTES    = 12,
449   UPB_DESCRIPTOR_TYPE_UINT32   = 13,
450   UPB_DESCRIPTOR_TYPE_ENUM     = 14,
451   UPB_DESCRIPTOR_TYPE_SFIXED32 = 15,
452   UPB_DESCRIPTOR_TYPE_SFIXED64 = 16,
453   UPB_DESCRIPTOR_TYPE_SINT32   = 17,
454   UPB_DESCRIPTOR_TYPE_SINT64   = 18
455 } upb_descriptortype_t;
456 
457 extern const uint8_t upb_desctype_to_fieldtype[];
458 
459 #endif  /* UPB_H_ */
460 /*
461 ** structs.int.h: structures definitions that are internal to upb.
462 */
463 
464 #ifndef UPB_STRUCTS_H_
465 #define UPB_STRUCTS_H_
466 
467 
468 struct upb_array {
469   upb_fieldtype_t type;
470   uint8_t element_size;
471   void *data;   /* Each element is element_size. */
472   size_t len;   /* Measured in elements. */
473   size_t size;  /* Measured in elements. */
474   upb_arena *arena;
475 };
476 
477 #endif  /* UPB_STRUCTS_H_ */
478 
479 
480 #ifdef __cplusplus
481 
482 namespace upb {
483 class Array;
484 class Map;
485 class MapIterator;
486 class MessageLayout;
487 }
488 
489 #endif
490 
491 /* TODO(haberman): C++ accessors */
492 
493 #ifdef __cplusplus
494 extern "C" {
495 #endif
496 
497 typedef void upb_msg;
498 
499 struct upb_array;
500 typedef struct upb_array upb_array;
501 
502 struct upb_map;
503 typedef struct upb_map upb_map;
504 
505 struct upb_mapiter;
506 typedef struct upb_mapiter upb_mapiter;
507 
508 /** upb_msglayout *************************************************************/
509 
510 /* upb_msglayout represents the memory layout of a given upb_msgdef.  The
511  * members are public so generated code can initialize them, but users MUST NOT
512  * read or write any of its members. */
513 
514 typedef struct {
515   uint32_t number;
516   uint16_t offset;
517   int16_t presence;      /* If >0, hasbit_index+1.  If <0, oneof_index+1. */
518   uint16_t submsg_index;  /* undefined if descriptortype != MESSAGE or GROUP. */
519   uint8_t descriptortype;
520   uint8_t label;
521 } upb_msglayout_field;
522 
523 typedef struct upb_msglayout {
524   const struct upb_msglayout *const* submsgs;
525   const upb_msglayout_field *fields;
526   /* Must be aligned to sizeof(void*).  Doesn't include internal members like
527    * unknown fields, extension dict, pointer to msglayout, etc. */
528   uint16_t size;
529   uint16_t field_count;
530   bool extendable;
531 } upb_msglayout;
532 
533 /** upb_strview ************************************************************/
534 
535 typedef struct {
536   const char *data;
537   size_t size;
538 } upb_strview;
539 
upb_strview_make(const char * data,size_t size)540 UPB_INLINE upb_strview upb_strview_make(const char *data, size_t size) {
541   upb_strview ret;
542   ret.data = data;
543   ret.size = size;
544   return ret;
545 }
546 
upb_strview_makez(const char * data)547 UPB_INLINE upb_strview upb_strview_makez(const char *data) {
548   return upb_strview_make(data, strlen(data));
549 }
550 
upb_strview_eql(upb_strview a,upb_strview b)551 UPB_INLINE bool upb_strview_eql(upb_strview a, upb_strview b) {
552   return a.size == b.size && memcmp(a.data, b.data, a.size) == 0;
553 }
554 
555 #define UPB_STRVIEW_INIT(ptr, len) {ptr, len}
556 
557 #define UPB_STRVIEW_FORMAT "%.*s"
558 #define UPB_STRVIEW_ARGS(view) (int)(view).size, (view).data
559 
560 /** upb_msgval ****************************************************************/
561 
562 /* A union representing all possible protobuf values.  Used for generic get/set
563  * operations. */
564 
565 typedef union {
566   bool b;
567   float flt;
568   double dbl;
569   int32_t i32;
570   int64_t i64;
571   uint32_t u32;
572   uint64_t u64;
573   const upb_map* map;
574   const upb_msg* msg;
575   const upb_array* arr;
576   const void* ptr;
577   upb_strview str;
578 } upb_msgval;
579 
580 #define ACCESSORS(name, membername, ctype) \
581   UPB_INLINE ctype upb_msgval_get ## name(upb_msgval v) { \
582     return v.membername; \
583   } \
584   UPB_INLINE void upb_msgval_set ## name(upb_msgval *v, ctype cval) { \
585     v->membername = cval; \
586   } \
587   UPB_INLINE upb_msgval upb_msgval_ ## name(ctype v) { \
588     upb_msgval ret; \
589     ret.membername = v; \
590     return ret; \
591   }
592 
ACCESSORS(bool,b,bool)593 ACCESSORS(bool,   b,   bool)
594 ACCESSORS(float,  flt, float)
595 ACCESSORS(double, dbl, double)
596 ACCESSORS(int32,  i32, int32_t)
597 ACCESSORS(int64,  i64, int64_t)
598 ACCESSORS(uint32, u32, uint32_t)
599 ACCESSORS(uint64, u64, uint64_t)
600 ACCESSORS(map,    map, const upb_map*)
601 ACCESSORS(msg,    msg, const upb_msg*)
602 ACCESSORS(ptr,    ptr, const void*)
603 ACCESSORS(arr,    arr, const upb_array*)
604 ACCESSORS(str,    str, upb_strview)
605 
606 #undef ACCESSORS
607 
608 UPB_INLINE upb_msgval upb_msgval_makestr(const char *data, size_t size) {
609   return upb_msgval_str(upb_strview_make(data, size));
610 }
611 
612 /** upb_msg *******************************************************************/
613 
614 /* A upb_msg represents a protobuf message.  It always corresponds to a specific
615  * upb_msglayout, which describes how it is laid out in memory.  */
616 
617 /* Creates a new message of the given type/layout in this arena. */
618 upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a);
619 
620 /* Returns the arena for the given message. */
621 upb_arena *upb_msg_arena(const upb_msg *msg);
622 
623 void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len);
624 const char *upb_msg_getunknown(const upb_msg *msg, size_t *len);
625 
626 /* Read-only message API.  Can be safely called by anyone. */
627 
628 /* Returns the value associated with this field:
629  *   - for scalar fields (including strings), the value directly.
630  *   - return upb_msg*, or upb_map* for msg/map.
631  *     If the field is unset for these field types, returns NULL.
632  *
633  * TODO(haberman): should we let users store cached array/map/msg
634  * pointers here for fields that are unset?  Could be useful for the
635  * strongly-owned submessage model (ie. generated C API that doesn't use
636  * arenas).
637  */
638 upb_msgval upb_msg_get(const upb_msg *msg,
639                        int field_index,
640                        const upb_msglayout *l);
641 
642 /* May only be called for fields where upb_fielddef_haspresence(f) == true. */
643 bool upb_msg_has(const upb_msg *msg,
644                  int field_index,
645                  const upb_msglayout *l);
646 
647 /* Mutable message API.  May only be called by the owner of the message who
648  * knows its ownership scheme and how to keep it consistent. */
649 
650 /* Sets the given field to the given value.  Does not perform any memory
651  * management: if you overwrite a pointer to a msg/array/map/string without
652  * cleaning it up (or using an arena) it will leak.
653  */
654 void upb_msg_set(upb_msg *msg,
655                  int field_index,
656                  upb_msgval val,
657                  const upb_msglayout *l);
658 
659 /* For a primitive field, set it back to its default. For repeated, string, and
660  * submessage fields set it back to NULL.  This could involve releasing some
661  * internal memory (for example, from an extension dictionary), but it is not
662  * recursive in any way and will not recover any memory that may be used by
663  * arrays/maps/strings/msgs that this field may have pointed to.
664  */
665 bool upb_msg_clearfield(upb_msg *msg,
666                         int field_index,
667                         const upb_msglayout *l);
668 
669 /* TODO(haberman): copyfrom()/mergefrom()? */
670 
671 /** upb_array *****************************************************************/
672 
673 /* A upb_array stores data for a repeated field.  The memory management
674  * semantics are the same as upb_msg.  A upb_array allocates dynamic
675  * memory internally for the array elements. */
676 
677 upb_array *upb_array_new(upb_fieldtype_t type, upb_arena *a);
678 upb_fieldtype_t upb_array_type(const upb_array *arr);
679 
680 /* Read-only interface.  Safe for anyone to call. */
681 
682 size_t upb_array_size(const upb_array *arr);
683 upb_msgval upb_array_get(const upb_array *arr, size_t i);
684 
685 /* Write interface.  May only be called by the message's owner who can enforce
686  * its memory management invariants. */
687 
688 bool upb_array_set(upb_array *arr, size_t i, upb_msgval val);
689 
690 /** upb_map *******************************************************************/
691 
692 /* A upb_map stores data for a map field.  The memory management semantics are
693  * the same as upb_msg, with one notable exception.  upb_map will internally
694  * store a copy of all string keys, but *not* any string values or submessages.
695  * So you must ensure that any string or message values outlive the map, and you
696  * must delete them manually when they are no longer required. */
697 
698 upb_map *upb_map_new(upb_fieldtype_t ktype, upb_fieldtype_t vtype,
699                      upb_arena *a);
700 
701 /* Read-only interface.  Safe for anyone to call. */
702 
703 size_t upb_map_size(const upb_map *map);
704 upb_fieldtype_t upb_map_keytype(const upb_map *map);
705 upb_fieldtype_t upb_map_valuetype(const upb_map *map);
706 bool upb_map_get(const upb_map *map, upb_msgval key, upb_msgval *val);
707 
708 /* Write interface.  May only be called by the message's owner who can enforce
709  * its memory management invariants. */
710 
711 /* Sets or overwrites an entry in the map.  Return value indicates whether
712  * the operation succeeded or failed with OOM, and also whether an existing
713  * key was replaced or not. */
714 bool upb_map_set(upb_map *map,
715                  upb_msgval key, upb_msgval val,
716                  upb_msgval *valremoved);
717 
718 /* Deletes an entry in the map.  Returns true if the key was present. */
719 bool upb_map_del(upb_map *map, upb_msgval key);
720 
721 /** upb_mapiter ***************************************************************/
722 
723 /* For iterating over a map.  Map iterators are invalidated by mutations to the
724  * map, but an invalidated iterator will never return junk or crash the process.
725  * An invalidated iterator may return entries that were already returned though,
726  * and if you keep invalidating the iterator during iteration, the program may
727  * enter an infinite loop. */
728 
729 size_t upb_mapiter_sizeof();
730 
731 void upb_mapiter_begin(upb_mapiter *i, const upb_map *t);
732 upb_mapiter *upb_mapiter_new(const upb_map *t, upb_alloc *a);
733 void upb_mapiter_free(upb_mapiter *i, upb_alloc *a);
734 void upb_mapiter_next(upb_mapiter *i);
735 bool upb_mapiter_done(const upb_mapiter *i);
736 
737 upb_msgval upb_mapiter_key(const upb_mapiter *i);
738 upb_msgval upb_mapiter_value(const upb_mapiter *i);
739 void upb_mapiter_setdone(upb_mapiter *i);
740 bool upb_mapiter_isequal(const upb_mapiter *i1, const upb_mapiter *i2);
741 
742 #ifdef __cplusplus
743 }  /* extern "C" */
744 #endif
745 
746 #endif /* UPB_MSG_H_ */
747 /* This file was generated by upbc (the upb compiler) from the input
748  * file:
749  *
750  *     google/protobuf/descriptor.proto
751  *
752  * Do not edit -- your changes will be discarded when the file is
753  * regenerated. */
754 
755 #ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_
756 #define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_
757 
758 /*
759 ** Functions for use by generated code.  These are not public and users must
760 ** not call them directly.
761 */
762 
763 #ifndef UPB_GENERATED_UTIL_H_
764 #define UPB_GENERATED_UTIL_H_
765 
766 #include <stdint.h>
767 
768 #define PTR_AT(msg, ofs, type) (type*)((const char*)msg + ofs)
769 
_upb_array_accessor(const void * msg,size_t ofs,size_t * size)770 UPB_INLINE const void *_upb_array_accessor(const void *msg, size_t ofs,
771                                            size_t *size) {
772   const upb_array *arr = *PTR_AT(msg, ofs, const upb_array*);
773   if (arr) {
774     if (size) *size = arr->len;
775     return arr->data;
776   } else {
777     if (size) *size = 0;
778     return NULL;
779   }
780 }
781 
_upb_array_mutable_accessor(void * msg,size_t ofs,size_t * size)782 UPB_INLINE void *_upb_array_mutable_accessor(void *msg, size_t ofs,
783                                              size_t *size) {
784   upb_array *arr = *PTR_AT(msg, ofs, upb_array*);
785   if (arr) {
786     if (size) *size = arr->len;
787     return arr->data;
788   } else {
789     if (size) *size = 0;
790     return NULL;
791   }
792 }
793 
794 /* TODO(haberman): this is a mess.  It will improve when upb_array no longer
795  * carries reflective state (type, elem_size). */
_upb_array_resize_accessor(void * msg,size_t ofs,size_t size,size_t elem_size,upb_fieldtype_t type,upb_arena * arena)796 UPB_INLINE void *_upb_array_resize_accessor(void *msg, size_t ofs, size_t size,
797                                             size_t elem_size,
798                                             upb_fieldtype_t type,
799                                             upb_arena *arena) {
800   upb_array *arr = *PTR_AT(msg, ofs, upb_array*);
801 
802   if (!arr) {
803     arr = upb_array_new(type, arena);
804     if (!arr) return NULL;
805     *PTR_AT(msg, ofs, upb_array*) = arr;
806   }
807 
808   if (size > arr->size) {
809     size_t new_size = UPB_MAX(arr->size, 4);
810     size_t old_bytes = arr->size * elem_size;
811     size_t new_bytes;
812     while (new_size < size) new_size *= 2;
813     new_bytes = new_size * elem_size;
814     arr->data = upb_arena_realloc(arena, arr->data, old_bytes, new_bytes);
815     if (!arr->data) {
816       return NULL;
817     }
818     arr->size = new_size;
819   }
820 
821   arr->len = size;
822   return arr->data;
823 }
824 
_upb_array_append_accessor(void * msg,size_t ofs,size_t elem_size,upb_fieldtype_t type,const void * value,upb_arena * arena)825 UPB_INLINE bool _upb_array_append_accessor(void *msg, size_t ofs,
826                                            size_t elem_size,
827                                            upb_fieldtype_t type,
828                                            const void *value,
829                                            upb_arena *arena) {
830   upb_array *arr = *PTR_AT(msg, ofs, upb_array*);
831   size_t i = arr ? arr->len : 0;
832   void *data =
833       _upb_array_resize_accessor(msg, ofs, i + 1, elem_size, type, arena);
834   if (!data) return false;
835   memcpy(PTR_AT(data, i * elem_size, char), value, elem_size);
836   return true;
837 }
838 
_upb_has_field(const void * msg,size_t idx)839 UPB_INLINE bool _upb_has_field(const void *msg, size_t idx) {
840   return (*PTR_AT(msg, idx / 8, const char) & (1 << (idx % 8))) != 0;
841 }
842 
_upb_sethas(const void * msg,size_t idx)843 UPB_INLINE bool _upb_sethas(const void *msg, size_t idx) {
844   return (*PTR_AT(msg, idx / 8, char)) |= (1 << (idx % 8));
845 }
846 
_upb_clearhas(const void * msg,size_t idx)847 UPB_INLINE bool _upb_clearhas(const void *msg, size_t idx) {
848   return (*PTR_AT(msg, idx / 8, char)) &= ~(1 << (idx % 8));
849 }
850 
_upb_has_oneof_field(const void * msg,size_t case_ofs,int32_t num)851 UPB_INLINE bool _upb_has_oneof_field(const void *msg, size_t case_ofs, int32_t num) {
852   return *PTR_AT(msg, case_ofs, int32_t) == num;
853 }
854 
855 #undef PTR_AT
856 
857 #endif  /* UPB_GENERATED_UTIL_H_ */
858 
859 
860 /*
861 ** upb_decode: parsing into a upb_msg using a upb_msglayout.
862 */
863 
864 #ifndef UPB_DECODE_H_
865 #define UPB_DECODE_H_
866 
867 
868 #ifdef __cplusplus
869 extern "C" {
870 #endif
871 
872 bool upb_decode(const char *buf, size_t size, upb_msg *msg,
873                 const upb_msglayout *l);
874 
875 #ifdef __cplusplus
876 }  /* extern "C" */
877 #endif
878 
879 #endif  /* UPB_DECODE_H_ */
880 /*
881 ** upb_encode: parsing into a upb_msg using a upb_msglayout.
882 */
883 
884 #ifndef UPB_ENCODE_H_
885 #define UPB_ENCODE_H_
886 
887 
888 #ifdef __cplusplus
889 extern "C" {
890 #endif
891 
892 char *upb_encode(const void *msg, const upb_msglayout *l, upb_arena *arena,
893                  size_t *size);
894 
895 #ifdef __cplusplus
896 }  /* extern "C" */
897 #endif
898 
899 #endif  /* UPB_ENCODE_H_ */
900 #ifdef __cplusplus
901 extern "C" {
902 #endif
903 
904 struct google_protobuf_FileDescriptorSet;
905 struct google_protobuf_FileDescriptorProto;
906 struct google_protobuf_DescriptorProto;
907 struct google_protobuf_DescriptorProto_ExtensionRange;
908 struct google_protobuf_DescriptorProto_ReservedRange;
909 struct google_protobuf_ExtensionRangeOptions;
910 struct google_protobuf_FieldDescriptorProto;
911 struct google_protobuf_OneofDescriptorProto;
912 struct google_protobuf_EnumDescriptorProto;
913 struct google_protobuf_EnumDescriptorProto_EnumReservedRange;
914 struct google_protobuf_EnumValueDescriptorProto;
915 struct google_protobuf_ServiceDescriptorProto;
916 struct google_protobuf_MethodDescriptorProto;
917 struct google_protobuf_FileOptions;
918 struct google_protobuf_MessageOptions;
919 struct google_protobuf_FieldOptions;
920 struct google_protobuf_OneofOptions;
921 struct google_protobuf_EnumOptions;
922 struct google_protobuf_EnumValueOptions;
923 struct google_protobuf_ServiceOptions;
924 struct google_protobuf_MethodOptions;
925 struct google_protobuf_UninterpretedOption;
926 struct google_protobuf_UninterpretedOption_NamePart;
927 struct google_protobuf_SourceCodeInfo;
928 struct google_protobuf_SourceCodeInfo_Location;
929 struct google_protobuf_GeneratedCodeInfo;
930 struct google_protobuf_GeneratedCodeInfo_Annotation;
931 typedef struct google_protobuf_FileDescriptorSet google_protobuf_FileDescriptorSet;
932 typedef struct google_protobuf_FileDescriptorProto google_protobuf_FileDescriptorProto;
933 typedef struct google_protobuf_DescriptorProto google_protobuf_DescriptorProto;
934 typedef struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_DescriptorProto_ExtensionRange;
935 typedef struct google_protobuf_DescriptorProto_ReservedRange google_protobuf_DescriptorProto_ReservedRange;
936 typedef struct google_protobuf_ExtensionRangeOptions google_protobuf_ExtensionRangeOptions;
937 typedef struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto;
938 typedef struct google_protobuf_OneofDescriptorProto google_protobuf_OneofDescriptorProto;
939 typedef struct google_protobuf_EnumDescriptorProto google_protobuf_EnumDescriptorProto;
940 typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange google_protobuf_EnumDescriptorProto_EnumReservedRange;
941 typedef struct google_protobuf_EnumValueDescriptorProto google_protobuf_EnumValueDescriptorProto;
942 typedef struct google_protobuf_ServiceDescriptorProto google_protobuf_ServiceDescriptorProto;
943 typedef struct google_protobuf_MethodDescriptorProto google_protobuf_MethodDescriptorProto;
944 typedef struct google_protobuf_FileOptions google_protobuf_FileOptions;
945 typedef struct google_protobuf_MessageOptions google_protobuf_MessageOptions;
946 typedef struct google_protobuf_FieldOptions google_protobuf_FieldOptions;
947 typedef struct google_protobuf_OneofOptions google_protobuf_OneofOptions;
948 typedef struct google_protobuf_EnumOptions google_protobuf_EnumOptions;
949 typedef struct google_protobuf_EnumValueOptions google_protobuf_EnumValueOptions;
950 typedef struct google_protobuf_ServiceOptions google_protobuf_ServiceOptions;
951 typedef struct google_protobuf_MethodOptions google_protobuf_MethodOptions;
952 typedef struct google_protobuf_UninterpretedOption google_protobuf_UninterpretedOption;
953 typedef struct google_protobuf_UninterpretedOption_NamePart google_protobuf_UninterpretedOption_NamePart;
954 typedef struct google_protobuf_SourceCodeInfo google_protobuf_SourceCodeInfo;
955 typedef struct google_protobuf_SourceCodeInfo_Location google_protobuf_SourceCodeInfo_Location;
956 typedef struct google_protobuf_GeneratedCodeInfo google_protobuf_GeneratedCodeInfo;
957 typedef struct google_protobuf_GeneratedCodeInfo_Annotation google_protobuf_GeneratedCodeInfo_Annotation;
958 extern const upb_msglayout google_protobuf_FileDescriptorSet_msginit;
959 extern const upb_msglayout google_protobuf_FileDescriptorProto_msginit;
960 extern const upb_msglayout google_protobuf_DescriptorProto_msginit;
961 extern const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit;
962 extern const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit;
963 extern const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit;
964 extern const upb_msglayout google_protobuf_FieldDescriptorProto_msginit;
965 extern const upb_msglayout google_protobuf_OneofDescriptorProto_msginit;
966 extern const upb_msglayout google_protobuf_EnumDescriptorProto_msginit;
967 extern const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit;
968 extern const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit;
969 extern const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit;
970 extern const upb_msglayout google_protobuf_MethodDescriptorProto_msginit;
971 extern const upb_msglayout google_protobuf_FileOptions_msginit;
972 extern const upb_msglayout google_protobuf_MessageOptions_msginit;
973 extern const upb_msglayout google_protobuf_FieldOptions_msginit;
974 extern const upb_msglayout google_protobuf_OneofOptions_msginit;
975 extern const upb_msglayout google_protobuf_EnumOptions_msginit;
976 extern const upb_msglayout google_protobuf_EnumValueOptions_msginit;
977 extern const upb_msglayout google_protobuf_ServiceOptions_msginit;
978 extern const upb_msglayout google_protobuf_MethodOptions_msginit;
979 extern const upb_msglayout google_protobuf_UninterpretedOption_msginit;
980 extern const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit;
981 extern const upb_msglayout google_protobuf_SourceCodeInfo_msginit;
982 extern const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit;
983 extern const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit;
984 extern const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit;
985 
986 /* Enums */
987 
988 typedef enum {
989   google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1,
990   google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2,
991   google_protobuf_FieldDescriptorProto_LABEL_REPEATED = 3
992 } google_protobuf_FieldDescriptorProto_Label;
993 
994 typedef enum {
995   google_protobuf_FieldDescriptorProto_TYPE_DOUBLE = 1,
996   google_protobuf_FieldDescriptorProto_TYPE_FLOAT = 2,
997   google_protobuf_FieldDescriptorProto_TYPE_INT64 = 3,
998   google_protobuf_FieldDescriptorProto_TYPE_UINT64 = 4,
999   google_protobuf_FieldDescriptorProto_TYPE_INT32 = 5,
1000   google_protobuf_FieldDescriptorProto_TYPE_FIXED64 = 6,
1001   google_protobuf_FieldDescriptorProto_TYPE_FIXED32 = 7,
1002   google_protobuf_FieldDescriptorProto_TYPE_BOOL = 8,
1003   google_protobuf_FieldDescriptorProto_TYPE_STRING = 9,
1004   google_protobuf_FieldDescriptorProto_TYPE_GROUP = 10,
1005   google_protobuf_FieldDescriptorProto_TYPE_MESSAGE = 11,
1006   google_protobuf_FieldDescriptorProto_TYPE_BYTES = 12,
1007   google_protobuf_FieldDescriptorProto_TYPE_UINT32 = 13,
1008   google_protobuf_FieldDescriptorProto_TYPE_ENUM = 14,
1009   google_protobuf_FieldDescriptorProto_TYPE_SFIXED32 = 15,
1010   google_protobuf_FieldDescriptorProto_TYPE_SFIXED64 = 16,
1011   google_protobuf_FieldDescriptorProto_TYPE_SINT32 = 17,
1012   google_protobuf_FieldDescriptorProto_TYPE_SINT64 = 18
1013 } google_protobuf_FieldDescriptorProto_Type;
1014 
1015 typedef enum {
1016   google_protobuf_FieldOptions_STRING = 0,
1017   google_protobuf_FieldOptions_CORD = 1,
1018   google_protobuf_FieldOptions_STRING_PIECE = 2
1019 } google_protobuf_FieldOptions_CType;
1020 
1021 typedef enum {
1022   google_protobuf_FieldOptions_JS_NORMAL = 0,
1023   google_protobuf_FieldOptions_JS_STRING = 1,
1024   google_protobuf_FieldOptions_JS_NUMBER = 2
1025 } google_protobuf_FieldOptions_JSType;
1026 
1027 typedef enum {
1028   google_protobuf_FileOptions_SPEED = 1,
1029   google_protobuf_FileOptions_CODE_SIZE = 2,
1030   google_protobuf_FileOptions_LITE_RUNTIME = 3
1031 } google_protobuf_FileOptions_OptimizeMode;
1032 
1033 typedef enum {
1034   google_protobuf_MethodOptions_IDEMPOTENCY_UNKNOWN = 0,
1035   google_protobuf_MethodOptions_NO_SIDE_EFFECTS = 1,
1036   google_protobuf_MethodOptions_IDEMPOTENT = 2
1037 } google_protobuf_MethodOptions_IdempotencyLevel;
1038 
1039 
1040 /* google.protobuf.FileDescriptorSet */
1041 
google_protobuf_FileDescriptorSet_new(upb_arena * arena)1042 UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_new(upb_arena *arena) {
1043   return (google_protobuf_FileDescriptorSet *)upb_msg_new(&google_protobuf_FileDescriptorSet_msginit, arena);
1044 }
google_protobuf_FileDescriptorSet_parse(const char * buf,size_t size,upb_arena * arena)1045 UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parse(const char *buf, size_t size,
1046                         upb_arena *arena) {
1047   google_protobuf_FileDescriptorSet *ret = google_protobuf_FileDescriptorSet_new(arena);
1048   return (ret && upb_decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msginit)) ? ret : NULL;
1049 }
google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet * msg,upb_arena * arena,size_t * len)1050 UPB_INLINE char *google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet *msg, upb_arena *arena, size_t *len) {
1051   return upb_encode(msg, &google_protobuf_FileDescriptorSet_msginit, arena, len);
1052 }
1053 
google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet * msg,size_t * len)1054 UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet *msg, size_t *len) { return (const google_protobuf_FileDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); }
1055 
google_protobuf_FileDescriptorSet_mutable_file(google_protobuf_FileDescriptorSet * msg,size_t * len)1056 UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_mutable_file(google_protobuf_FileDescriptorSet *msg, size_t *len) {
1057   return (google_protobuf_FileDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
1058 }
google_protobuf_FileDescriptorSet_resize_file(google_protobuf_FileDescriptorSet * msg,size_t len,upb_arena * arena)1059 UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_resize_file(google_protobuf_FileDescriptorSet *msg, size_t len, upb_arena *arena) {
1060   return (google_protobuf_FileDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
1061 }
google_protobuf_FileDescriptorSet_add_file(google_protobuf_FileDescriptorSet * msg,upb_arena * arena)1062 UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file(google_protobuf_FileDescriptorSet *msg, upb_arena *arena) {
1063   struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena);
1064   bool ok = _upb_array_append_accessor(
1065       msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
1066   if (!ok) return NULL;
1067   return sub;
1068 }
1069 
1070 
1071 /* google.protobuf.FileDescriptorProto */
1072 
google_protobuf_FileDescriptorProto_new(upb_arena * arena)1073 UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_new(upb_arena *arena) {
1074   return (google_protobuf_FileDescriptorProto *)upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena);
1075 }
google_protobuf_FileDescriptorProto_parse(const char * buf,size_t size,upb_arena * arena)1076 UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parse(const char *buf, size_t size,
1077                         upb_arena *arena) {
1078   google_protobuf_FileDescriptorProto *ret = google_protobuf_FileDescriptorProto_new(arena);
1079   return (ret && upb_decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msginit)) ? ret : NULL;
1080 }
google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto * msg,upb_arena * arena,size_t * len)1081 UPB_INLINE char *google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto *msg, upb_arena *arena, size_t *len) {
1082   return upb_encode(msg, &google_protobuf_FileDescriptorProto_msginit, arena, len);
1083 }
1084 
google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto * msg)1085 UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 1); }
google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto * msg)1086 UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto * msg)1087 UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 2); }
google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto * msg)1088 UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)); }
google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto * msg,size_t * len)1089 UPB_INLINE upb_strview const* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(36, 72), len); }
google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto * msg,size_t * len)1090 UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_DescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(40, 80), len); }
google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto * msg,size_t * len)1091 UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(44, 88), len); }
google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto * msg,size_t * len)1092 UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_ServiceDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(48, 96), len); }
google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto * msg,size_t * len)1093 UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(52, 104), len); }
google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto * msg)1094 UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 4); }
google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto * msg)1095 UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_FileOptions*, UPB_SIZE(28, 56)); }
google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto * msg)1096 UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 5); }
google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto * msg)1097 UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_SourceCodeInfo*, UPB_SIZE(32, 64)); }
google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto * msg,size_t * len)1098 UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(56, 112), len); }
google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto * msg,size_t * len)1099 UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(60, 120), len); }
google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto * msg)1100 UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 3); }
google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto * msg)1101 UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(20, 40)); }
1102 
google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto * msg,upb_strview value)1103 UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_strview value) {
1104   _upb_sethas(msg, 1);
1105   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
1106 }
google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto * msg,upb_strview value)1107 UPB_INLINE void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_strview value) {
1108   _upb_sethas(msg, 2);
1109   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)) = value;
1110 }
google_protobuf_FileDescriptorProto_mutable_dependency(google_protobuf_FileDescriptorProto * msg,size_t * len)1111 UPB_INLINE upb_strview* google_protobuf_FileDescriptorProto_mutable_dependency(google_protobuf_FileDescriptorProto *msg, size_t *len) {
1112   return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 72), len);
1113 }
google_protobuf_FileDescriptorProto_resize_dependency(google_protobuf_FileDescriptorProto * msg,size_t len,upb_arena * arena)1114 UPB_INLINE upb_strview* google_protobuf_FileDescriptorProto_resize_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
1115   return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(36, 72), len, UPB_SIZE(8, 16), UPB_TYPE_STRING, arena);
1116 }
google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto * msg,upb_strview val,upb_arena * arena)1117 UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto *msg, upb_strview val, upb_arena *arena) {
1118   return _upb_array_append_accessor(
1119       msg, UPB_SIZE(36, 72), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena);
1120 }
google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto * msg,size_t * len)1121 UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto *msg, size_t *len) {
1122   return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(40, 80), len);
1123 }
google_protobuf_FileDescriptorProto_resize_message_type(google_protobuf_FileDescriptorProto * msg,size_t len,upb_arena * arena)1124 UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_resize_message_type(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
1125   return (google_protobuf_DescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(40, 80), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
1126 }
google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto * msg,upb_arena * arena)1127 UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
1128   struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena);
1129   bool ok = _upb_array_append_accessor(
1130       msg, UPB_SIZE(40, 80), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
1131   if (!ok) return NULL;
1132   return sub;
1133 }
google_protobuf_FileDescriptorProto_mutable_enum_type(google_protobuf_FileDescriptorProto * msg,size_t * len)1134 UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_mutable_enum_type(google_protobuf_FileDescriptorProto *msg, size_t *len) {
1135   return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(44, 88), len);
1136 }
google_protobuf_FileDescriptorProto_resize_enum_type(google_protobuf_FileDescriptorProto * msg,size_t len,upb_arena * arena)1137 UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_resize_enum_type(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
1138   return (google_protobuf_EnumDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(44, 88), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
1139 }
google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto * msg,upb_arena * arena)1140 UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
1141   struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena);
1142   bool ok = _upb_array_append_accessor(
1143       msg, UPB_SIZE(44, 88), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
1144   if (!ok) return NULL;
1145   return sub;
1146 }
google_protobuf_FileDescriptorProto_mutable_service(google_protobuf_FileDescriptorProto * msg,size_t * len)1147 UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_mutable_service(google_protobuf_FileDescriptorProto *msg, size_t *len) {
1148   return (google_protobuf_ServiceDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(48, 96), len);
1149 }
google_protobuf_FileDescriptorProto_resize_service(google_protobuf_FileDescriptorProto * msg,size_t len,upb_arena * arena)1150 UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_resize_service(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
1151   return (google_protobuf_ServiceDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(48, 96), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
1152 }
google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto * msg,upb_arena * arena)1153 UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
1154   struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena);
1155   bool ok = _upb_array_append_accessor(
1156       msg, UPB_SIZE(48, 96), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
1157   if (!ok) return NULL;
1158   return sub;
1159 }
google_protobuf_FileDescriptorProto_mutable_extension(google_protobuf_FileDescriptorProto * msg,size_t * len)1160 UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_mutable_extension(google_protobuf_FileDescriptorProto *msg, size_t *len) {
1161   return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(52, 104), len);
1162 }
google_protobuf_FileDescriptorProto_resize_extension(google_protobuf_FileDescriptorProto * msg,size_t len,upb_arena * arena)1163 UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_resize_extension(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
1164   return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(52, 104), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
1165 }
google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto * msg,upb_arena * arena)1166 UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
1167   struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
1168   bool ok = _upb_array_append_accessor(
1169       msg, UPB_SIZE(52, 104), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
1170   if (!ok) return NULL;
1171   return sub;
1172 }
google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto * msg,google_protobuf_FileOptions * value)1173 UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) {
1174   _upb_sethas(msg, 4);
1175   UPB_FIELD_AT(msg, google_protobuf_FileOptions*, UPB_SIZE(28, 56)) = value;
1176 }
google_protobuf_FileDescriptorProto_mutable_options(google_protobuf_FileDescriptorProto * msg,upb_arena * arena)1177 UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_mutable_options(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
1178   struct google_protobuf_FileOptions* sub = (struct google_protobuf_FileOptions*)google_protobuf_FileDescriptorProto_options(msg);
1179   if (sub == NULL) {
1180     sub = (struct google_protobuf_FileOptions*)upb_msg_new(&google_protobuf_FileOptions_msginit, arena);
1181     if (!sub) return NULL;
1182     google_protobuf_FileDescriptorProto_set_options(msg, sub);
1183   }
1184   return sub;
1185 }
google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto * msg,google_protobuf_SourceCodeInfo * value)1186 UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value) {
1187   _upb_sethas(msg, 5);
1188   UPB_FIELD_AT(msg, google_protobuf_SourceCodeInfo*, UPB_SIZE(32, 64)) = value;
1189 }
google_protobuf_FileDescriptorProto_mutable_source_code_info(google_protobuf_FileDescriptorProto * msg,upb_arena * arena)1190 UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_mutable_source_code_info(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
1191   struct google_protobuf_SourceCodeInfo* sub = (struct google_protobuf_SourceCodeInfo*)google_protobuf_FileDescriptorProto_source_code_info(msg);
1192   if (sub == NULL) {
1193     sub = (struct google_protobuf_SourceCodeInfo*)upb_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena);
1194     if (!sub) return NULL;
1195     google_protobuf_FileDescriptorProto_set_source_code_info(msg, sub);
1196   }
1197   return sub;
1198 }
google_protobuf_FileDescriptorProto_mutable_public_dependency(google_protobuf_FileDescriptorProto * msg,size_t * len)1199 UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependency(google_protobuf_FileDescriptorProto *msg, size_t *len) {
1200   return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(56, 112), len);
1201 }
google_protobuf_FileDescriptorProto_resize_public_dependency(google_protobuf_FileDescriptorProto * msg,size_t len,upb_arena * arena)1202 UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
1203   return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(56, 112), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena);
1204 }
google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto * msg,int32_t val,upb_arena * arena)1205 UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto *msg, int32_t val, upb_arena *arena) {
1206   return _upb_array_append_accessor(
1207       msg, UPB_SIZE(56, 112), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena);
1208 }
google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto * msg,size_t * len)1209 UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto *msg, size_t *len) {
1210   return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(60, 120), len);
1211 }
google_protobuf_FileDescriptorProto_resize_weak_dependency(google_protobuf_FileDescriptorProto * msg,size_t len,upb_arena * arena)1212 UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
1213   return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(60, 120), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena);
1214 }
google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto * msg,int32_t val,upb_arena * arena)1215 UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto *msg, int32_t val, upb_arena *arena) {
1216   return _upb_array_append_accessor(
1217       msg, UPB_SIZE(60, 120), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena);
1218 }
google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto * msg,upb_strview value)1219 UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_strview value) {
1220   _upb_sethas(msg, 3);
1221   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(20, 40)) = value;
1222 }
1223 
1224 
1225 /* google.protobuf.DescriptorProto */
1226 
google_protobuf_DescriptorProto_new(upb_arena * arena)1227 UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new(upb_arena *arena) {
1228   return (google_protobuf_DescriptorProto *)upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena);
1229 }
google_protobuf_DescriptorProto_parse(const char * buf,size_t size,upb_arena * arena)1230 UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parse(const char *buf, size_t size,
1231                         upb_arena *arena) {
1232   google_protobuf_DescriptorProto *ret = google_protobuf_DescriptorProto_new(arena);
1233   return (ret && upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_msginit)) ? ret : NULL;
1234 }
google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto * msg,upb_arena * arena,size_t * len)1235 UPB_INLINE char *google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto *msg, upb_arena *arena, size_t *len) {
1236   return upb_encode(msg, &google_protobuf_DescriptorProto_msginit, arena, len);
1237 }
1238 
google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto * msg)1239 UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto *msg) { return _upb_has_field(msg, 1); }
google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto * msg)1240 UPB_INLINE upb_strview google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto * msg,size_t * len)1241 UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 32), len); }
google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto * msg,size_t * len)1242 UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_DescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); }
google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto * msg,size_t * len)1243 UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); }
google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto * msg,size_t * len)1244 UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_DescriptorProto_ExtensionRange* const*)_upb_array_accessor(msg, UPB_SIZE(28, 56), len); }
google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto * msg,size_t * len)1245 UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(32, 64), len); }
google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto * msg)1246 UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto *msg) { return _upb_has_field(msg, 2); }
google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto * msg)1247 UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_MessageOptions*, UPB_SIZE(12, 24)); }
google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto * msg,size_t * len)1248 UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_OneofDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(36, 72), len); }
google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto * msg,size_t * len)1249 UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_DescriptorProto_ReservedRange* const*)_upb_array_accessor(msg, UPB_SIZE(40, 80), len); }
google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto * msg,size_t * len)1250 UPB_INLINE upb_strview const* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(44, 88), len); }
1251 
google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto * msg,upb_strview value)1252 UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_strview value) {
1253   _upb_sethas(msg, 1);
1254   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
1255 }
google_protobuf_DescriptorProto_mutable_field(google_protobuf_DescriptorProto * msg,size_t * len)1256 UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_field(google_protobuf_DescriptorProto *msg, size_t *len) {
1257   return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len);
1258 }
google_protobuf_DescriptorProto_resize_field(google_protobuf_DescriptorProto * msg,size_t len,upb_arena * arena)1259 UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_field(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
1260   return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
1261 }
google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto * msg,upb_arena * arena)1262 UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
1263   struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
1264   bool ok = _upb_array_append_accessor(
1265       msg, UPB_SIZE(16, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
1266   if (!ok) return NULL;
1267   return sub;
1268 }
google_protobuf_DescriptorProto_mutable_nested_type(google_protobuf_DescriptorProto * msg,size_t * len)1269 UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mutable_nested_type(google_protobuf_DescriptorProto *msg, size_t *len) {
1270   return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len);
1271 }
google_protobuf_DescriptorProto_resize_nested_type(google_protobuf_DescriptorProto * msg,size_t len,upb_arena * arena)1272 UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_resize_nested_type(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
1273   return (google_protobuf_DescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
1274 }
google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto * msg,upb_arena * arena)1275 UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
1276   struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena);
1277   bool ok = _upb_array_append_accessor(
1278       msg, UPB_SIZE(20, 40), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
1279   if (!ok) return NULL;
1280   return sub;
1281 }
google_protobuf_DescriptorProto_mutable_enum_type(google_protobuf_DescriptorProto * msg,size_t * len)1282 UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_mutable_enum_type(google_protobuf_DescriptorProto *msg, size_t *len) {
1283   return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len);
1284 }
google_protobuf_DescriptorProto_resize_enum_type(google_protobuf_DescriptorProto * msg,size_t len,upb_arena * arena)1285 UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_resize_enum_type(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
1286   return (google_protobuf_EnumDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
1287 }
google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto * msg,upb_arena * arena)1288 UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
1289   struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena);
1290   bool ok = _upb_array_append_accessor(
1291       msg, UPB_SIZE(24, 48), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
1292   if (!ok) return NULL;
1293   return sub;
1294 }
google_protobuf_DescriptorProto_mutable_extension_range(google_protobuf_DescriptorProto * msg,size_t * len)1295 UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_mutable_extension_range(google_protobuf_DescriptorProto *msg, size_t *len) {
1296   return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len);
1297 }
google_protobuf_DescriptorProto_resize_extension_range(google_protobuf_DescriptorProto * msg,size_t len,upb_arena * arena)1298 UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_resize_extension_range(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
1299   return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_resize_accessor(msg, UPB_SIZE(28, 56), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
1300 }
google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto * msg,upb_arena * arena)1301 UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
1302   struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena);
1303   bool ok = _upb_array_append_accessor(
1304       msg, UPB_SIZE(28, 56), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
1305   if (!ok) return NULL;
1306   return sub;
1307 }
google_protobuf_DescriptorProto_mutable_extension(google_protobuf_DescriptorProto * msg,size_t * len)1308 UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_extension(google_protobuf_DescriptorProto *msg, size_t *len) {
1309   return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(32, 64), len);
1310 }
google_protobuf_DescriptorProto_resize_extension(google_protobuf_DescriptorProto * msg,size_t len,upb_arena * arena)1311 UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_extension(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
1312   return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(32, 64), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
1313 }
google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto * msg,upb_arena * arena)1314 UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
1315   struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
1316   bool ok = _upb_array_append_accessor(
1317       msg, UPB_SIZE(32, 64), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
1318   if (!ok) return NULL;
1319   return sub;
1320 }
google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto * msg,google_protobuf_MessageOptions * value)1321 UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) {
1322   _upb_sethas(msg, 2);
1323   UPB_FIELD_AT(msg, google_protobuf_MessageOptions*, UPB_SIZE(12, 24)) = value;
1324 }
google_protobuf_DescriptorProto_mutable_options(google_protobuf_DescriptorProto * msg,upb_arena * arena)1325 UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProto_mutable_options(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
1326   struct google_protobuf_MessageOptions* sub = (struct google_protobuf_MessageOptions*)google_protobuf_DescriptorProto_options(msg);
1327   if (sub == NULL) {
1328     sub = (struct google_protobuf_MessageOptions*)upb_msg_new(&google_protobuf_MessageOptions_msginit, arena);
1329     if (!sub) return NULL;
1330     google_protobuf_DescriptorProto_set_options(msg, sub);
1331   }
1332   return sub;
1333 }
google_protobuf_DescriptorProto_mutable_oneof_decl(google_protobuf_DescriptorProto * msg,size_t * len)1334 UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_mutable_oneof_decl(google_protobuf_DescriptorProto *msg, size_t *len) {
1335   return (google_protobuf_OneofDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 72), len);
1336 }
google_protobuf_DescriptorProto_resize_oneof_decl(google_protobuf_DescriptorProto * msg,size_t len,upb_arena * arena)1337 UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_resize_oneof_decl(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
1338   return (google_protobuf_OneofDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(36, 72), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
1339 }
google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto * msg,upb_arena * arena)1340 UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
1341   struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena);
1342   bool ok = _upb_array_append_accessor(
1343       msg, UPB_SIZE(36, 72), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
1344   if (!ok) return NULL;
1345   return sub;
1346 }
google_protobuf_DescriptorProto_mutable_reserved_range(google_protobuf_DescriptorProto * msg,size_t * len)1347 UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_mutable_reserved_range(google_protobuf_DescriptorProto *msg, size_t *len) {
1348   return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(40, 80), len);
1349 }
google_protobuf_DescriptorProto_resize_reserved_range(google_protobuf_DescriptorProto * msg,size_t len,upb_arena * arena)1350 UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_resize_reserved_range(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
1351   return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_resize_accessor(msg, UPB_SIZE(40, 80), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
1352 }
google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto * msg,upb_arena * arena)1353 UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
1354   struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena);
1355   bool ok = _upb_array_append_accessor(
1356       msg, UPB_SIZE(40, 80), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
1357   if (!ok) return NULL;
1358   return sub;
1359 }
google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto * msg,size_t * len)1360 UPB_INLINE upb_strview* google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto *msg, size_t *len) {
1361   return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(44, 88), len);
1362 }
google_protobuf_DescriptorProto_resize_reserved_name(google_protobuf_DescriptorProto * msg,size_t len,upb_arena * arena)1363 UPB_INLINE upb_strview* google_protobuf_DescriptorProto_resize_reserved_name(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
1364   return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(44, 88), len, UPB_SIZE(8, 16), UPB_TYPE_STRING, arena);
1365 }
google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto * msg,upb_strview val,upb_arena * arena)1366 UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto *msg, upb_strview val, upb_arena *arena) {
1367   return _upb_array_append_accessor(
1368       msg, UPB_SIZE(44, 88), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena);
1369 }
1370 
1371 
1372 /* google.protobuf.DescriptorProto.ExtensionRange */
1373 
google_protobuf_DescriptorProto_ExtensionRange_new(upb_arena * arena)1374 UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_new(upb_arena *arena) {
1375   return (google_protobuf_DescriptorProto_ExtensionRange *)upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena);
1376 }
google_protobuf_DescriptorProto_ExtensionRange_parse(const char * buf,size_t size,upb_arena * arena)1377 UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parse(const char *buf, size_t size,
1378                         upb_arena *arena) {
1379   google_protobuf_DescriptorProto_ExtensionRange *ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena);
1380   return (ret && upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit)) ? ret : NULL;
1381 }
google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange * msg,upb_arena * arena,size_t * len)1382 UPB_INLINE char *google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange *msg, upb_arena *arena, size_t *len) {
1383   return upb_encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, arena, len);
1384 }
1385 
google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange * msg)1386 UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return _upb_has_field(msg, 1); }
google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange * msg)1387 UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); }
google_protobuf_DescriptorProto_ExtensionRange_has_end(const google_protobuf_DescriptorProto_ExtensionRange * msg)1388 UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return _upb_has_field(msg, 2); }
google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange * msg)1389 UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
google_protobuf_DescriptorProto_ExtensionRange_has_options(const google_protobuf_DescriptorProto_ExtensionRange * msg)1390 UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_options(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return _upb_has_field(msg, 3); }
google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange * msg)1391 UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return UPB_FIELD_AT(msg, const google_protobuf_ExtensionRangeOptions*, UPB_SIZE(12, 16)); }
1392 
google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange * msg,int32_t value)1393 UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) {
1394   _upb_sethas(msg, 1);
1395   UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value;
1396 }
google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange * msg,int32_t value)1397 UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) {
1398   _upb_sethas(msg, 2);
1399   UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
1400 }
google_protobuf_DescriptorProto_ExtensionRange_set_options(google_protobuf_DescriptorProto_ExtensionRange * msg,google_protobuf_ExtensionRangeOptions * value)1401 UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(google_protobuf_DescriptorProto_ExtensionRange *msg, google_protobuf_ExtensionRangeOptions* value) {
1402   _upb_sethas(msg, 3);
1403   UPB_FIELD_AT(msg, google_protobuf_ExtensionRangeOptions*, UPB_SIZE(12, 16)) = value;
1404 }
google_protobuf_DescriptorProto_ExtensionRange_mutable_options(google_protobuf_DescriptorProto_ExtensionRange * msg,upb_arena * arena)1405 UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_mutable_options(google_protobuf_DescriptorProto_ExtensionRange *msg, upb_arena *arena) {
1406   struct google_protobuf_ExtensionRangeOptions* sub = (struct google_protobuf_ExtensionRangeOptions*)google_protobuf_DescriptorProto_ExtensionRange_options(msg);
1407   if (sub == NULL) {
1408     sub = (struct google_protobuf_ExtensionRangeOptions*)upb_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena);
1409     if (!sub) return NULL;
1410     google_protobuf_DescriptorProto_ExtensionRange_set_options(msg, sub);
1411   }
1412   return sub;
1413 }
1414 
1415 
1416 /* google.protobuf.DescriptorProto.ReservedRange */
1417 
google_protobuf_DescriptorProto_ReservedRange_new(upb_arena * arena)1418 UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_new(upb_arena *arena) {
1419   return (google_protobuf_DescriptorProto_ReservedRange *)upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena);
1420 }
google_protobuf_DescriptorProto_ReservedRange_parse(const char * buf,size_t size,upb_arena * arena)1421 UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parse(const char *buf, size_t size,
1422                         upb_arena *arena) {
1423   google_protobuf_DescriptorProto_ReservedRange *ret = google_protobuf_DescriptorProto_ReservedRange_new(arena);
1424   return (ret && upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit)) ? ret : NULL;
1425 }
google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange * msg,upb_arena * arena,size_t * len)1426 UPB_INLINE char *google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange *msg, upb_arena *arena, size_t *len) {
1427   return upb_encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, arena, len);
1428 }
1429 
google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange * msg)1430 UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange *msg) { return _upb_has_field(msg, 1); }
google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange * msg)1431 UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); }
google_protobuf_DescriptorProto_ReservedRange_has_end(const google_protobuf_DescriptorProto_ReservedRange * msg)1432 UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { return _upb_has_field(msg, 2); }
google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange * msg)1433 UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
1434 
google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange * msg,int32_t value)1435 UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) {
1436   _upb_sethas(msg, 1);
1437   UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value;
1438 }
google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange * msg,int32_t value)1439 UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) {
1440   _upb_sethas(msg, 2);
1441   UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
1442 }
1443 
1444 
1445 /* google.protobuf.ExtensionRangeOptions */
1446 
google_protobuf_ExtensionRangeOptions_new(upb_arena * arena)1447 UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_new(upb_arena *arena) {
1448   return (google_protobuf_ExtensionRangeOptions *)upb_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena);
1449 }
google_protobuf_ExtensionRangeOptions_parse(const char * buf,size_t size,upb_arena * arena)1450 UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_parse(const char *buf, size_t size,
1451                         upb_arena *arena) {
1452   google_protobuf_ExtensionRangeOptions *ret = google_protobuf_ExtensionRangeOptions_new(arena);
1453   return (ret && upb_decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msginit)) ? ret : NULL;
1454 }
google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions * msg,upb_arena * arena,size_t * len)1455 UPB_INLINE char *google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions *msg, upb_arena *arena, size_t *len) {
1456   return upb_encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, arena, len);
1457 }
1458 
google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions * msg,size_t * len)1459 UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); }
1460 
google_protobuf_ExtensionRangeOptions_mutable_uninterpreted_option(google_protobuf_ExtensionRangeOptions * msg,size_t * len)1461 UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_mutable_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, size_t *len) {
1462   return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
1463 }
google_protobuf_ExtensionRangeOptions_resize_uninterpreted_option(google_protobuf_ExtensionRangeOptions * msg,size_t len,upb_arena * arena)1464 UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_resize_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, size_t len, upb_arena *arena) {
1465   return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
1466 }
google_protobuf_ExtensionRangeOptions_add_uninterpreted_option(google_protobuf_ExtensionRangeOptions * msg,upb_arena * arena)1467 UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, upb_arena *arena) {
1468   struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
1469   bool ok = _upb_array_append_accessor(
1470       msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
1471   if (!ok) return NULL;
1472   return sub;
1473 }
1474 
1475 
1476 /* google.protobuf.FieldDescriptorProto */
1477 
google_protobuf_FieldDescriptorProto_new(upb_arena * arena)1478 UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_new(upb_arena *arena) {
1479   return (google_protobuf_FieldDescriptorProto *)upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
1480 }
google_protobuf_FieldDescriptorProto_parse(const char * buf,size_t size,upb_arena * arena)1481 UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parse(const char *buf, size_t size,
1482                         upb_arena *arena) {
1483   google_protobuf_FieldDescriptorProto *ret = google_protobuf_FieldDescriptorProto_new(arena);
1484   return (ret && upb_decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msginit)) ? ret : NULL;
1485 }
google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto * msg,upb_arena * arena,size_t * len)1486 UPB_INLINE char *google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto *msg, upb_arena *arena, size_t *len) {
1487   return upb_encode(msg, &google_protobuf_FieldDescriptorProto_msginit, arena, len);
1488 }
1489 
google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto * msg)1490 UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 5); }
google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto * msg)1491 UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(32, 32)); }
google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto * msg)1492 UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 6); }
google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto * msg)1493 UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(40, 48)); }
google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto * msg)1494 UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 3); }
google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto * msg)1495 UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(24, 24)); }
google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto * msg)1496 UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 1); }
google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto * msg)1497 UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto * msg)1498 UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 2); }
google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto * msg)1499 UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(16, 16)); }
google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto * msg)1500 UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 7); }
google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto * msg)1501 UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(48, 64)); }
google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto * msg)1502 UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 8); }
google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto * msg)1503 UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(56, 80)); }
google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto * msg)1504 UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 10); }
google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto * msg)1505 UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_FieldOptions*, UPB_SIZE(72, 112)); }
google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto * msg)1506 UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 4); }
google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto * msg)1507 UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(28, 28)); }
google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto * msg)1508 UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 9); }
google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto * msg)1509 UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(64, 96)); }
1510 
google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto * msg,upb_strview value)1511 UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
1512   _upb_sethas(msg, 5);
1513   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(32, 32)) = value;
1514 }
google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto * msg,upb_strview value)1515 UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
1516   _upb_sethas(msg, 6);
1517   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(40, 48)) = value;
1518 }
google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto * msg,int32_t value)1519 UPB_INLINE void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
1520   _upb_sethas(msg, 3);
1521   UPB_FIELD_AT(msg, int32_t, UPB_SIZE(24, 24)) = value;
1522 }
google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto * msg,int32_t value)1523 UPB_INLINE void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
1524   _upb_sethas(msg, 1);
1525   UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
1526 }
google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto * msg,int32_t value)1527 UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
1528   _upb_sethas(msg, 2);
1529   UPB_FIELD_AT(msg, int32_t, UPB_SIZE(16, 16)) = value;
1530 }
google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto * msg,upb_strview value)1531 UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
1532   _upb_sethas(msg, 7);
1533   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(48, 64)) = value;
1534 }
google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto * msg,upb_strview value)1535 UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
1536   _upb_sethas(msg, 8);
1537   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(56, 80)) = value;
1538 }
google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto * msg,google_protobuf_FieldOptions * value)1539 UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) {
1540   _upb_sethas(msg, 10);
1541   UPB_FIELD_AT(msg, google_protobuf_FieldOptions*, UPB_SIZE(72, 112)) = value;
1542 }
google_protobuf_FieldDescriptorProto_mutable_options(google_protobuf_FieldDescriptorProto * msg,upb_arena * arena)1543 UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_mutable_options(google_protobuf_FieldDescriptorProto *msg, upb_arena *arena) {
1544   struct google_protobuf_FieldOptions* sub = (struct google_protobuf_FieldOptions*)google_protobuf_FieldDescriptorProto_options(msg);
1545   if (sub == NULL) {
1546     sub = (struct google_protobuf_FieldOptions*)upb_msg_new(&google_protobuf_FieldOptions_msginit, arena);
1547     if (!sub) return NULL;
1548     google_protobuf_FieldDescriptorProto_set_options(msg, sub);
1549   }
1550   return sub;
1551 }
google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto * msg,int32_t value)1552 UPB_INLINE void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
1553   _upb_sethas(msg, 4);
1554   UPB_FIELD_AT(msg, int32_t, UPB_SIZE(28, 28)) = value;
1555 }
google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto * msg,upb_strview value)1556 UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
1557   _upb_sethas(msg, 9);
1558   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(64, 96)) = value;
1559 }
1560 
1561 
1562 /* google.protobuf.OneofDescriptorProto */
1563 
google_protobuf_OneofDescriptorProto_new(upb_arena * arena)1564 UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_new(upb_arena *arena) {
1565   return (google_protobuf_OneofDescriptorProto *)upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena);
1566 }
google_protobuf_OneofDescriptorProto_parse(const char * buf,size_t size,upb_arena * arena)1567 UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parse(const char *buf, size_t size,
1568                         upb_arena *arena) {
1569   google_protobuf_OneofDescriptorProto *ret = google_protobuf_OneofDescriptorProto_new(arena);
1570   return (ret && upb_decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msginit)) ? ret : NULL;
1571 }
google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto * msg,upb_arena * arena,size_t * len)1572 UPB_INLINE char *google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto *msg, upb_arena *arena, size_t *len) {
1573   return upb_encode(msg, &google_protobuf_OneofDescriptorProto_msginit, arena, len);
1574 }
1575 
google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto * msg)1576 UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto *msg) { return _upb_has_field(msg, 1); }
google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto * msg)1577 UPB_INLINE upb_strview google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto * msg)1578 UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto *msg) { return _upb_has_field(msg, 2); }
google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto * msg)1579 UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_OneofOptions*, UPB_SIZE(12, 24)); }
1580 
google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto * msg,upb_strview value)1581 UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_strview value) {
1582   _upb_sethas(msg, 1);
1583   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
1584 }
google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto * msg,google_protobuf_OneofOptions * value)1585 UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto *msg, google_protobuf_OneofOptions* value) {
1586   _upb_sethas(msg, 2);
1587   UPB_FIELD_AT(msg, google_protobuf_OneofOptions*, UPB_SIZE(12, 24)) = value;
1588 }
google_protobuf_OneofDescriptorProto_mutable_options(google_protobuf_OneofDescriptorProto * msg,upb_arena * arena)1589 UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_mutable_options(google_protobuf_OneofDescriptorProto *msg, upb_arena *arena) {
1590   struct google_protobuf_OneofOptions* sub = (struct google_protobuf_OneofOptions*)google_protobuf_OneofDescriptorProto_options(msg);
1591   if (sub == NULL) {
1592     sub = (struct google_protobuf_OneofOptions*)upb_msg_new(&google_protobuf_OneofOptions_msginit, arena);
1593     if (!sub) return NULL;
1594     google_protobuf_OneofDescriptorProto_set_options(msg, sub);
1595   }
1596   return sub;
1597 }
1598 
1599 
1600 /* google.protobuf.EnumDescriptorProto */
1601 
google_protobuf_EnumDescriptorProto_new(upb_arena * arena)1602 UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_new(upb_arena *arena) {
1603   return (google_protobuf_EnumDescriptorProto *)upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena);
1604 }
google_protobuf_EnumDescriptorProto_parse(const char * buf,size_t size,upb_arena * arena)1605 UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parse(const char *buf, size_t size,
1606                         upb_arena *arena) {
1607   google_protobuf_EnumDescriptorProto *ret = google_protobuf_EnumDescriptorProto_new(arena);
1608   return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msginit)) ? ret : NULL;
1609 }
google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto * msg,upb_arena * arena,size_t * len)1610 UPB_INLINE char *google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto *msg, upb_arena *arena, size_t *len) {
1611   return upb_encode(msg, &google_protobuf_EnumDescriptorProto_msginit, arena, len);
1612 }
1613 
google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto * msg)1614 UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto *msg) { return _upb_has_field(msg, 1); }
google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto * msg)1615 UPB_INLINE upb_strview google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto * msg,size_t * len)1616 UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (const google_protobuf_EnumValueDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 32), len); }
google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto * msg)1617 UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto *msg) { return _upb_has_field(msg, 2); }
google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto * msg)1618 UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_EnumOptions*, UPB_SIZE(12, 24)); }
google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto * msg,size_t * len)1619 UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); }
google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto * msg,size_t * len)1620 UPB_INLINE upb_strview const* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); }
1621 
google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto * msg,upb_strview value)1622 UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_strview value) {
1623   _upb_sethas(msg, 1);
1624   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
1625 }
google_protobuf_EnumDescriptorProto_mutable_value(google_protobuf_EnumDescriptorProto * msg,size_t * len)1626 UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_mutable_value(google_protobuf_EnumDescriptorProto *msg, size_t *len) {
1627   return (google_protobuf_EnumValueDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len);
1628 }
google_protobuf_EnumDescriptorProto_resize_value(google_protobuf_EnumDescriptorProto * msg,size_t len,upb_arena * arena)1629 UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_resize_value(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_arena *arena) {
1630   return (google_protobuf_EnumValueDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
1631 }
google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto * msg,upb_arena * arena)1632 UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto *msg, upb_arena *arena) {
1633   struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena);
1634   bool ok = _upb_array_append_accessor(
1635       msg, UPB_SIZE(16, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
1636   if (!ok) return NULL;
1637   return sub;
1638 }
google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto * msg,google_protobuf_EnumOptions * value)1639 UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) {
1640   _upb_sethas(msg, 2);
1641   UPB_FIELD_AT(msg, google_protobuf_EnumOptions*, UPB_SIZE(12, 24)) = value;
1642 }
google_protobuf_EnumDescriptorProto_mutable_options(google_protobuf_EnumDescriptorProto * msg,upb_arena * arena)1643 UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_mutable_options(google_protobuf_EnumDescriptorProto *msg, upb_arena *arena) {
1644   struct google_protobuf_EnumOptions* sub = (struct google_protobuf_EnumOptions*)google_protobuf_EnumDescriptorProto_options(msg);
1645   if (sub == NULL) {
1646     sub = (struct google_protobuf_EnumOptions*)upb_msg_new(&google_protobuf_EnumOptions_msginit, arena);
1647     if (!sub) return NULL;
1648     google_protobuf_EnumDescriptorProto_set_options(msg, sub);
1649   }
1650   return sub;
1651 }
google_protobuf_EnumDescriptorProto_mutable_reserved_range(google_protobuf_EnumDescriptorProto * msg,size_t * len)1652 UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_mutable_reserved_range(google_protobuf_EnumDescriptorProto *msg, size_t *len) {
1653   return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len);
1654 }
google_protobuf_EnumDescriptorProto_resize_reserved_range(google_protobuf_EnumDescriptorProto * msg,size_t len,upb_arena * arena)1655 UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_resize_reserved_range(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_arena *arena) {
1656   return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
1657 }
google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto * msg,upb_arena * arena)1658 UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto *msg, upb_arena *arena) {
1659   struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena);
1660   bool ok = _upb_array_append_accessor(
1661       msg, UPB_SIZE(20, 40), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
1662   if (!ok) return NULL;
1663   return sub;
1664 }
google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto * msg,size_t * len)1665 UPB_INLINE upb_strview* google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto *msg, size_t *len) {
1666   return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len);
1667 }
google_protobuf_EnumDescriptorProto_resize_reserved_name(google_protobuf_EnumDescriptorProto * msg,size_t len,upb_arena * arena)1668 UPB_INLINE upb_strview* google_protobuf_EnumDescriptorProto_resize_reserved_name(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_arena *arena) {
1669   return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_SIZE(8, 16), UPB_TYPE_STRING, arena);
1670 }
google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto * msg,upb_strview val,upb_arena * arena)1671 UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto *msg, upb_strview val, upb_arena *arena) {
1672   return _upb_array_append_accessor(
1673       msg, UPB_SIZE(24, 48), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena);
1674 }
1675 
1676 
1677 /* google.protobuf.EnumDescriptorProto.EnumReservedRange */
1678 
google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_arena * arena)1679 UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_arena *arena) {
1680   return (google_protobuf_EnumDescriptorProto_EnumReservedRange *)upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena);
1681 }
google_protobuf_EnumDescriptorProto_EnumReservedRange_parse(const char * buf,size_t size,upb_arena * arena)1682 UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_parse(const char *buf, size_t size,
1683                         upb_arena *arena) {
1684   google_protobuf_EnumDescriptorProto_EnumReservedRange *ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena);
1685   return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit)) ? ret : NULL;
1686 }
google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange * msg,upb_arena * arena,size_t * len)1687 UPB_INLINE char *google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, upb_arena *arena, size_t *len) {
1688   return upb_encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena, len);
1689 }
1690 
google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange * msg)1691 UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return _upb_has_field(msg, 1); }
google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange * msg)1692 UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); }
google_protobuf_EnumDescriptorProto_EnumReservedRange_has_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange * msg)1693 UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return _upb_has_field(msg, 2); }
google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange * msg)1694 UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
1695 
google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange * msg,int32_t value)1696 UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) {
1697   _upb_sethas(msg, 1);
1698   UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value;
1699 }
google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(google_protobuf_EnumDescriptorProto_EnumReservedRange * msg,int32_t value)1700 UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) {
1701   _upb_sethas(msg, 2);
1702   UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
1703 }
1704 
1705 
1706 /* google.protobuf.EnumValueDescriptorProto */
1707 
google_protobuf_EnumValueDescriptorProto_new(upb_arena * arena)1708 UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_new(upb_arena *arena) {
1709   return (google_protobuf_EnumValueDescriptorProto *)upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena);
1710 }
google_protobuf_EnumValueDescriptorProto_parse(const char * buf,size_t size,upb_arena * arena)1711 UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parse(const char *buf, size_t size,
1712                         upb_arena *arena) {
1713   google_protobuf_EnumValueDescriptorProto *ret = google_protobuf_EnumValueDescriptorProto_new(arena);
1714   return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msginit)) ? ret : NULL;
1715 }
google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto * msg,upb_arena * arena,size_t * len)1716 UPB_INLINE char *google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto *msg, upb_arena *arena, size_t *len) {
1717   return upb_encode(msg, &google_protobuf_EnumValueDescriptorProto_msginit, arena, len);
1718 }
1719 
google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto * msg)1720 UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_has_field(msg, 2); }
google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto * msg)1721 UPB_INLINE upb_strview google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(8, 8)); }
google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto * msg)1722 UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_has_field(msg, 1); }
google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto * msg)1723 UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); }
google_protobuf_EnumValueDescriptorProto_has_options(const google_protobuf_EnumValueDescriptorProto * msg)1724 UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_has_field(msg, 3); }
google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto * msg)1725 UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_EnumValueOptions*, UPB_SIZE(16, 24)); }
1726 
google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto * msg,upb_strview value)1727 UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_strview value) {
1728   _upb_sethas(msg, 2);
1729   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(8, 8)) = value;
1730 }
google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto * msg,int32_t value)1731 UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) {
1732   _upb_sethas(msg, 1);
1733   UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value;
1734 }
google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto * msg,google_protobuf_EnumValueOptions * value)1735 UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value) {
1736   _upb_sethas(msg, 3);
1737   UPB_FIELD_AT(msg, google_protobuf_EnumValueOptions*, UPB_SIZE(16, 24)) = value;
1738 }
google_protobuf_EnumValueDescriptorProto_mutable_options(google_protobuf_EnumValueDescriptorProto * msg,upb_arena * arena)1739 UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_mutable_options(google_protobuf_EnumValueDescriptorProto *msg, upb_arena *arena) {
1740   struct google_protobuf_EnumValueOptions* sub = (struct google_protobuf_EnumValueOptions*)google_protobuf_EnumValueDescriptorProto_options(msg);
1741   if (sub == NULL) {
1742     sub = (struct google_protobuf_EnumValueOptions*)upb_msg_new(&google_protobuf_EnumValueOptions_msginit, arena);
1743     if (!sub) return NULL;
1744     google_protobuf_EnumValueDescriptorProto_set_options(msg, sub);
1745   }
1746   return sub;
1747 }
1748 
1749 
1750 /* google.protobuf.ServiceDescriptorProto */
1751 
google_protobuf_ServiceDescriptorProto_new(upb_arena * arena)1752 UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_new(upb_arena *arena) {
1753   return (google_protobuf_ServiceDescriptorProto *)upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena);
1754 }
google_protobuf_ServiceDescriptorProto_parse(const char * buf,size_t size,upb_arena * arena)1755 UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parse(const char *buf, size_t size,
1756                         upb_arena *arena) {
1757   google_protobuf_ServiceDescriptorProto *ret = google_protobuf_ServiceDescriptorProto_new(arena);
1758   return (ret && upb_decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msginit)) ? ret : NULL;
1759 }
google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto * msg,upb_arena * arena,size_t * len)1760 UPB_INLINE char *google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena, size_t *len) {
1761   return upb_encode(msg, &google_protobuf_ServiceDescriptorProto_msginit, arena, len);
1762 }
1763 
google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto * msg)1764 UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto *msg) { return _upb_has_field(msg, 1); }
google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto * msg)1765 UPB_INLINE upb_strview google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto * msg,size_t * len)1766 UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto *msg, size_t *len) { return (const google_protobuf_MethodDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 32), len); }
google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto * msg)1767 UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto *msg) { return _upb_has_field(msg, 2); }
google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto * msg)1768 UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_ServiceOptions*, UPB_SIZE(12, 24)); }
1769 
google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto * msg,upb_strview value)1770 UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_strview value) {
1771   _upb_sethas(msg, 1);
1772   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
1773 }
google_protobuf_ServiceDescriptorProto_mutable_method(google_protobuf_ServiceDescriptorProto * msg,size_t * len)1774 UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_mutable_method(google_protobuf_ServiceDescriptorProto *msg, size_t *len) {
1775   return (google_protobuf_MethodDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len);
1776 }
google_protobuf_ServiceDescriptorProto_resize_method(google_protobuf_ServiceDescriptorProto * msg,size_t len,upb_arena * arena)1777 UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_resize_method(google_protobuf_ServiceDescriptorProto *msg, size_t len, upb_arena *arena) {
1778   return (google_protobuf_MethodDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
1779 }
google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto * msg,upb_arena * arena)1780 UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena) {
1781   struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena);
1782   bool ok = _upb_array_append_accessor(
1783       msg, UPB_SIZE(16, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
1784   if (!ok) return NULL;
1785   return sub;
1786 }
google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto * msg,google_protobuf_ServiceOptions * value)1787 UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) {
1788   _upb_sethas(msg, 2);
1789   UPB_FIELD_AT(msg, google_protobuf_ServiceOptions*, UPB_SIZE(12, 24)) = value;
1790 }
google_protobuf_ServiceDescriptorProto_mutable_options(google_protobuf_ServiceDescriptorProto * msg,upb_arena * arena)1791 UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_mutable_options(google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena) {
1792   struct google_protobuf_ServiceOptions* sub = (struct google_protobuf_ServiceOptions*)google_protobuf_ServiceDescriptorProto_options(msg);
1793   if (sub == NULL) {
1794     sub = (struct google_protobuf_ServiceOptions*)upb_msg_new(&google_protobuf_ServiceOptions_msginit, arena);
1795     if (!sub) return NULL;
1796     google_protobuf_ServiceDescriptorProto_set_options(msg, sub);
1797   }
1798   return sub;
1799 }
1800 
1801 
1802 /* google.protobuf.MethodDescriptorProto */
1803 
google_protobuf_MethodDescriptorProto_new(upb_arena * arena)1804 UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_new(upb_arena *arena) {
1805   return (google_protobuf_MethodDescriptorProto *)upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena);
1806 }
google_protobuf_MethodDescriptorProto_parse(const char * buf,size_t size,upb_arena * arena)1807 UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parse(const char *buf, size_t size,
1808                         upb_arena *arena) {
1809   google_protobuf_MethodDescriptorProto *ret = google_protobuf_MethodDescriptorProto_new(arena);
1810   return (ret && upb_decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msginit)) ? ret : NULL;
1811 }
google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto * msg,upb_arena * arena,size_t * len)1812 UPB_INLINE char *google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto *msg, upb_arena *arena, size_t *len) {
1813   return upb_encode(msg, &google_protobuf_MethodDescriptorProto_msginit, arena, len);
1814 }
1815 
google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto * msg)1816 UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 3); }
google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto * msg)1817 UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto * msg)1818 UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 4); }
google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto * msg)1819 UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)); }
google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto * msg)1820 UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 5); }
google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto * msg)1821 UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(20, 40)); }
google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto * msg)1822 UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 6); }
google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto * msg)1823 UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_MethodOptions*, UPB_SIZE(28, 56)); }
google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto * msg)1824 UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 1); }
google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto * msg)1825 UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); }
google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto * msg)1826 UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 2); }
google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto * msg)1827 UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); }
1828 
google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto * msg,upb_strview value)1829 UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_strview value) {
1830   _upb_sethas(msg, 3);
1831   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
1832 }
google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto * msg,upb_strview value)1833 UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_strview value) {
1834   _upb_sethas(msg, 4);
1835   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)) = value;
1836 }
google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto * msg,upb_strview value)1837 UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_strview value) {
1838   _upb_sethas(msg, 5);
1839   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(20, 40)) = value;
1840 }
google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto * msg,google_protobuf_MethodOptions * value)1841 UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) {
1842   _upb_sethas(msg, 6);
1843   UPB_FIELD_AT(msg, google_protobuf_MethodOptions*, UPB_SIZE(28, 56)) = value;
1844 }
google_protobuf_MethodDescriptorProto_mutable_options(google_protobuf_MethodDescriptorProto * msg,upb_arena * arena)1845 UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_mutable_options(google_protobuf_MethodDescriptorProto *msg, upb_arena *arena) {
1846   struct google_protobuf_MethodOptions* sub = (struct google_protobuf_MethodOptions*)google_protobuf_MethodDescriptorProto_options(msg);
1847   if (sub == NULL) {
1848     sub = (struct google_protobuf_MethodOptions*)upb_msg_new(&google_protobuf_MethodOptions_msginit, arena);
1849     if (!sub) return NULL;
1850     google_protobuf_MethodDescriptorProto_set_options(msg, sub);
1851   }
1852   return sub;
1853 }
google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto * msg,bool value)1854 UPB_INLINE void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) {
1855   _upb_sethas(msg, 1);
1856   UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
1857 }
google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto * msg,bool value)1858 UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) {
1859   _upb_sethas(msg, 2);
1860   UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value;
1861 }
1862 
1863 
1864 /* google.protobuf.FileOptions */
1865 
google_protobuf_FileOptions_new(upb_arena * arena)1866 UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_arena *arena) {
1867   return (google_protobuf_FileOptions *)upb_msg_new(&google_protobuf_FileOptions_msginit, arena);
1868 }
google_protobuf_FileOptions_parse(const char * buf,size_t size,upb_arena * arena)1869 UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_parse(const char *buf, size_t size,
1870                         upb_arena *arena) {
1871   google_protobuf_FileOptions *ret = google_protobuf_FileOptions_new(arena);
1872   return (ret && upb_decode(buf, size, ret, &google_protobuf_FileOptions_msginit)) ? ret : NULL;
1873 }
google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions * msg,upb_arena * arena,size_t * len)1874 UPB_INLINE char *google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions *msg, upb_arena *arena, size_t *len) {
1875   return upb_encode(msg, &google_protobuf_FileOptions_msginit, arena, len);
1876 }
1877 
google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions * msg)1878 UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 11); }
google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions * msg)1879 UPB_INLINE upb_strview google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(28, 32)); }
google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions * msg)1880 UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 12); }
google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions * msg)1881 UPB_INLINE upb_strview google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(36, 48)); }
google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions * msg)1882 UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 1); }
google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions * msg)1883 UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions * msg)1884 UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 2); }
google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions * msg)1885 UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)); }
google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions * msg)1886 UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 13); }
google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions * msg)1887 UPB_INLINE upb_strview google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(44, 64)); }
google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions * msg)1888 UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 3); }
google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions * msg)1889 UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(17, 17)); }
google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions * msg)1890 UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 4); }
google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions * msg)1891 UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(18, 18)); }
google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions * msg)1892 UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 5); }
google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions * msg)1893 UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(19, 19)); }
google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions * msg)1894 UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 6); }
google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions * msg)1895 UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(20, 20)); }
google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions * msg)1896 UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 7); }
google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions * msg)1897 UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(21, 21)); }
google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions * msg)1898 UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 8); }
google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions * msg)1899 UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(22, 22)); }
google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions * msg)1900 UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 9); }
google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions * msg)1901 UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(23, 23)); }
google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions * msg)1902 UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 14); }
google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions * msg)1903 UPB_INLINE upb_strview google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(52, 80)); }
google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions * msg)1904 UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 15); }
google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions * msg)1905 UPB_INLINE upb_strview google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(60, 96)); }
google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions * msg)1906 UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 16); }
google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions * msg)1907 UPB_INLINE upb_strview google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(68, 112)); }
google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions * msg)1908 UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 17); }
google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions * msg)1909 UPB_INLINE upb_strview google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(76, 128)); }
google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions * msg)1910 UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 18); }
google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions * msg)1911 UPB_INLINE upb_strview google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(84, 144)); }
google_protobuf_FileOptions_has_php_generic_services(const google_protobuf_FileOptions * msg)1912 UPB_INLINE bool google_protobuf_FileOptions_has_php_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 10); }
google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions * msg)1913 UPB_INLINE bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)); }
google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions * msg,size_t * len)1914 UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(92, 160), len); }
1915 
google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions * msg,upb_strview value)1916 UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_strview value) {
1917   _upb_sethas(msg, 11);
1918   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(28, 32)) = value;
1919 }
google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions * msg,upb_strview value)1920 UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_strview value) {
1921   _upb_sethas(msg, 12);
1922   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(36, 48)) = value;
1923 }
google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions * msg,int32_t value)1924 UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, int32_t value) {
1925   _upb_sethas(msg, 1);
1926   UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
1927 }
google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions * msg,bool value)1928 UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions *msg, bool value) {
1929   _upb_sethas(msg, 2);
1930   UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)) = value;
1931 }
google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions * msg,upb_strview value)1932 UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_strview value) {
1933   _upb_sethas(msg, 13);
1934   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(44, 64)) = value;
1935 }
google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions * msg,bool value)1936 UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) {
1937   _upb_sethas(msg, 3);
1938   UPB_FIELD_AT(msg, bool, UPB_SIZE(17, 17)) = value;
1939 }
google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions * msg,bool value)1940 UPB_INLINE void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions *msg, bool value) {
1941   _upb_sethas(msg, 4);
1942   UPB_FIELD_AT(msg, bool, UPB_SIZE(18, 18)) = value;
1943 }
google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions * msg,bool value)1944 UPB_INLINE void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions *msg, bool value) {
1945   _upb_sethas(msg, 5);
1946   UPB_FIELD_AT(msg, bool, UPB_SIZE(19, 19)) = value;
1947 }
google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions * msg,bool value)1948 UPB_INLINE void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions *msg, bool value) {
1949   _upb_sethas(msg, 6);
1950   UPB_FIELD_AT(msg, bool, UPB_SIZE(20, 20)) = value;
1951 }
google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions * msg,bool value)1952 UPB_INLINE void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions *msg, bool value) {
1953   _upb_sethas(msg, 7);
1954   UPB_FIELD_AT(msg, bool, UPB_SIZE(21, 21)) = value;
1955 }
google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions * msg,bool value)1956 UPB_INLINE void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions *msg, bool value) {
1957   _upb_sethas(msg, 8);
1958   UPB_FIELD_AT(msg, bool, UPB_SIZE(22, 22)) = value;
1959 }
google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions * msg,bool value)1960 UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions *msg, bool value) {
1961   _upb_sethas(msg, 9);
1962   UPB_FIELD_AT(msg, bool, UPB_SIZE(23, 23)) = value;
1963 }
google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions * msg,upb_strview value)1964 UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_strview value) {
1965   _upb_sethas(msg, 14);
1966   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(52, 80)) = value;
1967 }
google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions * msg,upb_strview value)1968 UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_strview value) {
1969   _upb_sethas(msg, 15);
1970   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(60, 96)) = value;
1971 }
google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions * msg,upb_strview value)1972 UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_strview value) {
1973   _upb_sethas(msg, 16);
1974   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(68, 112)) = value;
1975 }
google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions * msg,upb_strview value)1976 UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_strview value) {
1977   _upb_sethas(msg, 17);
1978   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(76, 128)) = value;
1979 }
google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions * msg,upb_strview value)1980 UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_strview value) {
1981   _upb_sethas(msg, 18);
1982   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(84, 144)) = value;
1983 }
google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions * msg,bool value)1984 UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) {
1985   _upb_sethas(msg, 10);
1986   UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)) = value;
1987 }
google_protobuf_FileOptions_mutable_uninterpreted_option(google_protobuf_FileOptions * msg,size_t * len)1988 UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mutable_uninterpreted_option(google_protobuf_FileOptions *msg, size_t *len) {
1989   return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(92, 160), len);
1990 }
google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions * msg,size_t len,upb_arena * arena)1991 UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions *msg, size_t len, upb_arena *arena) {
1992   return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(92, 160), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
1993 }
google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions * msg,upb_arena * arena)1994 UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions *msg, upb_arena *arena) {
1995   struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
1996   bool ok = _upb_array_append_accessor(
1997       msg, UPB_SIZE(92, 160), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
1998   if (!ok) return NULL;
1999   return sub;
2000 }
2001 
2002 
2003 /* google.protobuf.MessageOptions */
2004 
google_protobuf_MessageOptions_new(upb_arena * arena)2005 UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(upb_arena *arena) {
2006   return (google_protobuf_MessageOptions *)upb_msg_new(&google_protobuf_MessageOptions_msginit, arena);
2007 }
google_protobuf_MessageOptions_parse(const char * buf,size_t size,upb_arena * arena)2008 UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_parse(const char *buf, size_t size,
2009                         upb_arena *arena) {
2010   google_protobuf_MessageOptions *ret = google_protobuf_MessageOptions_new(arena);
2011   return (ret && upb_decode(buf, size, ret, &google_protobuf_MessageOptions_msginit)) ? ret : NULL;
2012 }
google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions * msg,upb_arena * arena,size_t * len)2013 UPB_INLINE char *google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions *msg, upb_arena *arena, size_t *len) {
2014   return upb_encode(msg, &google_protobuf_MessageOptions_msginit, arena, len);
2015 }
2016 
google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions * msg)2017 UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 1); }
google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions * msg)2018 UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); }
google_protobuf_MessageOptions_has_no_standard_descriptor_accessor(const google_protobuf_MessageOptions * msg)2019 UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 2); }
google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions * msg)2020 UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); }
google_protobuf_MessageOptions_has_deprecated(const google_protobuf_MessageOptions * msg)2021 UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 3); }
google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions * msg)2022 UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(3, 3)); }
google_protobuf_MessageOptions_has_map_entry(const google_protobuf_MessageOptions * msg)2023 UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 4); }
google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions * msg)2024 UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(4, 4)); }
google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions * msg,size_t * len)2025 UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(8, 8), len); }
2026 
google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions * msg,bool value)2027 UPB_INLINE void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) {
2028   _upb_sethas(msg, 1);
2029   UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
2030 }
google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions * msg,bool value)2031 UPB_INLINE void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions *msg, bool value) {
2032   _upb_sethas(msg, 2);
2033   UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value;
2034 }
google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions * msg,bool value)2035 UPB_INLINE void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions *msg, bool value) {
2036   _upb_sethas(msg, 3);
2037   UPB_FIELD_AT(msg, bool, UPB_SIZE(3, 3)) = value;
2038 }
google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions * msg,bool value)2039 UPB_INLINE void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions *msg, bool value) {
2040   _upb_sethas(msg, 4);
2041   UPB_FIELD_AT(msg, bool, UPB_SIZE(4, 4)) = value;
2042 }
google_protobuf_MessageOptions_mutable_uninterpreted_option(google_protobuf_MessageOptions * msg,size_t * len)2043 UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_mutable_uninterpreted_option(google_protobuf_MessageOptions *msg, size_t *len) {
2044   return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(8, 8), len);
2045 }
google_protobuf_MessageOptions_resize_uninterpreted_option(google_protobuf_MessageOptions * msg,size_t len,upb_arena * arena)2046 UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_resize_uninterpreted_option(google_protobuf_MessageOptions *msg, size_t len, upb_arena *arena) {
2047   return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(8, 8), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
2048 }
google_protobuf_MessageOptions_add_uninterpreted_option(google_protobuf_MessageOptions * msg,upb_arena * arena)2049 UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option(google_protobuf_MessageOptions *msg, upb_arena *arena) {
2050   struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
2051   bool ok = _upb_array_append_accessor(
2052       msg, UPB_SIZE(8, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
2053   if (!ok) return NULL;
2054   return sub;
2055 }
2056 
2057 
2058 /* google.protobuf.FieldOptions */
2059 
google_protobuf_FieldOptions_new(upb_arena * arena)2060 UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_arena *arena) {
2061   return (google_protobuf_FieldOptions *)upb_msg_new(&google_protobuf_FieldOptions_msginit, arena);
2062 }
google_protobuf_FieldOptions_parse(const char * buf,size_t size,upb_arena * arena)2063 UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_parse(const char *buf, size_t size,
2064                         upb_arena *arena) {
2065   google_protobuf_FieldOptions *ret = google_protobuf_FieldOptions_new(arena);
2066   return (ret && upb_decode(buf, size, ret, &google_protobuf_FieldOptions_msginit)) ? ret : NULL;
2067 }
google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions * msg,upb_arena * arena,size_t * len)2068 UPB_INLINE char *google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions *msg, upb_arena *arena, size_t *len) {
2069   return upb_encode(msg, &google_protobuf_FieldOptions_msginit, arena, len);
2070 }
2071 
google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions * msg)2072 UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 1); }
google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions * msg)2073 UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions * msg)2074 UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 3); }
google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions * msg)2075 UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)); }
google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions * msg)2076 UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 4); }
google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions * msg)2077 UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(25, 25)); }
google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions * msg)2078 UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 5); }
google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions * msg)2079 UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(26, 26)); }
google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions * msg)2080 UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 2); }
google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions * msg)2081 UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(16, 16)); }
google_protobuf_FieldOptions_has_weak(const google_protobuf_FieldOptions * msg)2082 UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 6); }
google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions * msg)2083 UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(27, 27)); }
google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions * msg,size_t * len)2084 UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(28, 32), len); }
2085 
google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions * msg,int32_t value)2086 UPB_INLINE void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, int32_t value) {
2087   _upb_sethas(msg, 1);
2088   UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
2089 }
google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions * msg,bool value)2090 UPB_INLINE void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions *msg, bool value) {
2091   _upb_sethas(msg, 3);
2092   UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)) = value;
2093 }
google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions * msg,bool value)2094 UPB_INLINE void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions *msg, bool value) {
2095   _upb_sethas(msg, 4);
2096   UPB_FIELD_AT(msg, bool, UPB_SIZE(25, 25)) = value;
2097 }
google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions * msg,bool value)2098 UPB_INLINE void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions *msg, bool value) {
2099   _upb_sethas(msg, 5);
2100   UPB_FIELD_AT(msg, bool, UPB_SIZE(26, 26)) = value;
2101 }
google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions * msg,int32_t value)2102 UPB_INLINE void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions *msg, int32_t value) {
2103   _upb_sethas(msg, 2);
2104   UPB_FIELD_AT(msg, int32_t, UPB_SIZE(16, 16)) = value;
2105 }
google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions * msg,bool value)2106 UPB_INLINE void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions *msg, bool value) {
2107   _upb_sethas(msg, 6);
2108   UPB_FIELD_AT(msg, bool, UPB_SIZE(27, 27)) = value;
2109 }
google_protobuf_FieldOptions_mutable_uninterpreted_option(google_protobuf_FieldOptions * msg,size_t * len)2110 UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mutable_uninterpreted_option(google_protobuf_FieldOptions *msg, size_t *len) {
2111   return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 32), len);
2112 }
google_protobuf_FieldOptions_resize_uninterpreted_option(google_protobuf_FieldOptions * msg,size_t len,upb_arena * arena)2113 UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_resize_uninterpreted_option(google_protobuf_FieldOptions *msg, size_t len, upb_arena *arena) {
2114   return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(28, 32), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
2115 }
google_protobuf_FieldOptions_add_uninterpreted_option(google_protobuf_FieldOptions * msg,upb_arena * arena)2116 UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option(google_protobuf_FieldOptions *msg, upb_arena *arena) {
2117   struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
2118   bool ok = _upb_array_append_accessor(
2119       msg, UPB_SIZE(28, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
2120   if (!ok) return NULL;
2121   return sub;
2122 }
2123 
2124 
2125 /* google.protobuf.OneofOptions */
2126 
google_protobuf_OneofOptions_new(upb_arena * arena)2127 UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_new(upb_arena *arena) {
2128   return (google_protobuf_OneofOptions *)upb_msg_new(&google_protobuf_OneofOptions_msginit, arena);
2129 }
google_protobuf_OneofOptions_parse(const char * buf,size_t size,upb_arena * arena)2130 UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_parse(const char *buf, size_t size,
2131                         upb_arena *arena) {
2132   google_protobuf_OneofOptions *ret = google_protobuf_OneofOptions_new(arena);
2133   return (ret && upb_decode(buf, size, ret, &google_protobuf_OneofOptions_msginit)) ? ret : NULL;
2134 }
google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions * msg,upb_arena * arena,size_t * len)2135 UPB_INLINE char *google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions *msg, upb_arena *arena, size_t *len) {
2136   return upb_encode(msg, &google_protobuf_OneofOptions_msginit, arena, len);
2137 }
2138 
google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions * msg,size_t * len)2139 UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); }
2140 
google_protobuf_OneofOptions_mutable_uninterpreted_option(google_protobuf_OneofOptions * msg,size_t * len)2141 UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mutable_uninterpreted_option(google_protobuf_OneofOptions *msg, size_t *len) {
2142   return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
2143 }
google_protobuf_OneofOptions_resize_uninterpreted_option(google_protobuf_OneofOptions * msg,size_t len,upb_arena * arena)2144 UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_resize_uninterpreted_option(google_protobuf_OneofOptions *msg, size_t len, upb_arena *arena) {
2145   return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
2146 }
google_protobuf_OneofOptions_add_uninterpreted_option(google_protobuf_OneofOptions * msg,upb_arena * arena)2147 UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option(google_protobuf_OneofOptions *msg, upb_arena *arena) {
2148   struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
2149   bool ok = _upb_array_append_accessor(
2150       msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
2151   if (!ok) return NULL;
2152   return sub;
2153 }
2154 
2155 
2156 /* google.protobuf.EnumOptions */
2157 
google_protobuf_EnumOptions_new(upb_arena * arena)2158 UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_arena *arena) {
2159   return (google_protobuf_EnumOptions *)upb_msg_new(&google_protobuf_EnumOptions_msginit, arena);
2160 }
google_protobuf_EnumOptions_parse(const char * buf,size_t size,upb_arena * arena)2161 UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_parse(const char *buf, size_t size,
2162                         upb_arena *arena) {
2163   google_protobuf_EnumOptions *ret = google_protobuf_EnumOptions_new(arena);
2164   return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumOptions_msginit)) ? ret : NULL;
2165 }
google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions * msg,upb_arena * arena,size_t * len)2166 UPB_INLINE char *google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions *msg, upb_arena *arena, size_t *len) {
2167   return upb_encode(msg, &google_protobuf_EnumOptions_msginit, arena, len);
2168 }
2169 
google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions * msg)2170 UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions *msg) { return _upb_has_field(msg, 1); }
google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions * msg)2171 UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); }
google_protobuf_EnumOptions_has_deprecated(const google_protobuf_EnumOptions * msg)2172 UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf_EnumOptions *msg) { return _upb_has_field(msg, 2); }
google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions * msg)2173 UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); }
google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions * msg,size_t * len)2174 UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(4, 8), len); }
2175 
google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions * msg,bool value)2176 UPB_INLINE void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) {
2177   _upb_sethas(msg, 1);
2178   UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
2179 }
google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions * msg,bool value)2180 UPB_INLINE void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions *msg, bool value) {
2181   _upb_sethas(msg, 2);
2182   UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value;
2183 }
google_protobuf_EnumOptions_mutable_uninterpreted_option(google_protobuf_EnumOptions * msg,size_t * len)2184 UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mutable_uninterpreted_option(google_protobuf_EnumOptions *msg, size_t *len) {
2185   return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 8), len);
2186 }
google_protobuf_EnumOptions_resize_uninterpreted_option(google_protobuf_EnumOptions * msg,size_t len,upb_arena * arena)2187 UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_resize_uninterpreted_option(google_protobuf_EnumOptions *msg, size_t len, upb_arena *arena) {
2188   return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
2189 }
google_protobuf_EnumOptions_add_uninterpreted_option(google_protobuf_EnumOptions * msg,upb_arena * arena)2190 UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option(google_protobuf_EnumOptions *msg, upb_arena *arena) {
2191   struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
2192   bool ok = _upb_array_append_accessor(
2193       msg, UPB_SIZE(4, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
2194   if (!ok) return NULL;
2195   return sub;
2196 }
2197 
2198 
2199 /* google.protobuf.EnumValueOptions */
2200 
google_protobuf_EnumValueOptions_new(upb_arena * arena)2201 UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_new(upb_arena *arena) {
2202   return (google_protobuf_EnumValueOptions *)upb_msg_new(&google_protobuf_EnumValueOptions_msginit, arena);
2203 }
google_protobuf_EnumValueOptions_parse(const char * buf,size_t size,upb_arena * arena)2204 UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parse(const char *buf, size_t size,
2205                         upb_arena *arena) {
2206   google_protobuf_EnumValueOptions *ret = google_protobuf_EnumValueOptions_new(arena);
2207   return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumValueOptions_msginit)) ? ret : NULL;
2208 }
google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions * msg,upb_arena * arena,size_t * len)2209 UPB_INLINE char *google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions *msg, upb_arena *arena, size_t *len) {
2210   return upb_encode(msg, &google_protobuf_EnumValueOptions_msginit, arena, len);
2211 }
2212 
google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions * msg)2213 UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions *msg) { return _upb_has_field(msg, 1); }
google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions * msg)2214 UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); }
google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions * msg,size_t * len)2215 UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(4, 8), len); }
2216 
google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions * msg,bool value)2217 UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) {
2218   _upb_sethas(msg, 1);
2219   UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
2220 }
google_protobuf_EnumValueOptions_mutable_uninterpreted_option(google_protobuf_EnumValueOptions * msg,size_t * len)2221 UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_mutable_uninterpreted_option(google_protobuf_EnumValueOptions *msg, size_t *len) {
2222   return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 8), len);
2223 }
google_protobuf_EnumValueOptions_resize_uninterpreted_option(google_protobuf_EnumValueOptions * msg,size_t len,upb_arena * arena)2224 UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_resize_uninterpreted_option(google_protobuf_EnumValueOptions *msg, size_t len, upb_arena *arena) {
2225   return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
2226 }
google_protobuf_EnumValueOptions_add_uninterpreted_option(google_protobuf_EnumValueOptions * msg,upb_arena * arena)2227 UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option(google_protobuf_EnumValueOptions *msg, upb_arena *arena) {
2228   struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
2229   bool ok = _upb_array_append_accessor(
2230       msg, UPB_SIZE(4, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
2231   if (!ok) return NULL;
2232   return sub;
2233 }
2234 
2235 
2236 /* google.protobuf.ServiceOptions */
2237 
google_protobuf_ServiceOptions_new(upb_arena * arena)2238 UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(upb_arena *arena) {
2239   return (google_protobuf_ServiceOptions *)upb_msg_new(&google_protobuf_ServiceOptions_msginit, arena);
2240 }
google_protobuf_ServiceOptions_parse(const char * buf,size_t size,upb_arena * arena)2241 UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parse(const char *buf, size_t size,
2242                         upb_arena *arena) {
2243   google_protobuf_ServiceOptions *ret = google_protobuf_ServiceOptions_new(arena);
2244   return (ret && upb_decode(buf, size, ret, &google_protobuf_ServiceOptions_msginit)) ? ret : NULL;
2245 }
google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions * msg,upb_arena * arena,size_t * len)2246 UPB_INLINE char *google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions *msg, upb_arena *arena, size_t *len) {
2247   return upb_encode(msg, &google_protobuf_ServiceOptions_msginit, arena, len);
2248 }
2249 
google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions * msg)2250 UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions *msg) { return _upb_has_field(msg, 1); }
google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions * msg)2251 UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); }
google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions * msg,size_t * len)2252 UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(4, 8), len); }
2253 
google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions * msg,bool value)2254 UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) {
2255   _upb_sethas(msg, 1);
2256   UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
2257 }
google_protobuf_ServiceOptions_mutable_uninterpreted_option(google_protobuf_ServiceOptions * msg,size_t * len)2258 UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_mutable_uninterpreted_option(google_protobuf_ServiceOptions *msg, size_t *len) {
2259   return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 8), len);
2260 }
google_protobuf_ServiceOptions_resize_uninterpreted_option(google_protobuf_ServiceOptions * msg,size_t len,upb_arena * arena)2261 UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_resize_uninterpreted_option(google_protobuf_ServiceOptions *msg, size_t len, upb_arena *arena) {
2262   return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
2263 }
google_protobuf_ServiceOptions_add_uninterpreted_option(google_protobuf_ServiceOptions * msg,upb_arena * arena)2264 UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option(google_protobuf_ServiceOptions *msg, upb_arena *arena) {
2265   struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
2266   bool ok = _upb_array_append_accessor(
2267       msg, UPB_SIZE(4, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
2268   if (!ok) return NULL;
2269   return sub;
2270 }
2271 
2272 
2273 /* google.protobuf.MethodOptions */
2274 
google_protobuf_MethodOptions_new(upb_arena * arena)2275 UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_arena *arena) {
2276   return (google_protobuf_MethodOptions *)upb_msg_new(&google_protobuf_MethodOptions_msginit, arena);
2277 }
google_protobuf_MethodOptions_parse(const char * buf,size_t size,upb_arena * arena)2278 UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_parse(const char *buf, size_t size,
2279                         upb_arena *arena) {
2280   google_protobuf_MethodOptions *ret = google_protobuf_MethodOptions_new(arena);
2281   return (ret && upb_decode(buf, size, ret, &google_protobuf_MethodOptions_msginit)) ? ret : NULL;
2282 }
google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions * msg,upb_arena * arena,size_t * len)2283 UPB_INLINE char *google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions *msg, upb_arena *arena, size_t *len) {
2284   return upb_encode(msg, &google_protobuf_MethodOptions_msginit, arena, len);
2285 }
2286 
google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions * msg)2287 UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions *msg) { return _upb_has_field(msg, 2); }
google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions * msg)2288 UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)); }
google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions * msg)2289 UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions *msg) { return _upb_has_field(msg, 1); }
google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions * msg)2290 UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions * msg,size_t * len)2291 UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(20, 24), len); }
2292 
google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions * msg,bool value)2293 UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) {
2294   _upb_sethas(msg, 2);
2295   UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)) = value;
2296 }
google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions * msg,int32_t value)2297 UPB_INLINE void google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions *msg, int32_t value) {
2298   _upb_sethas(msg, 1);
2299   UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
2300 }
google_protobuf_MethodOptions_mutable_uninterpreted_option(google_protobuf_MethodOptions * msg,size_t * len)2301 UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_mutable_uninterpreted_option(google_protobuf_MethodOptions *msg, size_t *len) {
2302   return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 24), len);
2303 }
google_protobuf_MethodOptions_resize_uninterpreted_option(google_protobuf_MethodOptions * msg,size_t len,upb_arena * arena)2304 UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_resize_uninterpreted_option(google_protobuf_MethodOptions *msg, size_t len, upb_arena *arena) {
2305   return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 24), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
2306 }
google_protobuf_MethodOptions_add_uninterpreted_option(google_protobuf_MethodOptions * msg,upb_arena * arena)2307 UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option(google_protobuf_MethodOptions *msg, upb_arena *arena) {
2308   struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
2309   bool ok = _upb_array_append_accessor(
2310       msg, UPB_SIZE(20, 24), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
2311   if (!ok) return NULL;
2312   return sub;
2313 }
2314 
2315 
2316 /* google.protobuf.UninterpretedOption */
2317 
google_protobuf_UninterpretedOption_new(upb_arena * arena)2318 UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_new(upb_arena *arena) {
2319   return (google_protobuf_UninterpretedOption *)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
2320 }
google_protobuf_UninterpretedOption_parse(const char * buf,size_t size,upb_arena * arena)2321 UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parse(const char *buf, size_t size,
2322                         upb_arena *arena) {
2323   google_protobuf_UninterpretedOption *ret = google_protobuf_UninterpretedOption_new(arena);
2324   return (ret && upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_msginit)) ? ret : NULL;
2325 }
google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption * msg,upb_arena * arena,size_t * len)2326 UPB_INLINE char *google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption *msg, upb_arena *arena, size_t *len) {
2327   return upb_encode(msg, &google_protobuf_UninterpretedOption_msginit, arena, len);
2328 }
2329 
google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption * msg,size_t * len)2330 UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption *msg, size_t *len) { return (const google_protobuf_UninterpretedOption_NamePart* const*)_upb_array_accessor(msg, UPB_SIZE(56, 80), len); }
google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption * msg)2331 UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 4); }
google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption * msg)2332 UPB_INLINE upb_strview google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(32, 32)); }
google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption * msg)2333 UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 1); }
google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption * msg)2334 UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, uint64_t, UPB_SIZE(8, 8)); }
google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption * msg)2335 UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 2); }
google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption * msg)2336 UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, int64_t, UPB_SIZE(16, 16)); }
google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption * msg)2337 UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 3); }
google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption * msg)2338 UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, double, UPB_SIZE(24, 24)); }
google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption * msg)2339 UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 5); }
google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption * msg)2340 UPB_INLINE upb_strview google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(40, 48)); }
google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption * msg)2341 UPB_INLINE bool google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 6); }
google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption * msg)2342 UPB_INLINE upb_strview google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(48, 64)); }
2343 
google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption * msg,size_t * len)2344 UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption *msg, size_t *len) {
2345   return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_mutable_accessor(msg, UPB_SIZE(56, 80), len);
2346 }
google_protobuf_UninterpretedOption_resize_name(google_protobuf_UninterpretedOption * msg,size_t len,upb_arena * arena)2347 UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_resize_name(google_protobuf_UninterpretedOption *msg, size_t len, upb_arena *arena) {
2348   return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_resize_accessor(msg, UPB_SIZE(56, 80), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
2349 }
google_protobuf_UninterpretedOption_add_name(google_protobuf_UninterpretedOption * msg,upb_arena * arena)2350 UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name(google_protobuf_UninterpretedOption *msg, upb_arena *arena) {
2351   struct google_protobuf_UninterpretedOption_NamePart* sub = (struct google_protobuf_UninterpretedOption_NamePart*)upb_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena);
2352   bool ok = _upb_array_append_accessor(
2353       msg, UPB_SIZE(56, 80), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
2354   if (!ok) return NULL;
2355   return sub;
2356 }
google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption * msg,upb_strview value)2357 UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_strview value) {
2358   _upb_sethas(msg, 4);
2359   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(32, 32)) = value;
2360 }
google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption * msg,uint64_t value)2361 UPB_INLINE void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) {
2362   _upb_sethas(msg, 1);
2363   UPB_FIELD_AT(msg, uint64_t, UPB_SIZE(8, 8)) = value;
2364 }
google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption * msg,int64_t value)2365 UPB_INLINE void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value) {
2366   _upb_sethas(msg, 2);
2367   UPB_FIELD_AT(msg, int64_t, UPB_SIZE(16, 16)) = value;
2368 }
google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption * msg,double value)2369 UPB_INLINE void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value) {
2370   _upb_sethas(msg, 3);
2371   UPB_FIELD_AT(msg, double, UPB_SIZE(24, 24)) = value;
2372 }
google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption * msg,upb_strview value)2373 UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_strview value) {
2374   _upb_sethas(msg, 5);
2375   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(40, 48)) = value;
2376 }
google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption * msg,upb_strview value)2377 UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_strview value) {
2378   _upb_sethas(msg, 6);
2379   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(48, 64)) = value;
2380 }
2381 
2382 
2383 /* google.protobuf.UninterpretedOption.NamePart */
2384 
google_protobuf_UninterpretedOption_NamePart_new(upb_arena * arena)2385 UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_new(upb_arena *arena) {
2386   return (google_protobuf_UninterpretedOption_NamePart *)upb_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena);
2387 }
google_protobuf_UninterpretedOption_NamePart_parse(const char * buf,size_t size,upb_arena * arena)2388 UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parse(const char *buf, size_t size,
2389                         upb_arena *arena) {
2390   google_protobuf_UninterpretedOption_NamePart *ret = google_protobuf_UninterpretedOption_NamePart_new(arena);
2391   return (ret && upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msginit)) ? ret : NULL;
2392 }
google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart * msg,upb_arena * arena,size_t * len)2393 UPB_INLINE char *google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart *msg, upb_arena *arena, size_t *len) {
2394   return upb_encode(msg, &google_protobuf_UninterpretedOption_NamePart_msginit, arena, len);
2395 }
2396 
google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart * msg)2397 UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return _upb_has_field(msg, 2); }
google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart * msg)2398 UPB_INLINE upb_strview google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart * msg)2399 UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { return _upb_has_field(msg, 1); }
google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart * msg)2400 UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); }
2401 
google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart * msg,upb_strview value)2402 UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_strview value) {
2403   _upb_sethas(msg, 2);
2404   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
2405 }
google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart * msg,bool value)2406 UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value) {
2407   _upb_sethas(msg, 1);
2408   UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
2409 }
2410 
2411 
2412 /* google.protobuf.SourceCodeInfo */
2413 
google_protobuf_SourceCodeInfo_new(upb_arena * arena)2414 UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(upb_arena *arena) {
2415   return (google_protobuf_SourceCodeInfo *)upb_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena);
2416 }
google_protobuf_SourceCodeInfo_parse(const char * buf,size_t size,upb_arena * arena)2417 UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parse(const char *buf, size_t size,
2418                         upb_arena *arena) {
2419   google_protobuf_SourceCodeInfo *ret = google_protobuf_SourceCodeInfo_new(arena);
2420   return (ret && upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msginit)) ? ret : NULL;
2421 }
google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo * msg,upb_arena * arena,size_t * len)2422 UPB_INLINE char *google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo *msg, upb_arena *arena, size_t *len) {
2423   return upb_encode(msg, &google_protobuf_SourceCodeInfo_msginit, arena, len);
2424 }
2425 
google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo * msg,size_t * len)2426 UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo *msg, size_t *len) { return (const google_protobuf_SourceCodeInfo_Location* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); }
2427 
google_protobuf_SourceCodeInfo_mutable_location(google_protobuf_SourceCodeInfo * msg,size_t * len)2428 UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_mutable_location(google_protobuf_SourceCodeInfo *msg, size_t *len) {
2429   return (google_protobuf_SourceCodeInfo_Location**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
2430 }
google_protobuf_SourceCodeInfo_resize_location(google_protobuf_SourceCodeInfo * msg,size_t len,upb_arena * arena)2431 UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_resize_location(google_protobuf_SourceCodeInfo *msg, size_t len, upb_arena *arena) {
2432   return (google_protobuf_SourceCodeInfo_Location**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
2433 }
google_protobuf_SourceCodeInfo_add_location(google_protobuf_SourceCodeInfo * msg,upb_arena * arena)2434 UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location(google_protobuf_SourceCodeInfo *msg, upb_arena *arena) {
2435   struct google_protobuf_SourceCodeInfo_Location* sub = (struct google_protobuf_SourceCodeInfo_Location*)upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena);
2436   bool ok = _upb_array_append_accessor(
2437       msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
2438   if (!ok) return NULL;
2439   return sub;
2440 }
2441 
2442 
2443 /* google.protobuf.SourceCodeInfo.Location */
2444 
google_protobuf_SourceCodeInfo_Location_new(upb_arena * arena)2445 UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_new(upb_arena *arena) {
2446   return (google_protobuf_SourceCodeInfo_Location *)upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena);
2447 }
google_protobuf_SourceCodeInfo_Location_parse(const char * buf,size_t size,upb_arena * arena)2448 UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parse(const char *buf, size_t size,
2449                         upb_arena *arena) {
2450   google_protobuf_SourceCodeInfo_Location *ret = google_protobuf_SourceCodeInfo_Location_new(arena);
2451   return (ret && upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msginit)) ? ret : NULL;
2452 }
google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location * msg,upb_arena * arena,size_t * len)2453 UPB_INLINE char *google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location *msg, upb_arena *arena, size_t *len) {
2454   return upb_encode(msg, &google_protobuf_SourceCodeInfo_Location_msginit, arena, len);
2455 }
2456 
google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location * msg,size_t * len)2457 UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); }
google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location * msg,size_t * len)2458 UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); }
google_protobuf_SourceCodeInfo_Location_has_leading_comments(const google_protobuf_SourceCodeInfo_Location * msg)2459 UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return _upb_has_field(msg, 1); }
google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location * msg)2460 UPB_INLINE upb_strview google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location * msg)2461 UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return _upb_has_field(msg, 2); }
google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location * msg)2462 UPB_INLINE upb_strview google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)); }
google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location * msg,size_t * len)2463 UPB_INLINE upb_strview const* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(28, 56), len); }
2464 
google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location * msg,size_t * len)2465 UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) {
2466   return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len);
2467 }
google_protobuf_SourceCodeInfo_Location_resize_path(google_protobuf_SourceCodeInfo_Location * msg,size_t len,upb_arena * arena)2468 UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_path(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_arena *arena) {
2469   return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena);
2470 }
google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf_SourceCodeInfo_Location * msg,int32_t val,upb_arena * arena)2471 UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf_SourceCodeInfo_Location *msg, int32_t val, upb_arena *arena) {
2472   return _upb_array_append_accessor(
2473       msg, UPB_SIZE(20, 40), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena);
2474 }
google_protobuf_SourceCodeInfo_Location_mutable_span(google_protobuf_SourceCodeInfo_Location * msg,size_t * len)2475 UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) {
2476   return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len);
2477 }
google_protobuf_SourceCodeInfo_Location_resize_span(google_protobuf_SourceCodeInfo_Location * msg,size_t len,upb_arena * arena)2478 UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_span(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_arena *arena) {
2479   return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena);
2480 }
google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf_SourceCodeInfo_Location * msg,int32_t val,upb_arena * arena)2481 UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf_SourceCodeInfo_Location *msg, int32_t val, upb_arena *arena) {
2482   return _upb_array_append_accessor(
2483       msg, UPB_SIZE(24, 48), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena);
2484 }
google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location * msg,upb_strview value)2485 UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_strview value) {
2486   _upb_sethas(msg, 1);
2487   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
2488 }
google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location * msg,upb_strview value)2489 UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_strview value) {
2490   _upb_sethas(msg, 2);
2491   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)) = value;
2492 }
google_protobuf_SourceCodeInfo_Location_mutable_leading_detached_comments(google_protobuf_SourceCodeInfo_Location * msg,size_t * len)2493 UPB_INLINE upb_strview* google_protobuf_SourceCodeInfo_Location_mutable_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) {
2494   return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len);
2495 }
google_protobuf_SourceCodeInfo_Location_resize_leading_detached_comments(google_protobuf_SourceCodeInfo_Location * msg,size_t len,upb_arena * arena)2496 UPB_INLINE upb_strview* google_protobuf_SourceCodeInfo_Location_resize_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_arena *arena) {
2497   return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(28, 56), len, UPB_SIZE(8, 16), UPB_TYPE_STRING, arena);
2498 }
google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location * msg,upb_strview val,upb_arena * arena)2499 UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_strview val, upb_arena *arena) {
2500   return _upb_array_append_accessor(
2501       msg, UPB_SIZE(28, 56), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena);
2502 }
2503 
2504 
2505 /* google.protobuf.GeneratedCodeInfo */
2506 
google_protobuf_GeneratedCodeInfo_new(upb_arena * arena)2507 UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_new(upb_arena *arena) {
2508   return (google_protobuf_GeneratedCodeInfo *)upb_msg_new(&google_protobuf_GeneratedCodeInfo_msginit, arena);
2509 }
google_protobuf_GeneratedCodeInfo_parse(const char * buf,size_t size,upb_arena * arena)2510 UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_parse(const char *buf, size_t size,
2511                         upb_arena *arena) {
2512   google_protobuf_GeneratedCodeInfo *ret = google_protobuf_GeneratedCodeInfo_new(arena);
2513   return (ret && upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msginit)) ? ret : NULL;
2514 }
google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo * msg,upb_arena * arena,size_t * len)2515 UPB_INLINE char *google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo *msg, upb_arena *arena, size_t *len) {
2516   return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, arena, len);
2517 }
2518 
google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo * msg,size_t * len)2519 UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo *msg, size_t *len) { return (const google_protobuf_GeneratedCodeInfo_Annotation* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); }
2520 
google_protobuf_GeneratedCodeInfo_mutable_annotation(google_protobuf_GeneratedCodeInfo * msg,size_t * len)2521 UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_mutable_annotation(google_protobuf_GeneratedCodeInfo *msg, size_t *len) {
2522   return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
2523 }
google_protobuf_GeneratedCodeInfo_resize_annotation(google_protobuf_GeneratedCodeInfo * msg,size_t len,upb_arena * arena)2524 UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_resize_annotation(google_protobuf_GeneratedCodeInfo *msg, size_t len, upb_arena *arena) {
2525   return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
2526 }
google_protobuf_GeneratedCodeInfo_add_annotation(google_protobuf_GeneratedCodeInfo * msg,upb_arena * arena)2527 UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation(google_protobuf_GeneratedCodeInfo *msg, upb_arena *arena) {
2528   struct google_protobuf_GeneratedCodeInfo_Annotation* sub = (struct google_protobuf_GeneratedCodeInfo_Annotation*)upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena);
2529   bool ok = _upb_array_append_accessor(
2530       msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
2531   if (!ok) return NULL;
2532   return sub;
2533 }
2534 
2535 
2536 /* google.protobuf.GeneratedCodeInfo.Annotation */
2537 
google_protobuf_GeneratedCodeInfo_Annotation_new(upb_arena * arena)2538 UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_new(upb_arena *arena) {
2539   return (google_protobuf_GeneratedCodeInfo_Annotation *)upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena);
2540 }
google_protobuf_GeneratedCodeInfo_Annotation_parse(const char * buf,size_t size,upb_arena * arena)2541 UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_parse(const char *buf, size_t size,
2542                         upb_arena *arena) {
2543   google_protobuf_GeneratedCodeInfo_Annotation *ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena);
2544   return (ret && upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit)) ? ret : NULL;
2545 }
google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation * msg,upb_arena * arena,size_t * len)2546 UPB_INLINE char *google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_arena *arena, size_t *len) {
2547   return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena, len);
2548 }
2549 
google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation * msg,size_t * len)2550 UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(20, 32), len); }
google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation * msg)2551 UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_has_field(msg, 3); }
google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation * msg)2552 UPB_INLINE upb_strview google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 16)); }
google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation * msg)2553 UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_has_field(msg, 1); }
google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation * msg)2554 UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); }
google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation * msg)2555 UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_has_field(msg, 2); }
google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation * msg)2556 UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
2557 
google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation * msg,size_t * len)2558 UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t *len) {
2559   return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 32), len);
2560 }
google_protobuf_GeneratedCodeInfo_Annotation_resize_path(google_protobuf_GeneratedCodeInfo_Annotation * msg,size_t len,upb_arena * arena)2561 UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t len, upb_arena *arena) {
2562   return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(20, 32), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena);
2563 }
google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation * msg,int32_t val,upb_arena * arena)2564 UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t val, upb_arena *arena) {
2565   return _upb_array_append_accessor(
2566       msg, UPB_SIZE(20, 32), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena);
2567 }
google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation * msg,upb_strview value)2568 UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_strview value) {
2569   _upb_sethas(msg, 3);
2570   UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 16)) = value;
2571 }
google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation * msg,int32_t value)2572 UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) {
2573   _upb_sethas(msg, 1);
2574   UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value;
2575 }
google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation * msg,int32_t value)2576 UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) {
2577   _upb_sethas(msg, 2);
2578   UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
2579 }
2580 
2581 
2582 #ifdef __cplusplus
2583 }  /* extern "C" */
2584 #endif
2585 
2586 
2587 #endif  /* GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ */
2588 /*
2589 ** Defs are upb's internal representation of the constructs that can appear
2590 ** in a .proto file:
2591 **
2592 ** - upb::MessageDefPtr (upb_msgdef): describes a "message" construct.
2593 ** - upb::FieldDefPtr (upb_fielddef): describes a message field.
2594 ** - upb::FileDefPtr (upb_filedef): describes a .proto file and its defs.
2595 ** - upb::EnumDefPtr (upb_enumdef): describes an enum.
2596 ** - upb::OneofDefPtr (upb_oneofdef): describes a oneof.
2597 **
2598 ** TODO: definitions of services.
2599 **
2600 ** This is a mixed C/C++ interface that offers a full API to both languages.
2601 ** See the top-level README for more information.
2602 */
2603 
2604 #ifndef UPB_DEF_H_
2605 #define UPB_DEF_H_
2606 
2607 /*
2608 ** upb_table
2609 **
2610 ** This header is INTERNAL-ONLY!  Its interfaces are not public or stable!
2611 ** This file defines very fast int->upb_value (inttable) and string->upb_value
2612 ** (strtable) hash tables.
2613 **
2614 ** The table uses chained scatter with Brent's variation (inspired by the Lua
2615 ** implementation of hash tables).  The hash function for strings is Austin
2616 ** Appleby's "MurmurHash."
2617 **
2618 ** The inttable uses uintptr_t as its key, which guarantees it can be used to
2619 ** store pointers or integers of at least 32 bits (upb isn't really useful on
2620 ** systems where sizeof(void*) < 4).
2621 **
2622 ** The table must be homogenous (all values of the same type).  In debug
2623 ** mode, we check this on insert and lookup.
2624 */
2625 
2626 #ifndef UPB_TABLE_H_
2627 #define UPB_TABLE_H_
2628 
2629 #include <stdint.h>
2630 #include <string.h>
2631 
2632 #ifdef __cplusplus
2633 extern "C" {
2634 #endif
2635 
2636 
2637 /* upb_value ******************************************************************/
2638 
2639 /* A tagged union (stored untagged inside the table) so that we can check that
2640  * clients calling table accessors are correctly typed without having to have
2641  * an explosion of accessors. */
2642 typedef enum {
2643   UPB_CTYPE_INT32    = 1,
2644   UPB_CTYPE_INT64    = 2,
2645   UPB_CTYPE_UINT32   = 3,
2646   UPB_CTYPE_UINT64   = 4,
2647   UPB_CTYPE_BOOL     = 5,
2648   UPB_CTYPE_CSTR     = 6,
2649   UPB_CTYPE_PTR      = 7,
2650   UPB_CTYPE_CONSTPTR = 8,
2651   UPB_CTYPE_FPTR     = 9,
2652   UPB_CTYPE_FLOAT    = 10,
2653   UPB_CTYPE_DOUBLE   = 11
2654 } upb_ctype_t;
2655 
2656 typedef struct {
2657   uint64_t val;
2658 #ifndef NDEBUG
2659   /* In debug mode we carry the value type around also so we can check accesses
2660    * to be sure the right member is being read. */
2661   upb_ctype_t ctype;
2662 #endif
2663 } upb_value;
2664 
2665 #ifdef NDEBUG
2666 #define SET_TYPE(dest, val)      UPB_UNUSED(val)
2667 #else
2668 #define SET_TYPE(dest, val) dest = val
2669 #endif
2670 
2671 /* Like strdup(), which isn't always available since it's not ANSI C. */
2672 char *upb_strdup(const char *s, upb_alloc *a);
2673 /* Variant that works with a length-delimited rather than NULL-delimited string,
2674  * as supported by strtable. */
2675 char *upb_strdup2(const char *s, size_t len, upb_alloc *a);
2676 
upb_gstrdup(const char * s)2677 UPB_INLINE char *upb_gstrdup(const char *s) {
2678   return upb_strdup(s, &upb_alloc_global);
2679 }
2680 
_upb_value_setval(upb_value * v,uint64_t val,upb_ctype_t ctype)2681 UPB_INLINE void _upb_value_setval(upb_value *v, uint64_t val,
2682                                   upb_ctype_t ctype) {
2683   v->val = val;
2684   SET_TYPE(v->ctype, ctype);
2685 }
2686 
_upb_value_val(uint64_t val,upb_ctype_t ctype)2687 UPB_INLINE upb_value _upb_value_val(uint64_t val, upb_ctype_t ctype) {
2688   upb_value ret;
2689   _upb_value_setval(&ret, val, ctype);
2690   return ret;
2691 }
2692 
2693 /* For each value ctype, define the following set of functions:
2694  *
2695  * // Get/set an int32 from a upb_value.
2696  * int32_t upb_value_getint32(upb_value val);
2697  * void upb_value_setint32(upb_value *val, int32_t cval);
2698  *
2699  * // Construct a new upb_value from an int32.
2700  * upb_value upb_value_int32(int32_t val); */
2701 #define FUNCS(name, membername, type_t, converter, proto_type) \
2702   UPB_INLINE void upb_value_set ## name(upb_value *val, type_t cval) { \
2703     val->val = (converter)cval; \
2704     SET_TYPE(val->ctype, proto_type); \
2705   } \
2706   UPB_INLINE upb_value upb_value_ ## name(type_t val) { \
2707     upb_value ret; \
2708     upb_value_set ## name(&ret, val); \
2709     return ret; \
2710   } \
2711   UPB_INLINE type_t upb_value_get ## name(upb_value val) { \
2712     UPB_ASSERT_DEBUGVAR(val.ctype == proto_type); \
2713     return (type_t)(converter)val.val; \
2714   }
2715 
FUNCS(int32,int32,int32_t,int32_t,UPB_CTYPE_INT32)2716 FUNCS(int32,    int32,        int32_t,      int32_t,    UPB_CTYPE_INT32)
2717 FUNCS(int64,    int64,        int64_t,      int64_t,    UPB_CTYPE_INT64)
2718 FUNCS(uint32,   uint32,       uint32_t,     uint32_t,   UPB_CTYPE_UINT32)
2719 FUNCS(uint64,   uint64,       uint64_t,     uint64_t,   UPB_CTYPE_UINT64)
2720 FUNCS(bool,     _bool,        bool,         bool,       UPB_CTYPE_BOOL)
2721 FUNCS(cstr,     cstr,         char*,        uintptr_t,  UPB_CTYPE_CSTR)
2722 FUNCS(ptr,      ptr,          void*,        uintptr_t,  UPB_CTYPE_PTR)
2723 FUNCS(constptr, constptr,     const void*,  uintptr_t,  UPB_CTYPE_CONSTPTR)
2724 FUNCS(fptr,     fptr,         upb_func*,    uintptr_t,  UPB_CTYPE_FPTR)
2725 
2726 #undef FUNCS
2727 
2728 UPB_INLINE void upb_value_setfloat(upb_value *val, float cval) {
2729   memcpy(&val->val, &cval, sizeof(cval));
2730   SET_TYPE(val->ctype, UPB_CTYPE_FLOAT);
2731 }
2732 
upb_value_setdouble(upb_value * val,double cval)2733 UPB_INLINE void upb_value_setdouble(upb_value *val, double cval) {
2734   memcpy(&val->val, &cval, sizeof(cval));
2735   SET_TYPE(val->ctype, UPB_CTYPE_DOUBLE);
2736 }
2737 
upb_value_float(float cval)2738 UPB_INLINE upb_value upb_value_float(float cval) {
2739   upb_value ret;
2740   upb_value_setfloat(&ret, cval);
2741   return ret;
2742 }
2743 
upb_value_double(double cval)2744 UPB_INLINE upb_value upb_value_double(double cval) {
2745   upb_value ret;
2746   upb_value_setdouble(&ret, cval);
2747   return ret;
2748 }
2749 
2750 #undef SET_TYPE
2751 
2752 
2753 /* upb_tabkey *****************************************************************/
2754 
2755 /* Either:
2756  *   1. an actual integer key, or
2757  *   2. a pointer to a string prefixed by its uint32_t length, owned by us.
2758  *
2759  * ...depending on whether this is a string table or an int table.  We would
2760  * make this a union of those two types, but C89 doesn't support statically
2761  * initializing a non-first union member. */
2762 typedef uintptr_t upb_tabkey;
2763 
upb_tabstr(upb_tabkey key,uint32_t * len)2764 UPB_INLINE char *upb_tabstr(upb_tabkey key, uint32_t *len) {
2765   char* mem = (char*)key;
2766   if (len) memcpy(len, mem, sizeof(*len));
2767   return mem + sizeof(*len);
2768 }
2769 
2770 
2771 /* upb_tabval *****************************************************************/
2772 
2773 typedef struct {
2774   uint64_t val;
2775 } upb_tabval;
2776 
2777 #define UPB_TABVALUE_EMPTY_INIT  {-1}
2778 
2779 
2780 /* upb_table ******************************************************************/
2781 
2782 typedef struct _upb_tabent {
2783   upb_tabkey key;
2784   upb_tabval val;
2785 
2786   /* Internal chaining.  This is const so we can create static initializers for
2787    * tables.  We cast away const sometimes, but *only* when the containing
2788    * upb_table is known to be non-const.  This requires a bit of care, but
2789    * the subtlety is confined to table.c. */
2790   const struct _upb_tabent *next;
2791 } upb_tabent;
2792 
2793 typedef struct {
2794   size_t count;          /* Number of entries in the hash part. */
2795   size_t mask;           /* Mask to turn hash value -> bucket. */
2796   upb_ctype_t ctype;     /* Type of all values. */
2797   uint8_t size_lg2;      /* Size of the hashtable part is 2^size_lg2 entries. */
2798 
2799   /* Hash table entries.
2800    * Making this const isn't entirely accurate; what we really want is for it to
2801    * have the same const-ness as the table it's inside.  But there's no way to
2802    * declare that in C.  So we have to make it const so that we can statically
2803    * initialize const hash tables.  Then we cast away const when we have to.
2804    */
2805   const upb_tabent *entries;
2806 
2807 #ifndef NDEBUG
2808   /* This table's allocator.  We make the user pass it in to every relevant
2809    * function and only use this to check it in debug mode.  We do this solely
2810    * to keep upb_table as small as possible.  This might seem slightly paranoid
2811    * but the plan is to use upb_table for all map fields and extension sets in
2812    * a forthcoming message representation, so there could be a lot of these.
2813    * If this turns out to be too annoying later, we can change it (since this
2814    * is an internal-only header file). */
2815   upb_alloc *alloc;
2816 #endif
2817 } upb_table;
2818 
2819 typedef struct {
2820   upb_table t;
2821 } upb_strtable;
2822 
2823 typedef struct {
2824   upb_table t;              /* For entries that don't fit in the array part. */
2825   const upb_tabval *array;  /* Array part of the table. See const note above. */
2826   size_t array_size;        /* Array part size. */
2827   size_t array_count;       /* Array part number of elements. */
2828 } upb_inttable;
2829 
2830 #define UPB_INTTABLE_INIT(count, mask, ctype, size_lg2, ent, a, asize, acount) \
2831   {UPB_TABLE_INIT(count, mask, ctype, size_lg2, ent), a, asize, acount}
2832 
2833 #define UPB_EMPTY_INTTABLE_INIT(ctype) \
2834   UPB_INTTABLE_INIT(0, 0, ctype, 0, NULL, NULL, 0, 0)
2835 
2836 #define UPB_ARRAY_EMPTYENT -1
2837 
upb_table_size(const upb_table * t)2838 UPB_INLINE size_t upb_table_size(const upb_table *t) {
2839   if (t->size_lg2 == 0)
2840     return 0;
2841   else
2842     return 1 << t->size_lg2;
2843 }
2844 
2845 /* Internal-only functions, in .h file only out of necessity. */
upb_tabent_isempty(const upb_tabent * e)2846 UPB_INLINE bool upb_tabent_isempty(const upb_tabent *e) {
2847   return e->key == 0;
2848 }
2849 
2850 /* Used by some of the unit tests for generic hashing functionality. */
2851 uint32_t MurmurHash2(const void * key, size_t len, uint32_t seed);
2852 
upb_intkey(uintptr_t key)2853 UPB_INLINE uintptr_t upb_intkey(uintptr_t key) {
2854   return key;
2855 }
2856 
upb_inthash(uintptr_t key)2857 UPB_INLINE uint32_t upb_inthash(uintptr_t key) {
2858   return (uint32_t)key;
2859 }
2860 
upb_getentry(const upb_table * t,uint32_t hash)2861 static const upb_tabent *upb_getentry(const upb_table *t, uint32_t hash) {
2862   return t->entries + (hash & t->mask);
2863 }
2864 
upb_arrhas(upb_tabval key)2865 UPB_INLINE bool upb_arrhas(upb_tabval key) {
2866   return key.val != (uint64_t)-1;
2867 }
2868 
2869 /* Initialize and uninitialize a table, respectively.  If memory allocation
2870  * failed, false is returned that the table is uninitialized. */
2871 bool upb_inttable_init2(upb_inttable *table, upb_ctype_t ctype, upb_alloc *a);
2872 bool upb_strtable_init2(upb_strtable *table, upb_ctype_t ctype, upb_alloc *a);
2873 void upb_inttable_uninit2(upb_inttable *table, upb_alloc *a);
2874 void upb_strtable_uninit2(upb_strtable *table, upb_alloc *a);
2875 
upb_inttable_init(upb_inttable * table,upb_ctype_t ctype)2876 UPB_INLINE bool upb_inttable_init(upb_inttable *table, upb_ctype_t ctype) {
2877   return upb_inttable_init2(table, ctype, &upb_alloc_global);
2878 }
2879 
upb_strtable_init(upb_strtable * table,upb_ctype_t ctype)2880 UPB_INLINE bool upb_strtable_init(upb_strtable *table, upb_ctype_t ctype) {
2881   return upb_strtable_init2(table, ctype, &upb_alloc_global);
2882 }
2883 
upb_inttable_uninit(upb_inttable * table)2884 UPB_INLINE void upb_inttable_uninit(upb_inttable *table) {
2885   upb_inttable_uninit2(table, &upb_alloc_global);
2886 }
2887 
upb_strtable_uninit(upb_strtable * table)2888 UPB_INLINE void upb_strtable_uninit(upb_strtable *table) {
2889   upb_strtable_uninit2(table, &upb_alloc_global);
2890 }
2891 
2892 /* Returns the number of values in the table. */
2893 size_t upb_inttable_count(const upb_inttable *t);
upb_strtable_count(const upb_strtable * t)2894 UPB_INLINE size_t upb_strtable_count(const upb_strtable *t) {
2895   return t->t.count;
2896 }
2897 
2898 void upb_inttable_packedsize(const upb_inttable *t, size_t *size);
2899 void upb_strtable_packedsize(const upb_strtable *t, size_t *size);
2900 upb_inttable *upb_inttable_pack(const upb_inttable *t, void *p, size_t *ofs,
2901                                 size_t size);
2902 upb_strtable *upb_strtable_pack(const upb_strtable *t, void *p, size_t *ofs,
2903                                 size_t size);
2904 
2905 /* Inserts the given key into the hashtable with the given value.  The key must
2906  * not already exist in the hash table.  For string tables, the key must be
2907  * NULL-terminated, and the table will make an internal copy of the key.
2908  * Inttables must not insert a value of UINTPTR_MAX.
2909  *
2910  * If a table resize was required but memory allocation failed, false is
2911  * returned and the table is unchanged. */
2912 bool upb_inttable_insert2(upb_inttable *t, uintptr_t key, upb_value val,
2913                           upb_alloc *a);
2914 bool upb_strtable_insert3(upb_strtable *t, const char *key, size_t len,
2915                           upb_value val, upb_alloc *a);
2916 
upb_inttable_insert(upb_inttable * t,uintptr_t key,upb_value val)2917 UPB_INLINE bool upb_inttable_insert(upb_inttable *t, uintptr_t key,
2918                                     upb_value val) {
2919   return upb_inttable_insert2(t, key, val, &upb_alloc_global);
2920 }
2921 
upb_strtable_insert2(upb_strtable * t,const char * key,size_t len,upb_value val)2922 UPB_INLINE bool upb_strtable_insert2(upb_strtable *t, const char *key,
2923                                      size_t len, upb_value val) {
2924   return upb_strtable_insert3(t, key, len, val, &upb_alloc_global);
2925 }
2926 
2927 /* For NULL-terminated strings. */
upb_strtable_insert(upb_strtable * t,const char * key,upb_value val)2928 UPB_INLINE bool upb_strtable_insert(upb_strtable *t, const char *key,
2929                                     upb_value val) {
2930   return upb_strtable_insert2(t, key, strlen(key), val);
2931 }
2932 
2933 /* Looks up key in this table, returning "true" if the key was found.
2934  * If v is non-NULL, copies the value for this key into *v. */
2935 bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v);
2936 bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len,
2937                           upb_value *v);
2938 
2939 /* For NULL-terminated strings. */
upb_strtable_lookup(const upb_strtable * t,const char * key,upb_value * v)2940 UPB_INLINE bool upb_strtable_lookup(const upb_strtable *t, const char *key,
2941                                     upb_value *v) {
2942   return upb_strtable_lookup2(t, key, strlen(key), v);
2943 }
2944 
2945 /* Removes an item from the table.  Returns true if the remove was successful,
2946  * and stores the removed item in *val if non-NULL. */
2947 bool upb_inttable_remove(upb_inttable *t, uintptr_t key, upb_value *val);
2948 bool upb_strtable_remove3(upb_strtable *t, const char *key, size_t len,
2949                           upb_value *val, upb_alloc *alloc);
2950 
upb_strtable_remove2(upb_strtable * t,const char * key,size_t len,upb_value * val)2951 UPB_INLINE bool upb_strtable_remove2(upb_strtable *t, const char *key,
2952                                      size_t len, upb_value *val) {
2953   return upb_strtable_remove3(t, key, len, val, &upb_alloc_global);
2954 }
2955 
2956 /* For NULL-terminated strings. */
upb_strtable_remove(upb_strtable * t,const char * key,upb_value * v)2957 UPB_INLINE bool upb_strtable_remove(upb_strtable *t, const char *key,
2958                                     upb_value *v) {
2959   return upb_strtable_remove2(t, key, strlen(key), v);
2960 }
2961 
2962 /* Updates an existing entry in an inttable.  If the entry does not exist,
2963  * returns false and does nothing.  Unlike insert/remove, this does not
2964  * invalidate iterators. */
2965 bool upb_inttable_replace(upb_inttable *t, uintptr_t key, upb_value val);
2966 
2967 /* Handy routines for treating an inttable like a stack.  May not be mixed with
2968  * other insert/remove calls. */
2969 bool upb_inttable_push2(upb_inttable *t, upb_value val, upb_alloc *a);
2970 upb_value upb_inttable_pop(upb_inttable *t);
2971 
upb_inttable_push(upb_inttable * t,upb_value val)2972 UPB_INLINE bool upb_inttable_push(upb_inttable *t, upb_value val) {
2973   return upb_inttable_push2(t, val, &upb_alloc_global);
2974 }
2975 
2976 /* Convenience routines for inttables with pointer keys. */
2977 bool upb_inttable_insertptr2(upb_inttable *t, const void *key, upb_value val,
2978                              upb_alloc *a);
2979 bool upb_inttable_removeptr(upb_inttable *t, const void *key, upb_value *val);
2980 bool upb_inttable_lookupptr(
2981     const upb_inttable *t, const void *key, upb_value *val);
2982 
upb_inttable_insertptr(upb_inttable * t,const void * key,upb_value val)2983 UPB_INLINE bool upb_inttable_insertptr(upb_inttable *t, const void *key,
2984                                        upb_value val) {
2985   return upb_inttable_insertptr2(t, key, val, &upb_alloc_global);
2986 }
2987 
2988 /* Optimizes the table for the current set of entries, for both memory use and
2989  * lookup time.  Client should call this after all entries have been inserted;
2990  * inserting more entries is legal, but will likely require a table resize. */
2991 void upb_inttable_compact2(upb_inttable *t, upb_alloc *a);
2992 
upb_inttable_compact(upb_inttable * t)2993 UPB_INLINE void upb_inttable_compact(upb_inttable *t) {
2994   upb_inttable_compact2(t, &upb_alloc_global);
2995 }
2996 
2997 /* A special-case inlinable version of the lookup routine for 32-bit
2998  * integers. */
upb_inttable_lookup32(const upb_inttable * t,uint32_t key,upb_value * v)2999 UPB_INLINE bool upb_inttable_lookup32(const upb_inttable *t, uint32_t key,
3000                                       upb_value *v) {
3001   *v = upb_value_int32(0);  /* Silence compiler warnings. */
3002   if (key < t->array_size) {
3003     upb_tabval arrval = t->array[key];
3004     if (upb_arrhas(arrval)) {
3005       _upb_value_setval(v, arrval.val, t->t.ctype);
3006       return true;
3007     } else {
3008       return false;
3009     }
3010   } else {
3011     const upb_tabent *e;
3012     if (t->t.entries == NULL) return false;
3013     for (e = upb_getentry(&t->t, upb_inthash(key)); true; e = e->next) {
3014       if ((uint32_t)e->key == key) {
3015         _upb_value_setval(v, e->val.val, t->t.ctype);
3016         return true;
3017       }
3018       if (e->next == NULL) return false;
3019     }
3020   }
3021 }
3022 
3023 /* Exposed for testing only. */
3024 bool upb_strtable_resize(upb_strtable *t, size_t size_lg2, upb_alloc *a);
3025 
3026 /* Iterators ******************************************************************/
3027 
3028 /* Iterators for int and string tables.  We are subject to some kind of unusual
3029  * design constraints:
3030  *
3031  * For high-level languages:
3032  *  - we must be able to guarantee that we don't crash or corrupt memory even if
3033  *    the program accesses an invalidated iterator.
3034  *
3035  * For C++11 range-based for:
3036  *  - iterators must be copyable
3037  *  - iterators must be comparable
3038  *  - it must be possible to construct an "end" value.
3039  *
3040  * Iteration order is undefined.
3041  *
3042  * Modifying the table invalidates iterators.  upb_{str,int}table_done() is
3043  * guaranteed to work even on an invalidated iterator, as long as the table it
3044  * is iterating over has not been freed.  Calling next() or accessing data from
3045  * an invalidated iterator yields unspecified elements from the table, but it is
3046  * guaranteed not to crash and to return real table elements (except when done()
3047  * is true). */
3048 
3049 
3050 /* upb_strtable_iter **********************************************************/
3051 
3052 /*   upb_strtable_iter i;
3053  *   upb_strtable_begin(&i, t);
3054  *   for(; !upb_strtable_done(&i); upb_strtable_next(&i)) {
3055  *     const char *key = upb_strtable_iter_key(&i);
3056  *     const upb_value val = upb_strtable_iter_value(&i);
3057  *     // ...
3058  *   }
3059  */
3060 
3061 typedef struct {
3062   const upb_strtable *t;
3063   size_t index;
3064 } upb_strtable_iter;
3065 
3066 void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t);
3067 void upb_strtable_next(upb_strtable_iter *i);
3068 bool upb_strtable_done(const upb_strtable_iter *i);
3069 const char *upb_strtable_iter_key(const upb_strtable_iter *i);
3070 size_t upb_strtable_iter_keylength(const upb_strtable_iter *i);
3071 upb_value upb_strtable_iter_value(const upb_strtable_iter *i);
3072 void upb_strtable_iter_setdone(upb_strtable_iter *i);
3073 bool upb_strtable_iter_isequal(const upb_strtable_iter *i1,
3074                                const upb_strtable_iter *i2);
3075 
3076 
3077 /* upb_inttable_iter **********************************************************/
3078 
3079 /*   upb_inttable_iter i;
3080  *   upb_inttable_begin(&i, t);
3081  *   for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
3082  *     uintptr_t key = upb_inttable_iter_key(&i);
3083  *     upb_value val = upb_inttable_iter_value(&i);
3084  *     // ...
3085  *   }
3086  */
3087 
3088 typedef struct {
3089   const upb_inttable *t;
3090   size_t index;
3091   bool array_part;
3092 } upb_inttable_iter;
3093 
3094 void upb_inttable_begin(upb_inttable_iter *i, const upb_inttable *t);
3095 void upb_inttable_next(upb_inttable_iter *i);
3096 bool upb_inttable_done(const upb_inttable_iter *i);
3097 uintptr_t upb_inttable_iter_key(const upb_inttable_iter *i);
3098 upb_value upb_inttable_iter_value(const upb_inttable_iter *i);
3099 void upb_inttable_iter_setdone(upb_inttable_iter *i);
3100 bool upb_inttable_iter_isequal(const upb_inttable_iter *i1,
3101                                const upb_inttable_iter *i2);
3102 
3103 
3104 #ifdef __cplusplus
3105 }  /* extern "C" */
3106 #endif
3107 
3108 #endif  /* UPB_TABLE_H_ */
3109 
3110 #ifdef __cplusplus
3111 #include <cstring>
3112 #include <memory>
3113 #include <string>
3114 #include <vector>
3115 
3116 namespace upb {
3117 class EnumDefPtr;
3118 class FieldDefPtr;
3119 class FileDefPtr;
3120 class MessageDefPtr;
3121 class OneofDefPtr;
3122 class SymbolTable;
3123 }
3124 #endif
3125 
3126 struct upb_enumdef;
3127 typedef struct upb_enumdef upb_enumdef;
3128 struct upb_fielddef;
3129 typedef struct upb_fielddef upb_fielddef;
3130 struct upb_filedef;
3131 typedef struct upb_filedef upb_filedef;
3132 struct upb_msgdef;
3133 typedef struct upb_msgdef upb_msgdef;
3134 struct upb_oneofdef;
3135 typedef struct upb_oneofdef upb_oneofdef;
3136 struct upb_symtab;
3137 typedef struct upb_symtab upb_symtab;
3138 
3139 typedef enum {
3140   UPB_SYNTAX_PROTO2 = 2,
3141   UPB_SYNTAX_PROTO3 = 3
3142 } upb_syntax_t;
3143 
3144 /* All the different kind of well known type messages. For simplicity of check,
3145  * number wrappers and string wrappers are grouped together. Make sure the
3146  * order and merber of these groups are not changed.
3147  */
3148 typedef enum {
3149   UPB_WELLKNOWN_UNSPECIFIED,
3150   UPB_WELLKNOWN_ANY,
3151   UPB_WELLKNOWN_FIELDMASK,
3152   UPB_WELLKNOWN_DURATION,
3153   UPB_WELLKNOWN_TIMESTAMP,
3154   /* number wrappers */
3155   UPB_WELLKNOWN_DOUBLEVALUE,
3156   UPB_WELLKNOWN_FLOATVALUE,
3157   UPB_WELLKNOWN_INT64VALUE,
3158   UPB_WELLKNOWN_UINT64VALUE,
3159   UPB_WELLKNOWN_INT32VALUE,
3160   UPB_WELLKNOWN_UINT32VALUE,
3161   /* string wrappers */
3162   UPB_WELLKNOWN_STRINGVALUE,
3163   UPB_WELLKNOWN_BYTESVALUE,
3164   UPB_WELLKNOWN_BOOLVALUE,
3165   UPB_WELLKNOWN_VALUE,
3166   UPB_WELLKNOWN_LISTVALUE,
3167   UPB_WELLKNOWN_STRUCT
3168 } upb_wellknowntype_t;
3169 
3170 /* upb_fielddef ***************************************************************/
3171 
3172 /* Maximum field number allowed for FieldDefs.  This is an inherent limit of the
3173  * protobuf wire format. */
3174 #define UPB_MAX_FIELDNUMBER ((1 << 29) - 1)
3175 
3176 #ifdef __cplusplus
3177 extern "C" {
3178 #endif
3179 
3180 const char *upb_fielddef_fullname(const upb_fielddef *f);
3181 upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f);
3182 upb_descriptortype_t upb_fielddef_descriptortype(const upb_fielddef *f);
3183 upb_label_t upb_fielddef_label(const upb_fielddef *f);
3184 uint32_t upb_fielddef_number(const upb_fielddef *f);
3185 const char *upb_fielddef_name(const upb_fielddef *f);
3186 bool upb_fielddef_isextension(const upb_fielddef *f);
3187 bool upb_fielddef_lazy(const upb_fielddef *f);
3188 bool upb_fielddef_packed(const upb_fielddef *f);
3189 size_t upb_fielddef_getjsonname(const upb_fielddef *f, char *buf, size_t len);
3190 const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f);
3191 const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f);
3192 uint32_t upb_fielddef_index(const upb_fielddef *f);
3193 bool upb_fielddef_issubmsg(const upb_fielddef *f);
3194 bool upb_fielddef_isstring(const upb_fielddef *f);
3195 bool upb_fielddef_isseq(const upb_fielddef *f);
3196 bool upb_fielddef_isprimitive(const upb_fielddef *f);
3197 bool upb_fielddef_ismap(const upb_fielddef *f);
3198 int64_t upb_fielddef_defaultint64(const upb_fielddef *f);
3199 int32_t upb_fielddef_defaultint32(const upb_fielddef *f);
3200 uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f);
3201 uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f);
3202 bool upb_fielddef_defaultbool(const upb_fielddef *f);
3203 float upb_fielddef_defaultfloat(const upb_fielddef *f);
3204 double upb_fielddef_defaultdouble(const upb_fielddef *f);
3205 const char *upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len);
3206 bool upb_fielddef_hassubdef(const upb_fielddef *f);
3207 bool upb_fielddef_haspresence(const upb_fielddef *f);
3208 const upb_msgdef *upb_fielddef_msgsubdef(const upb_fielddef *f);
3209 const upb_enumdef *upb_fielddef_enumsubdef(const upb_fielddef *f);
3210 
3211 /* Internal only. */
3212 uint32_t upb_fielddef_selectorbase(const upb_fielddef *f);
3213 
3214 #ifdef __cplusplus
3215 }  /* extern "C" */
3216 
3217 /* A upb_fielddef describes a single field in a message.  It is most often
3218  * found as a part of a upb_msgdef, but can also stand alone to represent
3219  * an extension. */
3220 class upb::FieldDefPtr {
3221  public:
FieldDefPtr()3222   FieldDefPtr() : ptr_(nullptr) {}
FieldDefPtr(const upb_fielddef * ptr)3223   explicit FieldDefPtr(const upb_fielddef *ptr) : ptr_(ptr) {}
3224 
ptr()3225   const upb_fielddef* ptr() const { return ptr_; }
3226   explicit operator bool() const { return ptr_ != nullptr; }
3227 
3228   typedef upb_fieldtype_t Type;
3229   typedef upb_label_t Label;
3230   typedef upb_descriptortype_t DescriptorType;
3231 
full_name()3232   const char* full_name() const { return upb_fielddef_fullname(ptr_); }
3233 
type()3234   Type type() const { return upb_fielddef_type(ptr_); }
label()3235   Label label() const { return upb_fielddef_label(ptr_); }
name()3236   const char* name() const { return upb_fielddef_name(ptr_); }
number()3237   uint32_t number() const { return upb_fielddef_number(ptr_); }
is_extension()3238   bool is_extension() const { return upb_fielddef_isextension(ptr_); }
3239 
3240   /* Copies the JSON name for this field into the given buffer.  Returns the
3241    * actual size of the JSON name, including the NULL terminator.  If the
3242    * return value is 0, the JSON name is unset.  If the return value is
3243    * greater than len, the JSON name was truncated.  The buffer is always
3244    * NULL-terminated if len > 0.
3245    *
3246    * The JSON name always defaults to a camelCased version of the regular
3247    * name.  However if the regular name is unset, the JSON name will be unset
3248    * also.
3249    */
GetJsonName(char * buf,size_t len)3250   size_t GetJsonName(char *buf, size_t len) const {
3251     return upb_fielddef_getjsonname(ptr_, buf, len);
3252   }
3253 
3254   /* Convenience version of the above function which copies the JSON name
3255    * into the given string, returning false if the name is not set. */
3256   template <class T>
GetJsonName(T * str)3257   bool GetJsonName(T* str) {
3258     str->resize(GetJsonName(NULL, 0));
3259     GetJsonName(&(*str)[0], str->size());
3260     return str->size() > 0;
3261   }
3262 
3263   /* For UPB_TYPE_MESSAGE fields only where is_tag_delimited() == false,
3264    * indicates whether this field should have lazy parsing handlers that yield
3265    * the unparsed string for the submessage.
3266    *
3267    * TODO(haberman): I think we want to move this into a FieldOptions container
3268    * when we add support for custom options (the FieldOptions struct will
3269    * contain both regular FieldOptions like "lazy" *and* custom options). */
lazy()3270   bool lazy() const { return upb_fielddef_lazy(ptr_); }
3271 
3272   /* For non-string, non-submessage fields, this indicates whether binary
3273    * protobufs are encoded in packed or non-packed format.
3274    *
3275    * TODO(haberman): see note above about putting options like this into a
3276    * FieldOptions container. */
packed()3277   bool packed() const { return upb_fielddef_packed(ptr_); }
3278 
3279   /* An integer that can be used as an index into an array of fields for
3280    * whatever message this field belongs to.  Guaranteed to be less than
3281    * f->containing_type()->field_count().  May only be accessed once the def has
3282    * been finalized. */
index()3283   uint32_t index() const { return upb_fielddef_index(ptr_); }
3284 
3285   /* The MessageDef to which this field belongs.
3286    *
3287    * If this field has been added to a MessageDef, that message can be retrieved
3288    * directly (this is always the case for frozen FieldDefs).
3289    *
3290    * If the field has not yet been added to a MessageDef, you can set the name
3291    * of the containing type symbolically instead.  This is mostly useful for
3292    * extensions, where the extension is declared separately from the message. */
3293   MessageDefPtr containing_type() const;
3294 
3295   /* The OneofDef to which this field belongs, or NULL if this field is not part
3296    * of a oneof. */
3297   OneofDefPtr containing_oneof() const;
3298 
3299   /* The field's type according to the enum in descriptor.proto.  This is not
3300    * the same as UPB_TYPE_*, because it distinguishes between (for example)
3301    * INT32 and SINT32, whereas our "type" enum does not.  This return of
3302    * descriptor_type() is a function of type(), integer_format(), and
3303    * is_tag_delimited().  */
descriptor_type()3304   DescriptorType descriptor_type() const {
3305     return upb_fielddef_descriptortype(ptr_);
3306   }
3307 
3308   /* Convenient field type tests. */
IsSubMessage()3309   bool IsSubMessage() const { return upb_fielddef_issubmsg(ptr_); }
IsString()3310   bool IsString() const { return upb_fielddef_isstring(ptr_); }
IsSequence()3311   bool IsSequence() const { return upb_fielddef_isseq(ptr_); }
IsPrimitive()3312   bool IsPrimitive() const { return upb_fielddef_isprimitive(ptr_); }
IsMap()3313   bool IsMap() const { return upb_fielddef_ismap(ptr_); }
3314 
3315   /* Returns the non-string default value for this fielddef, which may either
3316    * be something the client set explicitly or the "default default" (0 for
3317    * numbers, empty for strings).  The field's type indicates the type of the
3318    * returned value, except for enum fields that are still mutable.
3319    *
3320    * Requires that the given function matches the field's current type. */
default_int64()3321   int64_t default_int64() const { return upb_fielddef_defaultint64(ptr_); }
default_int32()3322   int32_t default_int32() const { return upb_fielddef_defaultint32(ptr_); }
default_uint64()3323   uint64_t default_uint64() const { return upb_fielddef_defaultuint64(ptr_); }
default_uint32()3324   uint32_t default_uint32() const { return upb_fielddef_defaultuint32(ptr_); }
default_bool()3325   bool default_bool() const { return upb_fielddef_defaultbool(ptr_); }
default_float()3326   float default_float() const { return upb_fielddef_defaultfloat(ptr_); }
default_double()3327   double default_double() const { return upb_fielddef_defaultdouble(ptr_); }
3328 
3329   /* The resulting string is always NULL-terminated.  If non-NULL, the length
3330    * will be stored in *len. */
default_string(size_t * len)3331   const char *default_string(size_t * len) const {
3332     return upb_fielddef_defaultstr(ptr_, len);
3333   }
3334 
3335   /* Returns the enum or submessage def for this field, if any.  The field's
3336    * type must match (ie. you may only call enum_subdef() for fields where
3337    * type() == UPB_TYPE_ENUM). */
3338   EnumDefPtr enum_subdef() const;
3339   MessageDefPtr message_subdef() const;
3340 
3341  private:
3342   const upb_fielddef *ptr_;
3343 };
3344 
3345 #endif  /* __cplusplus */
3346 
3347 /* upb_oneofdef ***************************************************************/
3348 
3349 #ifdef __cplusplus
3350 extern "C" {
3351 #endif
3352 
3353 typedef upb_inttable_iter upb_oneof_iter;
3354 
3355 const char *upb_oneofdef_name(const upb_oneofdef *o);
3356 const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o);
3357 int upb_oneofdef_numfields(const upb_oneofdef *o);
3358 uint32_t upb_oneofdef_index(const upb_oneofdef *o);
3359 
3360 /* Oneof lookups:
3361  * - ntof:  look up a field by name.
3362  * - ntofz: look up a field by name (as a null-terminated string).
3363  * - itof:  look up a field by number. */
3364 const upb_fielddef *upb_oneofdef_ntof(const upb_oneofdef *o,
3365                                       const char *name, size_t length);
upb_oneofdef_ntofz(const upb_oneofdef * o,const char * name)3366 UPB_INLINE const upb_fielddef *upb_oneofdef_ntofz(const upb_oneofdef *o,
3367                                                   const char *name) {
3368   return upb_oneofdef_ntof(o, name, strlen(name));
3369 }
3370 const upb_fielddef *upb_oneofdef_itof(const upb_oneofdef *o, uint32_t num);
3371 
3372 /*  upb_oneof_iter i;
3373  *  for(upb_oneof_begin(&i, e); !upb_oneof_done(&i); upb_oneof_next(&i)) {
3374  *    // ...
3375  *  }
3376  */
3377 void upb_oneof_begin(upb_oneof_iter *iter, const upb_oneofdef *o);
3378 void upb_oneof_next(upb_oneof_iter *iter);
3379 bool upb_oneof_done(upb_oneof_iter *iter);
3380 upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter);
3381 void upb_oneof_iter_setdone(upb_oneof_iter *iter);
3382 bool upb_oneof_iter_isequal(const upb_oneof_iter *iter1,
3383                             const upb_oneof_iter *iter2);
3384 
3385 #ifdef __cplusplus
3386 }  /* extern "C" */
3387 
3388 /* Class that represents a oneof. */
3389 class upb::OneofDefPtr {
3390  public:
OneofDefPtr()3391   OneofDefPtr() : ptr_(nullptr) {}
OneofDefPtr(const upb_oneofdef * ptr)3392   explicit OneofDefPtr(const upb_oneofdef *ptr) : ptr_(ptr) {}
3393 
ptr()3394   const upb_oneofdef* ptr() const { return ptr_; }
3395   explicit operator bool() { return ptr_ != nullptr; }
3396 
3397   /* Returns the MessageDef that owns this OneofDef. */
3398   MessageDefPtr containing_type() const;
3399 
3400   /* Returns the name of this oneof. This is the name used to look up the oneof
3401    * by name once added to a message def. */
name()3402   const char* name() const { return upb_oneofdef_name(ptr_); }
3403 
3404   /* Returns the number of fields currently defined in the oneof. */
field_count()3405   int field_count() const { return upb_oneofdef_numfields(ptr_); }
3406 
3407   /* Looks up by name. */
FindFieldByName(const char * name,size_t len)3408   FieldDefPtr FindFieldByName(const char *name, size_t len) const {
3409     return FieldDefPtr(upb_oneofdef_ntof(ptr_, name, len));
3410   }
FindFieldByName(const char * name)3411   FieldDefPtr FindFieldByName(const char* name) const {
3412     return FieldDefPtr(upb_oneofdef_ntofz(ptr_, name));
3413   }
3414 
3415   template <class T>
FindFieldByName(const T & str)3416   FieldDefPtr FindFieldByName(const T& str) const {
3417     return FindFieldByName(str.c_str(), str.size());
3418   }
3419 
3420   /* Looks up by tag number. */
FindFieldByNumber(uint32_t num)3421   FieldDefPtr FindFieldByNumber(uint32_t num) const {
3422     return FieldDefPtr(upb_oneofdef_itof(ptr_, num));
3423   }
3424 
3425   class const_iterator
3426       : public std::iterator<std::forward_iterator_tag, FieldDefPtr> {
3427    public:
3428     void operator++() { upb_oneof_next(&iter_); }
3429 
3430     FieldDefPtr operator*() const {
3431       return FieldDefPtr(upb_oneof_iter_field(&iter_));
3432     }
3433 
3434     bool operator!=(const const_iterator& other) const {
3435       return !upb_oneof_iter_isequal(&iter_, &other.iter_);
3436     }
3437 
3438     bool operator==(const const_iterator& other) const {
3439       return upb_oneof_iter_isequal(&iter_, &other.iter_);
3440     }
3441 
3442    private:
3443     friend class OneofDefPtr;
3444 
const_iterator()3445     const_iterator() {}
const_iterator(OneofDefPtr o)3446     explicit const_iterator(OneofDefPtr o) {
3447       upb_oneof_begin(&iter_, o.ptr());
3448     }
end()3449     static const_iterator end() {
3450       const_iterator iter;
3451       upb_oneof_iter_setdone(&iter.iter_);
3452       return iter;
3453     }
3454 
3455     upb_oneof_iter iter_;
3456   };
3457 
begin()3458   const_iterator begin() const { return const_iterator(*this); }
end()3459   const_iterator end() const { return const_iterator::end(); }
3460 
3461  private:
3462   const upb_oneofdef *ptr_;
3463 };
3464 
containing_oneof()3465 inline upb::OneofDefPtr upb::FieldDefPtr::containing_oneof() const {
3466   return OneofDefPtr(upb_fielddef_containingoneof(ptr_));
3467 }
3468 
3469 #endif  /* __cplusplus */
3470 
3471 /* upb_msgdef *****************************************************************/
3472 
3473 typedef upb_inttable_iter upb_msg_field_iter;
3474 typedef upb_strtable_iter upb_msg_oneof_iter;
3475 
3476 /* Well-known field tag numbers for map-entry messages. */
3477 #define UPB_MAPENTRY_KEY   1
3478 #define UPB_MAPENTRY_VALUE 2
3479 
3480 /* Well-known field tag numbers for Any messages. */
3481 #define UPB_ANY_TYPE 1
3482 #define UPB_ANY_VALUE 2
3483 
3484 /* Well-known field tag numbers for timestamp messages. */
3485 #define UPB_DURATION_SECONDS 1
3486 #define UPB_DURATION_NANOS 2
3487 
3488 /* Well-known field tag numbers for duration messages. */
3489 #define UPB_TIMESTAMP_SECONDS 1
3490 #define UPB_TIMESTAMP_NANOS 2
3491 
3492 #ifdef __cplusplus
3493 extern "C" {
3494 #endif
3495 
3496 const char *upb_msgdef_fullname(const upb_msgdef *m);
3497 const upb_filedef *upb_msgdef_file(const upb_msgdef *m);
3498 const char *upb_msgdef_name(const upb_msgdef *m);
3499 int upb_msgdef_numoneofs(const upb_msgdef *m);
3500 upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m);
3501 bool upb_msgdef_mapentry(const upb_msgdef *m);
3502 upb_wellknowntype_t upb_msgdef_wellknowntype(const upb_msgdef *m);
3503 bool upb_msgdef_isnumberwrapper(const upb_msgdef *m);
3504 bool upb_msgdef_setsyntax(upb_msgdef *m, upb_syntax_t syntax);
3505 const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i);
3506 const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name,
3507                                     size_t len);
3508 const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name,
3509                                     size_t len);
3510 int upb_msgdef_numfields(const upb_msgdef *m);
3511 int upb_msgdef_numoneofs(const upb_msgdef *m);
3512 
upb_msgdef_ntooz(const upb_msgdef * m,const char * name)3513 UPB_INLINE const upb_oneofdef *upb_msgdef_ntooz(const upb_msgdef *m,
3514                                                const char *name) {
3515   return upb_msgdef_ntoo(m, name, strlen(name));
3516 }
3517 
upb_msgdef_ntofz(const upb_msgdef * m,const char * name)3518 UPB_INLINE const upb_fielddef *upb_msgdef_ntofz(const upb_msgdef *m,
3519                                                 const char *name) {
3520   return upb_msgdef_ntof(m, name, strlen(name));
3521 }
3522 
3523 /* Internal-only. */
3524 size_t upb_msgdef_selectorcount(const upb_msgdef *m);
3525 uint32_t upb_msgdef_submsgfieldcount(const upb_msgdef *m);
3526 
3527 /* Lookup of either field or oneof by name.  Returns whether either was found.
3528  * If the return is true, then the found def will be set, and the non-found
3529  * one set to NULL. */
3530 bool upb_msgdef_lookupname(const upb_msgdef *m, const char *name, size_t len,
3531                            const upb_fielddef **f, const upb_oneofdef **o);
3532 
upb_msgdef_lookupnamez(const upb_msgdef * m,const char * name,const upb_fielddef ** f,const upb_oneofdef ** o)3533 UPB_INLINE bool upb_msgdef_lookupnamez(const upb_msgdef *m, const char *name,
3534                                        const upb_fielddef **f,
3535                                        const upb_oneofdef **o) {
3536   return upb_msgdef_lookupname(m, name, strlen(name), f, o);
3537 }
3538 
3539 /* Iteration over fields and oneofs.  For example:
3540  *
3541  * upb_msg_field_iter i;
3542  * for(upb_msg_field_begin(&i, m);
3543  *     !upb_msg_field_done(&i);
3544  *     upb_msg_field_next(&i)) {
3545  *   upb_fielddef *f = upb_msg_iter_field(&i);
3546  *   // ...
3547  * }
3548  *
3549  * For C we don't have separate iterators for const and non-const.
3550  * It is the caller's responsibility to cast the upb_fielddef* to
3551  * const if the upb_msgdef* is const. */
3552 void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m);
3553 void upb_msg_field_next(upb_msg_field_iter *iter);
3554 bool upb_msg_field_done(const upb_msg_field_iter *iter);
3555 upb_fielddef *upb_msg_iter_field(const upb_msg_field_iter *iter);
3556 void upb_msg_field_iter_setdone(upb_msg_field_iter *iter);
3557 bool upb_msg_field_iter_isequal(const upb_msg_field_iter * iter1,
3558                                 const upb_msg_field_iter * iter2);
3559 
3560 /* Similar to above, we also support iterating through the oneofs in a
3561  * msgdef. */
3562 void upb_msg_oneof_begin(upb_msg_oneof_iter * iter, const upb_msgdef *m);
3563 void upb_msg_oneof_next(upb_msg_oneof_iter * iter);
3564 bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter);
3565 const upb_oneofdef *upb_msg_iter_oneof(const upb_msg_oneof_iter *iter);
3566 void upb_msg_oneof_iter_setdone(upb_msg_oneof_iter * iter);
3567 bool upb_msg_oneof_iter_isequal(const upb_msg_oneof_iter *iter1,
3568                                 const upb_msg_oneof_iter *iter2);
3569 
3570 #ifdef __cplusplus
3571 }  /* extern "C" */
3572 
3573 /* Structure that describes a single .proto message type. */
3574 class upb::MessageDefPtr {
3575  public:
MessageDefPtr()3576   MessageDefPtr() : ptr_(nullptr) {}
MessageDefPtr(const upb_msgdef * ptr)3577   explicit MessageDefPtr(const upb_msgdef *ptr) : ptr_(ptr) {}
3578 
ptr()3579   const upb_msgdef *ptr() const { return ptr_; }
3580   explicit operator bool() const { return ptr_ != nullptr; }
3581 
full_name()3582   const char* full_name() const { return upb_msgdef_fullname(ptr_); }
name()3583   const char* name() const { return upb_msgdef_name(ptr_); }
3584 
3585   /* The number of fields that belong to the MessageDef. */
field_count()3586   int field_count() const { return upb_msgdef_numfields(ptr_); }
3587 
3588   /* The number of oneofs that belong to the MessageDef. */
oneof_count()3589   int oneof_count() const { return upb_msgdef_numoneofs(ptr_); }
3590 
syntax()3591   upb_syntax_t syntax() const { return upb_msgdef_syntax(ptr_); }
3592 
3593   /* These return null pointers if the field is not found. */
FindFieldByNumber(uint32_t number)3594   FieldDefPtr FindFieldByNumber(uint32_t number) const {
3595     return FieldDefPtr(upb_msgdef_itof(ptr_, number));
3596   }
FindFieldByName(const char * name,size_t len)3597   FieldDefPtr FindFieldByName(const char* name, size_t len) const {
3598     return FieldDefPtr(upb_msgdef_ntof(ptr_, name, len));
3599   }
FindFieldByName(const char * name)3600   FieldDefPtr FindFieldByName(const char *name) const {
3601     return FieldDefPtr(upb_msgdef_ntofz(ptr_, name));
3602   }
3603 
3604   template <class T>
FindFieldByName(const T & str)3605   FieldDefPtr FindFieldByName(const T& str) const {
3606     return FindFieldByName(str.c_str(), str.size());
3607   }
3608 
FindOneofByName(const char * name,size_t len)3609   OneofDefPtr FindOneofByName(const char* name, size_t len) const {
3610     return OneofDefPtr(upb_msgdef_ntoo(ptr_, name, len));
3611   }
3612 
FindOneofByName(const char * name)3613   OneofDefPtr FindOneofByName(const char *name) const {
3614     return OneofDefPtr(upb_msgdef_ntooz(ptr_, name));
3615   }
3616 
3617   template <class T>
FindOneofByName(const T & str)3618   OneofDefPtr FindOneofByName(const T &str) const {
3619     return FindOneofByName(str.c_str(), str.size());
3620   }
3621 
3622   /* Is this message a map entry? */
mapentry()3623   bool mapentry() const { return upb_msgdef_mapentry(ptr_); }
3624 
3625   /* Return the type of well known type message. UPB_WELLKNOWN_UNSPECIFIED for
3626    * non-well-known message. */
wellknowntype()3627   upb_wellknowntype_t wellknowntype() const {
3628     return upb_msgdef_wellknowntype(ptr_);
3629   }
3630 
3631   /* Whether is a number wrapper. */
isnumberwrapper()3632   bool isnumberwrapper() const { return upb_msgdef_isnumberwrapper(ptr_); }
3633 
3634   /* Iteration over fields.  The order is undefined. */
3635   class const_field_iterator
3636       : public std::iterator<std::forward_iterator_tag, FieldDefPtr> {
3637    public:
3638     void operator++() { upb_msg_field_next(&iter_); }
3639 
3640     FieldDefPtr operator*() const {
3641       return FieldDefPtr(upb_msg_iter_field(&iter_));
3642     }
3643 
3644     bool operator!=(const const_field_iterator &other) const {
3645       return !upb_msg_field_iter_isequal(&iter_, &other.iter_);
3646     }
3647 
3648     bool operator==(const const_field_iterator &other) const {
3649       return upb_msg_field_iter_isequal(&iter_, &other.iter_);
3650     }
3651 
3652    private:
3653     friend class MessageDefPtr;
3654 
const_field_iterator()3655     explicit const_field_iterator() {}
3656 
const_field_iterator(MessageDefPtr msg)3657     explicit const_field_iterator(MessageDefPtr msg) {
3658       upb_msg_field_begin(&iter_, msg.ptr());
3659     }
3660 
end()3661     static const_field_iterator end() {
3662       const_field_iterator iter;
3663       upb_msg_field_iter_setdone(&iter.iter_);
3664       return iter;
3665     }
3666 
3667     upb_msg_field_iter iter_;
3668   };
3669 
3670   /* Iteration over oneofs. The order is undefined. */
3671   class const_oneof_iterator
3672       : public std::iterator<std::forward_iterator_tag, OneofDefPtr> {
3673    public:
3674 
3675     void operator++() { upb_msg_oneof_next(&iter_); }
3676 
3677     OneofDefPtr operator*() const {
3678       return OneofDefPtr(upb_msg_iter_oneof(&iter_));
3679     }
3680 
3681     bool operator!=(const const_oneof_iterator& other) const {
3682       return !upb_msg_oneof_iter_isequal(&iter_, &other.iter_);
3683     }
3684 
3685     bool operator==(const const_oneof_iterator &other) const {
3686       return upb_msg_oneof_iter_isequal(&iter_, &other.iter_);
3687     }
3688 
3689    private:
3690     friend class MessageDefPtr;
3691 
const_oneof_iterator()3692     const_oneof_iterator() {}
3693 
const_oneof_iterator(MessageDefPtr msg)3694     explicit const_oneof_iterator(MessageDefPtr msg) {
3695       upb_msg_oneof_begin(&iter_, msg.ptr());
3696     }
3697 
end()3698     static const_oneof_iterator end() {
3699       const_oneof_iterator iter;
3700       upb_msg_oneof_iter_setdone(&iter.iter_);
3701       return iter;
3702     }
3703 
3704     upb_msg_oneof_iter iter_;
3705   };
3706 
3707   class ConstFieldAccessor {
3708    public:
ConstFieldAccessor(const upb_msgdef * md)3709     explicit ConstFieldAccessor(const upb_msgdef* md) : md_(md) {}
begin()3710     const_field_iterator begin() { return MessageDefPtr(md_).field_begin(); }
end()3711     const_field_iterator end() { return MessageDefPtr(md_).field_end(); }
3712    private:
3713     const upb_msgdef* md_;
3714   };
3715 
3716   class ConstOneofAccessor {
3717    public:
ConstOneofAccessor(const upb_msgdef * md)3718     explicit ConstOneofAccessor(const upb_msgdef* md) : md_(md) {}
begin()3719     const_oneof_iterator begin() { return MessageDefPtr(md_).oneof_begin(); }
end()3720     const_oneof_iterator end() { return MessageDefPtr(md_).oneof_end(); }
3721    private:
3722     const upb_msgdef* md_;
3723   };
3724 
field_begin()3725   const_field_iterator field_begin() const {
3726     return const_field_iterator(*this);
3727   }
3728 
field_end()3729   const_field_iterator field_end() const { return const_field_iterator::end(); }
3730 
oneof_begin()3731   const_oneof_iterator oneof_begin() const {
3732     return const_oneof_iterator(*this);
3733   }
3734 
oneof_end()3735   const_oneof_iterator oneof_end() const { return const_oneof_iterator::end(); }
3736 
fields()3737   ConstFieldAccessor fields() const { return ConstFieldAccessor(ptr()); }
oneofs()3738   ConstOneofAccessor oneofs() const { return ConstOneofAccessor(ptr()); }
3739 
3740  private:
3741   const upb_msgdef* ptr_;
3742 };
3743 
message_subdef()3744 inline upb::MessageDefPtr upb::FieldDefPtr::message_subdef() const {
3745   return MessageDefPtr(upb_fielddef_msgsubdef(ptr_));
3746 }
3747 
containing_type()3748 inline upb::MessageDefPtr upb::FieldDefPtr::containing_type() const {
3749   return MessageDefPtr(upb_fielddef_containingtype(ptr_));
3750 }
3751 
containing_type()3752 inline upb::MessageDefPtr upb::OneofDefPtr::containing_type() const {
3753   return MessageDefPtr(upb_oneofdef_containingtype(ptr_));
3754 }
3755 
3756 #endif  /* __cplusplus */
3757 
3758 /* upb_enumdef ****************************************************************/
3759 
3760 typedef upb_strtable_iter upb_enum_iter;
3761 
3762 const char *upb_enumdef_fullname(const upb_enumdef *e);
3763 const char *upb_enumdef_name(const upb_enumdef *e);
3764 const upb_filedef *upb_enumdef_file(const upb_enumdef *e);
3765 int32_t upb_enumdef_default(const upb_enumdef *e);
3766 int upb_enumdef_numvals(const upb_enumdef *e);
3767 
3768 /* Enum lookups:
3769  * - ntoi:  look up a name with specified length.
3770  * - ntoiz: look up a name provided as a null-terminated string.
3771  * - iton:  look up an integer, returning the name as a null-terminated
3772  *          string. */
3773 bool upb_enumdef_ntoi(const upb_enumdef *e, const char *name, size_t len,
3774                       int32_t *num);
upb_enumdef_ntoiz(const upb_enumdef * e,const char * name,int32_t * num)3775 UPB_INLINE bool upb_enumdef_ntoiz(const upb_enumdef *e,
3776                                   const char *name, int32_t *num) {
3777   return upb_enumdef_ntoi(e, name, strlen(name), num);
3778 }
3779 const char *upb_enumdef_iton(const upb_enumdef *e, int32_t num);
3780 
3781 /*  upb_enum_iter i;
3782  *  for(upb_enum_begin(&i, e); !upb_enum_done(&i); upb_enum_next(&i)) {
3783  *    // ...
3784  *  }
3785  */
3786 void upb_enum_begin(upb_enum_iter *iter, const upb_enumdef *e);
3787 void upb_enum_next(upb_enum_iter *iter);
3788 bool upb_enum_done(upb_enum_iter *iter);
3789 const char *upb_enum_iter_name(upb_enum_iter *iter);
3790 int32_t upb_enum_iter_number(upb_enum_iter *iter);
3791 
3792 #ifdef __cplusplus
3793 
3794 class upb::EnumDefPtr {
3795  public:
EnumDefPtr()3796   EnumDefPtr() : ptr_(nullptr) {}
EnumDefPtr(const upb_enumdef * ptr)3797   explicit EnumDefPtr(const upb_enumdef* ptr) : ptr_(ptr) {}
3798 
ptr()3799   const upb_enumdef* ptr() const { return ptr_; }
3800   explicit operator bool() const { return ptr_ != nullptr; }
3801 
full_name()3802   const char* full_name() const { return upb_enumdef_fullname(ptr_); }
name()3803   const char* name() const { return upb_enumdef_name(ptr_); }
3804 
3805   /* The value that is used as the default when no field default is specified.
3806    * If not set explicitly, the first value that was added will be used.
3807    * The default value must be a member of the enum.
3808    * Requires that value_count() > 0. */
default_value()3809   int32_t default_value() const { return upb_enumdef_default(ptr_); }
3810 
3811   /* Returns the number of values currently defined in the enum.  Note that
3812    * multiple names can refer to the same number, so this may be greater than
3813    * the total number of unique numbers. */
value_count()3814   int value_count() const { return upb_enumdef_numvals(ptr_); }
3815 
3816   /* Lookups from name to integer, returning true if found. */
FindValueByName(const char * name,int32_t * num)3817   bool FindValueByName(const char *name, int32_t *num) const {
3818     return upb_enumdef_ntoiz(ptr_, name, num);
3819   }
3820 
3821   /* Finds the name corresponding to the given number, or NULL if none was
3822    * found.  If more than one name corresponds to this number, returns the
3823    * first one that was added. */
FindValueByNumber(int32_t num)3824   const char *FindValueByNumber(int32_t num) const {
3825     return upb_enumdef_iton(ptr_, num);
3826   }
3827 
3828   /* Iteration over name/value pairs.  The order is undefined.
3829    * Adding an enum val invalidates any iterators.
3830    *
3831    * TODO: make compatible with range-for, with elements as pairs? */
3832   class Iterator {
3833    public:
Iterator(EnumDefPtr e)3834     explicit Iterator(EnumDefPtr e) { upb_enum_begin(&iter_, e.ptr()); }
3835 
number()3836     int32_t number() { return upb_enum_iter_number(&iter_); }
name()3837     const char *name() { return upb_enum_iter_name(&iter_); }
Done()3838     bool Done() { return upb_enum_done(&iter_); }
Next()3839     void Next() { return upb_enum_next(&iter_); }
3840 
3841    private:
3842     upb_enum_iter iter_;
3843   };
3844 
3845  private:
3846   const upb_enumdef *ptr_;
3847 };
3848 
enum_subdef()3849 inline upb::EnumDefPtr upb::FieldDefPtr::enum_subdef() const {
3850   return EnumDefPtr(upb_fielddef_enumsubdef(ptr_));
3851 }
3852 
3853 #endif  /* __cplusplus */
3854 
3855 /* upb_filedef ****************************************************************/
3856 
3857 #ifdef __cplusplus
3858 extern "C" {
3859 #endif
3860 
3861 const char *upb_filedef_name(const upb_filedef *f);
3862 const char *upb_filedef_package(const upb_filedef *f);
3863 const char *upb_filedef_phpprefix(const upb_filedef *f);
3864 const char *upb_filedef_phpnamespace(const upb_filedef *f);
3865 upb_syntax_t upb_filedef_syntax(const upb_filedef *f);
3866 int upb_filedef_depcount(const upb_filedef *f);
3867 int upb_filedef_msgcount(const upb_filedef *f);
3868 int upb_filedef_enumcount(const upb_filedef *f);
3869 const upb_filedef *upb_filedef_dep(const upb_filedef *f, int i);
3870 const upb_msgdef *upb_filedef_msg(const upb_filedef *f, int i);
3871 const upb_enumdef *upb_filedef_enum(const upb_filedef *f, int i);
3872 
3873 #ifdef __cplusplus
3874 }  /* extern "C" */
3875 
3876 /* Class that represents a .proto file with some things defined in it.
3877  *
3878  * Many users won't care about FileDefs, but they are necessary if you want to
3879  * read the values of file-level options. */
3880 class upb::FileDefPtr {
3881  public:
FileDefPtr(const upb_filedef * ptr)3882   explicit FileDefPtr(const upb_filedef *ptr) : ptr_(ptr) {}
3883 
ptr()3884   const upb_filedef* ptr() const { return ptr_; }
3885   explicit operator bool() const { return ptr_ != nullptr; }
3886 
3887   /* Get/set name of the file (eg. "foo/bar.proto"). */
name()3888   const char* name() const { return upb_filedef_name(ptr_); }
3889 
3890   /* Package name for definitions inside the file (eg. "foo.bar"). */
package()3891   const char* package() const { return upb_filedef_package(ptr_); }
3892 
3893   /* Sets the php class prefix which is prepended to all php generated classes
3894    * from this .proto. Default is empty. */
phpprefix()3895   const char* phpprefix() const { return upb_filedef_phpprefix(ptr_); }
3896 
3897   /* Use this option to change the namespace of php generated classes. Default
3898    * is empty. When this option is empty, the package name will be used for
3899    * determining the namespace. */
phpnamespace()3900   const char* phpnamespace() const { return upb_filedef_phpnamespace(ptr_); }
3901 
3902   /* Syntax for the file.  Defaults to proto2. */
syntax()3903   upb_syntax_t syntax() const { return upb_filedef_syntax(ptr_); }
3904 
3905   /* Get the list of dependencies from the file.  These are returned in the
3906    * order that they were added to the FileDefPtr. */
dependency_count()3907   int dependency_count() const { return upb_filedef_depcount(ptr_); }
dependency(int index)3908   const FileDefPtr dependency(int index) const {
3909     return FileDefPtr(upb_filedef_dep(ptr_, index));
3910   }
3911 
3912  private:
3913   const upb_filedef* ptr_;
3914 };
3915 
3916 #endif  /* __cplusplus */
3917 
3918 /* upb_symtab *****************************************************************/
3919 
3920 #ifdef __cplusplus
3921 extern "C" {
3922 #endif
3923 
3924 upb_symtab *upb_symtab_new();
3925 void upb_symtab_free(upb_symtab* s);
3926 const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym);
3927 const upb_msgdef *upb_symtab_lookupmsg2(
3928     const upb_symtab *s, const char *sym, size_t len);
3929 const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym);
3930 const upb_filedef *upb_symtab_lookupfile(const upb_symtab *s, const char *name);
3931 int upb_symtab_filecount(const upb_symtab *s);
3932 const upb_filedef *upb_symtab_addfile(
3933     upb_symtab *s, const google_protobuf_FileDescriptorProto *file,
3934     upb_status *status);
3935 
3936 /* For generated code only: loads a generated descriptor. */
3937 typedef struct upb_def_init {
3938   struct upb_def_init **deps;
3939   const char *filename;
3940   upb_strview descriptor;
3941 } upb_def_init;
3942 
3943 bool _upb_symtab_loaddefinit(upb_symtab *s, const upb_def_init *init);
3944 
3945 #ifdef __cplusplus
3946 }  /* extern "C" */
3947 
3948 /* Non-const methods in upb::SymbolTable are NOT thread-safe. */
3949 class upb::SymbolTable {
3950  public:
SymbolTable()3951   SymbolTable() : ptr_(upb_symtab_new(), upb_symtab_free) {}
SymbolTable(upb_symtab * s)3952   explicit SymbolTable(upb_symtab* s) : ptr_(s, upb_symtab_free) {}
3953 
ptr()3954   const upb_symtab* ptr() const { return ptr_.get(); }
ptr()3955   upb_symtab* ptr() { return ptr_.get(); }
3956 
3957   /* Finds an entry in the symbol table with this exact name.  If not found,
3958    * returns NULL. */
LookupMessage(const char * sym)3959   MessageDefPtr LookupMessage(const char *sym) const {
3960     return MessageDefPtr(upb_symtab_lookupmsg(ptr_.get(), sym));
3961   }
3962 
LookupEnum(const char * sym)3963   EnumDefPtr LookupEnum(const char *sym) const {
3964     return EnumDefPtr(upb_symtab_lookupenum(ptr_.get(), sym));
3965   }
3966 
LookupFile(const char * name)3967   FileDefPtr LookupFile(const char *name) const {
3968     return FileDefPtr(upb_symtab_lookupfile(ptr_.get(), name));
3969   }
3970 
3971   /* TODO: iteration? */
3972 
3973   /* Adds the given serialized FileDescriptorProto to the pool. */
AddFile(const google_protobuf_FileDescriptorProto * file_proto,Status * status)3974   FileDefPtr AddFile(const google_protobuf_FileDescriptorProto *file_proto,
3975                      Status *status) {
3976     return FileDefPtr(
3977         upb_symtab_addfile(ptr_.get(), file_proto, status->ptr()));
3978   }
3979 
3980  private:
3981   std::unique_ptr<upb_symtab, decltype(&upb_symtab_free)> ptr_;
3982 };
3983 
upb_safecstr(const std::string & str)3984 UPB_INLINE const char* upb_safecstr(const std::string& str) {
3985   UPB_ASSERT(str.size() == std::strlen(str.c_str()));
3986   return str.c_str();
3987 }
3988 
3989 #endif  /* __cplusplus */
3990 
3991 #endif /* UPB_DEF_H_ */
3992 /*
3993 ** upb::Handlers (upb_handlers)
3994 **
3995 ** A upb_handlers is like a virtual table for a upb_msgdef.  Each field of the
3996 ** message can have associated functions that will be called when we are
3997 ** parsing or visiting a stream of data.  This is similar to how handlers work
3998 ** in SAX (the Simple API for XML).
3999 **
4000 ** The handlers have no idea where the data is coming from, so a single set of
4001 ** handlers could be used with two completely different data sources (for
4002 ** example, a parser and a visitor over in-memory objects).  This decoupling is
4003 ** the most important feature of upb, because it allows parsers and serializers
4004 ** to be highly reusable.
4005 **
4006 ** This is a mixed C/C++ interface that offers a full API to both languages.
4007 ** See the top-level README for more information.
4008 */
4009 
4010 #ifndef UPB_HANDLERS_H
4011 #define UPB_HANDLERS_H
4012 
4013 
4014 #ifdef __cplusplus
4015 namespace upb {
4016 class HandlersPtr;
4017 class HandlerCache;
4018 template <class T> class Handler;
4019 template <class T> struct CanonicalType;
4020 }  /* namespace upb */
4021 #endif
4022 
4023 
4024 /* The maximum depth that the handler graph can have.  This is a resource limit
4025  * for the C stack since we sometimes need to recursively traverse the graph.
4026  * Cycles are ok; the traversal will stop when it detects a cycle, but we must
4027  * hit the cycle before the maximum depth is reached.
4028  *
4029  * If having a single static limit is too inflexible, we can add another variant
4030  * of Handlers::Freeze that allows specifying this as a parameter. */
4031 #define UPB_MAX_HANDLER_DEPTH 64
4032 
4033 /* All the different types of handlers that can be registered.
4034  * Only needed for the advanced functions in upb::Handlers. */
4035 typedef enum {
4036   UPB_HANDLER_INT32,
4037   UPB_HANDLER_INT64,
4038   UPB_HANDLER_UINT32,
4039   UPB_HANDLER_UINT64,
4040   UPB_HANDLER_FLOAT,
4041   UPB_HANDLER_DOUBLE,
4042   UPB_HANDLER_BOOL,
4043   UPB_HANDLER_STARTSTR,
4044   UPB_HANDLER_STRING,
4045   UPB_HANDLER_ENDSTR,
4046   UPB_HANDLER_STARTSUBMSG,
4047   UPB_HANDLER_ENDSUBMSG,
4048   UPB_HANDLER_STARTSEQ,
4049   UPB_HANDLER_ENDSEQ
4050 } upb_handlertype_t;
4051 
4052 #define UPB_HANDLER_MAX (UPB_HANDLER_ENDSEQ+1)
4053 
4054 #define UPB_BREAK NULL
4055 
4056 /* A convenient definition for when no closure is needed. */
4057 extern char _upb_noclosure;
4058 #define UPB_NO_CLOSURE &_upb_noclosure
4059 
4060 /* A selector refers to a specific field handler in the Handlers object
4061  * (for example: the STARTSUBMSG handler for field "field15"). */
4062 typedef int32_t upb_selector_t;
4063 
4064 /* Static selectors for upb::Handlers. */
4065 #define UPB_STARTMSG_SELECTOR 0
4066 #define UPB_ENDMSG_SELECTOR 1
4067 #define UPB_UNKNOWN_SELECTOR 2
4068 #define UPB_STATIC_SELECTOR_COUNT 3
4069 
4070 /* Static selectors for upb::BytesHandler. */
4071 #define UPB_STARTSTR_SELECTOR 0
4072 #define UPB_STRING_SELECTOR 1
4073 #define UPB_ENDSTR_SELECTOR 2
4074 
4075 #ifdef __cplusplus
UniquePtrForType()4076 template<class T> const void *UniquePtrForType() {
4077   static const char ch = 0;
4078   return &ch;
4079 }
4080 #endif
4081 
4082 /* upb_handlers ************************************************************/
4083 
4084 /* Handler attributes, to be registered with the handler itself. */
4085 typedef struct {
4086   const void *handler_data;
4087   const void *closure_type;
4088   const void *return_closure_type;
4089   bool alwaysok;
4090 } upb_handlerattr;
4091 
4092 #define UPB_HANDLERATTR_INIT {NULL, NULL, NULL, false}
4093 
4094 /* Bufhandle, data passed along with a buffer to indicate its provenance. */
4095 typedef struct {
4096   /* The beginning of the buffer.  This may be different than the pointer
4097    * passed to a StringBuf handler because the handler may receive data
4098    * that is from the middle or end of a larger buffer. */
4099   const char *buf;
4100 
4101   /* The offset within the attached object where this buffer begins.  Only
4102    * meaningful if there is an attached object. */
4103   size_t objofs;
4104 
4105   /* The attached object (if any) and a pointer representing its type. */
4106   const void *obj;
4107   const void *objtype;
4108 
4109 #ifdef __cplusplus
4110   template <class T>
SetAttachedObject__anon209dce3838084111   void SetAttachedObject(const T* _obj) {
4112     obj = _obj;
4113     objtype = UniquePtrForType<T>();
4114   }
4115 
4116   template <class T>
GetAttachedObject__anon209dce3838084117   const T *GetAttachedObject() const {
4118     return objtype == UniquePtrForType<T>() ? static_cast<const T *>(obj)
4119                                             : NULL;
4120   }
4121 #endif
4122 } upb_bufhandle;
4123 
4124 #define UPB_BUFHANDLE_INIT {NULL, 0, NULL, NULL}
4125 
4126 /* Handler function typedefs. */
4127 typedef void upb_handlerfree(void *d);
4128 typedef bool upb_unknown_handlerfunc(void *c, const void *hd, const char *buf,
4129                                      size_t n);
4130 typedef bool upb_startmsg_handlerfunc(void *c, const void*);
4131 typedef bool upb_endmsg_handlerfunc(void *c, const void *, upb_status *status);
4132 typedef void* upb_startfield_handlerfunc(void *c, const void *hd);
4133 typedef bool upb_endfield_handlerfunc(void *c, const void *hd);
4134 typedef bool upb_int32_handlerfunc(void *c, const void *hd, int32_t val);
4135 typedef bool upb_int64_handlerfunc(void *c, const void *hd, int64_t val);
4136 typedef bool upb_uint32_handlerfunc(void *c, const void *hd, uint32_t val);
4137 typedef bool upb_uint64_handlerfunc(void *c, const void *hd, uint64_t val);
4138 typedef bool upb_float_handlerfunc(void *c, const void *hd, float val);
4139 typedef bool upb_double_handlerfunc(void *c, const void *hd, double val);
4140 typedef bool upb_bool_handlerfunc(void *c, const void *hd, bool val);
4141 typedef void *upb_startstr_handlerfunc(void *c, const void *hd,
4142                                        size_t size_hint);
4143 typedef size_t upb_string_handlerfunc(void *c, const void *hd, const char *buf,
4144                                       size_t n, const upb_bufhandle* handle);
4145 
4146 struct upb_handlers;
4147 typedef struct upb_handlers upb_handlers;
4148 
4149 #ifdef __cplusplus
4150 extern "C" {
4151 #endif
4152 
4153 /* Mutating accessors. */
4154 const upb_status *upb_handlers_status(upb_handlers *h);
4155 void upb_handlers_clearerr(upb_handlers *h);
4156 const upb_msgdef *upb_handlers_msgdef(const upb_handlers *h);
4157 bool upb_handlers_addcleanup(upb_handlers *h, void *p, upb_handlerfree *hfree);
4158 bool upb_handlers_setunknown(upb_handlers *h, upb_unknown_handlerfunc *func,
4159                              const upb_handlerattr *attr);
4160 bool upb_handlers_setstartmsg(upb_handlers *h, upb_startmsg_handlerfunc *func,
4161                               const upb_handlerattr *attr);
4162 bool upb_handlers_setendmsg(upb_handlers *h, upb_endmsg_handlerfunc *func,
4163                             const upb_handlerattr *attr);
4164 bool upb_handlers_setint32(upb_handlers *h, const upb_fielddef *f,
4165                            upb_int32_handlerfunc *func,
4166                            const upb_handlerattr *attr);
4167 bool upb_handlers_setint64(upb_handlers *h, const upb_fielddef *f,
4168                            upb_int64_handlerfunc *func,
4169                            const upb_handlerattr *attr);
4170 bool upb_handlers_setuint32(upb_handlers *h, const upb_fielddef *f,
4171                             upb_uint32_handlerfunc *func,
4172                             const upb_handlerattr *attr);
4173 bool upb_handlers_setuint64(upb_handlers *h, const upb_fielddef *f,
4174                             upb_uint64_handlerfunc *func,
4175                             const upb_handlerattr *attr);
4176 bool upb_handlers_setfloat(upb_handlers *h, const upb_fielddef *f,
4177                            upb_float_handlerfunc *func,
4178                            const upb_handlerattr *attr);
4179 bool upb_handlers_setdouble(upb_handlers *h, const upb_fielddef *f,
4180                             upb_double_handlerfunc *func,
4181                             const upb_handlerattr *attr);
4182 bool upb_handlers_setbool(upb_handlers *h, const upb_fielddef *f,
4183                           upb_bool_handlerfunc *func,
4184                           const upb_handlerattr *attr);
4185 bool upb_handlers_setstartstr(upb_handlers *h, const upb_fielddef *f,
4186                               upb_startstr_handlerfunc *func,
4187                               const upb_handlerattr *attr);
4188 bool upb_handlers_setstring(upb_handlers *h, const upb_fielddef *f,
4189                             upb_string_handlerfunc *func,
4190                             const upb_handlerattr *attr);
4191 bool upb_handlers_setendstr(upb_handlers *h, const upb_fielddef *f,
4192                             upb_endfield_handlerfunc *func,
4193                             const upb_handlerattr *attr);
4194 bool upb_handlers_setstartseq(upb_handlers *h, const upb_fielddef *f,
4195                               upb_startfield_handlerfunc *func,
4196                               const upb_handlerattr *attr);
4197 bool upb_handlers_setstartsubmsg(upb_handlers *h, const upb_fielddef *f,
4198                                  upb_startfield_handlerfunc *func,
4199                                  const upb_handlerattr *attr);
4200 bool upb_handlers_setendsubmsg(upb_handlers *h, const upb_fielddef *f,
4201                                upb_endfield_handlerfunc *func,
4202                                const upb_handlerattr *attr);
4203 bool upb_handlers_setendseq(upb_handlers *h, const upb_fielddef *f,
4204                             upb_endfield_handlerfunc *func,
4205                             const upb_handlerattr *attr);
4206 
4207 /* Read-only accessors. */
4208 const upb_handlers *upb_handlers_getsubhandlers(const upb_handlers *h,
4209                                                 const upb_fielddef *f);
4210 const upb_handlers *upb_handlers_getsubhandlers_sel(const upb_handlers *h,
4211                                                     upb_selector_t sel);
4212 upb_func *upb_handlers_gethandler(const upb_handlers *h, upb_selector_t s,
4213                                   const void **handler_data);
4214 bool upb_handlers_getattr(const upb_handlers *h, upb_selector_t s,
4215                           upb_handlerattr *attr);
4216 
4217 /* "Static" methods */
4218 upb_handlertype_t upb_handlers_getprimitivehandlertype(const upb_fielddef *f);
4219 bool upb_handlers_getselector(const upb_fielddef *f, upb_handlertype_t type,
4220                               upb_selector_t *s);
upb_handlers_getendselector(upb_selector_t start)4221 UPB_INLINE upb_selector_t upb_handlers_getendselector(upb_selector_t start) {
4222   return start + 1;
4223 }
4224 
4225 /* Internal-only. */
4226 uint32_t upb_handlers_selectorbaseoffset(const upb_fielddef *f);
4227 uint32_t upb_handlers_selectorcount(const upb_fielddef *f);
4228 
4229 #ifdef __cplusplus
4230 }  /* extern "C" */
4231 
4232 namespace upb {
4233 typedef upb_handlers Handlers;
4234 }
4235 
4236 /* Convenience macros for creating a Handler object that is wrapped with a
4237  * type-safe wrapper function that converts the "void*" parameters/returns
4238  * of the underlying C API into nice C++ function.
4239  *
4240  * Sample usage:
4241  *   void OnValue1(MyClosure* c, const MyHandlerData* d, int32_t val) {
4242  *     // do stuff ...
4243  *   }
4244  *
4245  *   // Handler that doesn't need any data bound to it.
4246  *   void OnValue2(MyClosure* c, int32_t val) {
4247  *     // do stuff ...
4248  *   }
4249  *
4250  *   // Handler that returns bool so it can return failure if necessary.
4251  *   bool OnValue3(MyClosure* c, int32_t val) {
4252  *     // do stuff ...
4253  *     return ok;
4254  *   }
4255  *
4256  *   // Member function handler.
4257  *   class MyClosure {
4258  *    public:
4259  *     void OnValue(int32_t val) {
4260  *       // do stuff ...
4261  *     }
4262  *   };
4263  *
4264  *   // Takes ownership of the MyHandlerData.
4265  *   handlers->SetInt32Handler(f1, UpbBind(OnValue1, new MyHandlerData(...)));
4266  *   handlers->SetInt32Handler(f2, UpbMakeHandler(OnValue2));
4267  *   handlers->SetInt32Handler(f1, UpbMakeHandler(OnValue3));
4268  *   handlers->SetInt32Handler(f2, UpbMakeHandler(&MyClosure::OnValue));
4269  */
4270 
4271 /* In C++11, the "template" disambiguator can appear even outside templates,
4272  * so all calls can safely use this pair of macros. */
4273 
4274 #define UpbMakeHandler(f) upb::MatchFunc(f).template GetFunc<f>()
4275 
4276 /* We have to be careful to only evaluate "d" once. */
4277 #define UpbBind(f, d) upb::MatchFunc(f).template GetFunc<f>((d))
4278 
4279 /* Handler: a struct that contains the (handler, data, deleter) tuple that is
4280  * used to register all handlers.  Users can Make() these directly but it's
4281  * more convenient to use the UpbMakeHandler/UpbBind macros above. */
4282 template <class T> class upb::Handler {
4283  public:
4284   /* The underlying, handler function signature that upb uses internally. */
4285   typedef T FuncPtr;
4286 
4287   /* Intentionally implicit. */
4288   template <class F> Handler(F func);
~Handler()4289   ~Handler() { UPB_ASSERT(registered_); }
4290 
4291   void AddCleanup(upb_handlers* h) const;
handler()4292   FuncPtr handler() const { return handler_; }
attr()4293   const upb_handlerattr& attr() const { return attr_; }
4294 
4295  private:
4296   Handler(const Handler&) = delete;
4297   Handler& operator=(const Handler&) = delete;
4298 
4299   FuncPtr handler_;
4300   mutable upb_handlerattr attr_;
4301   mutable bool registered_;
4302   void *cleanup_data_;
4303   upb_handlerfree *cleanup_func_;
4304 };
4305 
4306 /* A upb::Handlers object represents the set of handlers associated with a
4307  * message in the graph of messages.  You can think of it as a big virtual
4308  * table with functions corresponding to all the events that can fire while
4309  * parsing or visiting a message of a specific type.
4310  *
4311  * Any handlers that are not set behave as if they had successfully consumed
4312  * the value.  Any unset Start* handlers will propagate their closure to the
4313  * inner frame.
4314  *
4315  * The easiest way to create the *Handler objects needed by the Set* methods is
4316  * with the UpbBind() and UpbMakeHandler() macros; see below. */
4317 class upb::HandlersPtr {
4318  public:
HandlersPtr(upb_handlers * ptr)4319   HandlersPtr(upb_handlers* ptr) : ptr_(ptr) {}
4320 
ptr()4321   upb_handlers* ptr() const { return ptr_; }
4322 
4323   typedef upb_selector_t Selector;
4324   typedef upb_handlertype_t Type;
4325 
4326   typedef Handler<void *(*)(void *, const void *)> StartFieldHandler;
4327   typedef Handler<bool (*)(void *, const void *)> EndFieldHandler;
4328   typedef Handler<bool (*)(void *, const void *)> StartMessageHandler;
4329   typedef Handler<bool (*)(void *, const void *, upb_status *)>
4330       EndMessageHandler;
4331   typedef Handler<void *(*)(void *, const void *, size_t)> StartStringHandler;
4332   typedef Handler<size_t (*)(void *, const void *, const char *, size_t,
4333                              const upb_bufhandle *)>
4334       StringHandler;
4335 
4336   template <class T> struct ValueHandler {
4337     typedef Handler<bool(*)(void *, const void *, T)> H;
4338   };
4339 
4340   typedef ValueHandler<int32_t>::H     Int32Handler;
4341   typedef ValueHandler<int64_t>::H     Int64Handler;
4342   typedef ValueHandler<uint32_t>::H    UInt32Handler;
4343   typedef ValueHandler<uint64_t>::H    UInt64Handler;
4344   typedef ValueHandler<float>::H       FloatHandler;
4345   typedef ValueHandler<double>::H      DoubleHandler;
4346   typedef ValueHandler<bool>::H        BoolHandler;
4347 
4348   /* Any function pointer can be converted to this and converted back to its
4349    * correct type. */
4350   typedef void GenericFunction();
4351 
4352   typedef void HandlersCallback(const void *closure, upb_handlers *h);
4353 
4354   /* Returns the msgdef associated with this handlers object. */
message_def()4355   MessageDefPtr message_def() const {
4356     return MessageDefPtr(upb_handlers_msgdef(ptr()));
4357   }
4358 
4359   /* Adds the given pointer and function to the list of cleanup functions that
4360    * will be run when these handlers are freed.  If this pointer has previously
4361    * been registered, the function returns false and does nothing. */
AddCleanup(void * ptr,upb_handlerfree * cleanup)4362   bool AddCleanup(void *ptr, upb_handlerfree *cleanup) {
4363     return upb_handlers_addcleanup(ptr_, ptr, cleanup);
4364   }
4365 
4366   /* Sets the startmsg handler for the message, which is defined as follows:
4367    *
4368    *   bool startmsg(MyType* closure) {
4369    *     // Called when the message begins.  Returns true if processing should
4370    *     // continue.
4371    *     return true;
4372    *   }
4373    */
SetStartMessageHandler(const StartMessageHandler & h)4374   bool SetStartMessageHandler(const StartMessageHandler &h) {
4375     h.AddCleanup(ptr());
4376     return upb_handlers_setstartmsg(ptr(), h.handler(), &h.attr());
4377   }
4378 
4379   /* Sets the endmsg handler for the message, which is defined as follows:
4380    *
4381    *   bool endmsg(MyType* closure, upb_status *status) {
4382    *     // Called when processing of this message ends, whether in success or
4383    *     // failure.  "status" indicates the final status of processing, and
4384    *     // can also be modified in-place to update the final status.
4385    *   }
4386    */
SetEndMessageHandler(const EndMessageHandler & h)4387   bool SetEndMessageHandler(const EndMessageHandler& h) {
4388     h.AddCleanup(ptr());
4389     return upb_handlers_setendmsg(ptr(), h.handler(), &h.attr());
4390   }
4391 
4392   /* Sets the value handler for the given field, which is defined as follows
4393    * (this is for an int32 field; other field types will pass their native
4394    * C/C++ type for "val"):
4395    *
4396    *   bool OnValue(MyClosure* c, const MyHandlerData* d, int32_t val) {
4397    *     // Called when the field's value is encountered.  "d" contains
4398    *     // whatever data was bound to this field when it was registered.
4399    *     // Returns true if processing should continue.
4400    *     return true;
4401    *   }
4402    *
4403    *   handers->SetInt32Handler(f, UpbBind(OnValue, new MyHandlerData(...)));
4404    *
4405    * The value type must exactly match f->type().
4406    * For example, a handler that takes an int32_t parameter may only be used for
4407    * fields of type UPB_TYPE_INT32 and UPB_TYPE_ENUM.
4408    *
4409    * Returns false if the handler failed to register; in this case the cleanup
4410    * handler (if any) will be called immediately.
4411    */
SetInt32Handler(FieldDefPtr f,const Int32Handler & h)4412   bool SetInt32Handler(FieldDefPtr f, const Int32Handler &h) {
4413     h.AddCleanup(ptr());
4414     return upb_handlers_setint32(ptr(), f.ptr(), h.handler(), &h.attr());
4415   }
4416 
SetInt64Handler(FieldDefPtr f,const Int64Handler & h)4417   bool SetInt64Handler (FieldDefPtr f,  const Int64Handler& h) {
4418     h.AddCleanup(ptr());
4419     return upb_handlers_setint64(ptr(), f.ptr(), h.handler(), &h.attr());
4420   }
4421 
SetUInt32Handler(FieldDefPtr f,const UInt32Handler & h)4422   bool SetUInt32Handler(FieldDefPtr f, const UInt32Handler& h) {
4423     h.AddCleanup(ptr());
4424     return upb_handlers_setuint32(ptr(), f.ptr(), h.handler(), &h.attr());
4425   }
4426 
SetUInt64Handler(FieldDefPtr f,const UInt64Handler & h)4427   bool SetUInt64Handler(FieldDefPtr f, const UInt64Handler& h) {
4428     h.AddCleanup(ptr());
4429     return upb_handlers_setuint64(ptr(), f.ptr(), h.handler(), &h.attr());
4430   }
4431 
SetFloatHandler(FieldDefPtr f,const FloatHandler & h)4432   bool SetFloatHandler (FieldDefPtr f,  const FloatHandler& h) {
4433     h.AddCleanup(ptr());
4434     return upb_handlers_setfloat(ptr(), f.ptr(), h.handler(), &h.attr());
4435   }
4436 
SetDoubleHandler(FieldDefPtr f,const DoubleHandler & h)4437   bool SetDoubleHandler(FieldDefPtr f, const DoubleHandler& h) {
4438     h.AddCleanup(ptr());
4439     return upb_handlers_setdouble(ptr(), f.ptr(), h.handler(), &h.attr());
4440   }
4441 
SetBoolHandler(FieldDefPtr f,const BoolHandler & h)4442   bool SetBoolHandler(FieldDefPtr f, const BoolHandler &h) {
4443     h.AddCleanup(ptr());
4444     return upb_handlers_setbool(ptr(), f.ptr(), h.handler(), &h.attr());
4445   }
4446 
4447   /* Like the previous, but templated on the type on the value (ie. int32).
4448    * This is mostly useful to call from other templates.  To call this you must
4449    * specify the template parameter explicitly, ie:
4450    *   h->SetValueHandler<T>(f, UpbBind(MyHandler<T>, MyData)); */
4451   template <class T>
4452   bool SetValueHandler(
4453       FieldDefPtr f,
4454       const typename ValueHandler<typename CanonicalType<T>::Type>::H &handler);
4455 
4456   /* Sets handlers for a string field, which are defined as follows:
4457    *
4458    *   MySubClosure* startstr(MyClosure* c, const MyHandlerData* d,
4459    *                          size_t size_hint) {
4460    *     // Called when a string value begins.  The return value indicates the
4461    *     // closure for the string.  "size_hint" indicates the size of the
4462    *     // string if it is known, however if the string is length-delimited
4463    *     // and the end-of-string is not available size_hint will be zero.
4464    *     // This case is indistinguishable from the case where the size is
4465    *     // known to be zero.
4466    *     //
4467    *     // TODO(haberman): is it important to distinguish these cases?
4468    *     // If we had ssize_t as a type we could make -1 "unknown", but
4469    *     // ssize_t is POSIX (not ANSI) and therefore less portable.
4470    *     // In practice I suspect it won't be important to distinguish.
4471    *     return closure;
4472    *   }
4473    *
4474    *   size_t str(MyClosure* closure, const MyHandlerData* d,
4475    *              const char *str, size_t len) {
4476    *     // Called for each buffer of string data; the multiple physical buffers
4477    *     // are all part of the same logical string.  The return value indicates
4478    *     // how many bytes were consumed.  If this number is less than "len",
4479    *     // this will also indicate that processing should be halted for now,
4480    *     // like returning false or UPB_BREAK from any other callback.  If
4481    *     // number is greater than "len", the excess bytes will be skipped over
4482    *     // and not passed to the callback.
4483    *     return len;
4484    *   }
4485    *
4486    *   bool endstr(MyClosure* c, const MyHandlerData* d) {
4487    *     // Called when a string value ends.  Return value indicates whether
4488    *     // processing should continue.
4489    *     return true;
4490    *   }
4491    */
SetStartStringHandler(FieldDefPtr f,const StartStringHandler & h)4492   bool SetStartStringHandler(FieldDefPtr f, const StartStringHandler &h) {
4493     h.AddCleanup(ptr());
4494     return upb_handlers_setstartstr(ptr(), f.ptr(), h.handler(), &h.attr());
4495   }
4496 
SetStringHandler(FieldDefPtr f,const StringHandler & h)4497   bool SetStringHandler(FieldDefPtr f, const StringHandler& h) {
4498     h.AddCleanup(ptr());
4499     return upb_handlers_setstring(ptr(), f.ptr(), h.handler(), &h.attr());
4500   }
4501 
SetEndStringHandler(FieldDefPtr f,const EndFieldHandler & h)4502   bool SetEndStringHandler(FieldDefPtr f, const EndFieldHandler& h) {
4503     h.AddCleanup(ptr());
4504     return upb_handlers_setendstr(ptr(), f.ptr(), h.handler(), &h.attr());
4505   }
4506 
4507   /* Sets the startseq handler, which is defined as follows:
4508    *
4509    *   MySubClosure *startseq(MyClosure* c, const MyHandlerData* d) {
4510    *     // Called when a sequence (repeated field) begins.  The returned
4511    *     // pointer indicates the closure for the sequence (or UPB_BREAK
4512    *     // to interrupt processing).
4513    *     return closure;
4514    *   }
4515    *
4516    *   h->SetStartSequenceHandler(f, UpbBind(startseq, new MyHandlerData(...)));
4517    *
4518    * Returns "false" if "f" does not belong to this message or is not a
4519    * repeated field.
4520    */
SetStartSequenceHandler(FieldDefPtr f,const StartFieldHandler & h)4521   bool SetStartSequenceHandler(FieldDefPtr f, const StartFieldHandler &h) {
4522     h.AddCleanup(ptr());
4523     return upb_handlers_setstartseq(ptr(), f.ptr(), h.handler(), &h.attr());
4524   }
4525 
4526   /* Sets the startsubmsg handler for the given field, which is defined as
4527    * follows:
4528    *
4529    *   MySubClosure* startsubmsg(MyClosure* c, const MyHandlerData* d) {
4530    *     // Called when a submessage begins.  The returned pointer indicates the
4531    *     // closure for the sequence (or UPB_BREAK to interrupt processing).
4532    *     return closure;
4533    *   }
4534    *
4535    *   h->SetStartSubMessageHandler(f, UpbBind(startsubmsg,
4536    *                                           new MyHandlerData(...)));
4537    *
4538    * Returns "false" if "f" does not belong to this message or is not a
4539    * submessage/group field.
4540    */
SetStartSubMessageHandler(FieldDefPtr f,const StartFieldHandler & h)4541   bool SetStartSubMessageHandler(FieldDefPtr f, const StartFieldHandler& h) {
4542     h.AddCleanup(ptr());
4543     return upb_handlers_setstartsubmsg(ptr(), f.ptr(), h.handler(), &h.attr());
4544   }
4545 
4546   /* Sets the endsubmsg handler for the given field, which is defined as
4547    * follows:
4548    *
4549    *   bool endsubmsg(MyClosure* c, const MyHandlerData* d) {
4550    *     // Called when a submessage ends.  Returns true to continue processing.
4551    *     return true;
4552    *   }
4553    *
4554    * Returns "false" if "f" does not belong to this message or is not a
4555    * submessage/group field.
4556    */
SetEndSubMessageHandler(FieldDefPtr f,const EndFieldHandler & h)4557   bool SetEndSubMessageHandler(FieldDefPtr f, const EndFieldHandler &h) {
4558     h.AddCleanup(ptr());
4559     return upb_handlers_setendsubmsg(ptr(), f.ptr(), h.handler(), &h.attr());
4560   }
4561 
4562   /* Starts the endsubseq handler for the given field, which is defined as
4563    * follows:
4564    *
4565    *   bool endseq(MyClosure* c, const MyHandlerData* d) {
4566    *     // Called when a sequence ends.  Returns true continue processing.
4567    *     return true;
4568    *   }
4569    *
4570    * Returns "false" if "f" does not belong to this message or is not a
4571    * repeated field.
4572    */
SetEndSequenceHandler(FieldDefPtr f,const EndFieldHandler & h)4573   bool SetEndSequenceHandler(FieldDefPtr f, const EndFieldHandler &h) {
4574     h.AddCleanup(ptr());
4575     return upb_handlers_setendseq(ptr(), f.ptr(), h.handler(), &h.attr());
4576   }
4577 
4578  private:
4579   upb_handlers* ptr_;
4580 };
4581 
4582 #endif  /* __cplusplus */
4583 
4584 /* upb_handlercache ***********************************************************/
4585 
4586 /* A upb_handlercache lazily builds and caches upb_handlers.  You pass it a
4587  * function (with optional closure) that can build handlers for a given
4588  * message on-demand, and the cache maintains a map of msgdef->handlers. */
4589 
4590 #ifdef __cplusplus
4591 extern "C" {
4592 #endif
4593 
4594 struct upb_handlercache;
4595 typedef struct upb_handlercache upb_handlercache;
4596 
4597 typedef void upb_handlers_callback(const void *closure, upb_handlers *h);
4598 
4599 upb_handlercache *upb_handlercache_new(upb_handlers_callback *callback,
4600                                        const void *closure);
4601 void upb_handlercache_free(upb_handlercache *cache);
4602 const upb_handlers *upb_handlercache_get(upb_handlercache *cache,
4603                                          const upb_msgdef *md);
4604 bool upb_handlercache_addcleanup(upb_handlercache *h, void *p,
4605                                  upb_handlerfree *hfree);
4606 
4607 #ifdef __cplusplus
4608 }  /* extern "C" */
4609 
4610 class upb::HandlerCache {
4611  public:
HandlerCache(upb_handlers_callback * callback,const void * closure)4612   HandlerCache(upb_handlers_callback *callback, const void *closure)
4613       : ptr_(upb_handlercache_new(callback, closure), upb_handlercache_free) {}
4614   HandlerCache(HandlerCache&&) = default;
4615   HandlerCache& operator=(HandlerCache&&) = default;
HandlerCache(upb_handlercache * c)4616   HandlerCache(upb_handlercache* c) : ptr_(c, upb_handlercache_free) {}
4617 
ptr()4618   upb_handlercache* ptr() { return ptr_.get(); }
4619 
Get(MessageDefPtr md)4620   const upb_handlers *Get(MessageDefPtr md) {
4621     return upb_handlercache_get(ptr_.get(), md.ptr());
4622   }
4623 
4624  private:
4625   std::unique_ptr<upb_handlercache, decltype(&upb_handlercache_free)> ptr_;
4626 };
4627 
4628 #endif  /* __cplusplus */
4629 
4630 /* upb_byteshandler ***********************************************************/
4631 
4632 typedef struct {
4633   upb_func *func;
4634 
4635   /* It is wasteful to include the entire attributes here:
4636    *
4637    * * Some of the information is redundant (like storing the closure type
4638    *   separately for each handler that must match).
4639    * * Some of the info is only needed prior to freeze() (like closure types).
4640    * * alignment padding wastes a lot of space for alwaysok_.
4641    *
4642    * If/when the size and locality of handlers is an issue, we can optimize this
4643    * not to store the entire attr like this.  We do not expose the table's
4644    * layout to allow this optimization in the future. */
4645   upb_handlerattr attr;
4646 } upb_handlers_tabent;
4647 
4648 #define UPB_TABENT_INIT {NULL, UPB_HANDLERATTR_INIT}
4649 
4650 typedef struct {
4651   upb_handlers_tabent table[3];
4652 } upb_byteshandler;
4653 
4654 #define UPB_BYTESHANDLER_INIT                             \
4655   {                                                       \
4656     { UPB_TABENT_INIT, UPB_TABENT_INIT, UPB_TABENT_INIT } \
4657   }
4658 
upb_byteshandler_init(upb_byteshandler * handler)4659 UPB_INLINE void upb_byteshandler_init(upb_byteshandler *handler) {
4660   upb_byteshandler init = UPB_BYTESHANDLER_INIT;
4661   *handler = init;
4662 }
4663 
4664 #ifdef __cplusplus
4665 extern "C" {
4666 #endif
4667 
4668 /* Caller must ensure that "d" outlives the handlers. */
4669 bool upb_byteshandler_setstartstr(upb_byteshandler *h,
4670                                   upb_startstr_handlerfunc *func, void *d);
4671 bool upb_byteshandler_setstring(upb_byteshandler *h,
4672                                 upb_string_handlerfunc *func, void *d);
4673 bool upb_byteshandler_setendstr(upb_byteshandler *h,
4674                                 upb_endfield_handlerfunc *func, void *d);
4675 
4676 #ifdef __cplusplus
4677 }  /* extern "C" */
4678 
4679 namespace upb {
4680 typedef upb_byteshandler BytesHandler;
4681 }
4682 #endif
4683 
4684 /** Message handlers ******************************************************************/
4685 
4686 #ifdef __cplusplus
4687 extern "C" {
4688 #endif
4689 
4690 /* These are the handlers used internally by upb_msgfactory_getmergehandlers().
4691  * They write scalar data to a known offset from the message pointer.
4692  *
4693  * These would be trivial for anyone to implement themselves, but it's better
4694  * to use these because some JITs will recognize and specialize these instead
4695  * of actually calling the function. */
4696 
4697 /* Sets a handler for the given primitive field that will write the data at the
4698  * given offset.  If hasbit > 0, also sets a hasbit at the given bit offset
4699  * (addressing each byte low to high). */
4700 bool upb_msg_setscalarhandler(upb_handlers *h,
4701                               const upb_fielddef *f,
4702                               size_t offset,
4703                               int32_t hasbit);
4704 
4705 /* If the given handler is a msghandlers_primitive field, returns true and sets
4706  * *type, *offset and *hasbit.  Otherwise returns false. */
4707 bool upb_msg_getscalarhandlerdata(const upb_handlers *h,
4708                                   upb_selector_t s,
4709                                   upb_fieldtype_t *type,
4710                                   size_t *offset,
4711                                   int32_t *hasbit);
4712 
4713 
4714 
4715 #ifdef __cplusplus
4716 }  /* extern "C" */
4717 #endif
4718 
4719 /*
4720 ** Inline definitions for handlers.h, which are particularly long and a bit
4721 ** tricky.
4722 */
4723 
4724 #ifndef UPB_HANDLERS_INL_H_
4725 #define UPB_HANDLERS_INL_H_
4726 
4727 #include <limits.h>
4728 #include <stddef.h>
4729 
4730 #ifdef __cplusplus
4731 
4732 /* Type detection and typedefs for integer types.
4733  * For platforms where there are multiple 32-bit or 64-bit types, we need to be
4734  * able to enumerate them so we can properly create overloads for all variants.
4735  *
4736  * If any platform existed where there were three integer types with the same
4737  * size, this would have to become more complicated.  For example, short, int,
4738  * and long could all be 32-bits.  Even more diabolically, short, int, long,
4739  * and long long could all be 64 bits and still be standard-compliant.
4740  * However, few platforms are this strange, and it's unlikely that upb will be
4741  * used on the strangest ones. */
4742 
4743 /* Can't count on stdint.h limits like INT32_MAX, because in C++ these are
4744  * only defined when __STDC_LIMIT_MACROS are defined before the *first* include
4745  * of stdint.h.  We can't guarantee that someone else didn't include these first
4746  * without defining __STDC_LIMIT_MACROS. */
4747 #define UPB_INT32_MAX 0x7fffffffLL
4748 #define UPB_INT32_MIN (-UPB_INT32_MAX - 1)
4749 #define UPB_INT64_MAX 0x7fffffffffffffffLL
4750 #define UPB_INT64_MIN (-UPB_INT64_MAX - 1)
4751 
4752 #if INT_MAX == UPB_INT32_MAX && INT_MIN == UPB_INT32_MIN
4753 #define UPB_INT_IS_32BITS 1
4754 #endif
4755 
4756 #if LONG_MAX == UPB_INT32_MAX && LONG_MIN == UPB_INT32_MIN
4757 #define UPB_LONG_IS_32BITS 1
4758 #endif
4759 
4760 #if LONG_MAX == UPB_INT64_MAX && LONG_MIN == UPB_INT64_MIN
4761 #define UPB_LONG_IS_64BITS 1
4762 #endif
4763 
4764 #if LLONG_MAX == UPB_INT64_MAX && LLONG_MIN == UPB_INT64_MIN
4765 #define UPB_LLONG_IS_64BITS 1
4766 #endif
4767 
4768 /* We use macros instead of typedefs so we can undefine them later and avoid
4769  * leaking them outside this header file. */
4770 #if UPB_INT_IS_32BITS
4771 #define UPB_INT32_T int
4772 #define UPB_UINT32_T unsigned int
4773 
4774 #if UPB_LONG_IS_32BITS
4775 #define UPB_TWO_32BIT_TYPES 1
4776 #define UPB_INT32ALT_T long
4777 #define UPB_UINT32ALT_T unsigned long
4778 #endif  /* UPB_LONG_IS_32BITS */
4779 
4780 #elif UPB_LONG_IS_32BITS  /* && !UPB_INT_IS_32BITS */
4781 #define UPB_INT32_T long
4782 #define UPB_UINT32_T unsigned long
4783 #endif  /* UPB_INT_IS_32BITS */
4784 
4785 
4786 #if UPB_LONG_IS_64BITS
4787 #define UPB_INT64_T long
4788 #define UPB_UINT64_T unsigned long
4789 
4790 #if UPB_LLONG_IS_64BITS
4791 #define UPB_TWO_64BIT_TYPES 1
4792 #define UPB_INT64ALT_T long long
4793 #define UPB_UINT64ALT_T unsigned long long
4794 #endif  /* UPB_LLONG_IS_64BITS */
4795 
4796 #elif UPB_LLONG_IS_64BITS  /* && !UPB_LONG_IS_64BITS */
4797 #define UPB_INT64_T long long
4798 #define UPB_UINT64_T unsigned long long
4799 #endif  /* UPB_LONG_IS_64BITS */
4800 
4801 #undef UPB_INT32_MAX
4802 #undef UPB_INT32_MIN
4803 #undef UPB_INT64_MAX
4804 #undef UPB_INT64_MIN
4805 #undef UPB_INT_IS_32BITS
4806 #undef UPB_LONG_IS_32BITS
4807 #undef UPB_LONG_IS_64BITS
4808 #undef UPB_LLONG_IS_64BITS
4809 
4810 
4811 namespace upb {
4812 
4813 typedef void CleanupFunc(void *ptr);
4814 
4815 /* Template to remove "const" from "const T*" and just return "T*".
4816  *
4817  * We define a nonsense default because otherwise it will fail to instantiate as
4818  * a function parameter type even in cases where we don't expect any caller to
4819  * actually match the overload. */
4820 class CouldntRemoveConst {};
4821 template <class T> struct remove_constptr { typedef CouldntRemoveConst type; };
4822 template <class T> struct remove_constptr<const T *> { typedef T *type; };
4823 
4824 /* Template that we use below to remove a template specialization from
4825  * consideration if it matches a specific type. */
4826 template <class T, class U> struct disable_if_same { typedef void Type; };
4827 template <class T> struct disable_if_same<T, T> {};
4828 
4829 template <class T> void DeletePointer(void *p) { delete static_cast<T>(p); }
4830 
4831 template <class T1, class T2>
4832 struct FirstUnlessVoidOrBool {
4833   typedef T1 value;
4834 };
4835 
4836 template <class T2>
4837 struct FirstUnlessVoidOrBool<void, T2> {
4838   typedef T2 value;
4839 };
4840 
4841 template <class T2>
4842 struct FirstUnlessVoidOrBool<bool, T2> {
4843   typedef T2 value;
4844 };
4845 
4846 template<class T, class U>
4847 struct is_same {
4848   static bool value;
4849 };
4850 
4851 template<class T>
4852 struct is_same<T, T> {
4853   static bool value;
4854 };
4855 
4856 template<class T, class U>
4857 bool is_same<T, U>::value = false;
4858 
4859 template<class T>
4860 bool is_same<T, T>::value = true;
4861 
4862 /* FuncInfo *******************************************************************/
4863 
4864 /* Info about the user's original, pre-wrapped function. */
4865 template <class C, class R = void>
4866 struct FuncInfo {
4867   /* The type of the closure that the function takes (its first param). */
4868   typedef C Closure;
4869 
4870   /* The return type. */
4871   typedef R Return;
4872 };
4873 
4874 /* Func ***********************************************************************/
4875 
4876 /* Func1, Func2, Func3: Template classes representing a function and its
4877  * signature.
4878  *
4879  * Since the function is a template parameter, calling the function can be
4880  * inlined at compile-time and does not require a function pointer at runtime.
4881  * These functions are not bound to a handler data so have no data or cleanup
4882  * handler. */
4883 struct UnboundFunc {
4884   CleanupFunc *GetCleanup() { return nullptr; }
4885   void *GetData() { return nullptr; }
4886 };
4887 
4888 template <class R, class P1, R F(P1), class I>
4889 struct Func1 : public UnboundFunc {
4890   typedef R Return;
4891   typedef I FuncInfo;
4892   static R Call(P1 p1) { return F(p1); }
4893 };
4894 
4895 template <class R, class P1, class P2, R F(P1, P2), class I>
4896 struct Func2 : public UnboundFunc {
4897   typedef R Return;
4898   typedef I FuncInfo;
4899   static R Call(P1 p1, P2 p2) { return F(p1, p2); }
4900 };
4901 
4902 template <class R, class P1, class P2, class P3, R F(P1, P2, P3), class I>
4903 struct Func3 : public UnboundFunc {
4904   typedef R Return;
4905   typedef I FuncInfo;
4906   static R Call(P1 p1, P2 p2, P3 p3) { return F(p1, p2, p3); }
4907 };
4908 
4909 template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4),
4910           class I>
4911 struct Func4 : public UnboundFunc {
4912   typedef R Return;
4913   typedef I FuncInfo;
4914   static R Call(P1 p1, P2 p2, P3 p3, P4 p4) { return F(p1, p2, p3, p4); }
4915 };
4916 
4917 template <class R, class P1, class P2, class P3, class P4, class P5,
4918           R F(P1, P2, P3, P4, P5), class I>
4919 struct Func5 : public UnboundFunc {
4920   typedef R Return;
4921   typedef I FuncInfo;
4922   static R Call(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) {
4923     return F(p1, p2, p3, p4, p5);
4924   }
4925 };
4926 
4927 /* BoundFunc ******************************************************************/
4928 
4929 /* BoundFunc2, BoundFunc3: Like Func2/Func3 except also contains a value that
4930  * shall be bound to the function's second parameter.
4931  *
4932  * Note that the second parameter is a const pointer, but our stored bound value
4933  * is non-const so we can free it when the handlers are destroyed. */
4934 template <class T>
4935 struct BoundFunc {
4936   typedef typename remove_constptr<T>::type MutableP2;
4937   explicit BoundFunc(MutableP2 data_) : data(data_) {}
4938   CleanupFunc *GetCleanup() { return &DeletePointer<MutableP2>; }
4939   MutableP2 GetData() { return data; }
4940   MutableP2 data;
4941 };
4942 
4943 template <class R, class P1, class P2, R F(P1, P2), class I>
4944 struct BoundFunc2 : public BoundFunc<P2> {
4945   typedef BoundFunc<P2> Base;
4946   typedef I FuncInfo;
4947   explicit BoundFunc2(typename Base::MutableP2 arg) : Base(arg) {}
4948 };
4949 
4950 template <class R, class P1, class P2, class P3, R F(P1, P2, P3), class I>
4951 struct BoundFunc3 : public BoundFunc<P2> {
4952   typedef BoundFunc<P2> Base;
4953   typedef I FuncInfo;
4954   explicit BoundFunc3(typename Base::MutableP2 arg) : Base(arg) {}
4955 };
4956 
4957 template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4),
4958           class I>
4959 struct BoundFunc4 : public BoundFunc<P2> {
4960   typedef BoundFunc<P2> Base;
4961   typedef I FuncInfo;
4962   explicit BoundFunc4(typename Base::MutableP2 arg) : Base(arg) {}
4963 };
4964 
4965 template <class R, class P1, class P2, class P3, class P4, class P5,
4966           R F(P1, P2, P3, P4, P5), class I>
4967 struct BoundFunc5 : public BoundFunc<P2> {
4968   typedef BoundFunc<P2> Base;
4969   typedef I FuncInfo;
4970   explicit BoundFunc5(typename Base::MutableP2 arg) : Base(arg) {}
4971 };
4972 
4973 /* FuncSig ********************************************************************/
4974 
4975 /* FuncSig1, FuncSig2, FuncSig3: template classes reflecting a function
4976  * *signature*, but without a specific function attached.
4977  *
4978  * These classes contain member functions that can be invoked with a
4979  * specific function to return a Func/BoundFunc class. */
4980 template <class R, class P1>
4981 struct FuncSig1 {
4982   template <R F(P1)>
4983   Func1<R, P1, F, FuncInfo<P1, R> > GetFunc() {
4984     return Func1<R, P1, F, FuncInfo<P1, R> >();
4985   }
4986 };
4987 
4988 template <class R, class P1, class P2>
4989 struct FuncSig2 {
4990   template <R F(P1, P2)>
4991   Func2<R, P1, P2, F, FuncInfo<P1, R> > GetFunc() {
4992     return Func2<R, P1, P2, F, FuncInfo<P1, R> >();
4993   }
4994 
4995   template <R F(P1, P2)>
4996   BoundFunc2<R, P1, P2, F, FuncInfo<P1, R> > GetFunc(
4997       typename remove_constptr<P2>::type param2) {
4998     return BoundFunc2<R, P1, P2, F, FuncInfo<P1, R> >(param2);
4999   }
5000 };
5001 
5002 template <class R, class P1, class P2, class P3>
5003 struct FuncSig3 {
5004   template <R F(P1, P2, P3)>
5005   Func3<R, P1, P2, P3, F, FuncInfo<P1, R> > GetFunc() {
5006     return Func3<R, P1, P2, P3, F, FuncInfo<P1, R> >();
5007   }
5008 
5009   template <R F(P1, P2, P3)>
5010   BoundFunc3<R, P1, P2, P3, F, FuncInfo<P1, R> > GetFunc(
5011       typename remove_constptr<P2>::type param2) {
5012     return BoundFunc3<R, P1, P2, P3, F, FuncInfo<P1, R> >(param2);
5013   }
5014 };
5015 
5016 template <class R, class P1, class P2, class P3, class P4>
5017 struct FuncSig4 {
5018   template <R F(P1, P2, P3, P4)>
5019   Func4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> > GetFunc() {
5020     return Func4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> >();
5021   }
5022 
5023   template <R F(P1, P2, P3, P4)>
5024   BoundFunc4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> > GetFunc(
5025       typename remove_constptr<P2>::type param2) {
5026     return BoundFunc4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> >(param2);
5027   }
5028 };
5029 
5030 template <class R, class P1, class P2, class P3, class P4, class P5>
5031 struct FuncSig5 {
5032   template <R F(P1, P2, P3, P4, P5)>
5033   Func5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> > GetFunc() {
5034     return Func5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> >();
5035   }
5036 
5037   template <R F(P1, P2, P3, P4, P5)>
5038   BoundFunc5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> > GetFunc(
5039       typename remove_constptr<P2>::type param2) {
5040     return BoundFunc5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> >(param2);
5041   }
5042 };
5043 
5044 /* Overloaded template function that can construct the appropriate FuncSig*
5045  * class given a function pointer by deducing the template parameters. */
5046 template <class R, class P1>
5047 inline FuncSig1<R, P1> MatchFunc(R (*f)(P1)) {
5048   UPB_UNUSED(f);  /* Only used for template parameter deduction. */
5049   return FuncSig1<R, P1>();
5050 }
5051 
5052 template <class R, class P1, class P2>
5053 inline FuncSig2<R, P1, P2> MatchFunc(R (*f)(P1, P2)) {
5054   UPB_UNUSED(f);  /* Only used for template parameter deduction. */
5055   return FuncSig2<R, P1, P2>();
5056 }
5057 
5058 template <class R, class P1, class P2, class P3>
5059 inline FuncSig3<R, P1, P2, P3> MatchFunc(R (*f)(P1, P2, P3)) {
5060   UPB_UNUSED(f);  /* Only used for template parameter deduction. */
5061   return FuncSig3<R, P1, P2, P3>();
5062 }
5063 
5064 template <class R, class P1, class P2, class P3, class P4>
5065 inline FuncSig4<R, P1, P2, P3, P4> MatchFunc(R (*f)(P1, P2, P3, P4)) {
5066   UPB_UNUSED(f);  /* Only used for template parameter deduction. */
5067   return FuncSig4<R, P1, P2, P3, P4>();
5068 }
5069 
5070 template <class R, class P1, class P2, class P3, class P4, class P5>
5071 inline FuncSig5<R, P1, P2, P3, P4, P5> MatchFunc(R (*f)(P1, P2, P3, P4, P5)) {
5072   UPB_UNUSED(f);  /* Only used for template parameter deduction. */
5073   return FuncSig5<R, P1, P2, P3, P4, P5>();
5074 }
5075 
5076 /* MethodSig ******************************************************************/
5077 
5078 /* CallMethod*: a function template that calls a given method. */
5079 template <class R, class C, R (C::*F)()>
5080 R CallMethod0(C *obj) {
5081   return ((*obj).*F)();
5082 }
5083 
5084 template <class R, class C, class P1, R (C::*F)(P1)>
5085 R CallMethod1(C *obj, P1 arg1) {
5086   return ((*obj).*F)(arg1);
5087 }
5088 
5089 template <class R, class C, class P1, class P2, R (C::*F)(P1, P2)>
5090 R CallMethod2(C *obj, P1 arg1, P2 arg2) {
5091   return ((*obj).*F)(arg1, arg2);
5092 }
5093 
5094 template <class R, class C, class P1, class P2, class P3, R (C::*F)(P1, P2, P3)>
5095 R CallMethod3(C *obj, P1 arg1, P2 arg2, P3 arg3) {
5096   return ((*obj).*F)(arg1, arg2, arg3);
5097 }
5098 
5099 template <class R, class C, class P1, class P2, class P3, class P4,
5100           R (C::*F)(P1, P2, P3, P4)>
5101 R CallMethod4(C *obj, P1 arg1, P2 arg2, P3 arg3, P4 arg4) {
5102   return ((*obj).*F)(arg1, arg2, arg3, arg4);
5103 }
5104 
5105 /* MethodSig: like FuncSig, but for member functions.
5106  *
5107  * GetFunc() returns a normal FuncN object, so after calling GetFunc() no
5108  * more logic is required to special-case methods. */
5109 template <class R, class C>
5110 struct MethodSig0 {
5111   template <R (C::*F)()>
5112   Func1<R, C *, CallMethod0<R, C, F>, FuncInfo<C *, R> > GetFunc() {
5113     return Func1<R, C *, CallMethod0<R, C, F>, FuncInfo<C *, R> >();
5114   }
5115 };
5116 
5117 template <class R, class C, class P1>
5118 struct MethodSig1 {
5119   template <R (C::*F)(P1)>
5120   Func2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> > GetFunc() {
5121     return Func2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> >();
5122   }
5123 
5124   template <R (C::*F)(P1)>
5125   BoundFunc2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> > GetFunc(
5126       typename remove_constptr<P1>::type param1) {
5127     return BoundFunc2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> >(
5128         param1);
5129   }
5130 };
5131 
5132 template <class R, class C, class P1, class P2>
5133 struct MethodSig2 {
5134   template <R (C::*F)(P1, P2)>
5135   Func3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>, FuncInfo<C *, R> >
5136   GetFunc() {
5137     return Func3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>,
5138                  FuncInfo<C *, R> >();
5139   }
5140 
5141   template <R (C::*F)(P1, P2)>
5142   BoundFunc3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>, FuncInfo<C *, R> >
5143   GetFunc(typename remove_constptr<P1>::type param1) {
5144     return BoundFunc3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>,
5145                       FuncInfo<C *, R> >(param1);
5146   }
5147 };
5148 
5149 template <class R, class C, class P1, class P2, class P3>
5150 struct MethodSig3 {
5151   template <R (C::*F)(P1, P2, P3)>
5152   Func4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>, FuncInfo<C *, R> >
5153   GetFunc() {
5154     return Func4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>,
5155                  FuncInfo<C *, R> >();
5156   }
5157 
5158   template <R (C::*F)(P1, P2, P3)>
5159   BoundFunc4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>,
5160              FuncInfo<C *, R> >
5161   GetFunc(typename remove_constptr<P1>::type param1) {
5162     return BoundFunc4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>,
5163                       FuncInfo<C *, R> >(param1);
5164   }
5165 };
5166 
5167 template <class R, class C, class P1, class P2, class P3, class P4>
5168 struct MethodSig4 {
5169   template <R (C::*F)(P1, P2, P3, P4)>
5170   Func5<R, C *, P1, P2, P3, P4, CallMethod4<R, C, P1, P2, P3, P4, F>,
5171         FuncInfo<C *, R> >
5172   GetFunc() {
5173     return Func5<R, C *, P1, P2, P3, P4, CallMethod4<R, C, P1, P2, P3, P4, F>,
5174                  FuncInfo<C *, R> >();
5175   }
5176 
5177   template <R (C::*F)(P1, P2, P3, P4)>
5178   BoundFunc5<R, C *, P1, P2, P3, P4, CallMethod4<R, C, P1, P2, P3, P4, F>,
5179              FuncInfo<C *, R> >
5180   GetFunc(typename remove_constptr<P1>::type param1) {
5181     return BoundFunc5<R, C *, P1, P2, P3, P4,
5182                       CallMethod4<R, C, P1, P2, P3, P4, F>, FuncInfo<C *, R> >(
5183         param1);
5184   }
5185 };
5186 
5187 template <class R, class C>
5188 inline MethodSig0<R, C> MatchFunc(R (C::*f)()) {
5189   UPB_UNUSED(f);  /* Only used for template parameter deduction. */
5190   return MethodSig0<R, C>();
5191 }
5192 
5193 template <class R, class C, class P1>
5194 inline MethodSig1<R, C, P1> MatchFunc(R (C::*f)(P1)) {
5195   UPB_UNUSED(f);  /* Only used for template parameter deduction. */
5196   return MethodSig1<R, C, P1>();
5197 }
5198 
5199 template <class R, class C, class P1, class P2>
5200 inline MethodSig2<R, C, P1, P2> MatchFunc(R (C::*f)(P1, P2)) {
5201   UPB_UNUSED(f);  /* Only used for template parameter deduction. */
5202   return MethodSig2<R, C, P1, P2>();
5203 }
5204 
5205 template <class R, class C, class P1, class P2, class P3>
5206 inline MethodSig3<R, C, P1, P2, P3> MatchFunc(R (C::*f)(P1, P2, P3)) {
5207   UPB_UNUSED(f);  /* Only used for template parameter deduction. */
5208   return MethodSig3<R, C, P1, P2, P3>();
5209 }
5210 
5211 template <class R, class C, class P1, class P2, class P3, class P4>
5212 inline MethodSig4<R, C, P1, P2, P3, P4> MatchFunc(R (C::*f)(P1, P2, P3, P4)) {
5213   UPB_UNUSED(f);  /* Only used for template parameter deduction. */
5214   return MethodSig4<R, C, P1, P2, P3, P4>();
5215 }
5216 
5217 /* MaybeWrapReturn ************************************************************/
5218 
5219 /* Template class that attempts to wrap the return value of the function so it
5220  * matches the expected type.  There are two main adjustments it may make:
5221  *
5222  *   1. If the function returns void, make it return the expected type and with
5223  *      a value that always indicates success.
5224  *   2. If the function returns bool, make it return the expected type with a
5225  *      value that indicates success or failure.
5226  *
5227  * The "expected type" for return is:
5228  *   1. void* for start handlers.  If the closure parameter has a different type
5229  *      we will cast it to void* for the return in the success case.
5230  *   2. size_t for string buffer handlers.
5231  *   3. bool for everything else. */
5232 
5233 /* Template parameters are FuncN type and desired return type. */
5234 template <class F, class R, class Enable = void>
5235 struct MaybeWrapReturn;
5236 
5237 /* If the return type matches, return the given function unwrapped. */
5238 template <class F>
5239 struct MaybeWrapReturn<F, typename F::Return> {
5240   typedef F Func;
5241 };
5242 
5243 /* Function wrapper that munges the return value from void to (bool)true. */
5244 template <class P1, class P2, void F(P1, P2)>
5245 bool ReturnTrue2(P1 p1, P2 p2) {
5246   F(p1, p2);
5247   return true;
5248 }
5249 
5250 template <class P1, class P2, class P3, void F(P1, P2, P3)>
5251 bool ReturnTrue3(P1 p1, P2 p2, P3 p3) {
5252   F(p1, p2, p3);
5253   return true;
5254 }
5255 
5256 /* Function wrapper that munges the return value from void to (void*)arg1  */
5257 template <class P1, class P2, void F(P1, P2)>
5258 void *ReturnClosure2(P1 p1, P2 p2) {
5259   F(p1, p2);
5260   return p1;
5261 }
5262 
5263 template <class P1, class P2, class P3, void F(P1, P2, P3)>
5264 void *ReturnClosure3(P1 p1, P2 p2, P3 p3) {
5265   F(p1, p2, p3);
5266   return p1;
5267 }
5268 
5269 /* Function wrapper that munges the return value from R to void*. */
5270 template <class R, class P1, class P2, R F(P1, P2)>
5271 void *CastReturnToVoidPtr2(P1 p1, P2 p2) {
5272   return F(p1, p2);
5273 }
5274 
5275 template <class R, class P1, class P2, class P3, R F(P1, P2, P3)>
5276 void *CastReturnToVoidPtr3(P1 p1, P2 p2, P3 p3) {
5277   return F(p1, p2, p3);
5278 }
5279 
5280 /* Function wrapper that munges the return value from bool to void*. */
5281 template <class P1, class P2, bool F(P1, P2)>
5282 void *ReturnClosureOrBreak2(P1 p1, P2 p2) {
5283   return F(p1, p2) ? p1 : UPB_BREAK;
5284 }
5285 
5286 template <class P1, class P2, class P3, bool F(P1, P2, P3)>
5287 void *ReturnClosureOrBreak3(P1 p1, P2 p2, P3 p3) {
5288   return F(p1, p2, p3) ? p1 : UPB_BREAK;
5289 }
5290 
5291 /* For the string callback, which takes five params, returns the size param. */
5292 template <class P1, class P2,
5293           void F(P1, P2, const char *, size_t, const upb_bufhandle *)>
5294 size_t ReturnStringLen(P1 p1, P2 p2, const char *p3, size_t p4,
5295                        const upb_bufhandle *p5) {
5296   F(p1, p2, p3, p4, p5);
5297   return p4;
5298 }
5299 
5300 /* For the string callback, which takes five params, returns the size param or
5301  * zero. */
5302 template <class P1, class P2,
5303           bool F(P1, P2, const char *, size_t, const upb_bufhandle *)>
5304 size_t ReturnNOr0(P1 p1, P2 p2, const char *p3, size_t p4,
5305                   const upb_bufhandle *p5) {
5306   return F(p1, p2, p3, p4, p5) ? p4 : 0;
5307 }
5308 
5309 /* If we have a function returning void but want a function returning bool, wrap
5310  * it in a function that returns true. */
5311 template <class P1, class P2, void F(P1, P2), class I>
5312 struct MaybeWrapReturn<Func2<void, P1, P2, F, I>, bool> {
5313   typedef Func2<bool, P1, P2, ReturnTrue2<P1, P2, F>, I> Func;
5314 };
5315 
5316 template <class P1, class P2, class P3, void F(P1, P2, P3), class I>
5317 struct MaybeWrapReturn<Func3<void, P1, P2, P3, F, I>, bool> {
5318   typedef Func3<bool, P1, P2, P3, ReturnTrue3<P1, P2, P3, F>, I> Func;
5319 };
5320 
5321 /* If our function returns void but we want one returning void*, wrap it in a
5322  * function that returns the first argument. */
5323 template <class P1, class P2, void F(P1, P2), class I>
5324 struct MaybeWrapReturn<Func2<void, P1, P2, F, I>, void *> {
5325   typedef Func2<void *, P1, P2, ReturnClosure2<P1, P2, F>, I> Func;
5326 };
5327 
5328 template <class P1, class P2, class P3, void F(P1, P2, P3), class I>
5329 struct MaybeWrapReturn<Func3<void, P1, P2, P3, F, I>, void *> {
5330   typedef Func3<void *, P1, P2, P3, ReturnClosure3<P1, P2, P3, F>, I> Func;
5331 };
5332 
5333 /* If our function returns R* but we want one returning void*, wrap it in a
5334  * function that casts to void*. */
5335 template <class R, class P1, class P2, R *F(P1, P2), class I>
5336 struct MaybeWrapReturn<Func2<R *, P1, P2, F, I>, void *,
5337                        typename disable_if_same<R *, void *>::Type> {
5338   typedef Func2<void *, P1, P2, CastReturnToVoidPtr2<R *, P1, P2, F>, I> Func;
5339 };
5340 
5341 template <class R, class P1, class P2, class P3, R *F(P1, P2, P3), class I>
5342 struct MaybeWrapReturn<Func3<R *, P1, P2, P3, F, I>, void *,
5343                        typename disable_if_same<R *, void *>::Type> {
5344   typedef Func3<void *, P1, P2, P3, CastReturnToVoidPtr3<R *, P1, P2, P3, F>, I>
5345       Func;
5346 };
5347 
5348 /* If our function returns bool but we want one returning void*, wrap it in a
5349  * function that returns either the first param or UPB_BREAK. */
5350 template <class P1, class P2, bool F(P1, P2), class I>
5351 struct MaybeWrapReturn<Func2<bool, P1, P2, F, I>, void *> {
5352   typedef Func2<void *, P1, P2, ReturnClosureOrBreak2<P1, P2, F>, I> Func;
5353 };
5354 
5355 template <class P1, class P2, class P3, bool F(P1, P2, P3), class I>
5356 struct MaybeWrapReturn<Func3<bool, P1, P2, P3, F, I>, void *> {
5357   typedef Func3<void *, P1, P2, P3, ReturnClosureOrBreak3<P1, P2, P3, F>, I>
5358       Func;
5359 };
5360 
5361 /* If our function returns void but we want one returning size_t, wrap it in a
5362  * function that returns the size argument. */
5363 template <class P1, class P2,
5364           void F(P1, P2, const char *, size_t, const upb_bufhandle *), class I>
5365 struct MaybeWrapReturn<
5366     Func5<void, P1, P2, const char *, size_t, const upb_bufhandle *, F, I>,
5367           size_t> {
5368   typedef Func5<size_t, P1, P2, const char *, size_t, const upb_bufhandle *,
5369                 ReturnStringLen<P1, P2, F>, I> Func;
5370 };
5371 
5372 /* If our function returns bool but we want one returning size_t, wrap it in a
5373  * function that returns either 0 or the buf size. */
5374 template <class P1, class P2,
5375           bool F(P1, P2, const char *, size_t, const upb_bufhandle *), class I>
5376 struct MaybeWrapReturn<
5377     Func5<bool, P1, P2, const char *, size_t, const upb_bufhandle *, F, I>,
5378     size_t> {
5379   typedef Func5<size_t, P1, P2, const char *, size_t, const upb_bufhandle *,
5380                 ReturnNOr0<P1, P2, F>, I> Func;
5381 };
5382 
5383 /* ConvertParams **************************************************************/
5384 
5385 /* Template class that converts the function parameters if necessary, and
5386  * ignores the HandlerData parameter if appropriate.
5387  *
5388  * Template parameter is the are FuncN function type. */
5389 template <class F, class T>
5390 struct ConvertParams;
5391 
5392 /* Function that discards the handler data parameter. */
5393 template <class R, class P1, R F(P1)>
5394 R IgnoreHandlerData2(void *p1, const void *hd) {
5395   UPB_UNUSED(hd);
5396   return F(static_cast<P1>(p1));
5397 }
5398 
5399 template <class R, class P1, class P2Wrapper, class P2Wrapped,
5400           R F(P1, P2Wrapped)>
5401 R IgnoreHandlerData3(void *p1, const void *hd, P2Wrapper p2) {
5402   UPB_UNUSED(hd);
5403   return F(static_cast<P1>(p1), p2);
5404 }
5405 
5406 template <class R, class P1, class P2, class P3, R F(P1, P2, P3)>
5407 R IgnoreHandlerData4(void *p1, const void *hd, P2 p2, P3 p3) {
5408   UPB_UNUSED(hd);
5409   return F(static_cast<P1>(p1), p2, p3);
5410 }
5411 
5412 template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4)>
5413 R IgnoreHandlerData5(void *p1, const void *hd, P2 p2, P3 p3, P4 p4) {
5414   UPB_UNUSED(hd);
5415   return F(static_cast<P1>(p1), p2, p3, p4);
5416 }
5417 
5418 template <class R, class P1, R F(P1, const char*, size_t)>
5419 R IgnoreHandlerDataIgnoreHandle(void *p1, const void *hd, const char *p2,
5420                                 size_t p3, const upb_bufhandle *handle) {
5421   UPB_UNUSED(hd);
5422   UPB_UNUSED(handle);
5423   return F(static_cast<P1>(p1), p2, p3);
5424 }
5425 
5426 /* Function that casts the handler data parameter. */
5427 template <class R, class P1, class P2, R F(P1, P2)>
5428 R CastHandlerData2(void *c, const void *hd) {
5429   return F(static_cast<P1>(c), static_cast<P2>(hd));
5430 }
5431 
5432 template <class R, class P1, class P2, class P3Wrapper, class P3Wrapped,
5433           R F(P1, P2, P3Wrapped)>
5434 R CastHandlerData3(void *c, const void *hd, P3Wrapper p3) {
5435   return F(static_cast<P1>(c), static_cast<P2>(hd), p3);
5436 }
5437 
5438 template <class R, class P1, class P2, class P3, class P4, class P5,
5439           R F(P1, P2, P3, P4, P5)>
5440 R CastHandlerData5(void *c, const void *hd, P3 p3, P4 p4, P5 p5) {
5441   return F(static_cast<P1>(c), static_cast<P2>(hd), p3, p4, p5);
5442 }
5443 
5444 template <class R, class P1, class P2, R F(P1, P2, const char *, size_t)>
5445 R CastHandlerDataIgnoreHandle(void *c, const void *hd, const char *p3,
5446                               size_t p4, const upb_bufhandle *handle) {
5447   UPB_UNUSED(handle);
5448   return F(static_cast<P1>(c), static_cast<P2>(hd), p3, p4);
5449 }
5450 
5451 /* For unbound functions, ignore the handler data. */
5452 template <class R, class P1, R F(P1), class I, class T>
5453 struct ConvertParams<Func1<R, P1, F, I>, T> {
5454   typedef Func2<R, void *, const void *, IgnoreHandlerData2<R, P1, F>, I> Func;
5455 };
5456 
5457 template <class R, class P1, class P2, R F(P1, P2), class I,
5458           class R2, class P1_2, class P2_2, class P3_2>
5459 struct ConvertParams<Func2<R, P1, P2, F, I>,
5460                      R2 (*)(P1_2, P2_2, P3_2)> {
5461   typedef Func3<R, void *, const void *, P3_2,
5462                 IgnoreHandlerData3<R, P1, P3_2, P2, F>, I> Func;
5463 };
5464 
5465 /* For StringBuffer only; this ignores both the handler data and the
5466  * upb_bufhandle. */
5467 template <class R, class P1, R F(P1, const char *, size_t), class I, class T>
5468 struct ConvertParams<Func3<R, P1, const char *, size_t, F, I>, T> {
5469   typedef Func5<R, void *, const void *, const char *, size_t,
5470                 const upb_bufhandle *, IgnoreHandlerDataIgnoreHandle<R, P1, F>,
5471                 I> Func;
5472 };
5473 
5474 template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4),
5475           class I, class T>
5476 struct ConvertParams<Func4<R, P1, P2, P3, P4, F, I>, T> {
5477   typedef Func5<R, void *, const void *, P2, P3, P4,
5478                 IgnoreHandlerData5<R, P1, P2, P3, P4, F>, I> Func;
5479 };
5480 
5481 /* For bound functions, cast the handler data. */
5482 template <class R, class P1, class P2, R F(P1, P2), class I, class T>
5483 struct ConvertParams<BoundFunc2<R, P1, P2, F, I>, T> {
5484   typedef Func2<R, void *, const void *, CastHandlerData2<R, P1, P2, F>, I>
5485       Func;
5486 };
5487 
5488 template <class R, class P1, class P2, class P3, R F(P1, P2, P3), class I,
5489           class R2, class P1_2, class P2_2, class P3_2>
5490 struct ConvertParams<BoundFunc3<R, P1, P2, P3, F, I>,
5491                      R2 (*)(P1_2, P2_2, P3_2)> {
5492   typedef Func3<R, void *, const void *, P3_2,
5493                 CastHandlerData3<R, P1, P2, P3_2, P3, F>, I> Func;
5494 };
5495 
5496 /* For StringBuffer only; this ignores the upb_bufhandle. */
5497 template <class R, class P1, class P2, R F(P1, P2, const char *, size_t),
5498           class I, class T>
5499 struct ConvertParams<BoundFunc4<R, P1, P2, const char *, size_t, F, I>, T> {
5500   typedef Func5<R, void *, const void *, const char *, size_t,
5501                 const upb_bufhandle *,
5502                 CastHandlerDataIgnoreHandle<R, P1, P2, F>, I>
5503       Func;
5504 };
5505 
5506 template <class R, class P1, class P2, class P3, class P4, class P5,
5507           R F(P1, P2, P3, P4, P5), class I, class T>
5508 struct ConvertParams<BoundFunc5<R, P1, P2, P3, P4, P5, F, I>, T> {
5509   typedef Func5<R, void *, const void *, P3, P4, P5,
5510                 CastHandlerData5<R, P1, P2, P3, P4, P5, F>, I> Func;
5511 };
5512 
5513 /* utype/ltype are upper/lower-case, ctype is canonical C type, vtype is
5514  * variant C type. */
5515 #define TYPE_METHODS(utype, ltype, ctype, vtype)                      \
5516   template <>                                                         \
5517   struct CanonicalType<vtype> {                                       \
5518     typedef ctype Type;                                               \
5519   };                                                                  \
5520   template <>                                                         \
5521   inline bool HandlersPtr::SetValueHandler<vtype>(                    \
5522       FieldDefPtr f, const HandlersPtr::utype##Handler &handler) {    \
5523     handler.AddCleanup(ptr());                                        \
5524     return upb_handlers_set##ltype(ptr(), f.ptr(), handler.handler(), \
5525                                    &handler.attr());                  \
5526   }
5527 
5528 TYPE_METHODS(Double, double, double,   double)
5529 TYPE_METHODS(Float,  float,  float,    float)
5530 TYPE_METHODS(UInt64, uint64, uint64_t, UPB_UINT64_T)
5531 TYPE_METHODS(UInt32, uint32, uint32_t, UPB_UINT32_T)
5532 TYPE_METHODS(Int64,  int64,  int64_t,  UPB_INT64_T)
5533 TYPE_METHODS(Int32,  int32,  int32_t,  UPB_INT32_T)
5534 TYPE_METHODS(Bool,   bool,   bool,     bool)
5535 
5536 #ifdef UPB_TWO_32BIT_TYPES
5537 TYPE_METHODS(Int32,  int32,  int32_t,  UPB_INT32ALT_T)
5538 TYPE_METHODS(UInt32, uint32, uint32_t, UPB_UINT32ALT_T)
5539 #endif
5540 
5541 #ifdef UPB_TWO_64BIT_TYPES
5542 TYPE_METHODS(Int64,  int64,  int64_t,  UPB_INT64ALT_T)
5543 TYPE_METHODS(UInt64, uint64, uint64_t, UPB_UINT64ALT_T)
5544 #endif
5545 #undef TYPE_METHODS
5546 
5547 template <> struct CanonicalType<Status*> {
5548   typedef Status* Type;
5549 };
5550 
5551 template <class F> struct ReturnOf;
5552 
5553 template <class R, class P1, class P2>
5554 struct ReturnOf<R (*)(P1, P2)> {
5555   typedef R Return;
5556 };
5557 
5558 template <class R, class P1, class P2, class P3>
5559 struct ReturnOf<R (*)(P1, P2, P3)> {
5560   typedef R Return;
5561 };
5562 
5563 template <class R, class P1, class P2, class P3, class P4>
5564 struct ReturnOf<R (*)(P1, P2, P3, P4)> {
5565   typedef R Return;
5566 };
5567 
5568 template <class R, class P1, class P2, class P3, class P4, class P5>
5569 struct ReturnOf<R (*)(P1, P2, P3, P4, P5)> {
5570   typedef R Return;
5571 };
5572 
5573 
5574 template <class T>
5575 template <class F>
5576 inline Handler<T>::Handler(F func)
5577     : registered_(false),
5578       cleanup_data_(func.GetData()),
5579       cleanup_func_(func.GetCleanup()) {
5580   attr_.handler_data = func.GetData();
5581   typedef typename ReturnOf<T>::Return Return;
5582   typedef typename ConvertParams<F, T>::Func ConvertedParamsFunc;
5583   typedef typename MaybeWrapReturn<ConvertedParamsFunc, Return>::Func
5584       ReturnWrappedFunc;
5585   handler_ = ReturnWrappedFunc().Call;
5586 
5587   /* Set attributes based on what templates can statically tell us about the
5588    * user's function. */
5589 
5590   /* If the original function returns void, then we know that we wrapped it to
5591    * always return ok. */
5592   bool always_ok = is_same<typename F::FuncInfo::Return, void>::value;
5593   attr_.alwaysok = always_ok;
5594 
5595   /* Closure parameter and return type. */
5596   attr_.closure_type = UniquePtrForType<typename F::FuncInfo::Closure>();
5597 
5598   /* We use the closure type (from the first parameter) if the return type is
5599    * void or bool, since these are the two cases we wrap to return the closure's
5600    * type anyway.
5601    *
5602    * This is all nonsense for non START* handlers, but it doesn't matter because
5603    * in that case the value will be ignored. */
5604   typedef typename FirstUnlessVoidOrBool<typename F::FuncInfo::Return,
5605                                          typename F::FuncInfo::Closure>::value
5606       EffectiveReturn;
5607   attr_.return_closure_type = UniquePtrForType<EffectiveReturn>();
5608 }
5609 
5610 template <class T>
5611 inline void Handler<T>::AddCleanup(upb_handlers* h) const {
5612   UPB_ASSERT(!registered_);
5613   registered_ = true;
5614   if (cleanup_func_) {
5615     bool ok = upb_handlers_addcleanup(h, cleanup_data_, cleanup_func_);
5616     UPB_ASSERT(ok);
5617   }
5618 }
5619 
5620 }  /* namespace upb */
5621 
5622 #endif  /* __cplusplus */
5623 
5624 
5625 #undef UPB_TWO_32BIT_TYPES
5626 #undef UPB_TWO_64BIT_TYPES
5627 #undef UPB_INT32_T
5628 #undef UPB_UINT32_T
5629 #undef UPB_INT32ALT_T
5630 #undef UPB_UINT32ALT_T
5631 #undef UPB_INT64_T
5632 #undef UPB_UINT64_T
5633 #undef UPB_INT64ALT_T
5634 #undef UPB_UINT64ALT_T
5635 
5636 #endif  /* UPB_HANDLERS_INL_H_ */
5637 
5638 #endif  /* UPB_HANDLERS_H */
5639 /*
5640 ** upb::Sink (upb_sink)
5641 ** upb::BytesSink (upb_bytessink)
5642 **
5643 ** A upb_sink is an object that binds a upb_handlers object to some runtime
5644 ** state.  It is the object that can actually receive data via the upb_handlers
5645 ** interface.
5646 **
5647 ** Unlike upb_def and upb_handlers, upb_sink is never frozen, immutable, or
5648 ** thread-safe.  You can create as many of them as you want, but each one may
5649 ** only be used in a single thread at a time.
5650 **
5651 ** If we compare with class-based OOP, a you can think of a upb_def as an
5652 ** abstract base class, a upb_handlers as a concrete derived class, and a
5653 ** upb_sink as an object (class instance).
5654 */
5655 
5656 #ifndef UPB_SINK_H
5657 #define UPB_SINK_H
5658 
5659 
5660 #ifdef __cplusplus
5661 namespace upb {
5662 class BytesSink;
5663 class Sink;
5664 }
5665 #endif
5666 
5667 /* upb_sink *******************************************************************/
5668 
5669 #ifdef __cplusplus
5670 extern "C" {
5671 #endif
5672 
5673 typedef struct {
5674   const upb_handlers *handlers;
5675   void *closure;
5676 } upb_sink;
5677 
5678 #define PUTVAL(type, ctype)                                           \
5679   UPB_INLINE bool upb_sink_put##type(upb_sink s, upb_selector_t sel,  \
5680                                      ctype val) {                     \
5681     typedef upb_##type##_handlerfunc functype;                        \
5682     functype *func;                                                   \
5683     const void *hd;                                                   \
5684     if (!s.handlers) return true;                                     \
5685     func = (functype *)upb_handlers_gethandler(s.handlers, sel, &hd); \
5686     if (!func) return true;                                           \
5687     return func(s.closure, hd, val);                                  \
5688   }
5689 
5690 PUTVAL(int32,  int32_t)
5691 PUTVAL(int64,  int64_t)
5692 PUTVAL(uint32, uint32_t)
5693 PUTVAL(uint64, uint64_t)
5694 PUTVAL(float,  float)
5695 PUTVAL(double, double)
5696 PUTVAL(bool,   bool)
5697 #undef PUTVAL
5698 
5699 UPB_INLINE void upb_sink_reset(upb_sink *s, const upb_handlers *h, void *c) {
5700   s->handlers = h;
5701   s->closure = c;
5702 }
5703 
5704 UPB_INLINE size_t upb_sink_putstring(upb_sink s, upb_selector_t sel,
5705                                      const char *buf, size_t n,
5706                                      const upb_bufhandle *handle) {
5707   typedef upb_string_handlerfunc func;
5708   func *handler;
5709   const void *hd;
5710   if (!s.handlers) return n;
5711   handler = (func *)upb_handlers_gethandler(s.handlers, sel, &hd);
5712 
5713   if (!handler) return n;
5714   return handler(s.closure, hd, buf, n, handle);
5715 }
5716 
5717 UPB_INLINE bool upb_sink_putunknown(upb_sink s, const char *buf, size_t n) {
5718   typedef upb_unknown_handlerfunc func;
5719   func *handler;
5720   const void *hd;
5721   if (!s.handlers) return true;
5722   handler =
5723       (func *)upb_handlers_gethandler(s.handlers, UPB_UNKNOWN_SELECTOR, &hd);
5724 
5725   if (!handler) return n;
5726   return handler(s.closure, hd, buf, n);
5727 }
5728 
5729 UPB_INLINE bool upb_sink_startmsg(upb_sink s) {
5730   typedef upb_startmsg_handlerfunc func;
5731   func *startmsg;
5732   const void *hd;
5733   if (!s.handlers) return true;
5734   startmsg =
5735       (func *)upb_handlers_gethandler(s.handlers, UPB_STARTMSG_SELECTOR, &hd);
5736 
5737   if (!startmsg) return true;
5738   return startmsg(s.closure, hd);
5739 }
5740 
5741 UPB_INLINE bool upb_sink_endmsg(upb_sink s, upb_status *status) {
5742   typedef upb_endmsg_handlerfunc func;
5743   func *endmsg;
5744   const void *hd;
5745   if (!s.handlers) return true;
5746   endmsg =
5747       (func *)upb_handlers_gethandler(s.handlers, UPB_ENDMSG_SELECTOR, &hd);
5748 
5749   if (!endmsg) return true;
5750   return endmsg(s.closure, hd, status);
5751 }
5752 
5753 UPB_INLINE bool upb_sink_startseq(upb_sink s, upb_selector_t sel,
5754                                   upb_sink *sub) {
5755   typedef upb_startfield_handlerfunc func;
5756   func *startseq;
5757   const void *hd;
5758   sub->closure = s.closure;
5759   sub->handlers = s.handlers;
5760   if (!s.handlers) return true;
5761   startseq = (func*)upb_handlers_gethandler(s.handlers, sel, &hd);
5762 
5763   if (!startseq) return true;
5764   sub->closure = startseq(s.closure, hd);
5765   return sub->closure ? true : false;
5766 }
5767 
5768 UPB_INLINE bool upb_sink_endseq(upb_sink s, upb_selector_t sel) {
5769   typedef upb_endfield_handlerfunc func;
5770   func *endseq;
5771   const void *hd;
5772   if (!s.handlers) return true;
5773   endseq = (func*)upb_handlers_gethandler(s.handlers, sel, &hd);
5774 
5775   if (!endseq) return true;
5776   return endseq(s.closure, hd);
5777 }
5778 
5779 UPB_INLINE bool upb_sink_startstr(upb_sink s, upb_selector_t sel,
5780                                   size_t size_hint, upb_sink *sub) {
5781   typedef upb_startstr_handlerfunc func;
5782   func *startstr;
5783   const void *hd;
5784   sub->closure = s.closure;
5785   sub->handlers = s.handlers;
5786   if (!s.handlers) return true;
5787   startstr = (func*)upb_handlers_gethandler(s.handlers, sel, &hd);
5788 
5789   if (!startstr) return true;
5790   sub->closure = startstr(s.closure, hd, size_hint);
5791   return sub->closure ? true : false;
5792 }
5793 
5794 UPB_INLINE bool upb_sink_endstr(upb_sink s, upb_selector_t sel) {
5795   typedef upb_endfield_handlerfunc func;
5796   func *endstr;
5797   const void *hd;
5798   if (!s.handlers) return true;
5799   endstr = (func*)upb_handlers_gethandler(s.handlers, sel, &hd);
5800 
5801   if (!endstr) return true;
5802   return endstr(s.closure, hd);
5803 }
5804 
5805 UPB_INLINE bool upb_sink_startsubmsg(upb_sink s, upb_selector_t sel,
5806                                      upb_sink *sub) {
5807   typedef upb_startfield_handlerfunc func;
5808   func *startsubmsg;
5809   const void *hd;
5810   sub->closure = s.closure;
5811   if (!s.handlers) {
5812     sub->handlers = NULL;
5813     return true;
5814   }
5815   sub->handlers = upb_handlers_getsubhandlers_sel(s.handlers, sel);
5816   startsubmsg = (func*)upb_handlers_gethandler(s.handlers, sel, &hd);
5817 
5818   if (!startsubmsg) return true;
5819   sub->closure = startsubmsg(s.closure, hd);
5820   return sub->closure ? true : false;
5821 }
5822 
5823 UPB_INLINE bool upb_sink_endsubmsg(upb_sink s, upb_selector_t sel) {
5824   typedef upb_endfield_handlerfunc func;
5825   func *endsubmsg;
5826   const void *hd;
5827   if (!s.handlers) return true;
5828   endsubmsg = (func*)upb_handlers_gethandler(s.handlers, sel, &hd);
5829 
5830   if (!endsubmsg) return s.closure;
5831   return endsubmsg(s.closure, hd);
5832 }
5833 
5834 #ifdef __cplusplus
5835 }  /* extern "C" */
5836 
5837 /* A upb::Sink is an object that binds a upb::Handlers object to some runtime
5838  * state.  It represents an endpoint to which data can be sent.
5839  *
5840  * TODO(haberman): right now all of these functions take selectors.  Should they
5841  * take selectorbase instead?
5842  *
5843  * ie. instead of calling:
5844  *   sink->StartString(FOO_FIELD_START_STRING, ...)
5845  * a selector base would let you say:
5846  *   sink->StartString(FOO_FIELD, ...)
5847  *
5848  * This would make call sites a little nicer and require emitting fewer selector
5849  * definitions in .h files.
5850  *
5851  * But the current scheme has the benefit that you can retrieve a function
5852  * pointer for any handler with handlers->GetHandler(selector), without having
5853  * to have a separate GetHandler() function for each handler type.  The JIT
5854  * compiler uses this.  To accommodate we'd have to expose a separate
5855  * GetHandler() for every handler type.
5856  *
5857  * Also to ponder: selectors right now are independent of a specific Handlers
5858  * instance.  In other words, they allocate a number to every possible handler
5859  * that *could* be registered, without knowing anything about what handlers
5860  * *are* registered.  That means that using selectors as table offsets prohibits
5861  * us from compacting the handler table at Freeze() time.  If the table is very
5862  * sparse, this could be wasteful.
5863  *
5864  * Having another selector-like thing that is specific to a Handlers instance
5865  * would allow this compacting, but then it would be impossible to write code
5866  * ahead-of-time that can be bound to any Handlers instance at runtime.  For
5867  * example, a .proto file parser written as straight C will not know what
5868  * Handlers it will be bound to, so when it calls sink->StartString() what
5869  * selector will it pass?  It needs a selector like we have today, that is
5870  * independent of any particular upb::Handlers.
5871  *
5872  * Is there a way then to allow Handlers table compaction? */
5873 class upb::Sink {
5874  public:
5875   /* Constructor with no initialization; must be Reset() before use. */
5876   Sink() {}
5877 
5878   Sink(const Sink&) = default;
5879   Sink& operator=(const Sink&) = default;
5880 
5881   Sink(const upb_sink& sink) : sink_(sink) {}
5882   Sink &operator=(const upb_sink &sink) {
5883     sink_ = sink;
5884     return *this;
5885   }
5886 
5887   upb_sink sink() { return sink_; }
5888 
5889   /* Constructs a new sink for the given frozen handlers and closure.
5890    *
5891    * TODO: once the Handlers know the expected closure type, verify that T
5892    * matches it. */
5893   template <class T> Sink(const upb_handlers* handlers, T* closure) {
5894     Reset(handlers, closure);
5895   }
5896 
5897   upb_sink* ptr() { return &sink_; }
5898 
5899   /* Resets the value of the sink. */
5900   template <class T> void Reset(const upb_handlers* handlers, T* closure) {
5901     upb_sink_reset(&sink_, handlers, closure);
5902   }
5903 
5904   /* Returns the top-level object that is bound to this sink.
5905    *
5906    * TODO: once the Handlers know the expected closure type, verify that T
5907    * matches it. */
5908   template <class T> T* GetObject() const {
5909     return static_cast<T*>(sink_.closure);
5910   }
5911 
5912   /* Functions for pushing data into the sink.
5913    *
5914    * These return false if processing should stop (either due to error or just
5915    * to suspend).
5916    *
5917    * These may not be called from within one of the same sink's handlers (in
5918    * other words, handlers are not re-entrant). */
5919 
5920   /* Should be called at the start and end of every message; both the top-level
5921    * message and submessages.  This means that submessages should use the
5922    * following sequence:
5923    *   sink->StartSubMessage(startsubmsg_selector);
5924    *   sink->StartMessage();
5925    *   // ...
5926    *   sink->EndMessage(&status);
5927    *   sink->EndSubMessage(endsubmsg_selector); */
5928   bool StartMessage() { return upb_sink_startmsg(sink_); }
5929   bool EndMessage(upb_status *status) {
5930     return upb_sink_endmsg(sink_, status);
5931   }
5932 
5933   /* Putting of individual values.  These work for both repeated and
5934    * non-repeated fields, but for repeated fields you must wrap them in
5935    * calls to StartSequence()/EndSequence(). */
5936   bool PutInt32(HandlersPtr::Selector s, int32_t val) {
5937     return upb_sink_putint32(sink_, s, val);
5938   }
5939 
5940   bool PutInt64(HandlersPtr::Selector s, int64_t val) {
5941     return upb_sink_putint64(sink_, s, val);
5942   }
5943 
5944   bool PutUInt32(HandlersPtr::Selector s, uint32_t val) {
5945     return upb_sink_putuint32(sink_, s, val);
5946   }
5947 
5948   bool PutUInt64(HandlersPtr::Selector s, uint64_t val) {
5949     return upb_sink_putuint64(sink_, s, val);
5950   }
5951 
5952   bool PutFloat(HandlersPtr::Selector s, float val) {
5953     return upb_sink_putfloat(sink_, s, val);
5954   }
5955 
5956   bool PutDouble(HandlersPtr::Selector s, double val) {
5957     return upb_sink_putdouble(sink_, s, val);
5958   }
5959 
5960   bool PutBool(HandlersPtr::Selector s, bool val) {
5961     return upb_sink_putbool(sink_, s, val);
5962   }
5963 
5964   /* Putting of string/bytes values.  Each string can consist of zero or more
5965    * non-contiguous buffers of data.
5966    *
5967    * For StartString(), the function will write a sink for the string to "sub."
5968    * The sub-sink must be used for any/all PutStringBuffer() calls. */
5969   bool StartString(HandlersPtr::Selector s, size_t size_hint, Sink* sub) {
5970     upb_sink sub_c;
5971     bool ret = upb_sink_startstr(sink_, s, size_hint, &sub_c);
5972     *sub = sub_c;
5973     return ret;
5974   }
5975 
5976   size_t PutStringBuffer(HandlersPtr::Selector s, const char *buf, size_t len,
5977                          const upb_bufhandle *handle) {
5978     return upb_sink_putstring(sink_, s, buf, len, handle);
5979   }
5980 
5981   bool EndString(HandlersPtr::Selector s) {
5982     return upb_sink_endstr(sink_, s);
5983   }
5984 
5985   /* For submessage fields.
5986    *
5987    * For StartSubMessage(), the function will write a sink for the string to
5988    * "sub." The sub-sink must be used for any/all handlers called within the
5989    * submessage. */
5990   bool StartSubMessage(HandlersPtr::Selector s, Sink* sub) {
5991     upb_sink sub_c;
5992     bool ret = upb_sink_startsubmsg(sink_, s, &sub_c);
5993     *sub = sub_c;
5994     return ret;
5995   }
5996 
5997   bool EndSubMessage(HandlersPtr::Selector s) {
5998     return upb_sink_endsubmsg(sink_, s);
5999   }
6000 
6001   /* For repeated fields of any type, the sequence of values must be wrapped in
6002    * these calls.
6003    *
6004    * For StartSequence(), the function will write a sink for the string to
6005    * "sub." The sub-sink must be used for any/all handlers called within the
6006    * sequence. */
6007   bool StartSequence(HandlersPtr::Selector s, Sink* sub) {
6008     upb_sink sub_c;
6009     bool ret = upb_sink_startseq(sink_, s, &sub_c);
6010     *sub = sub_c;
6011     return ret;
6012   }
6013 
6014   bool EndSequence(HandlersPtr::Selector s) {
6015     return upb_sink_endseq(sink_, s);
6016   }
6017 
6018   /* Copy and assign specifically allowed.
6019    * We don't even bother making these members private because so many
6020    * functions need them and this is mainly just a dumb data container anyway.
6021    */
6022 
6023  private:
6024   upb_sink sink_;
6025 };
6026 
6027 #endif  /* __cplusplus */
6028 
6029 /* upb_bytessink **************************************************************/
6030 
6031 typedef struct {
6032   const upb_byteshandler *handler;
6033   void *closure;
6034 } upb_bytessink ;
6035 
6036 UPB_INLINE void upb_bytessink_reset(upb_bytessink* s, const upb_byteshandler *h,
6037                                     void *closure) {
6038   s->handler = h;
6039   s->closure = closure;
6040 }
6041 
6042 UPB_INLINE bool upb_bytessink_start(upb_bytessink s, size_t size_hint,
6043                                     void **subc) {
6044   typedef upb_startstr_handlerfunc func;
6045   func *start;
6046   *subc = s.closure;
6047   if (!s.handler) return true;
6048   start = (func *)s.handler->table[UPB_STARTSTR_SELECTOR].func;
6049 
6050   if (!start) return true;
6051   *subc = start(s.closure,
6052                 s.handler->table[UPB_STARTSTR_SELECTOR].attr.handler_data,
6053                 size_hint);
6054   return *subc != NULL;
6055 }
6056 
6057 UPB_INLINE size_t upb_bytessink_putbuf(upb_bytessink s, void *subc,
6058                                        const char *buf, size_t size,
6059                                        const upb_bufhandle* handle) {
6060   typedef upb_string_handlerfunc func;
6061   func *putbuf;
6062   if (!s.handler) return true;
6063   putbuf = (func *)s.handler->table[UPB_STRING_SELECTOR].func;
6064 
6065   if (!putbuf) return true;
6066   return putbuf(subc, s.handler->table[UPB_STRING_SELECTOR].attr.handler_data,
6067                 buf, size, handle);
6068 }
6069 
6070 UPB_INLINE bool upb_bytessink_end(upb_bytessink s) {
6071   typedef upb_endfield_handlerfunc func;
6072   func *end;
6073   if (!s.handler) return true;
6074   end = (func *)s.handler->table[UPB_ENDSTR_SELECTOR].func;
6075 
6076   if (!end) return true;
6077   return end(s.closure,
6078              s.handler->table[UPB_ENDSTR_SELECTOR].attr.handler_data);
6079 }
6080 
6081 #ifdef __cplusplus
6082 
6083 class upb::BytesSink {
6084  public:
6085   BytesSink() {}
6086 
6087   BytesSink(const BytesSink&) = default;
6088   BytesSink& operator=(const BytesSink&) = default;
6089 
6090   BytesSink(const upb_bytessink& sink) : sink_(sink) {}
6091   BytesSink &operator=(const upb_bytessink &sink) {
6092     sink_ = sink;
6093     return *this;
6094   }
6095 
6096   upb_bytessink sink() { return sink_; }
6097 
6098   /* Constructs a new sink for the given frozen handlers and closure.
6099    *
6100    * TODO(haberman): once the Handlers know the expected closure type, verify
6101    * that T matches it. */
6102   template <class T> BytesSink(const upb_byteshandler* handler, T* closure) {
6103     upb_bytessink_reset(sink_, handler, closure);
6104   }
6105 
6106   /* Resets the value of the sink. */
6107   template <class T> void Reset(const upb_byteshandler* handler, T* closure) {
6108     upb_bytessink_reset(&sink_, handler, closure);
6109   }
6110 
6111   bool Start(size_t size_hint, void **subc) {
6112     return upb_bytessink_start(sink_, size_hint, subc);
6113   }
6114 
6115   size_t PutBuffer(void *subc, const char *buf, size_t len,
6116                    const upb_bufhandle *handle) {
6117     return upb_bytessink_putbuf(sink_, subc, buf, len, handle);
6118   }
6119 
6120   bool End() {
6121     return upb_bytessink_end(sink_);
6122   }
6123 
6124  private:
6125   upb_bytessink sink_;
6126 };
6127 
6128 #endif  /* __cplusplus */
6129 
6130 /* upb_bufsrc *****************************************************************/
6131 
6132 #ifdef __cplusplus
6133 extern "C" {
6134 #endif
6135 
6136 bool upb_bufsrc_putbuf(const char *buf, size_t len, upb_bytessink sink);
6137 
6138 #ifdef __cplusplus
6139 }  /* extern "C" */
6140 
6141 namespace upb {
6142 template <class T> bool PutBuffer(const T& str, BytesSink sink) {
6143   return upb_bufsrc_putbuf(str.data(), str.size(), sink.sink());
6144 }
6145 }
6146 
6147 #endif  /* __cplusplus */
6148 
6149 #endif
6150 
6151 
6152 #ifndef UPB_MSGFACTORY_H_
6153 #define UPB_MSGFACTORY_H_
6154 
6155 /** upb_msgfactory ************************************************************/
6156 
6157 struct upb_msgfactory;
6158 typedef struct upb_msgfactory upb_msgfactory;
6159 
6160 #ifdef __cplusplus
6161 extern "C" {
6162 #endif
6163 
6164 /* A upb_msgfactory contains a cache of upb_msglayout, upb_handlers, and
6165  * upb_visitorplan objects.  These are the objects necessary to represent,
6166  * populate, and and visit upb_msg objects.
6167  *
6168  * These caches are all populated by upb_msgdef, and lazily created on demand.
6169  */
6170 
6171 /* Creates and destroys a msgfactory, respectively.  The messages for this
6172  * msgfactory must come from |symtab| (which should outlive the msgfactory). */
6173 upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab);
6174 void upb_msgfactory_free(upb_msgfactory *f);
6175 
6176 const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f);
6177 
6178 /* The functions to get cached objects, lazily creating them on demand.  These
6179  * all require:
6180  *
6181  * - m is in upb_msgfactory_symtab(f)
6182  * - upb_msgdef_mapentry(m) == false (since map messages can't have layouts).
6183  *
6184  * The returned objects will live for as long as the msgfactory does.
6185  *
6186  * TODO(haberman): consider making this thread-safe and take a const
6187  * upb_msgfactory. */
6188 const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f,
6189                                               const upb_msgdef *m);
6190 
6191 #ifdef __cplusplus
6192 }  /* extern "C" */
6193 #endif
6194 
6195 #endif /* UPB_MSGFACTORY_H_ */
6196 /*
6197 ** Internal-only definitions for the decoder.
6198 */
6199 
6200 #ifndef UPB_DECODER_INT_H_
6201 #define UPB_DECODER_INT_H_
6202 
6203 /*
6204 ** upb::pb::Decoder
6205 **
6206 ** A high performance, streaming, resumable decoder for the binary protobuf
6207 ** format.
6208 **
6209 ** This interface works the same regardless of what decoder backend is being
6210 ** used.  A client of this class does not need to know whether decoding is using
6211 ** a JITted decoder (DynASM, LLVM, etc) or an interpreted decoder.  By default,
6212 ** it will always use the fastest available decoder.  However, you can call
6213 ** set_allow_jit(false) to disable any JIT decoder that might be available.
6214 ** This is primarily useful for testing purposes.
6215 */
6216 
6217 #ifndef UPB_DECODER_H_
6218 #define UPB_DECODER_H_
6219 
6220 
6221 #ifdef __cplusplus
6222 namespace upb {
6223 namespace pb {
6224 class CodeCache;
6225 class DecoderPtr;
6226 class DecoderMethodPtr;
6227 class DecoderMethodOptions;
6228 }  /* namespace pb */
6229 }  /* namespace upb */
6230 #endif
6231 
6232 /* The maximum number of bytes we are required to buffer internally between
6233  * calls to the decoder.  The value is 14: a 5 byte unknown tag plus ten-byte
6234  * varint, less one because we are buffering an incomplete value.
6235  *
6236  * Should only be used by unit tests. */
6237 #define UPB_DECODER_MAX_RESIDUAL_BYTES 14
6238 
6239 /* upb_pbdecodermethod ********************************************************/
6240 
6241 struct upb_pbdecodermethod;
6242 typedef struct upb_pbdecodermethod upb_pbdecodermethod;
6243 
6244 #ifdef __cplusplus
6245 extern "C" {
6246 #endif
6247 
6248 const upb_handlers *upb_pbdecodermethod_desthandlers(
6249     const upb_pbdecodermethod *m);
6250 const upb_byteshandler *upb_pbdecodermethod_inputhandler(
6251     const upb_pbdecodermethod *m);
6252 bool upb_pbdecodermethod_isnative(const upb_pbdecodermethod *m);
6253 
6254 #ifdef __cplusplus
6255 }  /* extern "C" */
6256 
6257 /* Represents the code to parse a protobuf according to a destination
6258  * Handlers. */
6259 class upb::pb::DecoderMethodPtr {
6260  public:
6261   DecoderMethodPtr() : ptr_(nullptr) {}
6262   DecoderMethodPtr(const upb_pbdecodermethod* ptr) : ptr_(ptr) {}
6263 
6264   const upb_pbdecodermethod* ptr() { return ptr_; }
6265 
6266   /* The destination handlers that are statically bound to this method.
6267    * This method is only capable of outputting to a sink that uses these
6268    * handlers. */
6269   const Handlers *dest_handlers() const {
6270     return upb_pbdecodermethod_desthandlers(ptr_);
6271   }
6272 
6273   /* The input handlers for this decoder method. */
6274   const BytesHandler* input_handler() const {
6275     return upb_pbdecodermethod_inputhandler(ptr_);
6276   }
6277 
6278   /* Whether this method is native. */
6279   bool is_native() const {
6280     return upb_pbdecodermethod_isnative(ptr_);
6281   }
6282 
6283  private:
6284   const upb_pbdecodermethod* ptr_;
6285 };
6286 
6287 #endif
6288 
6289 /* upb_pbdecoder **************************************************************/
6290 
6291 /* Preallocation hint: decoder won't allocate more bytes than this when first
6292  * constructed.  This hint may be an overestimate for some build configurations.
6293  * But if the decoder library is upgraded without recompiling the application,
6294  * it may be an underestimate. */
6295 #define UPB_PB_DECODER_SIZE 4416
6296 
6297 struct upb_pbdecoder;
6298 typedef struct upb_pbdecoder upb_pbdecoder;
6299 
6300 #ifdef __cplusplus
6301 extern "C" {
6302 #endif
6303 
6304 upb_pbdecoder *upb_pbdecoder_create(upb_arena *arena,
6305                                     const upb_pbdecodermethod *method,
6306                                     upb_sink output, upb_status *status);
6307 const upb_pbdecodermethod *upb_pbdecoder_method(const upb_pbdecoder *d);
6308 upb_bytessink upb_pbdecoder_input(upb_pbdecoder *d);
6309 uint64_t upb_pbdecoder_bytesparsed(const upb_pbdecoder *d);
6310 size_t upb_pbdecoder_maxnesting(const upb_pbdecoder *d);
6311 bool upb_pbdecoder_setmaxnesting(upb_pbdecoder *d, size_t max);
6312 void upb_pbdecoder_reset(upb_pbdecoder *d);
6313 
6314 #ifdef __cplusplus
6315 }  /* extern "C" */
6316 
6317 /* A Decoder receives binary protobuf data on its input sink and pushes the
6318  * decoded data to its output sink. */
6319 class upb::pb::DecoderPtr {
6320  public:
6321   DecoderPtr() : ptr_(nullptr) {}
6322   DecoderPtr(upb_pbdecoder* ptr) : ptr_(ptr) {}
6323 
6324   upb_pbdecoder* ptr() { return ptr_; }
6325 
6326   /* Constructs a decoder instance for the given method, which must outlive this
6327    * decoder.  Any errors during parsing will be set on the given status, which
6328    * must also outlive this decoder.
6329    *
6330    * The sink must match the given method. */
6331   static DecoderPtr Create(Arena *arena, DecoderMethodPtr method,
6332                            upb::Sink output, Status *status) {
6333     return DecoderPtr(upb_pbdecoder_create(arena->ptr(), method.ptr(),
6334                                            output.sink(), status->ptr()));
6335   }
6336 
6337   /* Returns the DecoderMethod this decoder is parsing from. */
6338   const DecoderMethodPtr method() const {
6339     return DecoderMethodPtr(upb_pbdecoder_method(ptr_));
6340   }
6341 
6342   /* The sink on which this decoder receives input. */
6343   BytesSink input() { return BytesSink(upb_pbdecoder_input(ptr())); }
6344 
6345   /* Returns number of bytes successfully parsed.
6346    *
6347    * This can be useful for determining the stream position where an error
6348    * occurred.
6349    *
6350    * This value may not be up-to-date when called from inside a parsing
6351    * callback. */
6352   uint64_t BytesParsed() { return upb_pbdecoder_bytesparsed(ptr()); }
6353 
6354   /* Gets/sets the parsing nexting limit.  If the total number of nested
6355    * submessages and repeated fields hits this limit, parsing will fail.  This
6356    * is a resource limit that controls the amount of memory used by the parsing
6357    * stack.
6358    *
6359    * Setting the limit will fail if the parser is currently suspended at a depth
6360    * greater than this, or if memory allocation of the stack fails. */
6361   size_t max_nesting() { return upb_pbdecoder_maxnesting(ptr()); }
6362   bool set_max_nesting(size_t max) { return upb_pbdecoder_maxnesting(ptr()); }
6363 
6364   void Reset() { upb_pbdecoder_reset(ptr()); }
6365 
6366   static const size_t kSize = UPB_PB_DECODER_SIZE;
6367 
6368  private:
6369   upb_pbdecoder *ptr_;
6370 };
6371 
6372 #endif  /* __cplusplus */
6373 
6374 /* upb_pbcodecache ************************************************************/
6375 
6376 /* Lazily builds and caches decoder methods that will push data to the given
6377  * handlers.  The destination handlercache must outlive this object. */
6378 
6379 struct upb_pbcodecache;
6380 typedef struct upb_pbcodecache upb_pbcodecache;
6381 
6382 #ifdef __cplusplus
6383 extern "C" {
6384 #endif
6385 
6386 upb_pbcodecache *upb_pbcodecache_new(upb_handlercache *dest);
6387 void upb_pbcodecache_free(upb_pbcodecache *c);
6388 bool upb_pbcodecache_allowjit(const upb_pbcodecache *c);
6389 void upb_pbcodecache_setallowjit(upb_pbcodecache *c, bool allow);
6390 void upb_pbcodecache_setlazy(upb_pbcodecache *c, bool lazy);
6391 const upb_pbdecodermethod *upb_pbcodecache_get(upb_pbcodecache *c,
6392                                                const upb_msgdef *md);
6393 
6394 #ifdef __cplusplus
6395 }  /* extern "C" */
6396 
6397 /* A class for caching protobuf processing code, whether bytecode for the
6398  * interpreted decoder or machine code for the JIT.
6399  *
6400  * This class is not thread-safe. */
6401 class upb::pb::CodeCache {
6402  public:
6403   CodeCache(upb::HandlerCache *dest)
6404       : ptr_(upb_pbcodecache_new(dest->ptr()), upb_pbcodecache_free) {}
6405   CodeCache(CodeCache&&) = default;
6406   CodeCache& operator=(CodeCache&&) = default;
6407 
6408   upb_pbcodecache* ptr() { return ptr_.get(); }
6409   const upb_pbcodecache* ptr() const { return ptr_.get(); }
6410 
6411   /* Whether the cache is allowed to generate machine code.  Defaults to true.
6412    * There is no real reason to turn it off except for testing or if you are
6413    * having a specific problem with the JIT.
6414    *
6415    * Note that allow_jit = true does not *guarantee* that the code will be JIT
6416    * compiled.  If this platform is not supported or the JIT was not compiled
6417    * in, the code may still be interpreted. */
6418   bool allow_jit() const { return upb_pbcodecache_allowjit(ptr()); }
6419 
6420   /* This may only be called when the object is first constructed, and prior to
6421    * any code generation. */
6422   void set_allow_jit(bool allow) { upb_pbcodecache_setallowjit(ptr(), allow); }
6423 
6424   /* Should the decoder push submessages to lazy handlers for fields that have
6425    * them?  The caller should set this iff the lazy handlers expect data that is
6426    * in protobuf binary format and the caller wishes to lazy parse it. */
6427   void set_lazy(bool lazy) { upb_pbcodecache_setlazy(ptr(), lazy); }
6428 
6429   /* Returns a DecoderMethod that can push data to the given handlers.
6430    * If a suitable method already exists, it will be returned from the cache. */
6431   const DecoderMethodPtr Get(MessageDefPtr md) {
6432     return DecoderMethodPtr(upb_pbcodecache_get(ptr(), md.ptr()));
6433   }
6434 
6435  private:
6436   std::unique_ptr<upb_pbcodecache, decltype(&upb_pbcodecache_free)> ptr_;
6437 };
6438 
6439 #endif  /* __cplusplus */
6440 
6441 #endif  /* UPB_DECODER_H_ */
6442 
6443 /* Opcode definitions.  The canonical meaning of each opcode is its
6444  * implementation in the interpreter (the JIT is written to match this).
6445  *
6446  * All instructions have the opcode in the low byte.
6447  * Instruction format for most instructions is:
6448  *
6449  * +-------------------+--------+
6450  * |     arg (24)      | op (8) |
6451  * +-------------------+--------+
6452  *
6453  * Exceptions are indicated below.  A few opcodes are multi-word. */
6454 typedef enum {
6455   /* Opcodes 1-8, 13, 15-18 parse their respective descriptor types.
6456    * Arg for all of these is the upb selector for this field. */
6457 #define T(type) OP_PARSE_ ## type = UPB_DESCRIPTOR_TYPE_ ## type
6458   T(DOUBLE), T(FLOAT), T(INT64), T(UINT64), T(INT32), T(FIXED64), T(FIXED32),
6459   T(BOOL), T(UINT32), T(SFIXED32), T(SFIXED64), T(SINT32), T(SINT64),
6460 #undef T
6461   OP_STARTMSG       = 9,   /* No arg. */
6462   OP_ENDMSG         = 10,  /* No arg. */
6463   OP_STARTSEQ       = 11,
6464   OP_ENDSEQ         = 12,
6465   OP_STARTSUBMSG    = 14,
6466   OP_ENDSUBMSG      = 19,
6467   OP_STARTSTR       = 20,
6468   OP_STRING         = 21,
6469   OP_ENDSTR         = 22,
6470 
6471   OP_PUSHTAGDELIM   = 23,  /* No arg. */
6472   OP_PUSHLENDELIM   = 24,  /* No arg. */
6473   OP_POP            = 25,  /* No arg. */
6474   OP_SETDELIM       = 26,  /* No arg. */
6475   OP_SETBIGGROUPNUM = 27,  /* two words:
6476                             *   | unused (24)     | opc (8) |
6477                             *   |        groupnum (32)      | */
6478   OP_CHECKDELIM     = 28,
6479   OP_CALL           = 29,
6480   OP_RET            = 30,
6481   OP_BRANCH         = 31,
6482 
6483   /* Different opcodes depending on how many bytes expected. */
6484   OP_TAG1           = 32,  /* | match tag (16) | jump target (8) | opc (8) | */
6485   OP_TAG2           = 33,  /* | match tag (16) | jump target (8) | opc (8) | */
6486   OP_TAGN           = 34,  /* three words: */
6487                            /*   | unused (16) | jump target(8) | opc (8) | */
6488                            /*   |           match tag 1 (32)             | */
6489                            /*   |           match tag 2 (32)             | */
6490 
6491   OP_SETDISPATCH    = 35,  /* N words: */
6492                            /*   | unused (24)         | opc | */
6493                            /*   | upb_inttable* (32 or 64)  | */
6494 
6495   OP_DISPATCH       = 36,  /* No arg. */
6496 
6497   OP_HALT           = 37   /* No arg. */
6498 } opcode;
6499 
6500 #define OP_MAX OP_HALT
6501 
6502 UPB_INLINE opcode getop(uint32_t instr) { return (opcode)(instr & 0xff); }
6503 
6504 struct upb_pbcodecache {
6505   upb_arena *arena;
6506   upb_handlercache *dest;
6507   bool allow_jit;
6508   bool lazy;
6509 
6510   /* Array of mgroups. */
6511   upb_inttable groups;
6512 };
6513 
6514 /* Method group; represents a set of decoder methods that had their code
6515  * emitted together.  Immutable once created.  */
6516 typedef struct {
6517   /* Maps upb_msgdef/upb_handlers -> upb_pbdecodermethod.  Owned by us.
6518    *
6519    * Ideally this would be on pbcodecache (if we were actually caching code).
6520    * Right now we don't actually cache anything, which is wasteful. */
6521   upb_inttable methods;
6522 
6523   /* The bytecode for our methods, if any exists.  Owned by us. */
6524   uint32_t *bytecode;
6525   uint32_t *bytecode_end;
6526 
6527 #ifdef UPB_USE_JIT_X64
6528   /* JIT-generated machine code, if any. */
6529   upb_string_handlerfunc *jit_code;
6530   /* The size of the jit_code (required to munmap()). */
6531   size_t jit_size;
6532   char *debug_info;
6533   void *dl;
6534 #endif
6535 } mgroup;
6536 
6537 /* The maximum that any submessages can be nested.  Matches proto2's limit.
6538  * This specifies the size of the decoder's statically-sized array and therefore
6539  * setting it high will cause the upb::pb::Decoder object to be larger.
6540  *
6541  * If necessary we can add a runtime-settable property to Decoder that allow
6542  * this to be larger than the compile-time setting, but this would add
6543  * complexity, particularly since we would have to decide how/if to give users
6544  * the ability to set a custom memory allocation function. */
6545 #define UPB_DECODER_MAX_NESTING 64
6546 
6547 /* Internal-only struct used by the decoder. */
6548 typedef struct {
6549   /* Space optimization note: we store two pointers here that the JIT
6550    * doesn't need at all; the upb_handlers* inside the sink and
6551    * the dispatch table pointer.  We can optimze so that the JIT uses
6552    * smaller stack frames than the interpreter.  The only thing we need
6553    * to guarantee is that the fallback routines can find end_ofs. */
6554   upb_sink sink;
6555 
6556   /* The absolute stream offset of the end-of-frame delimiter.
6557    * Non-delimited frames (groups and non-packed repeated fields) reuse the
6558    * delimiter of their parent, even though the frame may not end there.
6559    *
6560    * NOTE: the JIT stores a slightly different value here for non-top frames.
6561    * It stores the value relative to the end of the enclosed message.  But the
6562    * top frame is still stored the same way, which is important for ensuring
6563    * that calls from the JIT into C work correctly. */
6564   uint64_t end_ofs;
6565   const uint32_t *base;
6566 
6567   /* 0 indicates a length-delimited field.
6568    * A positive number indicates a known group.
6569    * A negative number indicates an unknown group. */
6570   int32_t groupnum;
6571   upb_inttable *dispatch;  /* Not used by the JIT. */
6572 } upb_pbdecoder_frame;
6573 
6574 struct upb_pbdecodermethod {
6575   /* While compiling, the base is relative in "ofs", after compiling it is
6576    * absolute in "ptr". */
6577   union {
6578     uint32_t ofs;     /* PC offset of method. */
6579     void *ptr;        /* Pointer to bytecode or machine code for this method. */
6580   } code_base;
6581 
6582   /* The decoder method group to which this method belongs. */
6583   const mgroup *group;
6584 
6585   /* Whether this method is native code or bytecode. */
6586   bool is_native_;
6587 
6588   /* The handler one calls to invoke this method. */
6589   upb_byteshandler input_handler_;
6590 
6591   /* The destination handlers this method is bound to.  We own a ref. */
6592   const upb_handlers *dest_handlers_;
6593 
6594   /* Dispatch table -- used by both bytecode decoder and JIT when encountering a
6595    * field number that wasn't the one we were expecting to see.  See
6596    * decoder.int.h for the layout of this table. */
6597   upb_inttable dispatch;
6598 };
6599 
6600 struct upb_pbdecoder {
6601   upb_arena *arena;
6602 
6603   /* Our input sink. */
6604   upb_bytessink input_;
6605 
6606   /* The decoder method we are parsing with (owned). */
6607   const upb_pbdecodermethod *method_;
6608 
6609   size_t call_len;
6610   const uint32_t *pc, *last;
6611 
6612   /* Current input buffer and its stream offset. */
6613   const char *buf, *ptr, *end, *checkpoint;
6614 
6615   /* End of the delimited region, relative to ptr, NULL if not in this buf. */
6616   const char *delim_end;
6617 
6618   /* End of the delimited region, relative to ptr, end if not in this buf. */
6619   const char *data_end;
6620 
6621   /* Overall stream offset of "buf." */
6622   uint64_t bufstart_ofs;
6623 
6624   /* Buffer for residual bytes not parsed from the previous buffer. */
6625   char residual[UPB_DECODER_MAX_RESIDUAL_BYTES];
6626   char *residual_end;
6627 
6628   /* Bytes of data that should be discarded from the input beore we start
6629    * parsing again.  We set this when we internally determine that we can
6630    * safely skip the next N bytes, but this region extends past the current
6631    * user buffer. */
6632   size_t skip;
6633 
6634   /* Stores the user buffer passed to our decode function. */
6635   const char *buf_param;
6636   size_t size_param;
6637   const upb_bufhandle *handle;
6638 
6639   /* Our internal stack. */
6640   upb_pbdecoder_frame *stack, *top, *limit;
6641   const uint32_t **callstack;
6642   size_t stack_size;
6643 
6644   upb_status *status;
6645 
6646 #ifdef UPB_USE_JIT_X64
6647   /* Used momentarily by the generated code to store a value while a user
6648    * function is called. */
6649   uint32_t tmp_len;
6650 
6651   const void *saved_rsp;
6652 #endif
6653 };
6654 
6655 /* Decoder entry points; used as handlers. */
6656 void *upb_pbdecoder_startbc(void *closure, const void *pc, size_t size_hint);
6657 void *upb_pbdecoder_startjit(void *closure, const void *hd, size_t size_hint);
6658 size_t upb_pbdecoder_decode(void *closure, const void *hd, const char *buf,
6659                             size_t size, const upb_bufhandle *handle);
6660 bool upb_pbdecoder_end(void *closure, const void *handler_data);
6661 
6662 /* Decoder-internal functions that the JIT calls to handle fallback paths. */
6663 int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf,
6664                              size_t size, const upb_bufhandle *handle);
6665 size_t upb_pbdecoder_suspend(upb_pbdecoder *d);
6666 int32_t upb_pbdecoder_skipunknown(upb_pbdecoder *d, int32_t fieldnum,
6667                                   uint8_t wire_type);
6668 int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d, uint64_t expected);
6669 int32_t upb_pbdecoder_decode_varint_slow(upb_pbdecoder *d, uint64_t *u64);
6670 int32_t upb_pbdecoder_decode_f32(upb_pbdecoder *d, uint32_t *u32);
6671 int32_t upb_pbdecoder_decode_f64(upb_pbdecoder *d, uint64_t *u64);
6672 void upb_pbdecoder_seterr(upb_pbdecoder *d, const char *msg);
6673 
6674 /* Error messages that are shared between the bytecode and JIT decoders. */
6675 extern const char *kPbDecoderStackOverflow;
6676 extern const char *kPbDecoderSubmessageTooLong;
6677 
6678 /* Access to decoderplan members needed by the decoder. */
6679 const char *upb_pbdecoder_getopname(unsigned int op);
6680 
6681 /* JIT codegen entry point. */
6682 void upb_pbdecoder_jit(mgroup *group);
6683 void upb_pbdecoder_freejit(mgroup *group);
6684 
6685 /* A special label that means "do field dispatch for this message and branch to
6686  * wherever that takes you." */
6687 #define LABEL_DISPATCH 0
6688 
6689 /* A special slot in the dispatch table that stores the epilogue (ENDMSG and/or
6690  * RET) for branching to when we find an appropriate ENDGROUP tag. */
6691 #define DISPATCH_ENDMSG 0
6692 
6693 /* It's important to use this invalid wire type instead of 0 (which is a valid
6694  * wire type). */
6695 #define NO_WIRE_TYPE 0xff
6696 
6697 /* The dispatch table layout is:
6698  *   [field number] -> [ 48-bit offset ][ 8-bit wt2 ][ 8-bit wt1 ]
6699  *
6700  * If wt1 matches, jump to the 48-bit offset.  If wt2 matches, lookup
6701  * (UPB_MAX_FIELDNUMBER + fieldnum) and jump there.
6702  *
6703  * We need two wire types because of packed/non-packed compatibility.  A
6704  * primitive repeated field can use either wire type and be valid.  While we
6705  * could key the table on fieldnum+wiretype, the table would be 8x sparser.
6706  *
6707  * Storing two wire types in the primary value allows us to quickly rule out
6708  * the second wire type without needing to do a separate lookup (this case is
6709  * less common than an unknown field). */
6710 UPB_INLINE uint64_t upb_pbdecoder_packdispatch(uint64_t ofs, uint8_t wt1,
6711                                                uint8_t wt2) {
6712   return (ofs << 16) | (wt2 << 8) | wt1;
6713 }
6714 
6715 UPB_INLINE void upb_pbdecoder_unpackdispatch(uint64_t dispatch, uint64_t *ofs,
6716                                              uint8_t *wt1, uint8_t *wt2) {
6717   *wt1 = (uint8_t)dispatch;
6718   *wt2 = (uint8_t)(dispatch >> 8);
6719   *ofs = dispatch >> 16;
6720 }
6721 
6722 /* All of the functions in decoder.c that return int32_t return values according
6723  * to the following scheme:
6724  *   1. negative values indicate a return code from the following list.
6725  *   2. positive values indicate that error or end of buffer was hit, and
6726  *      that the decode function should immediately return the given value
6727  *      (the decoder state has already been suspended and is ready to be
6728  *      resumed). */
6729 #define DECODE_OK -1
6730 #define DECODE_MISMATCH -2  /* Used only from checktag_slow(). */
6731 #define DECODE_ENDGROUP -3  /* Used only from checkunknown(). */
6732 
6733 #define CHECK_RETURN(x) { int32_t ret = x; if (ret >= 0) return ret; }
6734 
6735 #endif  /* UPB_DECODER_INT_H_ */
6736 /*
6737 ** A number of routines for varint manipulation (we keep them all around to
6738 ** have multiple approaches available for benchmarking).
6739 */
6740 
6741 #ifndef UPB_VARINT_DECODER_H_
6742 #define UPB_VARINT_DECODER_H_
6743 
6744 #include <assert.h>
6745 #include <stdint.h>
6746 #include <string.h>
6747 
6748 #ifdef __cplusplus
6749 extern "C" {
6750 #endif
6751 
6752 #define UPB_MAX_WIRE_TYPE 5
6753 
6754 /* The maximum number of bytes that it takes to encode a 64-bit varint. */
6755 #define UPB_PB_VARINT_MAX_LEN 10
6756 
6757 /* Array of the "native" (ie. non-packed-repeated) wire type for the given a
6758  * descriptor type (upb_descriptortype_t). */
6759 extern const uint8_t upb_pb_native_wire_types[];
6760 
6761 UPB_INLINE uint64_t byteswap64(uint64_t val)
6762 {
6763   return ((((val) & 0xff00000000000000ull) >> 56)
6764     | (((val) & 0x00ff000000000000ull) >> 40)
6765     | (((val) & 0x0000ff0000000000ull) >> 24)
6766     | (((val) & 0x000000ff00000000ull) >> 8)
6767     | (((val) & 0x00000000ff000000ull) << 8)
6768     | (((val) & 0x0000000000ff0000ull) << 24)
6769     | (((val) & 0x000000000000ff00ull) << 40)
6770     | (((val) & 0x00000000000000ffull) << 56));
6771 }
6772 
6773 /* Zig-zag encoding/decoding **************************************************/
6774 
6775 UPB_INLINE int32_t upb_zzdec_32(uint32_t n) {
6776   return (n >> 1) ^ -(int32_t)(n & 1);
6777 }
6778 UPB_INLINE int64_t upb_zzdec_64(uint64_t n) {
6779   return (n >> 1) ^ -(int64_t)(n & 1);
6780 }
6781 UPB_INLINE uint32_t upb_zzenc_32(int32_t n) { return (n << 1) ^ (n >> 31); }
6782 UPB_INLINE uint64_t upb_zzenc_64(int64_t n) { return (n << 1) ^ (n >> 63); }
6783 
6784 /* Decoding *******************************************************************/
6785 
6786 /* All decoding functions return this struct by value. */
6787 typedef struct {
6788   const char *p;  /* NULL if the varint was unterminated. */
6789   uint64_t val;
6790 } upb_decoderet;
6791 
6792 UPB_INLINE upb_decoderet upb_decoderet_make(const char *p, uint64_t val) {
6793   upb_decoderet ret;
6794   ret.p = p;
6795   ret.val = val;
6796   return ret;
6797 }
6798 
6799 upb_decoderet upb_vdecode_max8_branch32(upb_decoderet r);
6800 upb_decoderet upb_vdecode_max8_branch64(upb_decoderet r);
6801 
6802 /* Template for a function that checks the first two bytes with branching
6803  * and dispatches 2-10 bytes with a separate function.  Note that this may read
6804  * up to 10 bytes, so it must not be used unless there are at least ten bytes
6805  * left in the buffer! */
6806 #define UPB_VARINT_DECODER_CHECK2(name, decode_max8_function)                  \
6807 UPB_INLINE upb_decoderet upb_vdecode_check2_ ## name(const char *_p) {         \
6808   uint8_t *p = (uint8_t*)_p;                                                   \
6809   upb_decoderet r;                                                             \
6810   if ((*p & 0x80) == 0) {                                                      \
6811   /* Common case: one-byte varint. */                                          \
6812     return upb_decoderet_make(_p + 1, *p & 0x7fU);                             \
6813   }                                                                            \
6814   r = upb_decoderet_make(_p + 2, (*p & 0x7fU) | ((*(p + 1) & 0x7fU) << 7));    \
6815   if ((*(p + 1) & 0x80) == 0) {                                                \
6816     /* Two-byte varint. */                                                     \
6817     return r;                                                                  \
6818   }                                                                            \
6819   /* Longer varint, fallback to out-of-line function. */                       \
6820   return decode_max8_function(r);                                              \
6821 }
6822 
6823 UPB_VARINT_DECODER_CHECK2(branch32, upb_vdecode_max8_branch32)
6824 UPB_VARINT_DECODER_CHECK2(branch64, upb_vdecode_max8_branch64)
6825 #undef UPB_VARINT_DECODER_CHECK2
6826 
6827 /* Our canonical functions for decoding varints, based on the currently
6828  * favored best-performing implementations. */
6829 UPB_INLINE upb_decoderet upb_vdecode_fast(const char *p) {
6830   if (sizeof(long) == 8)
6831     return upb_vdecode_check2_branch64(p);
6832   else
6833     return upb_vdecode_check2_branch32(p);
6834 }
6835 
6836 
6837 /* Encoding *******************************************************************/
6838 
6839 UPB_INLINE int upb_value_size(uint64_t val) {
6840 #ifdef __GNUC__
6841   int high_bit = 63 - __builtin_clzll(val);  /* 0-based, undef if val == 0. */
6842 #else
6843   int high_bit = 0;
6844   uint64_t tmp = val;
6845   while(tmp >>= 1) high_bit++;
6846 #endif
6847   return val == 0 ? 1 : high_bit / 8 + 1;
6848 }
6849 
6850 /* Encodes a 64-bit varint into buf (which must be >=UPB_PB_VARINT_MAX_LEN
6851  * bytes long), returning how many bytes were used.
6852  *
6853  * TODO: benchmark and optimize if necessary. */
6854 UPB_INLINE size_t upb_vencode64(uint64_t val, char *buf) {
6855   size_t i;
6856   if (val == 0) { buf[0] = 0; return 1; }
6857   i = 0;
6858   while (val) {
6859     uint8_t byte = val & 0x7fU;
6860     val >>= 7;
6861     if (val) byte |= 0x80U;
6862     buf[i++] = byte;
6863   }
6864   return i;
6865 }
6866 
6867 UPB_INLINE size_t upb_varint_size(uint64_t val) {
6868   char buf[UPB_PB_VARINT_MAX_LEN];
6869   return upb_vencode64(val, buf);
6870 }
6871 
6872 /* Encodes a 32-bit varint, *not* sign-extended. */
6873 UPB_INLINE uint64_t upb_vencode32(uint32_t val) {
6874   char buf[UPB_PB_VARINT_MAX_LEN];
6875   size_t bytes = upb_vencode64(val, buf);
6876   uint64_t ret = 0;
6877   UPB_ASSERT(bytes <= 5);
6878   memcpy(&ret, buf, bytes);
6879 #ifdef UPB_BIG_ENDIAN
6880   ret = byteswap64(ret);
6881 #endif
6882   UPB_ASSERT(ret <= 0xffffffffffU);
6883   return ret;
6884 }
6885 
6886 #ifdef __cplusplus
6887 }  /* extern "C" */
6888 #endif
6889 
6890 #endif  /* UPB_VARINT_DECODER_H_ */
6891 /*
6892 ** upb::pb::Encoder (upb_pb_encoder)
6893 **
6894 ** Implements a set of upb_handlers that write protobuf data to the binary wire
6895 ** format.
6896 **
6897 ** This encoder implementation does not have any access to any out-of-band or
6898 ** precomputed lengths for submessages, so it must buffer submessages internally
6899 ** before it can emit the first byte.
6900 */
6901 
6902 #ifndef UPB_ENCODER_H_
6903 #define UPB_ENCODER_H_
6904 
6905 
6906 #ifdef __cplusplus
6907 namespace upb {
6908 namespace pb {
6909 class EncoderPtr;
6910 }  /* namespace pb */
6911 }  /* namespace upb */
6912 #endif
6913 
6914 #define UPB_PBENCODER_MAX_NESTING 100
6915 
6916 /* upb_pb_encoder *************************************************************/
6917 
6918 /* Preallocation hint: decoder won't allocate more bytes than this when first
6919  * constructed.  This hint may be an overestimate for some build configurations.
6920  * But if the decoder library is upgraded without recompiling the application,
6921  * it may be an underestimate. */
6922 #define UPB_PB_ENCODER_SIZE 784
6923 
6924 struct upb_pb_encoder;
6925 typedef struct upb_pb_encoder upb_pb_encoder;
6926 
6927 #ifdef __cplusplus
6928 extern "C" {
6929 #endif
6930 
6931 upb_sink upb_pb_encoder_input(upb_pb_encoder *p);
6932 upb_pb_encoder* upb_pb_encoder_create(upb_arena* a, const upb_handlers* h,
6933                                       upb_bytessink output);
6934 
6935 /* Lazily builds and caches handlers that will push encoded data to a bytessink.
6936  * Any msgdef objects used with this object must outlive it. */
6937 upb_handlercache *upb_pb_encoder_newcache();
6938 
6939 #ifdef __cplusplus
6940 }  /* extern "C" { */
6941 
6942 class upb::pb::EncoderPtr {
6943  public:
6944   EncoderPtr(upb_pb_encoder* ptr) : ptr_(ptr) {}
6945 
6946   upb_pb_encoder* ptr() { return ptr_; }
6947 
6948   /* Creates a new encoder in the given environment.  The Handlers must have
6949    * come from NewHandlers() below. */
6950   static EncoderPtr Create(Arena* arena, const Handlers* handlers,
6951                            BytesSink output) {
6952     return EncoderPtr(
6953         upb_pb_encoder_create(arena->ptr(), handlers, output.sink()));
6954   }
6955 
6956   /* The input to the encoder. */
6957   upb::Sink input() { return upb_pb_encoder_input(ptr()); }
6958 
6959   /* Creates a new set of handlers for this MessageDef. */
6960   static HandlerCache NewCache() {
6961     return HandlerCache(upb_pb_encoder_newcache());
6962   }
6963 
6964   static const size_t kSize = UPB_PB_ENCODER_SIZE;
6965 
6966  private:
6967   upb_pb_encoder* ptr_;
6968 };
6969 
6970 #endif  /* __cplusplus */
6971 
6972 #endif  /* UPB_ENCODER_H_ */
6973 /*
6974 ** upb::pb::TextPrinter (upb_textprinter)
6975 **
6976 ** Handlers for writing to protobuf text format.
6977 */
6978 
6979 #ifndef UPB_TEXT_H_
6980 #define UPB_TEXT_H_
6981 
6982 
6983 #ifdef __cplusplus
6984 namespace upb {
6985 namespace pb {
6986 class TextPrinterPtr;
6987 }  /* namespace pb */
6988 }  /* namespace upb */
6989 #endif
6990 
6991 /* upb_textprinter ************************************************************/
6992 
6993 struct upb_textprinter;
6994 typedef struct upb_textprinter upb_textprinter;
6995 
6996 #ifdef __cplusplus
6997 extern "C" {
6998 #endif
6999 
7000 /* C API. */
7001 upb_textprinter *upb_textprinter_create(upb_arena *arena, const upb_handlers *h,
7002                                         upb_bytessink output);
7003 void upb_textprinter_setsingleline(upb_textprinter *p, bool single_line);
7004 upb_sink upb_textprinter_input(upb_textprinter *p);
7005 upb_handlercache *upb_textprinter_newcache();
7006 
7007 #ifdef __cplusplus
7008 }  /* extern "C" */
7009 
7010 class upb::pb::TextPrinterPtr {
7011  public:
7012   TextPrinterPtr(upb_textprinter* ptr) : ptr_(ptr) {}
7013 
7014   /* The given handlers must have come from NewHandlers().  It must outlive the
7015    * TextPrinter. */
7016   static TextPrinterPtr Create(Arena *arena, upb::HandlersPtr *handlers,
7017                                BytesSink output) {
7018     return TextPrinterPtr(
7019         upb_textprinter_create(arena->ptr(), handlers->ptr(), output.sink()));
7020   }
7021 
7022   void SetSingleLineMode(bool single_line) {
7023     upb_textprinter_setsingleline(ptr_, single_line);
7024   }
7025 
7026   Sink input() { return upb_textprinter_input(ptr_); }
7027 
7028   /* If handler caching becomes a requirement we can add a code cache as in
7029    * decoder.h */
7030   static HandlerCache NewCache() {
7031     return HandlerCache(upb_textprinter_newcache());
7032   }
7033 
7034  private:
7035   upb_textprinter* ptr_;
7036 };
7037 
7038 #endif
7039 
7040 #endif  /* UPB_TEXT_H_ */
7041 /*
7042 ** upb::json::Parser (upb_json_parser)
7043 **
7044 ** Parses JSON according to a specific schema.
7045 ** Support for parsing arbitrary JSON (schema-less) will be added later.
7046 */
7047 
7048 #ifndef UPB_JSON_PARSER_H_
7049 #define UPB_JSON_PARSER_H_
7050 
7051 
7052 #ifdef __cplusplus
7053 namespace upb {
7054 namespace json {
7055 class CodeCache;
7056 class ParserPtr;
7057 class ParserMethodPtr;
7058 }  /* namespace json */
7059 }  /* namespace upb */
7060 #endif
7061 
7062 /* upb_json_parsermethod ******************************************************/
7063 
7064 struct upb_json_parsermethod;
7065 typedef struct upb_json_parsermethod upb_json_parsermethod;
7066 
7067 #ifdef __cplusplus
7068 extern "C" {
7069 #endif
7070 
7071 const upb_byteshandler* upb_json_parsermethod_inputhandler(
7072     const upb_json_parsermethod* m);
7073 
7074 #ifdef __cplusplus
7075 }  /* extern "C" */
7076 
7077 class upb::json::ParserMethodPtr {
7078  public:
7079   ParserMethodPtr() : ptr_(nullptr) {}
7080   ParserMethodPtr(const upb_json_parsermethod* ptr) : ptr_(ptr) {}
7081 
7082   const upb_json_parsermethod* ptr() const { return ptr_; }
7083 
7084   const BytesHandler* input_handler() const {
7085     return upb_json_parsermethod_inputhandler(ptr());
7086   }
7087 
7088  private:
7089   const upb_json_parsermethod* ptr_;
7090 };
7091 
7092 #endif  /* __cplusplus */
7093 
7094 /* upb_json_parser ************************************************************/
7095 
7096 /* Preallocation hint: parser won't allocate more bytes than this when first
7097  * constructed.  This hint may be an overestimate for some build configurations.
7098  * But if the parser library is upgraded without recompiling the application,
7099  * it may be an underestimate. */
7100 #define UPB_JSON_PARSER_SIZE 5712
7101 
7102 struct upb_json_parser;
7103 typedef struct upb_json_parser upb_json_parser;
7104 
7105 #ifdef __cplusplus
7106 extern "C" {
7107 #endif
7108 
7109 upb_json_parser* upb_json_parser_create(upb_arena* a,
7110                                         const upb_json_parsermethod* m,
7111                                         const upb_symtab* symtab,
7112                                         upb_sink output,
7113                                         upb_status *status,
7114                                         bool ignore_json_unknown);
7115 upb_bytessink upb_json_parser_input(upb_json_parser* p);
7116 
7117 #ifdef __cplusplus
7118 }  /* extern "C" */
7119 
7120 /* Parses an incoming BytesStream, pushing the results to the destination
7121  * sink. */
7122 class upb::json::ParserPtr {
7123  public:
7124   ParserPtr(upb_json_parser* ptr) : ptr_(ptr) {}
7125 
7126   static ParserPtr Create(Arena* arena, ParserMethodPtr method,
7127                           SymbolTable* symtab, Sink output, Status* status,
7128                           bool ignore_json_unknown) {
7129     upb_symtab* symtab_ptr = symtab ? symtab->ptr() : nullptr;
7130     return ParserPtr(upb_json_parser_create(
7131         arena->ptr(), method.ptr(), symtab_ptr, output.sink(), status->ptr(),
7132         ignore_json_unknown));
7133   }
7134 
7135   BytesSink input() { return upb_json_parser_input(ptr_); }
7136 
7137  private:
7138   upb_json_parser* ptr_;
7139 };
7140 
7141 #endif  /* __cplusplus */
7142 
7143 /* upb_json_codecache *********************************************************/
7144 
7145 /* Lazily builds and caches decoder methods that will push data to the given
7146  * handlers.  The upb_symtab object(s) must outlive this object. */
7147 
7148 struct upb_json_codecache;
7149 typedef struct upb_json_codecache upb_json_codecache;
7150 
7151 #ifdef __cplusplus
7152 extern "C" {
7153 #endif
7154 
7155 upb_json_codecache *upb_json_codecache_new();
7156 void upb_json_codecache_free(upb_json_codecache *cache);
7157 const upb_json_parsermethod* upb_json_codecache_get(upb_json_codecache* cache,
7158                                                     const upb_msgdef* md);
7159 
7160 #ifdef __cplusplus
7161 }  /* extern "C" */
7162 
7163 class upb::json::CodeCache {
7164  public:
7165   CodeCache() : ptr_(upb_json_codecache_new(), upb_json_codecache_free) {}
7166 
7167   /* Returns a DecoderMethod that can push data to the given handlers.
7168    * If a suitable method already exists, it will be returned from the cache. */
7169   ParserMethodPtr Get(MessageDefPtr md) {
7170     return upb_json_codecache_get(ptr_.get(), md.ptr());
7171   }
7172 
7173  private:
7174   std::unique_ptr<upb_json_codecache, decltype(&upb_json_codecache_free)> ptr_;
7175 };
7176 
7177 #endif
7178 
7179 #endif  /* UPB_JSON_PARSER_H_ */
7180 /*
7181 ** upb::json::Printer
7182 **
7183 ** Handlers that emit JSON according to a specific protobuf schema.
7184 */
7185 
7186 #ifndef UPB_JSON_TYPED_PRINTER_H_
7187 #define UPB_JSON_TYPED_PRINTER_H_
7188 
7189 
7190 #ifdef __cplusplus
7191 namespace upb {
7192 namespace json {
7193 class PrinterPtr;
7194 }  /* namespace json */
7195 }  /* namespace upb */
7196 #endif
7197 
7198 /* upb_json_printer ***********************************************************/
7199 
7200 #define UPB_JSON_PRINTER_SIZE 192
7201 
7202 struct upb_json_printer;
7203 typedef struct upb_json_printer upb_json_printer;
7204 
7205 #ifdef __cplusplus
7206 extern "C" {
7207 #endif
7208 
7209 /* Native C API. */
7210 upb_json_printer *upb_json_printer_create(upb_arena *a, const upb_handlers *h,
7211                                           upb_bytessink output);
7212 upb_sink upb_json_printer_input(upb_json_printer *p);
7213 const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md,
7214                                                  bool preserve_fieldnames,
7215                                                  const void *owner);
7216 
7217 /* Lazily builds and caches handlers that will push encoded data to a bytessink.
7218  * Any msgdef objects used with this object must outlive it. */
7219 upb_handlercache *upb_json_printer_newcache(bool preserve_proto_fieldnames);
7220 
7221 #ifdef __cplusplus
7222 }  /* extern "C" */
7223 
7224 /* Prints an incoming stream of data to a BytesSink in JSON format. */
7225 class upb::json::PrinterPtr {
7226  public:
7227   PrinterPtr(upb_json_printer* ptr) : ptr_(ptr) {}
7228 
7229   static PrinterPtr Create(Arena *arena, const upb::Handlers *handlers,
7230                            BytesSink output) {
7231     return PrinterPtr(
7232         upb_json_printer_create(arena->ptr(), handlers, output.sink()));
7233   }
7234 
7235   /* The input to the printer. */
7236   Sink input() { return upb_json_printer_input(ptr_); }
7237 
7238   static const size_t kSize = UPB_JSON_PRINTER_SIZE;
7239 
7240   static HandlerCache NewCache(bool preserve_proto_fieldnames) {
7241     return upb_json_printer_newcache(preserve_proto_fieldnames);
7242   }
7243 
7244  private:
7245   upb_json_printer* ptr_;
7246 };
7247 
7248 #endif  /* __cplusplus */
7249 
7250 #endif  /* UPB_JSON_TYPED_PRINTER_H_ */
7251 
7252 #undef UPB_SIZE
7253 #undef UPB_FIELD_AT
7254 #undef UPB_READ_ONEOF
7255 #undef UPB_WRITE_ONEOF
7256