Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: third_party/protobuf/php/ext/google/protobuf/upb.h

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Amalgamated source file 1 // Amalgamated source file
2 /* 2 /*
3 ** Defs are upb's internal representation of the constructs that can appear 3 ** Defs are upb's internal representation of the constructs that can appear
4 ** in a .proto file: 4 ** in a .proto file:
5 ** 5 **
6 ** - upb::MessageDef (upb_msgdef): describes a "message" construct. 6 ** - upb::MessageDef (upb_msgdef): describes a "message" construct.
7 ** - upb::FieldDef (upb_fielddef): describes a message field. 7 ** - upb::FieldDef (upb_fielddef): describes a message field.
8 ** - upb::FileDef (upb_filedef): describes a .proto file and its defs.
8 ** - upb::EnumDef (upb_enumdef): describes an enum. 9 ** - upb::EnumDef (upb_enumdef): describes an enum.
9 ** - upb::OneofDef (upb_oneofdef): describes a oneof. 10 ** - upb::OneofDef (upb_oneofdef): describes a oneof.
10 ** - upb::Def (upb_def): base class of all the others. 11 ** - upb::Def (upb_def): base class of all the others.
11 ** 12 **
12 ** TODO: definitions of services. 13 ** TODO: definitions of services.
13 ** 14 **
14 ** Like upb_refcounted objects, defs are mutable only until frozen, and are 15 ** Like upb_refcounted objects, defs are mutable only until frozen, and are
15 ** only thread-safe once frozen. 16 ** only thread-safe once frozen.
16 ** 17 **
17 ** This is a mixed C/C++ interface that offers a full API to both languages. 18 ** This is a mixed C/C++ interface that offers a full API to both languages.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 ** store pointers or integers of at least 32 bits (upb isn't really useful on 55 ** store pointers or integers of at least 32 bits (upb isn't really useful on
55 ** systems where sizeof(void*) < 4). 56 ** systems where sizeof(void*) < 4).
56 ** 57 **
57 ** The table must be homogenous (all values of the same type). In debug 58 ** The table must be homogenous (all values of the same type). In debug
58 ** mode, we check this on insert and lookup. 59 ** mode, we check this on insert and lookup.
59 */ 60 */
60 61
61 #ifndef UPB_TABLE_H_ 62 #ifndef UPB_TABLE_H_
62 #define UPB_TABLE_H_ 63 #define UPB_TABLE_H_
63 64
64 #include <assert.h> 65 // php.h intentionally defined NDEBUG. We have to define this macro in order to
66 // be used together with php.h
67 #ifndef NDEBUG
68 #define NDEBUG
69 #endif
70
65 #include <stdint.h> 71 #include <stdint.h>
66 #include <string.h> 72 #include <string.h>
67 /* 73 /*
68 ** This file contains shared definitions that are widely used across upb. 74 ** This file contains shared definitions that are widely used across upb.
69 ** 75 **
70 ** This is a mixed C/C++ interface that offers a full API to both languages. 76 ** This is a mixed C/C++ interface that offers a full API to both languages.
71 ** See the top-level README for more information. 77 ** See the top-level README for more information.
72 */ 78 */
73 79
74 #ifndef UPB_H_ 80 #ifndef UPB_H_
75 #define UPB_H_ 81 #define UPB_H_
76 82
77 #include <assert.h> 83 #include <assert.h>
78 #include <stdarg.h> 84 #include <stdarg.h>
79 #include <stdbool.h> 85 #include <stdbool.h>
80 #include <stddef.h> 86 #include <stddef.h>
81 87
88 #ifdef __cplusplus
89 namespace upb {
90 class Allocator;
91 class Arena;
92 class Environment;
93 class ErrorSpace;
94 class Status;
95 template <int N> class InlinedArena;
96 template <int N> class InlinedEnvironment;
97 }
98 #endif
99
82 /* UPB_INLINE: inline if possible, emit standalone code if required. */ 100 /* UPB_INLINE: inline if possible, emit standalone code if required. */
83 #ifdef __cplusplus 101 #ifdef __cplusplus
84 #define UPB_INLINE inline 102 #define UPB_INLINE inline
85 #elif defined (__GNUC__) 103 #elif defined (__GNUC__)
86 #define UPB_INLINE static __inline__ 104 #define UPB_INLINE static __inline__
87 #else 105 #else
88 #define UPB_INLINE static 106 #define UPB_INLINE static
89 #endif 107 #endif
90 108
91 /* Define UPB_BIG_ENDIAN manually if you're on big endian and your compiler 109 /* Define UPB_BIG_ENDIAN manually if you're on big endian and your compiler
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 #define UPB_DISALLOW_COPY_AND_ASSIGN(class_name) \ 157 #define UPB_DISALLOW_COPY_AND_ASSIGN(class_name) \
140 class_name(const class_name&) = delete; \ 158 class_name(const class_name&) = delete; \
141 void operator=(const class_name&) = delete; 159 void operator=(const class_name&) = delete;
142 #define UPB_DISALLOW_POD_OPS(class_name, full_class_name) \ 160 #define UPB_DISALLOW_POD_OPS(class_name, full_class_name) \
143 class_name() = delete; \ 161 class_name() = delete; \
144 ~class_name() = delete; \ 162 ~class_name() = delete; \
145 UPB_DISALLOW_COPY_AND_ASSIGN(class_name) 163 UPB_DISALLOW_COPY_AND_ASSIGN(class_name)
146 #define UPB_ASSERT_STDLAYOUT(type) \ 164 #define UPB_ASSERT_STDLAYOUT(type) \
147 static_assert(std::is_standard_layout<type>::value, \ 165 static_assert(std::is_standard_layout<type>::value, \
148 #type " must be standard layout"); 166 #type " must be standard layout");
167 #define UPB_FINAL final
149 #else /* !defined(UPB_CXX11) */ 168 #else /* !defined(UPB_CXX11) */
150 #define UPB_DISALLOW_COPY_AND_ASSIGN(class_name) \ 169 #define UPB_DISALLOW_COPY_AND_ASSIGN(class_name) \
151 class_name(const class_name&); \ 170 class_name(const class_name&); \
152 void operator=(const class_name&); 171 void operator=(const class_name&);
153 #define UPB_DISALLOW_POD_OPS(class_name, full_class_name) \ 172 #define UPB_DISALLOW_POD_OPS(class_name, full_class_name) \
154 class_name(); \ 173 class_name(); \
155 ~class_name(); \ 174 ~class_name(); \
156 UPB_DISALLOW_COPY_AND_ASSIGN(class_name) 175 UPB_DISALLOW_COPY_AND_ASSIGN(class_name)
157 #define UPB_ASSERT_STDLAYOUT(type) 176 #define UPB_ASSERT_STDLAYOUT(type)
177 #define UPB_FINAL
158 #endif 178 #endif
159 179
160 /* UPB_DECLARE_TYPE() 180 /* UPB_DECLARE_TYPE()
161 * UPB_DECLARE_DERIVED_TYPE() 181 * UPB_DECLARE_DERIVED_TYPE()
162 * UPB_DECLARE_DERIVED_TYPE2() 182 * UPB_DECLARE_DERIVED_TYPE2()
163 * 183 *
164 * Macros for declaring C and C++ types both, including inheritance. 184 * Macros for declaring C and C++ types both, including inheritance.
165 * The inheritance doesn't use real C++ inheritance, to stay compatible with C. 185 * The inheritance doesn't use real C++ inheritance, to stay compatible with C.
166 * 186 *
167 * These macros also provide upcasts: 187 * These macros also provide upcasts:
(...skipping 18 matching lines...) Expand all
186 #define UPB_PRIVATE_FOR_CPP private: 206 #define UPB_PRIVATE_FOR_CPP private:
187 #define UPB_DECLARE_TYPE(cppname, cname) typedef cppname cname; 207 #define UPB_DECLARE_TYPE(cppname, cname) typedef cppname cname;
188 208
189 #define UPB_DECLARE_DERIVED_TYPE(cppname, cppbase, cname, cbase) \ 209 #define UPB_DECLARE_DERIVED_TYPE(cppname, cppbase, cname, cbase) \
190 UPB_DECLARE_TYPE(cppname, cname) \ 210 UPB_DECLARE_TYPE(cppname, cname) \
191 UPB_C_UPCASTS(cname, cbase) \ 211 UPB_C_UPCASTS(cname, cbase) \
192 namespace upb { \ 212 namespace upb { \
193 template <> \ 213 template <> \
194 class Pointer<cppname> : public PointerBase<cppname, cppbase> { \ 214 class Pointer<cppname> : public PointerBase<cppname, cppbase> { \
195 public: \ 215 public: \
196 explicit Pointer(cppname* ptr) : PointerBase(ptr) {} \ 216 explicit Pointer(cppname* ptr) \
217 : PointerBase<cppname, cppbase>(ptr) {} \
197 }; \ 218 }; \
198 template <> \ 219 template <> \
199 class Pointer<const cppname> \ 220 class Pointer<const cppname> \
200 : public PointerBase<const cppname, const cppbase> { \ 221 : public PointerBase<const cppname, const cppbase> { \
201 public: \ 222 public: \
202 explicit Pointer(const cppname* ptr) : PointerBase(ptr) {} \ 223 explicit Pointer(const cppname* ptr) \
224 : PointerBase<const cppname, const cppbase>(ptr) {} \
203 }; \ 225 }; \
204 } 226 }
205 227
206 #define UPB_DECLARE_DERIVED_TYPE2(cppname, cppbase, cppbase2, cname, cbase, \ 228 #define UPB_DECLARE_DERIVED_TYPE2(cppname, cppbase, cppbase2, cname, cbase, \
207 cbase2) \ 229 cbase2) \
208 UPB_DECLARE_TYPE(cppname, cname) \ 230 UPB_DECLARE_TYPE(cppname, cname) \
209 UPB_C_UPCASTS2(cname, cbase, cbase2) \ 231 UPB_C_UPCASTS2(cname, cbase, cbase2) \
210 namespace upb { \ 232 namespace upb { \
211 template <> \ 233 template <> \
212 class Pointer<cppname> : public PointerBase2<cppname, cppbase, cppbase2> { \ 234 class Pointer<cppname> : public PointerBase2<cppname, cppbase, cppbase2> { \
213 public: \ 235 public: \
214 explicit Pointer(cppname* ptr) : PointerBase2(ptr) {} \ 236 explicit Pointer(cppname* ptr) \
237 : PointerBase2<cppname, cppbase, cppbase2>(ptr) {} \
215 }; \ 238 }; \
216 template <> \ 239 template <> \
217 class Pointer<const cppname> \ 240 class Pointer<const cppname> \
218 : public PointerBase2<const cppname, const cppbase, const cppbase2> { \ 241 : public PointerBase2<const cppname, const cppbase, const cppbase2> { \
219 public: \ 242 public: \
220 explicit Pointer(const cppname* ptr) : PointerBase2(ptr) {} \ 243 explicit Pointer(const cppname* ptr) \
244 : PointerBase2<const cppname, const cppbase, const cppbase2>(ptr) {} \
221 }; \ 245 }; \
222 } 246 }
223 247
224 #else /* !defined(__cplusplus) */ 248 #else /* !defined(__cplusplus) */
225 249
226 #define UPB_BEGIN_EXTERN_C 250 #define UPB_BEGIN_EXTERN_C
227 #define UPB_END_EXTERN_C 251 #define UPB_END_EXTERN_C
228 #define UPB_PRIVATE_FOR_CPP 252 #define UPB_PRIVATE_FOR_CPP
229 #define UPB_DECLARE_TYPE(cppname, cname) \ 253 #define UPB_DECLARE_TYPE(cppname, cname) \
230 struct cname; \ 254 struct cname; \
231 typedef struct cname cname; 255 typedef struct cname cname;
232 #define UPB_DECLARE_DERIVED_TYPE(cppname, cppbase, cname, cbase) \ 256 #define UPB_DECLARE_DERIVED_TYPE(cppname, cppbase, cname, cbase) \
233 UPB_DECLARE_TYPE(cppname, cname) \ 257 UPB_DECLARE_TYPE(cppname, cname) \
234 UPB_C_UPCASTS(cname, cbase) 258 UPB_C_UPCASTS(cname, cbase)
235 #define UPB_DECLARE_DERIVED_TYPE2(cppname, cppbase, cppbase2, \ 259 #define UPB_DECLARE_DERIVED_TYPE2(cppname, cppbase, cppbase2, \
236 cname, cbase, cbase2) \ 260 cname, cbase, cbase2) \
237 UPB_DECLARE_TYPE(cppname, cname) \ 261 UPB_DECLARE_TYPE(cppname, cname) \
238 UPB_C_UPCASTS2(cname, cbase, cbase2) 262 UPB_C_UPCASTS2(cname, cbase, cbase2)
239 263
240 #endif /* defined(__cplusplus) */ 264 #endif /* defined(__cplusplus) */
241 265
242 #define UPB_MAX(x, y) ((x) > (y) ? (x) : (y)) 266 #define UPB_MAX(x, y) ((x) > (y) ? (x) : (y))
243 #define UPB_MIN(x, y) ((x) < (y) ? (x) : (y)) 267 #define UPB_MIN(x, y) ((x) < (y) ? (x) : (y))
244 268
245 #define UPB_UNUSED(var) (void)var 269 #define UPB_UNUSED(var) (void)var
246 270
247 /* For asserting something about a variable when the variable is not used for 271 /* UPB_ASSERT(): in release mode, we use the expression without letting it be
248 * anything else. This prevents "unused variable" warnings when compiling in 272 * evaluated. This prevents "unused variable" warnings. */
249 * debug mode. */ 273 #ifdef NDEBUG
250 #define UPB_ASSERT_VAR(var, predicate) UPB_UNUSED(var); assert(predicate) 274 #define UPB_ASSERT(expr) do {} while (false && (expr))
275 #else
276 #define UPB_ASSERT(expr) assert(expr)
277 #endif
278
279 /* UPB_ASSERT_DEBUGVAR(): assert that uses functions or variables that only
280 * exist in debug mode. This turns into regular assert. */
281 #define UPB_ASSERT_DEBUGVAR(expr) assert(expr)
251 282
252 /* Generic function type. */ 283 /* Generic function type. */
253 typedef void upb_func(); 284 typedef void upb_func();
254 285
286
255 /* C++ Casts ******************************************************************/ 287 /* C++ Casts ******************************************************************/
256 288
257 #ifdef __cplusplus 289 #ifdef __cplusplus
258 290
259 namespace upb { 291 namespace upb {
260 292
261 template <class T> class Pointer; 293 template <class T> class Pointer;
262 294
263 /* Casts to a subclass. The caller must know that cast is correct; an 295 /* Casts to a subclass. The caller must know that cast is correct; an
264 * incorrect cast will throw an assertion failure in debug mode. 296 * incorrect cast will throw an assertion failure in debug mode.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 public: 354 public:
323 explicit PointerBase2(T* ptr) : PointerBase<T, Base>(ptr) {} 355 explicit PointerBase2(T* ptr) : PointerBase<T, Base>(ptr) {}
324 operator Base2*() { return Pointer<Base>(*this); } 356 operator Base2*() { return Pointer<Base>(*this); }
325 }; 357 };
326 358
327 } 359 }
328 360
329 #endif 361 #endif
330 362
331 363
332 /* upb::reffed_ptr ************************************************************/ 364 /* upb::ErrorSpace ************************************************************/
333 365
334 #ifdef __cplusplus 366 /* A upb::ErrorSpace represents some domain of possible error values. This lets
335 367 * upb::Status attach specific error codes to operations, like POSIX/C errno,
336 #include <algorithm> /* For std::swap(). */ 368 * Win32 error codes, etc. Clients who want to know the very specific error
337 369 * code can check the error space and then know the type of the integer code.
338 namespace upb { 370 *
339 371 * NOTE: upb::ErrorSpace is currently not used and should be considered
340 /* Provides RAII semantics for upb refcounted objects. Each reffed_ptr owns a 372 * experimental. It is important primarily in cases where upb is performing
341 * ref on whatever object it points to (if any). */ 373 * I/O, but upb doesn't currently have any components that do this. */
342 template <class T> class reffed_ptr {
343 public:
344 reffed_ptr() : ptr_(NULL) {}
345
346 /* If ref_donor is NULL, takes a new ref, otherwise adopts from ref_donor. */
347 template <class U>
348 reffed_ptr(U* val, const void* ref_donor = NULL)
349 : ptr_(upb::upcast(val)) {
350 if (ref_donor) {
351 assert(ptr_);
352 ptr_->DonateRef(ref_donor, this);
353 } else if (ptr_) {
354 ptr_->Ref(this);
355 }
356 }
357
358 template <class U>
359 reffed_ptr(const reffed_ptr<U>& other)
360 : ptr_(upb::upcast(other.get())) {
361 if (ptr_) ptr_->Ref(this);
362 }
363
364 ~reffed_ptr() { if (ptr_) ptr_->Unref(this); }
365
366 template <class U>
367 reffed_ptr& operator=(const reffed_ptr<U>& other) {
368 reset(other.get());
369 return *this;
370 }
371
372 reffed_ptr& operator=(const reffed_ptr& other) {
373 reset(other.get());
374 return *this;
375 }
376
377 /* TODO(haberman): add C++11 move construction/assignment for greater
378 * efficiency. */
379
380 void swap(reffed_ptr& other) {
381 if (ptr_ == other.ptr_) {
382 return;
383 }
384
385 if (ptr_) ptr_->DonateRef(this, &other);
386 if (other.ptr_) other.ptr_->DonateRef(&other, this);
387 std::swap(ptr_, other.ptr_);
388 }
389
390 T& operator*() const {
391 assert(ptr_);
392 return *ptr_;
393 }
394
395 T* operator->() const {
396 assert(ptr_);
397 return ptr_;
398 }
399
400 T* get() const { return ptr_; }
401
402 /* If ref_donor is NULL, takes a new ref, otherwise adopts from ref_donor. */
403 template <class U>
404 void reset(U* ptr = NULL, const void* ref_donor = NULL) {
405 reffed_ptr(ptr, ref_donor).swap(*this);
406 }
407
408 template <class U>
409 reffed_ptr<U> down_cast() {
410 return reffed_ptr<U>(upb::down_cast<U*>(get()));
411 }
412
413 template <class U>
414 reffed_ptr<U> dyn_cast() {
415 return reffed_ptr<U>(upb::dyn_cast<U*>(get()));
416 }
417
418 /* Plain release() is unsafe; if we were the only owner, it would leak the
419 * object. Instead we provide this: */
420 T* ReleaseTo(const void* new_owner) {
421 T* ret = NULL;
422 ptr_->DonateRef(this, new_owner);
423 std::swap(ret, ptr_);
424 return ret;
425 }
426
427 private:
428 T* ptr_;
429 };
430
431 } /* namespace upb */
432
433 #endif /* __cplusplus */
434
435
436 /* upb::Status ****************************************************************/
437
438 #ifdef __cplusplus
439 namespace upb {
440 class ErrorSpace;
441 class Status;
442 }
443 #endif
444 374
445 UPB_DECLARE_TYPE(upb::ErrorSpace, upb_errorspace) 375 UPB_DECLARE_TYPE(upb::ErrorSpace, upb_errorspace)
446 UPB_DECLARE_TYPE(upb::Status, upb_status)
447
448 /* The maximum length of an error message before it will get truncated. */
449 #define UPB_STATUS_MAX_MESSAGE 128
450
451 /* An error callback function is used to report errors from some component.
452 * The function can return "true" to indicate that the component should try
453 * to recover and proceed, but this is not always possible. */
454 typedef bool upb_errcb_t(void *closure, const upb_status* status);
455 376
456 #ifdef __cplusplus 377 #ifdef __cplusplus
457 class upb::ErrorSpace { 378 class upb::ErrorSpace {
458 #else 379 #else
459 struct upb_errorspace { 380 struct upb_errorspace {
460 #endif 381 #endif
461 const char *name; 382 const char *name;
462 /* Should the error message in the status object according to this code. */ 383 };
463 void (*set_message)(upb_status* status, int code); 384
464 }; 385
465 386 /* upb::Status ****************************************************************/
466 #ifdef __cplusplus 387
467 388 /* upb::Status represents a success or failure status and error message.
468 /* Object representing a success or failure status.
469 * It owns no resources and allocates no memory, so it should work 389 * It owns no resources and allocates no memory, so it should work
470 * even in OOM situations. */ 390 * even in OOM situations. */
471 391 UPB_DECLARE_TYPE(upb::Status, upb_status)
472 class upb::Status { 392
473 public: 393 /* The maximum length of an error message before it will get truncated. */
474 Status(); 394 #define UPB_STATUS_MAX_MESSAGE 128
475 395
476 /* Returns true if there is no error. */ 396 UPB_BEGIN_EXTERN_C
477 bool ok() const; 397
478
479 /* Optional error space and code, useful if the caller wants to
480 * programmatically check the specific kind of error. */
481 ErrorSpace* error_space();
482 int code() const;
483
484 const char *error_message() const;
485
486 /* The error message will be truncated if it is longer than
487 * UPB_STATUS_MAX_MESSAGE-4. */
488 void SetErrorMessage(const char* msg);
489 void SetFormattedErrorMessage(const char* fmt, ...);
490
491 /* If there is no error message already, this will use the ErrorSpace to
492 * populate the error message for this code. The caller can still call
493 * SetErrorMessage() to give a more specific message. */
494 void SetErrorCode(ErrorSpace* space, int code);
495
496 /* Resets the status to a successful state with no message. */
497 void Clear();
498
499 void CopyFrom(const Status& other);
500
501 private:
502 UPB_DISALLOW_COPY_AND_ASSIGN(Status)
503 #else
504 struct upb_status {
505 #endif
506 bool ok_;
507
508 /* Specific status code defined by some error space (optional). */
509 int code_;
510 upb_errorspace *error_space_;
511
512 /* Error message; NULL-terminated. */
513 char msg[UPB_STATUS_MAX_MESSAGE];
514 };
515
516 #define UPB_STATUS_INIT {true, 0, NULL, {0}}
517
518 #ifdef __cplusplus
519 extern "C" {
520 #endif
521
522 /* The returned string is invalidated by any other call into the status. */
523 const char *upb_status_errmsg(const upb_status *status); 398 const char *upb_status_errmsg(const upb_status *status);
524 bool upb_ok(const upb_status *status); 399 bool upb_ok(const upb_status *status);
525 upb_errorspace *upb_status_errspace(const upb_status *status); 400 upb_errorspace *upb_status_errspace(const upb_status *status);
526 int upb_status_errcode(const upb_status *status); 401 int upb_status_errcode(const upb_status *status);
527 402
528 /* Any of the functions that write to a status object allow status to be NULL, 403 /* Any of the functions that write to a status object allow status to be NULL,
529 * to support use cases where the function's caller does not care about the 404 * to support use cases where the function's caller does not care about the
530 * status message. */ 405 * status message. */
531 void upb_status_clear(upb_status *status); 406 void upb_status_clear(upb_status *status);
532 void upb_status_seterrmsg(upb_status *status, const char *msg); 407 void upb_status_seterrmsg(upb_status *status, const char *msg);
533 void upb_status_seterrf(upb_status *status, const char *fmt, ...); 408 void upb_status_seterrf(upb_status *status, const char *fmt, ...);
534 void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args); 409 void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args);
535 void upb_status_seterrcode(upb_status *status, upb_errorspace *space, int code);
536 void upb_status_copy(upb_status *to, const upb_status *from); 410 void upb_status_copy(upb_status *to, const upb_status *from);
537 411
538 #ifdef __cplusplus 412 UPB_END_EXTERN_C
539 } /* extern "C" */ 413
540 414 #ifdef __cplusplus
541 namespace upb { 415
542 416 class upb::Status {
543 /* C++ Wrappers */ 417 public:
544 inline Status::Status() { Clear(); } 418 Status() { upb_status_clear(this); }
545 inline bool Status::ok() const { return upb_ok(this); } 419
546 inline const char* Status::error_message() const { 420 /* Returns true if there is no error. */
547 return upb_status_errmsg(this); 421 bool ok() const { return upb_ok(this); }
548 } 422
549 inline void Status::SetErrorMessage(const char* msg) { 423 /* Optional error space and code, useful if the caller wants to
550 upb_status_seterrmsg(this, msg); 424 * programmatically check the specific kind of error. */
551 } 425 ErrorSpace* error_space() { return upb_status_errspace(this); }
552 inline void Status::SetFormattedErrorMessage(const char* fmt, ...) { 426 int error_code() const { return upb_status_errcode(this); }
553 va_list args; 427
554 va_start(args, fmt); 428 /* The returned string is invalidated by any other call into the status. */
555 upb_status_vseterrf(this, fmt, args); 429 const char *error_message() const { return upb_status_errmsg(this); }
556 va_end(args); 430
557 } 431 /* The error message will be truncated if it is longer than
558 inline void Status::SetErrorCode(ErrorSpace* space, int code) { 432 * UPB_STATUS_MAX_MESSAGE-4. */
559 upb_status_seterrcode(this, space, code); 433 void SetErrorMessage(const char* msg) { upb_status_seterrmsg(this, msg); }
560 } 434 void SetFormattedErrorMessage(const char* fmt, ...) {
561 inline void Status::Clear() { upb_status_clear(this); } 435 va_list args;
562 inline void Status::CopyFrom(const Status& other) { 436 va_start(args, fmt);
563 upb_status_copy(this, &other); 437 upb_status_vseterrf(this, fmt, args);
564 } 438 va_end(args);
565 439 }
566 } /* namespace upb */ 440
567 441 /* Resets the status to a successful state with no message. */
442 void Clear() { upb_status_clear(this); }
443
444 void CopyFrom(const Status& other) { upb_status_copy(this, &other); }
445
446 private:
447 UPB_DISALLOW_COPY_AND_ASSIGN(Status)
448 #else
449 struct upb_status {
568 #endif 450 #endif
451 bool ok_;
452
453 /* Specific status code defined by some error space (optional). */
454 int code_;
455 upb_errorspace *error_space_;
456
457 /* TODO(haberman): add file/line of error? */
458
459 /* Error message; NULL-terminated. */
460 char msg[UPB_STATUS_MAX_MESSAGE];
461 };
462
463 #define UPB_STATUS_INIT {true, 0, NULL, {0}}
464
465
466 /** Built-in error spaces. ****************************************************/
467
468 /* Errors raised by upb that we want to be able to detect programmatically. */
469 typedef enum {
470 UPB_NOMEM /* Can't reuse ENOMEM because it is POSIX, not ISO C. */
471 } upb_errcode_t;
472
473 extern upb_errorspace upb_upberr;
474
475 void upb_upberr_setoom(upb_status *s);
476
477 /* Since errno is defined by standard C, we define an error space for it in
478 * core upb. Other error spaces should be defined in other, platform-specific
479 * modules. */
480
481 extern upb_errorspace upb_errnoerr;
482
483
484 /** upb::Allocator ************************************************************/
485
486 /* A upb::Allocator is a possibly-stateful allocator object.
487 *
488 * It could either be an arena allocator (which doesn't require individual
489 * free() calls) or a regular malloc() (which does). The client must therefore
490 * free memory unless it knows that the allocator is an arena allocator. */
491 UPB_DECLARE_TYPE(upb::Allocator, upb_alloc)
492
493 /* A malloc()/free() function.
494 * If "size" is 0 then the function acts like free(), otherwise it acts like
495 * realloc(). Only "oldsize" bytes from a previous allocation are preserved. */
496 typedef void *upb_alloc_func(upb_alloc *alloc, void *ptr, size_t oldsize,
497 size_t size);
498
499 #ifdef __cplusplus
500
501 class upb::Allocator UPB_FINAL {
502 public:
503 Allocator() {}
504
505 private:
506 UPB_DISALLOW_COPY_AND_ASSIGN(Allocator)
507
508 public:
509 #else
510 struct upb_alloc {
511 #endif /* __cplusplus */
512 upb_alloc_func *func;
513 };
514
515 UPB_INLINE void *upb_malloc(upb_alloc *alloc, size_t size) {
516 UPB_ASSERT(size > 0);
517 return alloc->func(alloc, NULL, 0, size);
518 }
519
520 UPB_INLINE void *upb_realloc(upb_alloc *alloc, void *ptr, size_t oldsize,
521 size_t size) {
522 UPB_ASSERT(size > 0);
523 return alloc->func(alloc, ptr, oldsize, size);
524 }
525
526 UPB_INLINE void upb_free(upb_alloc *alloc, void *ptr) {
527 alloc->func(alloc, ptr, 0, 0);
528 }
529
530 /* The global allocator used by upb. Uses the standard malloc()/free(). */
531
532 extern upb_alloc upb_alloc_global;
533
534 /* Functions that hard-code the global malloc.
535 *
536 * We still get benefit because we can put custom logic into our global
537 * allocator, like injecting out-of-memory faults in debug/testing builds. */
538
539 UPB_INLINE void *upb_gmalloc(size_t size) {
540 return upb_malloc(&upb_alloc_global, size);
541 }
542
543 UPB_INLINE void *upb_grealloc(void *ptr, size_t oldsize, size_t size) {
544 return upb_realloc(&upb_alloc_global, ptr, oldsize, size);
545 }
546
547 UPB_INLINE void upb_gfree(void *ptr) {
548 upb_free(&upb_alloc_global, ptr);
549 }
550
551 /* upb::Arena *****************************************************************/
552
553 /* upb::Arena is a specific allocator implementation that uses arena allocation.
554 * The user provides an allocator that will be used to allocate the underlying
555 * arena blocks. Arenas by nature do not require the individual allocations
556 * to be freed. However the Arena does allow users to register cleanup
557 * functions that will run when the arena is destroyed.
558 *
559 * A upb::Arena is *not* thread-safe.
560 *
561 * You could write a thread-safe arena allocator that satisfies the
562 * upb::Allocator interface, but it would not be as efficient for the
563 * single-threaded case. */
564 UPB_DECLARE_TYPE(upb::Arena, upb_arena)
565
566 typedef void upb_cleanup_func(void *ud);
567
568 #define UPB_ARENA_BLOCK_OVERHEAD (sizeof(size_t)*4)
569
570 UPB_BEGIN_EXTERN_C
571
572 void upb_arena_init(upb_arena *a);
573 void upb_arena_init2(upb_arena *a, void *mem, size_t n, upb_alloc *alloc);
574 void upb_arena_uninit(upb_arena *a);
575 upb_alloc *upb_arena_alloc(upb_arena *a);
576 bool upb_arena_addcleanup(upb_arena *a, upb_cleanup_func *func, void *ud);
577 size_t upb_arena_bytesallocated(const upb_arena *a);
578 void upb_arena_setnextblocksize(upb_arena *a, size_t size);
579 void upb_arena_setmaxblocksize(upb_arena *a, size_t size);
580
581 UPB_END_EXTERN_C
582
583 #ifdef __cplusplus
584
585 class upb::Arena {
586 public:
587 /* A simple arena with no initial memory block and the default allocator. */
588 Arena() { upb_arena_init(this); }
589
590 /* Constructs an arena with the given initial block which allocates blocks
591 * with the given allocator. The given allocator must outlive the Arena.
592 *
593 * If you pass NULL for the allocator it will default to the global allocator
594 * upb_alloc_global, and NULL/0 for the initial block will cause there to be
595 * no initial block. */
596 Arena(void *mem, size_t len, Allocator* a) {
597 upb_arena_init2(this, mem, len, a);
598 }
599
600 ~Arena() { upb_arena_uninit(this); }
601
602 /* Sets the size of the next block the Arena will request (unless the
603 * requested allocation is larger). Each block will double in size until the
604 * max limit is reached. */
605 void SetNextBlockSize(size_t size) { upb_arena_setnextblocksize(this, size); }
606
607 /* Sets the maximum block size. No blocks larger than this will be requested
608 * from the underlying allocator unless individual arena allocations are
609 * larger. */
610 void SetMaxBlockSize(size_t size) { upb_arena_setmaxblocksize(this, size); }
611
612 /* Allows this arena to be used as a generic allocator.
613 *
614 * The arena does not need free() calls so when using Arena as an allocator
615 * it is safe to skip them. However they are no-ops so there is no harm in
616 * calling free() either. */
617 Allocator* allocator() { return upb_arena_alloc(this); }
618
619 /* Add a cleanup function to run when the arena is destroyed.
620 * Returns false on out-of-memory. */
621 bool AddCleanup(upb_cleanup_func* func, void* ud) {
622 return upb_arena_addcleanup(this, func, ud);
623 }
624
625 /* Total number of bytes that have been allocated. It is undefined what
626 * Realloc() does to this counter. */
627 size_t BytesAllocated() const {
628 return upb_arena_bytesallocated(this);
629 }
630
631 private:
632 UPB_DISALLOW_COPY_AND_ASSIGN(Arena)
633
634 #else
635 struct upb_arena {
636 #endif /* __cplusplus */
637 /* We implement the allocator interface.
638 * This must be the first member of upb_arena! */
639 upb_alloc alloc;
640
641 /* Allocator to allocate arena blocks. We are responsible for freeing these
642 * when we are destroyed. */
643 upb_alloc *block_alloc;
644
645 size_t bytes_allocated;
646 size_t next_block_size;
647 size_t max_block_size;
648
649 /* Linked list of blocks. Points to an arena_block, defined in env.c */
650 void *block_head;
651
652 /* Cleanup entries. Pointer to a cleanup_ent, defined in env.c */
653 void *cleanup_head;
654
655 /* For future expansion, since the size of this struct is exposed to users. */
656 void *future1;
657 void *future2;
658 };
659
660
661 /* upb::Environment ***********************************************************/
662
663 /* A upb::Environment provides a means for injecting malloc and an
664 * error-reporting callback into encoders/decoders. This allows them to be
665 * independent of nearly all assumptions about their actual environment.
666 *
667 * It is also a container for allocating the encoders/decoders themselves that
668 * insulates clients from knowing their actual size. This provides ABI
669 * compatibility even if the size of the objects change. And this allows the
670 * structure definitions to be in the .c files instead of the .h files, making
671 * the .h files smaller and more readable.
672 *
673 * We might want to consider renaming this to "Pipeline" if/when the concept of
674 * a pipeline element becomes more formalized. */
675 UPB_DECLARE_TYPE(upb::Environment, upb_env)
676
677 /* A function that receives an error report from an encoder or decoder. The
678 * callback can return true to request that the error should be recovered, but
679 * if the error is not recoverable this has no effect. */
680 typedef bool upb_error_func(void *ud, const upb_status *status);
681
682 UPB_BEGIN_EXTERN_C
683
684 void upb_env_init(upb_env *e);
685 void upb_env_init2(upb_env *e, void *mem, size_t n, upb_alloc *alloc);
686 void upb_env_uninit(upb_env *e);
687
688 void upb_env_initonly(upb_env *e);
689
690 upb_arena *upb_env_arena(upb_env *e);
691 bool upb_env_ok(const upb_env *e);
692 void upb_env_seterrorfunc(upb_env *e, upb_error_func *func, void *ud);
693
694 /* Convenience wrappers around the methods of the contained arena. */
695 void upb_env_reporterrorsto(upb_env *e, upb_status *s);
696 bool upb_env_reporterror(upb_env *e, const upb_status *s);
697 void *upb_env_malloc(upb_env *e, size_t size);
698 void *upb_env_realloc(upb_env *e, void *ptr, size_t oldsize, size_t size);
699 void upb_env_free(upb_env *e, void *ptr);
700 bool upb_env_addcleanup(upb_env *e, upb_cleanup_func *func, void *ud);
701 size_t upb_env_bytesallocated(const upb_env *e);
702
703 UPB_END_EXTERN_C
704
705 #ifdef __cplusplus
706
707 class upb::Environment {
708 public:
709 /* The given Arena must outlive this environment. */
710 Environment() { upb_env_initonly(this); }
711
712 Environment(void *mem, size_t len, Allocator *a) : arena_(mem, len, a) {
713 upb_env_initonly(this);
714 }
715
716 Arena* arena() { return upb_env_arena(this); }
717
718 /* Set a custom error reporting function. */
719 void SetErrorFunction(upb_error_func* func, void* ud) {
720 upb_env_seterrorfunc(this, func, ud);
721 }
722
723 /* Set the error reporting function to simply copy the status to the given
724 * status and abort. */
725 void ReportErrorsTo(Status* status) { upb_env_reporterrorsto(this, status); }
726
727 /* Returns true if all allocations and AddCleanup() calls have succeeded,
728 * and no errors were reported with ReportError() (except ones that recovered
729 * successfully). */
730 bool ok() const { return upb_env_ok(this); }
731
732 /* Reports an error to this environment's callback, returning true if
733 * the caller should try to recover. */
734 bool ReportError(const Status* status) {
735 return upb_env_reporterror(this, status);
736 }
737
738 private:
739 UPB_DISALLOW_COPY_AND_ASSIGN(Environment)
740
741 #else
742 struct upb_env {
743 #endif /* __cplusplus */
744 upb_arena arena_;
745 upb_error_func *error_func_;
746 void *error_ud_;
747 bool ok_;
748 };
749
750
751 /* upb::InlinedArena **********************************************************/
752 /* upb::InlinedEnvironment ****************************************************/
753
754 /* upb::InlinedArena and upb::InlinedEnvironment seed their arenas with a
755 * predefined amount of memory. No heap memory will be allocated until the
756 * initial block is exceeded.
757 *
758 * These types only exist in C++ */
759
760 #ifdef __cplusplus
761
762 template <int N> class upb::InlinedArena : public upb::Arena {
763 public:
764 InlinedArena() : Arena(initial_block_, N, NULL) {}
765 explicit InlinedArena(Allocator* a) : Arena(initial_block_, N, a) {}
766
767 private:
768 UPB_DISALLOW_COPY_AND_ASSIGN(InlinedArena)
769
770 char initial_block_[N + UPB_ARENA_BLOCK_OVERHEAD];
771 };
772
773 template <int N> class upb::InlinedEnvironment : public upb::Environment {
774 public:
775 InlinedEnvironment() : Environment(initial_block_, N, NULL) {}
776 explicit InlinedEnvironment(Allocator *a)
777 : Environment(initial_block_, N, a) {}
778
779 private:
780 UPB_DISALLOW_COPY_AND_ASSIGN(InlinedEnvironment)
781
782 char initial_block_[N + UPB_ARENA_BLOCK_OVERHEAD];
783 };
784
785 #endif /* __cplusplus */
786
787
569 788
570 #endif /* UPB_H_ */ 789 #endif /* UPB_H_ */
571 790
572 #ifdef __cplusplus 791 #ifdef __cplusplus
573 extern "C" { 792 extern "C" {
574 #endif 793 #endif
575 794
576 795
577 /* upb_value ******************************************************************/ 796 /* upb_value ******************************************************************/
578 797
(...skipping 21 matching lines...) Expand all
600 #endif 819 #endif
601 } upb_value; 820 } upb_value;
602 821
603 #ifdef NDEBUG 822 #ifdef NDEBUG
604 #define SET_TYPE(dest, val) UPB_UNUSED(val) 823 #define SET_TYPE(dest, val) UPB_UNUSED(val)
605 #else 824 #else
606 #define SET_TYPE(dest, val) dest = val 825 #define SET_TYPE(dest, val) dest = val
607 #endif 826 #endif
608 827
609 /* Like strdup(), which isn't always available since it's not ANSI C. */ 828 /* Like strdup(), which isn't always available since it's not ANSI C. */
610 char *upb_strdup(const char *s); 829 char *upb_strdup(const char *s, upb_alloc *a);
611 /* Variant that works with a length-delimited rather than NULL-delimited string, 830 /* Variant that works with a length-delimited rather than NULL-delimited string,
612 * as supported by strtable. */ 831 * as supported by strtable. */
613 char *upb_strdup2(const char *s, size_t len); 832 char *upb_strdup2(const char *s, size_t len, upb_alloc *a);
833
834 UPB_INLINE char *upb_gstrdup(const char *s) {
835 return upb_strdup(s, &upb_alloc_global);
836 }
614 837
615 UPB_INLINE void _upb_value_setval(upb_value *v, uint64_t val, 838 UPB_INLINE void _upb_value_setval(upb_value *v, uint64_t val,
616 upb_ctype_t ctype) { 839 upb_ctype_t ctype) {
617 v->val = val; 840 v->val = val;
618 SET_TYPE(v->ctype, ctype); 841 SET_TYPE(v->ctype, ctype);
619 } 842 }
620 843
621 UPB_INLINE upb_value _upb_value_val(uint64_t val, upb_ctype_t ctype) { 844 UPB_INLINE upb_value _upb_value_val(uint64_t val, upb_ctype_t ctype) {
622 upb_value ret; 845 upb_value ret;
623 _upb_value_setval(&ret, val, ctype); 846 _upb_value_setval(&ret, val, ctype);
(...skipping 12 matching lines...) Expand all
636 UPB_INLINE void upb_value_set ## name(upb_value *val, type_t cval) { \ 859 UPB_INLINE void upb_value_set ## name(upb_value *val, type_t cval) { \
637 val->val = (converter)cval; \ 860 val->val = (converter)cval; \
638 SET_TYPE(val->ctype, proto_type); \ 861 SET_TYPE(val->ctype, proto_type); \
639 } \ 862 } \
640 UPB_INLINE upb_value upb_value_ ## name(type_t val) { \ 863 UPB_INLINE upb_value upb_value_ ## name(type_t val) { \
641 upb_value ret; \ 864 upb_value ret; \
642 upb_value_set ## name(&ret, val); \ 865 upb_value_set ## name(&ret, val); \
643 return ret; \ 866 return ret; \
644 } \ 867 } \
645 UPB_INLINE type_t upb_value_get ## name(upb_value val) { \ 868 UPB_INLINE type_t upb_value_get ## name(upb_value val) { \
646 assert(val.ctype == proto_type); \ 869 UPB_ASSERT_DEBUGVAR(val.ctype == proto_type); \
647 return (type_t)(converter)val.val; \ 870 return (type_t)(converter)val.val; \
648 } 871 }
649 872
650 FUNCS(int32, int32, int32_t, int32_t, UPB_CTYPE_INT32) 873 FUNCS(int32, int32, int32_t, int32_t, UPB_CTYPE_INT32)
651 FUNCS(int64, int64, int64_t, int64_t, UPB_CTYPE_INT64) 874 FUNCS(int64, int64, int64_t, int64_t, UPB_CTYPE_INT64)
652 FUNCS(uint32, uint32, uint32_t, uint32_t, UPB_CTYPE_UINT32) 875 FUNCS(uint32, uint32, uint32_t, uint32_t, UPB_CTYPE_UINT32)
653 FUNCS(uint64, uint64, uint64_t, uint64_t, UPB_CTYPE_UINT64) 876 FUNCS(uint64, uint64, uint64_t, uint64_t, UPB_CTYPE_UINT64)
654 FUNCS(bool, _bool, bool, bool, UPB_CTYPE_BOOL) 877 FUNCS(bool, _bool, bool, bool, UPB_CTYPE_BOOL)
655 FUNCS(cstr, cstr, char*, uintptr_t, UPB_CTYPE_CSTR) 878 FUNCS(cstr, cstr, char*, uintptr_t, UPB_CTYPE_CSTR)
656 FUNCS(ptr, ptr, void*, uintptr_t, UPB_CTYPE_PTR) 879 FUNCS(ptr, ptr, void*, uintptr_t, UPB_CTYPE_PTR)
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 upb_ctype_t ctype; /* Type of all values. */ 1003 upb_ctype_t ctype; /* Type of all values. */
781 uint8_t size_lg2; /* Size of the hashtable part is 2^size_lg2 entries. */ 1004 uint8_t size_lg2; /* Size of the hashtable part is 2^size_lg2 entries. */
782 1005
783 /* Hash table entries. 1006 /* Hash table entries.
784 * Making this const isn't entirely accurate; what we really want is for it to 1007 * Making this const isn't entirely accurate; what we really want is for it to
785 * have the same const-ness as the table it's inside. But there's no way to 1008 * have the same const-ness as the table it's inside. But there's no way to
786 * declare that in C. So we have to make it const so that we can statically 1009 * declare that in C. So we have to make it const so that we can statically
787 * initialize const hash tables. Then we cast away const when we have to. 1010 * initialize const hash tables. Then we cast away const when we have to.
788 */ 1011 */
789 const upb_tabent *entries; 1012 const upb_tabent *entries;
1013
1014 #ifndef NDEBUG
1015 /* This table's allocator. We make the user pass it in to every relevant
1016 * function and only use this to check it in debug mode. We do this solely
1017 * to keep upb_table as small as possible. This might seem slightly paranoid
1018 * but the plan is to use upb_table for all map fields and extension sets in
1019 * a forthcoming message representation, so there could be a lot of these.
1020 * If this turns out to be too annoying later, we can change it (since this
1021 * is an internal-only header file). */
1022 upb_alloc *alloc;
1023 #endif
790 } upb_table; 1024 } upb_table;
791 1025
1026 #ifdef NDEBUG
1027 # define UPB_TABLE_INIT(count, mask, ctype, size_lg2, entries) \
1028 {count, mask, ctype, size_lg2, entries}
1029 #else
1030 # ifdef UPB_DEBUG_REFS
1031 /* At the moment the only mutable tables we statically initialize are debug
1032 * ref tables. */
1033 # define UPB_TABLE_INIT(count, mask, ctype, size_lg2, entries) \
1034 {count, mask, ctype, size_lg2, entries, &upb_alloc_debugrefs}
1035 # else
1036 # define UPB_TABLE_INIT(count, mask, ctype, size_lg2, entries) \
1037 {count, mask, ctype, size_lg2, entries, NULL}
1038 # endif
1039 #endif
1040
792 typedef struct { 1041 typedef struct {
793 upb_table t; 1042 upb_table t;
794 } upb_strtable; 1043 } upb_strtable;
795 1044
796 #define UPB_STRTABLE_INIT(count, mask, ctype, size_lg2, entries) \ 1045 #define UPB_STRTABLE_INIT(count, mask, ctype, size_lg2, entries) \
797 {{count, mask, ctype, size_lg2, entries}} 1046 {UPB_TABLE_INIT(count, mask, ctype, size_lg2, entries)}
798 1047
799 #define UPB_EMPTY_STRTABLE_INIT(ctype) \ 1048 #define UPB_EMPTY_STRTABLE_INIT(ctype) \
800 UPB_STRTABLE_INIT(0, 0, ctype, 0, NULL) 1049 UPB_STRTABLE_INIT(0, 0, ctype, 0, NULL)
801 1050
802 typedef struct { 1051 typedef struct {
803 upb_table t; /* For entries that don't fit in the array part. */ 1052 upb_table t; /* For entries that don't fit in the array part. */
804 const upb_tabval *array; /* Array part of the table. See const note above. */ 1053 const upb_tabval *array; /* Array part of the table. See const note above. */
805 size_t array_size; /* Array part size. */ 1054 size_t array_size; /* Array part size. */
806 size_t array_count; /* Array part number of elements. */ 1055 size_t array_count; /* Array part number of elements. */
807 } upb_inttable; 1056 } upb_inttable;
808 1057
809 #define UPB_INTTABLE_INIT(count, mask, ctype, size_lg2, ent, a, asize, acount) \ 1058 #define UPB_INTTABLE_INIT(count, mask, ctype, size_lg2, ent, a, asize, acount) \
810 {{count, mask, ctype, size_lg2, ent}, a, asize, acount} 1059 {UPB_TABLE_INIT(count, mask, ctype, size_lg2, ent), a, asize, acount}
811 1060
812 #define UPB_EMPTY_INTTABLE_INIT(ctype) \ 1061 #define UPB_EMPTY_INTTABLE_INIT(ctype) \
813 UPB_INTTABLE_INIT(0, 0, ctype, 0, NULL, NULL, 0, 0) 1062 UPB_INTTABLE_INIT(0, 0, ctype, 0, NULL, NULL, 0, 0)
814 1063
815 #define UPB_ARRAY_EMPTYENT -1 1064 #define UPB_ARRAY_EMPTYENT -1
816 1065
817 UPB_INLINE size_t upb_table_size(const upb_table *t) { 1066 UPB_INLINE size_t upb_table_size(const upb_table *t) {
818 if (t->size_lg2 == 0) 1067 if (t->size_lg2 == 0)
819 return 0; 1068 return 0;
820 else 1069 else
(...skipping 19 matching lines...) Expand all
840 static const upb_tabent *upb_getentry(const upb_table *t, uint32_t hash) { 1089 static const upb_tabent *upb_getentry(const upb_table *t, uint32_t hash) {
841 return t->entries + (hash & t->mask); 1090 return t->entries + (hash & t->mask);
842 } 1091 }
843 1092
844 UPB_INLINE bool upb_arrhas(upb_tabval key) { 1093 UPB_INLINE bool upb_arrhas(upb_tabval key) {
845 return key.val != (uint64_t)-1; 1094 return key.val != (uint64_t)-1;
846 } 1095 }
847 1096
848 /* Initialize and uninitialize a table, respectively. If memory allocation 1097 /* Initialize and uninitialize a table, respectively. If memory allocation
849 * failed, false is returned that the table is uninitialized. */ 1098 * failed, false is returned that the table is uninitialized. */
850 bool upb_inttable_init(upb_inttable *table, upb_ctype_t ctype); 1099 bool upb_inttable_init2(upb_inttable *table, upb_ctype_t ctype, upb_alloc *a);
851 bool upb_strtable_init(upb_strtable *table, upb_ctype_t ctype); 1100 bool upb_strtable_init2(upb_strtable *table, upb_ctype_t ctype, upb_alloc *a);
852 void upb_inttable_uninit(upb_inttable *table); 1101 void upb_inttable_uninit2(upb_inttable *table, upb_alloc *a);
853 void upb_strtable_uninit(upb_strtable *table); 1102 void upb_strtable_uninit2(upb_strtable *table, upb_alloc *a);
1103
1104 UPB_INLINE bool upb_inttable_init(upb_inttable *table, upb_ctype_t ctype) {
1105 return upb_inttable_init2(table, ctype, &upb_alloc_global);
1106 }
1107
1108 UPB_INLINE bool upb_strtable_init(upb_strtable *table, upb_ctype_t ctype) {
1109 return upb_strtable_init2(table, ctype, &upb_alloc_global);
1110 }
1111
1112 UPB_INLINE void upb_inttable_uninit(upb_inttable *table) {
1113 upb_inttable_uninit2(table, &upb_alloc_global);
1114 }
1115
1116 UPB_INLINE void upb_strtable_uninit(upb_strtable *table) {
1117 upb_strtable_uninit2(table, &upb_alloc_global);
1118 }
854 1119
855 /* Returns the number of values in the table. */ 1120 /* Returns the number of values in the table. */
856 size_t upb_inttable_count(const upb_inttable *t); 1121 size_t upb_inttable_count(const upb_inttable *t);
857 UPB_INLINE size_t upb_strtable_count(const upb_strtable *t) { 1122 UPB_INLINE size_t upb_strtable_count(const upb_strtable *t) {
858 return t->t.count; 1123 return t->t.count;
859 } 1124 }
860 1125
861 /* Inserts the given key into the hashtable with the given value. The key must 1126 /* Inserts the given key into the hashtable with the given value. The key must
862 * not already exist in the hash table. For string tables, the key must be 1127 * not already exist in the hash table. For string tables, the key must be
863 * NULL-terminated, and the table will make an internal copy of the key. 1128 * NULL-terminated, and the table will make an internal copy of the key.
864 * Inttables must not insert a value of UINTPTR_MAX. 1129 * Inttables must not insert a value of UINTPTR_MAX.
865 * 1130 *
866 * If a table resize was required but memory allocation failed, false is 1131 * If a table resize was required but memory allocation failed, false is
867 * returned and the table is unchanged. */ 1132 * returned and the table is unchanged. */
868 bool upb_inttable_insert(upb_inttable *t, uintptr_t key, upb_value val); 1133 bool upb_inttable_insert2(upb_inttable *t, uintptr_t key, upb_value val,
869 bool upb_strtable_insert2(upb_strtable *t, const char *key, size_t len, 1134 upb_alloc *a);
870 upb_value val); 1135 bool upb_strtable_insert3(upb_strtable *t, const char *key, size_t len,
1136 upb_value val, upb_alloc *a);
1137
1138 UPB_INLINE bool upb_inttable_insert(upb_inttable *t, uintptr_t key,
1139 upb_value val) {
1140 return upb_inttable_insert2(t, key, val, &upb_alloc_global);
1141 }
1142
1143 UPB_INLINE bool upb_strtable_insert2(upb_strtable *t, const char *key,
1144 size_t len, upb_value val) {
1145 return upb_strtable_insert3(t, key, len, val, &upb_alloc_global);
1146 }
871 1147
872 /* For NULL-terminated strings. */ 1148 /* For NULL-terminated strings. */
873 UPB_INLINE bool upb_strtable_insert(upb_strtable *t, const char *key, 1149 UPB_INLINE bool upb_strtable_insert(upb_strtable *t, const char *key,
874 upb_value val) { 1150 upb_value val) {
875 return upb_strtable_insert2(t, key, strlen(key), val); 1151 return upb_strtable_insert2(t, key, strlen(key), val);
876 } 1152 }
877 1153
878 /* Looks up key in this table, returning "true" if the key was found. 1154 /* Looks up key in this table, returning "true" if the key was found.
879 * If v is non-NULL, copies the value for this key into *v. */ 1155 * If v is non-NULL, copies the value for this key into *v. */
880 bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v); 1156 bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v);
881 bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len, 1157 bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len,
882 upb_value *v); 1158 upb_value *v);
883 1159
884 /* For NULL-terminated strings. */ 1160 /* For NULL-terminated strings. */
885 UPB_INLINE bool upb_strtable_lookup(const upb_strtable *t, const char *key, 1161 UPB_INLINE bool upb_strtable_lookup(const upb_strtable *t, const char *key,
886 upb_value *v) { 1162 upb_value *v) {
887 return upb_strtable_lookup2(t, key, strlen(key), v); 1163 return upb_strtable_lookup2(t, key, strlen(key), v);
888 } 1164 }
889 1165
890 /* Removes an item from the table. Returns true if the remove was successful, 1166 /* Removes an item from the table. Returns true if the remove was successful,
891 * and stores the removed item in *val if non-NULL. */ 1167 * and stores the removed item in *val if non-NULL. */
892 bool upb_inttable_remove(upb_inttable *t, uintptr_t key, upb_value *val); 1168 bool upb_inttable_remove(upb_inttable *t, uintptr_t key, upb_value *val);
893 bool upb_strtable_remove2(upb_strtable *t, const char *key, size_t len, 1169 bool upb_strtable_remove3(upb_strtable *t, const char *key, size_t len,
894 upb_value *val); 1170 upb_value *val, upb_alloc *alloc);
1171
1172 UPB_INLINE bool upb_strtable_remove2(upb_strtable *t, const char *key,
1173 size_t len, upb_value *val) {
1174 return upb_strtable_remove3(t, key, len, val, &upb_alloc_global);
1175 }
895 1176
896 /* For NULL-terminated strings. */ 1177 /* For NULL-terminated strings. */
897 UPB_INLINE bool upb_strtable_remove(upb_strtable *t, const char *key, 1178 UPB_INLINE bool upb_strtable_remove(upb_strtable *t, const char *key,
898 upb_value *v) { 1179 upb_value *v) {
899 return upb_strtable_remove2(t, key, strlen(key), v); 1180 return upb_strtable_remove2(t, key, strlen(key), v);
900 } 1181 }
901 1182
902 /* Updates an existing entry in an inttable. If the entry does not exist, 1183 /* Updates an existing entry in an inttable. If the entry does not exist,
903 * returns false and does nothing. Unlike insert/remove, this does not 1184 * returns false and does nothing. Unlike insert/remove, this does not
904 * invalidate iterators. */ 1185 * invalidate iterators. */
905 bool upb_inttable_replace(upb_inttable *t, uintptr_t key, upb_value val); 1186 bool upb_inttable_replace(upb_inttable *t, uintptr_t key, upb_value val);
906 1187
907 /* Handy routines for treating an inttable like a stack. May not be mixed with 1188 /* Handy routines for treating an inttable like a stack. May not be mixed with
908 * other insert/remove calls. */ 1189 * other insert/remove calls. */
909 bool upb_inttable_push(upb_inttable *t, upb_value val); 1190 bool upb_inttable_push2(upb_inttable *t, upb_value val, upb_alloc *a);
910 upb_value upb_inttable_pop(upb_inttable *t); 1191 upb_value upb_inttable_pop(upb_inttable *t);
911 1192
1193 UPB_INLINE bool upb_inttable_push(upb_inttable *t, upb_value val) {
1194 return upb_inttable_push2(t, val, &upb_alloc_global);
1195 }
1196
912 /* Convenience routines for inttables with pointer keys. */ 1197 /* Convenience routines for inttables with pointer keys. */
913 bool upb_inttable_insertptr(upb_inttable *t, const void *key, upb_value val); 1198 bool upb_inttable_insertptr2(upb_inttable *t, const void *key, upb_value val,
1199 upb_alloc *a);
914 bool upb_inttable_removeptr(upb_inttable *t, const void *key, upb_value *val); 1200 bool upb_inttable_removeptr(upb_inttable *t, const void *key, upb_value *val);
915 bool upb_inttable_lookupptr( 1201 bool upb_inttable_lookupptr(
916 const upb_inttable *t, const void *key, upb_value *val); 1202 const upb_inttable *t, const void *key, upb_value *val);
917 1203
1204 UPB_INLINE bool upb_inttable_insertptr(upb_inttable *t, const void *key,
1205 upb_value val) {
1206 return upb_inttable_insertptr2(t, key, val, &upb_alloc_global);
1207 }
1208
918 /* Optimizes the table for the current set of entries, for both memory use and 1209 /* Optimizes the table for the current set of entries, for both memory use and
919 * lookup time. Client should call this after all entries have been inserted; 1210 * lookup time. Client should call this after all entries have been inserted;
920 * inserting more entries is legal, but will likely require a table resize. */ 1211 * inserting more entries is legal, but will likely require a table resize. */
921 void upb_inttable_compact(upb_inttable *t); 1212 void upb_inttable_compact2(upb_inttable *t, upb_alloc *a);
1213
1214 UPB_INLINE void upb_inttable_compact(upb_inttable *t) {
1215 upb_inttable_compact2(t, &upb_alloc_global);
1216 }
922 1217
923 /* A special-case inlinable version of the lookup routine for 32-bit 1218 /* A special-case inlinable version of the lookup routine for 32-bit
924 * integers. */ 1219 * integers. */
925 UPB_INLINE bool upb_inttable_lookup32(const upb_inttable *t, uint32_t key, 1220 UPB_INLINE bool upb_inttable_lookup32(const upb_inttable *t, uint32_t key,
926 upb_value *v) { 1221 upb_value *v) {
927 *v = upb_value_int32(0); /* Silence compiler warnings. */ 1222 *v = upb_value_int32(0); /* Silence compiler warnings. */
928 if (key < t->array_size) { 1223 if (key < t->array_size) {
929 upb_tabval arrval = t->array[key]; 1224 upb_tabval arrval = t->array[key];
930 if (upb_arrhas(arrval)) { 1225 if (upb_arrhas(arrval)) {
931 _upb_value_setval(v, arrval.val, t->t.ctype); 1226 _upb_value_setval(v, arrval.val, t->t.ctype);
932 return true; 1227 return true;
933 } else { 1228 } else {
934 return false; 1229 return false;
935 } 1230 }
936 } else { 1231 } else {
937 const upb_tabent *e; 1232 const upb_tabent *e;
938 if (t->t.entries == NULL) return false; 1233 if (t->t.entries == NULL) return false;
939 for (e = upb_getentry(&t->t, upb_inthash(key)); true; e = e->next) { 1234 for (e = upb_getentry(&t->t, upb_inthash(key)); true; e = e->next) {
940 if ((uint32_t)e->key == key) { 1235 if ((uint32_t)e->key == key) {
941 _upb_value_setval(v, e->val.val, t->t.ctype); 1236 _upb_value_setval(v, e->val.val, t->t.ctype);
942 return true; 1237 return true;
943 } 1238 }
944 if (e->next == NULL) return false; 1239 if (e->next == NULL) return false;
945 } 1240 }
946 } 1241 }
947 } 1242 }
948 1243
949 /* Exposed for testing only. */ 1244 /* Exposed for testing only. */
950 bool upb_strtable_resize(upb_strtable *t, size_t size_lg2); 1245 bool upb_strtable_resize(upb_strtable *t, size_t size_lg2, upb_alloc *a);
951 1246
952 /* Iterators ******************************************************************/ 1247 /* Iterators ******************************************************************/
953 1248
954 /* Iterators for int and string tables. We are subject to some kind of unusual 1249 /* Iterators for int and string tables. We are subject to some kind of unusual
955 * design constraints: 1250 * design constraints:
956 * 1251 *
957 * For high-level languages: 1252 * For high-level languages:
958 * - we must be able to guarantee that we don't crash or corrupt memory even if 1253 * - we must be able to guarantee that we don't crash or corrupt memory even if
959 * the program accesses an invalidated iterator. 1254 * the program accesses an invalidated iterator.
960 * 1255 *
(...skipping 24 matching lines...) Expand all
985 */ 1280 */
986 1281
987 typedef struct { 1282 typedef struct {
988 const upb_strtable *t; 1283 const upb_strtable *t;
989 size_t index; 1284 size_t index;
990 } upb_strtable_iter; 1285 } upb_strtable_iter;
991 1286
992 void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t); 1287 void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t);
993 void upb_strtable_next(upb_strtable_iter *i); 1288 void upb_strtable_next(upb_strtable_iter *i);
994 bool upb_strtable_done(const upb_strtable_iter *i); 1289 bool upb_strtable_done(const upb_strtable_iter *i);
995 const char *upb_strtable_iter_key(upb_strtable_iter *i); 1290 const char *upb_strtable_iter_key(const upb_strtable_iter *i);
996 size_t upb_strtable_iter_keylength(upb_strtable_iter *i); 1291 size_t upb_strtable_iter_keylength(const upb_strtable_iter *i);
997 upb_value upb_strtable_iter_value(const upb_strtable_iter *i); 1292 upb_value upb_strtable_iter_value(const upb_strtable_iter *i);
998 void upb_strtable_iter_setdone(upb_strtable_iter *i); 1293 void upb_strtable_iter_setdone(upb_strtable_iter *i);
999 bool upb_strtable_iter_isequal(const upb_strtable_iter *i1, 1294 bool upb_strtable_iter_isequal(const upb_strtable_iter *i1,
1000 const upb_strtable_iter *i2); 1295 const upb_strtable_iter *i2);
1001 1296
1002 1297
1003 /* upb_inttable_iter **********************************************************/ 1298 /* upb_inttable_iter **********************************************************/
1004 1299
1005 /* upb_inttable_iter i; 1300 /* upb_inttable_iter i;
1006 * upb_inttable_begin(&i, t); 1301 * upb_inttable_begin(&i, t);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 * the code that originally created the object. 1334 * the code that originally created the object.
1040 * 1335 *
1041 * Enabling this requires the application to define upb_lock()/upb_unlock() 1336 * Enabling this requires the application to define upb_lock()/upb_unlock()
1042 * functions that acquire/release a global mutex (or #define UPB_THREAD_UNSAFE). 1337 * functions that acquire/release a global mutex (or #define UPB_THREAD_UNSAFE).
1043 * For this reason we don't enable it by default, even in debug builds. 1338 * For this reason we don't enable it by default, even in debug builds.
1044 */ 1339 */
1045 1340
1046 /* #define UPB_DEBUG_REFS */ 1341 /* #define UPB_DEBUG_REFS */
1047 1342
1048 #ifdef __cplusplus 1343 #ifdef __cplusplus
1049 namespace upb { class RefCounted; } 1344 namespace upb {
1345 class RefCounted;
1346 template <class T> class reffed_ptr;
1347 }
1050 #endif 1348 #endif
1051 1349
1052 UPB_DECLARE_TYPE(upb::RefCounted, upb_refcounted) 1350 UPB_DECLARE_TYPE(upb::RefCounted, upb_refcounted)
1053 1351
1054 struct upb_refcounted_vtbl; 1352 struct upb_refcounted_vtbl;
1055 1353
1056 #ifdef __cplusplus 1354 #ifdef __cplusplus
1057 1355
1058 class upb::RefCounted { 1356 class upb::RefCounted {
1059 public: 1357 public:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 1405
1108 bool is_frozen; 1406 bool is_frozen;
1109 1407
1110 #ifdef UPB_DEBUG_REFS 1408 #ifdef UPB_DEBUG_REFS
1111 upb_inttable *refs; /* Maps owner -> trackedref for incoming refs. */ 1409 upb_inttable *refs; /* Maps owner -> trackedref for incoming refs. */
1112 upb_inttable *ref2s; /* Set of targets for outgoing ref2s. */ 1410 upb_inttable *ref2s; /* Set of targets for outgoing ref2s. */
1113 #endif 1411 #endif
1114 }; 1412 };
1115 1413
1116 #ifdef UPB_DEBUG_REFS 1414 #ifdef UPB_DEBUG_REFS
1117 #define UPB_REFCOUNT_INIT(refs, ref2s) \ 1415 extern upb_alloc upb_alloc_debugrefs;
1118 {&static_refcount, NULL, NULL, 0, true, refs, ref2s} 1416 #define UPB_REFCOUNT_INIT(vtbl, refs, ref2s) \
1417 {&static_refcount, NULL, vtbl, 0, true, refs, ref2s}
1119 #else 1418 #else
1120 #define UPB_REFCOUNT_INIT(refs, ref2s) {&static_refcount, NULL, NULL, 0, true} 1419 #define UPB_REFCOUNT_INIT(vtbl, refs, ref2s) \
1420 {&static_refcount, NULL, vtbl, 0, true}
1121 #endif 1421 #endif
1122 1422
1123 UPB_BEGIN_EXTERN_C 1423 UPB_BEGIN_EXTERN_C
1124 1424
1125 /* It is better to use tracked refs when possible, for the extra debugging 1425 /* It is better to use tracked refs when possible, for the extra debugging
1126 * capability. But if this is not possible (because you don't have easy access 1426 * capability. But if this is not possible (because you don't have easy access
1127 * to a stable pointer value that is associated with the ref), you can pass 1427 * to a stable pointer value that is associated with the ref), you can pass
1128 * UPB_UNTRACKED_REF instead. */ 1428 * UPB_UNTRACKED_REF instead. */
1129 extern const void *UPB_UNTRACKED_REF; 1429 extern const void *UPB_UNTRACKED_REF;
1130 1430
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 } 1543 }
1244 inline void RefCounted::DonateRef(const void *from, const void *to) const { 1544 inline void RefCounted::DonateRef(const void *from, const void *to) const {
1245 upb_refcounted_donateref(this, from, to); 1545 upb_refcounted_donateref(this, from, to);
1246 } 1546 }
1247 inline void RefCounted::CheckRef(const void *owner) const { 1547 inline void RefCounted::CheckRef(const void *owner) const {
1248 upb_refcounted_checkref(this, owner); 1548 upb_refcounted_checkref(this, owner);
1249 } 1549 }
1250 } /* namespace upb */ 1550 } /* namespace upb */
1251 #endif 1551 #endif
1252 1552
1553
1554 /* upb::reffed_ptr ************************************************************/
1555
1556 #ifdef __cplusplus
1557
1558 #include <algorithm> /* For std::swap(). */
1559
1560 /* Provides RAII semantics for upb refcounted objects. Each reffed_ptr owns a
1561 * ref on whatever object it points to (if any). */
1562 template <class T> class upb::reffed_ptr {
1563 public:
1564 reffed_ptr() : ptr_(NULL) {}
1565
1566 /* If ref_donor is NULL, takes a new ref, otherwise adopts from ref_donor. */
1567 template <class U>
1568 reffed_ptr(U* val, const void* ref_donor = NULL)
1569 : ptr_(upb::upcast(val)) {
1570 if (ref_donor) {
1571 UPB_ASSERT(ptr_);
1572 ptr_->DonateRef(ref_donor, this);
1573 } else if (ptr_) {
1574 ptr_->Ref(this);
1575 }
1576 }
1577
1578 template <class U>
1579 reffed_ptr(const reffed_ptr<U>& other)
1580 : ptr_(upb::upcast(other.get())) {
1581 if (ptr_) ptr_->Ref(this);
1582 }
1583
1584 reffed_ptr(const reffed_ptr& other)
1585 : ptr_(upb::upcast(other.get())) {
1586 if (ptr_) ptr_->Ref(this);
1587 }
1588
1589 ~reffed_ptr() { if (ptr_) ptr_->Unref(this); }
1590
1591 template <class U>
1592 reffed_ptr& operator=(const reffed_ptr<U>& other) {
1593 reset(other.get());
1594 return *this;
1595 }
1596
1597 reffed_ptr& operator=(const reffed_ptr& other) {
1598 reset(other.get());
1599 return *this;
1600 }
1601
1602 /* TODO(haberman): add C++11 move construction/assignment for greater
1603 * efficiency. */
1604
1605 void swap(reffed_ptr& other) {
1606 if (ptr_ == other.ptr_) {
1607 return;
1608 }
1609
1610 if (ptr_) ptr_->DonateRef(this, &other);
1611 if (other.ptr_) other.ptr_->DonateRef(&other, this);
1612 std::swap(ptr_, other.ptr_);
1613 }
1614
1615 T& operator*() const {
1616 UPB_ASSERT(ptr_);
1617 return *ptr_;
1618 }
1619
1620 T* operator->() const {
1621 UPB_ASSERT(ptr_);
1622 return ptr_;
1623 }
1624
1625 T* get() const { return ptr_; }
1626
1627 /* If ref_donor is NULL, takes a new ref, otherwise adopts from ref_donor. */
1628 template <class U>
1629 void reset(U* ptr = NULL, const void* ref_donor = NULL) {
1630 reffed_ptr(ptr, ref_donor).swap(*this);
1631 }
1632
1633 template <class U>
1634 reffed_ptr<U> down_cast() {
1635 return reffed_ptr<U>(upb::down_cast<U*>(get()));
1636 }
1637
1638 template <class U>
1639 reffed_ptr<U> dyn_cast() {
1640 return reffed_ptr<U>(upb::dyn_cast<U*>(get()));
1641 }
1642
1643 /* Plain release() is unsafe; if we were the only owner, it would leak the
1644 * object. Instead we provide this: */
1645 T* ReleaseTo(const void* new_owner) {
1646 T* ret = NULL;
1647 ptr_->DonateRef(this, new_owner);
1648 std::swap(ret, ptr_);
1649 return ret;
1650 }
1651
1652 private:
1653 T* ptr_;
1654 };
1655
1656 #endif /* __cplusplus */
1657
1253 #endif /* UPB_REFCOUNT_H_ */ 1658 #endif /* UPB_REFCOUNT_H_ */
1254 1659
1255 #ifdef __cplusplus 1660 #ifdef __cplusplus
1256 #include <cstring> 1661 #include <cstring>
1257 #include <string> 1662 #include <string>
1258 #include <vector> 1663 #include <vector>
1259 1664
1260 namespace upb { 1665 namespace upb {
1261 class Def; 1666 class Def;
1262 class EnumDef; 1667 class EnumDef;
1263 class FieldDef; 1668 class FieldDef;
1669 class FileDef;
1264 class MessageDef; 1670 class MessageDef;
1265 class OneofDef; 1671 class OneofDef;
1266 } 1672 }
1267 #endif 1673 #endif
1268 1674
1269 UPB_DECLARE_DERIVED_TYPE(upb::Def, upb::RefCounted, upb_def, upb_refcounted) 1675 UPB_DECLARE_DERIVED_TYPE(upb::Def, upb::RefCounted, upb_def, upb_refcounted)
1676 UPB_DECLARE_DERIVED_TYPE(upb::OneofDef, upb::RefCounted, upb_oneofdef,
1677 upb_refcounted)
1678 UPB_DECLARE_DERIVED_TYPE(upb::FileDef, upb::RefCounted, upb_filedef,
1679 upb_refcounted)
1270 1680
1271 /* The maximum message depth that the type graph can have. This is a resource 1681 /* The maximum message depth that the type graph can have. This is a resource
1272 * limit for the C stack since we sometimes need to recursively traverse the 1682 * limit for the C stack since we sometimes need to recursively traverse the
1273 * graph. Cycles are ok; the traversal will stop when it detects a cycle, but 1683 * graph. Cycles are ok; the traversal will stop when it detects a cycle, but
1274 * we must hit the cycle before the maximum depth is reached. 1684 * we must hit the cycle before the maximum depth is reached.
1275 * 1685 *
1276 * If having a single static limit is too inflexible, we can add another variant 1686 * If having a single static limit is too inflexible, we can add another variant
1277 * of Def::Freeze that allows specifying this as a parameter. */ 1687 * of Def::Freeze that allows specifying this as a parameter. */
1278 #define UPB_MAX_MESSAGE_DEPTH 64 1688 #define UPB_MAX_MESSAGE_DEPTH 64
1279 1689
1280 1690
1281 /* upb::Def: base class for defs *********************************************/ 1691 /* upb::Def: base class for top-level defs ***********************************/
1282 1692
1283 /* All the different kind of defs we support. These correspond 1:1 with 1693 /* All the different kind of defs that can be defined at the top-level and put
1284 * declarations in a .proto file. */ 1694 * in a SymbolTable or appear in a FileDef::defs() list. This excludes some
1695 * defs (like oneofs and files). It only includes fields because they can be
1696 * defined as extensions. */
1285 typedef enum { 1697 typedef enum {
1286 UPB_DEF_MSG, 1698 UPB_DEF_MSG,
1287 UPB_DEF_FIELD, 1699 UPB_DEF_FIELD,
1288 UPB_DEF_ENUM, 1700 UPB_DEF_ENUM,
1289 UPB_DEF_ONEOF,
1290 UPB_DEF_SERVICE, /* Not yet implemented. */ 1701 UPB_DEF_SERVICE, /* Not yet implemented. */
1291 UPB_DEF_ANY = -1 /* Wildcard for upb_symtab_get*() */ 1702 UPB_DEF_ANY = -1 /* Wildcard for upb_symtab_get*() */
1292 } upb_deftype_t; 1703 } upb_deftype_t;
1293 1704
1294 #ifdef __cplusplus 1705 #ifdef __cplusplus
1295 1706
1296 /* The base class of all defs. Its base is upb::RefCounted (use upb::upcast() 1707 /* The base class of all defs. Its base is upb::RefCounted (use upb::upcast()
1297 * to convert). */ 1708 * to convert). */
1298 class upb::Def { 1709 class upb::Def {
1299 public: 1710 public:
1300 typedef upb_deftype_t Type; 1711 typedef upb_deftype_t Type;
1301 1712
1302 Def* Dup(const void *owner) const; 1713 Def* Dup(const void *owner) const;
1303 1714
1304 /* upb::RefCounted methods like Ref()/Unref(). */ 1715 /* upb::RefCounted methods like Ref()/Unref(). */
1305 UPB_REFCOUNTED_CPPMETHODS 1716 UPB_REFCOUNTED_CPPMETHODS
1306 1717
1307 Type def_type() const; 1718 Type def_type() const;
1308 1719
1309 /* "fullname" is the def's fully-qualified name (eg. foo.bar.Message). */ 1720 /* "fullname" is the def's fully-qualified name (eg. foo.bar.Message). */
1310 const char *full_name() const; 1721 const char *full_name() const;
1311 1722
1723 /* The final part of a def's name (eg. Message). */
1724 const char *name() const;
1725
1312 /* The def must be mutable. Caller retains ownership of fullname. Defs are 1726 /* The def must be mutable. Caller retains ownership of fullname. Defs are
1313 * not required to have a name; if a def has no name when it is frozen, it 1727 * not required to have a name; if a def has no name when it is frozen, it
1314 * will remain an anonymous def. On failure, returns false and details in "s" 1728 * will remain an anonymous def. On failure, returns false and details in "s"
1315 * if non-NULL. */ 1729 * if non-NULL. */
1316 bool set_full_name(const char* fullname, upb::Status* s); 1730 bool set_full_name(const char* fullname, upb::Status* s);
1317 bool set_full_name(const std::string &fullname, upb::Status* s); 1731 bool set_full_name(const std::string &fullname, upb::Status* s);
1318 1732
1733 /* The file in which this def appears. It is not necessary to add a def to a
1734 * file (and consequently the accessor may return NULL). Set this by calling
1735 * file->Add(def). */
1736 FileDef* file() const;
1737
1319 /* Freezes the given defs; this validates all constraints and marks the defs 1738 /* Freezes the given defs; this validates all constraints and marks the defs
1320 * as frozen (read-only). "defs" may not contain any fielddefs, but fields 1739 * as frozen (read-only). "defs" may not contain any fielddefs, but fields
1321 * of any msgdefs will be frozen. 1740 * of any msgdefs will be frozen.
1322 * 1741 *
1323 * Symbolic references to sub-types and enum defaults must have already been 1742 * Symbolic references to sub-types and enum defaults must have already been
1324 * resolved. Any mutable defs reachable from any of "defs" must also be in 1743 * resolved. Any mutable defs reachable from any of "defs" must also be in
1325 * the list; more formally, "defs" must be a transitive closure of mutable 1744 * the list; more formally, "defs" must be a transitive closure of mutable
1326 * defs. 1745 * defs.
1327 * 1746 *
1328 * After this operation succeeds, the finalized defs must only be accessed 1747 * After this operation succeeds, the finalized defs must only be accessed
1329 * through a const pointer! */ 1748 * through a const pointer! */
1330 static bool Freeze(Def* const* defs, int n, Status* status); 1749 static bool Freeze(Def* const* defs, size_t n, Status* status);
1331 static bool Freeze(const std::vector<Def*>& defs, Status* status); 1750 static bool Freeze(const std::vector<Def*>& defs, Status* status);
1332 1751
1333 private: 1752 private:
1334 UPB_DISALLOW_POD_OPS(Def, upb::Def) 1753 UPB_DISALLOW_POD_OPS(Def, upb::Def)
1335 }; 1754 };
1336 1755
1337 #endif /* __cplusplus */ 1756 #endif /* __cplusplus */
1338 1757
1339 UPB_BEGIN_EXTERN_C 1758 UPB_BEGIN_EXTERN_C
1340 1759
1341 /* Native C API. */ 1760 /* Native C API. */
1342 upb_def *upb_def_dup(const upb_def *def, const void *owner); 1761 upb_def *upb_def_dup(const upb_def *def, const void *owner);
1343 1762
1344 /* Include upb_refcounted methods like upb_def_ref()/upb_def_unref(). */ 1763 /* Include upb_refcounted methods like upb_def_ref()/upb_def_unref(). */
1345 UPB_REFCOUNTED_CMETHODS(upb_def, upb_def_upcast) 1764 UPB_REFCOUNTED_CMETHODS(upb_def, upb_def_upcast)
1346 1765
1347 upb_deftype_t upb_def_type(const upb_def *d); 1766 upb_deftype_t upb_def_type(const upb_def *d);
1348 const char *upb_def_fullname(const upb_def *d); 1767 const char *upb_def_fullname(const upb_def *d);
1768 const char *upb_def_name(const upb_def *d);
1769 const upb_filedef *upb_def_file(const upb_def *d);
1349 bool upb_def_setfullname(upb_def *def, const char *fullname, upb_status *s); 1770 bool upb_def_setfullname(upb_def *def, const char *fullname, upb_status *s);
1350 bool upb_def_freeze(upb_def *const *defs, int n, upb_status *s); 1771 bool upb_def_freeze(upb_def *const *defs, size_t n, upb_status *s);
1772
1773 /* Temporary API: for internal use only. */
1774 bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s);
1351 1775
1352 UPB_END_EXTERN_C 1776 UPB_END_EXTERN_C
1353 1777
1354 1778
1355 /* upb::Def casts *************************************************************/ 1779 /* upb::Def casts *************************************************************/
1356 1780
1357 #ifdef __cplusplus 1781 #ifdef __cplusplus
1358 #define UPB_CPP_CASTS(cname, cpptype) \ 1782 #define UPB_CPP_CASTS(cname, cpptype) \
1359 namespace upb { \ 1783 namespace upb { \
1360 template <> \ 1784 template <> \
(...skipping 28 matching lines...) Expand all
1389 1813
1390 /* Dynamic casts, for determining if a def is of a particular type at runtime. 1814 /* Dynamic casts, for determining if a def is of a particular type at runtime.
1391 * Downcasts, for when some wants to assert that a def is of a particular type. 1815 * Downcasts, for when some wants to assert that a def is of a particular type.
1392 * These are only checked if we are building debug. */ 1816 * These are only checked if we are building debug. */
1393 #define UPB_DEF_CASTS(lower, upper, cpptype) \ 1817 #define UPB_DEF_CASTS(lower, upper, cpptype) \
1394 UPB_INLINE const upb_##lower *upb_dyncast_##lower(const upb_def *def) { \ 1818 UPB_INLINE const upb_##lower *upb_dyncast_##lower(const upb_def *def) { \
1395 if (upb_def_type(def) != UPB_DEF_##upper) return NULL; \ 1819 if (upb_def_type(def) != UPB_DEF_##upper) return NULL; \
1396 return (upb_##lower *)def; \ 1820 return (upb_##lower *)def; \
1397 } \ 1821 } \
1398 UPB_INLINE const upb_##lower *upb_downcast_##lower(const upb_def *def) { \ 1822 UPB_INLINE const upb_##lower *upb_downcast_##lower(const upb_def *def) { \
1399 assert(upb_def_type(def) == UPB_DEF_##upper); \ 1823 UPB_ASSERT(upb_def_type(def) == UPB_DEF_##upper); \
1400 return (const upb_##lower *)def; \ 1824 return (const upb_##lower *)def; \
1401 } \ 1825 } \
1402 UPB_INLINE upb_##lower *upb_dyncast_##lower##_mutable(upb_def *def) { \ 1826 UPB_INLINE upb_##lower *upb_dyncast_##lower##_mutable(upb_def *def) { \
1403 return (upb_##lower *)upb_dyncast_##lower(def); \ 1827 return (upb_##lower *)upb_dyncast_##lower(def); \
1404 } \ 1828 } \
1405 UPB_INLINE upb_##lower *upb_downcast_##lower##_mutable(upb_def *def) { \ 1829 UPB_INLINE upb_##lower *upb_downcast_##lower##_mutable(upb_def *def) { \
1406 return (upb_##lower *)upb_downcast_##lower(def); \ 1830 return (upb_##lower *)upb_downcast_##lower(def); \
1407 } \ 1831 } \
1408 UPB_CPP_CASTS(lower, cpptype) 1832 UPB_CPP_CASTS(lower, cpptype)
1409 1833
1410 #define UPB_DEFINE_DEF(cppname, lower, upper, cppmethods, members) \ 1834 #define UPB_DEFINE_DEF(cppname, lower, upper, cppmethods, members) \
1411 UPB_DEFINE_CLASS2(cppname, upb::Def, upb::RefCounted, cppmethods, \ 1835 UPB_DEFINE_CLASS2(cppname, upb::Def, upb::RefCounted, cppmethods, \
1412 members) \ 1836 members) \
1413 UPB_DEF_CASTS(lower, upper, cppname) 1837 UPB_DEF_CASTS(lower, upper, cppname)
1414 1838
1415 #define UPB_DECLARE_DEF_TYPE(cppname, lower, upper) \ 1839 #define UPB_DECLARE_DEF_TYPE(cppname, lower, upper) \
1416 UPB_DECLARE_DERIVED_TYPE2(cppname, upb::Def, upb::RefCounted, \ 1840 UPB_DECLARE_DERIVED_TYPE2(cppname, upb::Def, upb::RefCounted, \
1417 upb_ ## lower, upb_def, upb_refcounted) \ 1841 upb_ ## lower, upb_def, upb_refcounted) \
1418 UPB_DEF_CASTS(lower, upper, cppname) 1842 UPB_DEF_CASTS(lower, upper, cppname)
1419 1843
1420 UPB_DECLARE_DEF_TYPE(upb::FieldDef, fielddef, FIELD) 1844 UPB_DECLARE_DEF_TYPE(upb::FieldDef, fielddef, FIELD)
1421 UPB_DECLARE_DEF_TYPE(upb::MessageDef, msgdef, MSG) 1845 UPB_DECLARE_DEF_TYPE(upb::MessageDef, msgdef, MSG)
1422 UPB_DECLARE_DEF_TYPE(upb::EnumDef, enumdef, ENUM) 1846 UPB_DECLARE_DEF_TYPE(upb::EnumDef, enumdef, ENUM)
1423 UPB_DECLARE_DEF_TYPE(upb::OneofDef, oneofdef, ONEOF)
1424 1847
1425 #undef UPB_DECLARE_DEF_TYPE 1848 #undef UPB_DECLARE_DEF_TYPE
1426 #undef UPB_DEF_CASTS 1849 #undef UPB_DEF_CASTS
1427 #undef UPB_CPP_CASTS 1850 #undef UPB_CPP_CASTS
1428 1851
1429 1852
1430 /* upb::FieldDef **************************************************************/ 1853 /* upb::FieldDef **************************************************************/
1431 1854
1432 /* The types a field can have. Note that this list is not identical to the 1855 /* The types a field can have. Note that this list is not identical to the
1433 * types defined in descriptor.proto, which gives INT32 and SINT32 separate 1856 * types defined in descriptor.proto, which gives INT32 and SINT32 separate
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1476 UPB_DESCRIPTOR_TYPE_MESSAGE = 11, 1899 UPB_DESCRIPTOR_TYPE_MESSAGE = 11,
1477 UPB_DESCRIPTOR_TYPE_BYTES = 12, 1900 UPB_DESCRIPTOR_TYPE_BYTES = 12,
1478 UPB_DESCRIPTOR_TYPE_UINT32 = 13, 1901 UPB_DESCRIPTOR_TYPE_UINT32 = 13,
1479 UPB_DESCRIPTOR_TYPE_ENUM = 14, 1902 UPB_DESCRIPTOR_TYPE_ENUM = 14,
1480 UPB_DESCRIPTOR_TYPE_SFIXED32 = 15, 1903 UPB_DESCRIPTOR_TYPE_SFIXED32 = 15,
1481 UPB_DESCRIPTOR_TYPE_SFIXED64 = 16, 1904 UPB_DESCRIPTOR_TYPE_SFIXED64 = 16,
1482 UPB_DESCRIPTOR_TYPE_SINT32 = 17, 1905 UPB_DESCRIPTOR_TYPE_SINT32 = 17,
1483 UPB_DESCRIPTOR_TYPE_SINT64 = 18 1906 UPB_DESCRIPTOR_TYPE_SINT64 = 18
1484 } upb_descriptortype_t; 1907 } upb_descriptortype_t;
1485 1908
1909 typedef enum {
1910 UPB_SYNTAX_PROTO2 = 2,
1911 UPB_SYNTAX_PROTO3 = 3
1912 } upb_syntax_t;
1913
1486 /* Maximum field number allowed for FieldDefs. This is an inherent limit of the 1914 /* Maximum field number allowed for FieldDefs. This is an inherent limit of the
1487 * protobuf wire format. */ 1915 * protobuf wire format. */
1488 #define UPB_MAX_FIELDNUMBER ((1 << 29) - 1) 1916 #define UPB_MAX_FIELDNUMBER ((1 << 29) - 1)
1489 1917
1490 #ifdef __cplusplus 1918 #ifdef __cplusplus
1491 1919
1492 /* A upb_fielddef describes a single field in a message. It is most often 1920 /* A upb_fielddef describes a single field in a message. It is most often
1493 * found as a part of a upb_msgdef, but can also stand alone to represent 1921 * found as a part of a upb_msgdef, but can also stand alone to represent
1494 * an extension. 1922 * an extension.
1495 * 1923 *
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 /* Functionality from upb::Def. */ 1958 /* Functionality from upb::Def. */
1531 const char* full_name() const; 1959 const char* full_name() const;
1532 1960
1533 bool type_is_set() const; /* set_[descriptor_]type() has been called? */ 1961 bool type_is_set() const; /* set_[descriptor_]type() has been called? */
1534 Type type() const; /* Requires that type_is_set() == true. */ 1962 Type type() const; /* Requires that type_is_set() == true. */
1535 Label label() const; /* Defaults to UPB_LABEL_OPTIONAL. */ 1963 Label label() const; /* Defaults to UPB_LABEL_OPTIONAL. */
1536 const char* name() const; /* NULL if uninitialized. */ 1964 const char* name() const; /* NULL if uninitialized. */
1537 uint32_t number() const; /* Returns 0 if uninitialized. */ 1965 uint32_t number() const; /* Returns 0 if uninitialized. */
1538 bool is_extension() const; 1966 bool is_extension() const;
1539 1967
1968 /* Copies the JSON name for this field into the given buffer. Returns the
1969 * actual size of the JSON name, including the NULL terminator. If the
1970 * return value is 0, the JSON name is unset. If the return value is
1971 * greater than len, the JSON name was truncated. The buffer is always
1972 * NULL-terminated if len > 0.
1973 *
1974 * The JSON name always defaults to a camelCased version of the regular
1975 * name. However if the regular name is unset, the JSON name will be unset
1976 * also.
1977 */
1978 size_t GetJsonName(char* buf, size_t len) const;
1979
1980 /* Convenience version of the above function which copies the JSON name
1981 * into the given string, returning false if the name is not set. */
1982 template <class T>
1983 bool GetJsonName(T* str) {
1984 str->resize(GetJsonName(NULL, 0));
1985 GetJsonName(&(*str)[0], str->size());
1986 return str->size() > 0;
1987 }
1988
1540 /* For UPB_TYPE_MESSAGE fields only where is_tag_delimited() == false, 1989 /* For UPB_TYPE_MESSAGE fields only where is_tag_delimited() == false,
1541 * indicates whether this field should have lazy parsing handlers that yield 1990 * indicates whether this field should have lazy parsing handlers that yield
1542 * the unparsed string for the submessage. 1991 * the unparsed string for the submessage.
1543 * 1992 *
1544 * TODO(haberman): I think we want to move this into a FieldOptions container 1993 * TODO(haberman): I think we want to move this into a FieldOptions container
1545 * when we add support for custom options (the FieldOptions struct will 1994 * when we add support for custom options (the FieldOptions struct will
1546 * contain both regular FieldOptions like "lazy" *and* custom options). */ 1995 * contain both regular FieldOptions like "lazy" *and* custom options). */
1547 bool lazy() const; 1996 bool lazy() const;
1548 1997
1549 /* For non-string, non-submessage fields, this indicates whether binary 1998 /* For non-string, non-submessage fields, this indicates whether binary
1550 * protobufs are encoded in packed or non-packed format. 1999 * protobufs are encoded in packed or non-packed format.
1551 * 2000 *
1552 * TODO(haberman): see note above about putting options like this into a 2001 * TODO(haberman): see note above about putting options like this into a
1553 * FieldOptions container. */ 2002 * FieldOptions container. */
1554 bool packed() const; 2003 bool packed() const;
1555 2004
1556 /* An integer that can be used as an index into an array of fields for 2005 /* An integer that can be used as an index into an array of fields for
1557 * whatever message this field belongs to. Guaranteed to be less than 2006 * whatever message this field belongs to. Guaranteed to be less than
1558 * f->containing_type()->field_count(). May only be accessed once the def has 2007 * f->containing_type()->field_count(). May only be accessed once the def has
1559 * been finalized. */ 2008 * been finalized. */
1560 int index() const; 2009 uint32_t index() const;
1561 2010
1562 /* The MessageDef to which this field belongs. 2011 /* The MessageDef to which this field belongs.
1563 * 2012 *
1564 * If this field has been added to a MessageDef, that message can be retrieved 2013 * If this field has been added to a MessageDef, that message can be retrieved
1565 * directly (this is always the case for frozen FieldDefs). 2014 * directly (this is always the case for frozen FieldDefs).
1566 * 2015 *
1567 * If the field has not yet been added to a MessageDef, you can set the name 2016 * If the field has not yet been added to a MessageDef, you can set the name
1568 * of the containing type symbolically instead. This is mostly useful for 2017 * of the containing type symbolically instead. This is mostly useful for
1569 * extensions, where the extension is declared separately from the message. */ 2018 * extensions, where the extension is declared separately from the message. */
1570 const MessageDef* containing_type() const; 2019 const MessageDef* containing_type() const;
(...skipping 11 matching lines...) Expand all
1582 * appropriately. */ 2031 * appropriately. */
1583 DescriptorType descriptor_type() const; 2032 DescriptorType descriptor_type() const;
1584 2033
1585 /* Convenient field type tests. */ 2034 /* Convenient field type tests. */
1586 bool IsSubMessage() const; 2035 bool IsSubMessage() const;
1587 bool IsString() const; 2036 bool IsString() const;
1588 bool IsSequence() const; 2037 bool IsSequence() const;
1589 bool IsPrimitive() const; 2038 bool IsPrimitive() const;
1590 bool IsMap() const; 2039 bool IsMap() const;
1591 2040
2041 /* Whether this field must be able to explicitly represent presence:
2042 *
2043 * * This is always false for repeated fields (an empty repeated field is
2044 * equivalent to a repeated field with zero entries).
2045 *
2046 * * This is always true for submessages.
2047 *
2048 * * For other fields, it depends on the message (see
2049 * MessageDef::SetPrimitivesHavePresence())
2050 */
2051 bool HasPresence() const;
2052
1592 /* How integers are encoded. Only meaningful for integer types. 2053 /* How integers are encoded. Only meaningful for integer types.
1593 * Defaults to UPB_INTFMT_VARIABLE, and is reset when "type" changes. */ 2054 * Defaults to UPB_INTFMT_VARIABLE, and is reset when "type" changes. */
1594 IntegerFormat integer_format() const; 2055 IntegerFormat integer_format() const;
1595 2056
1596 /* Whether a submessage field is tag-delimited or not (if false, then 2057 /* Whether a submessage field is tag-delimited or not (if false, then
1597 * length-delimited). May only be set when type() == UPB_TYPE_MESSAGE. */ 2058 * length-delimited). May only be set when type() == UPB_TYPE_MESSAGE. */
1598 bool is_tag_delimited() const; 2059 bool is_tag_delimited() const;
1599 2060
1600 /* Returns the non-string default value for this fielddef, which may either 2061 /* Returns the non-string default value for this fielddef, which may either
1601 * be something the client set explicitly or the "default default" (0 for 2062 * be something the client set explicitly or the "default default" (0 for
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 * MessageDef, and may not be set after that. 2144 * MessageDef, and may not be set after that.
1684 * 2145 *
1685 * "name" is the same as full_name()/set_full_name(), but since fielddefs 2146 * "name" is the same as full_name()/set_full_name(), but since fielddefs
1686 * most often use simple, non-qualified names, we provide this accessor 2147 * most often use simple, non-qualified names, we provide this accessor
1687 * also. Generally only extensions will want to think of this name as 2148 * also. Generally only extensions will want to think of this name as
1688 * fully-qualified. */ 2149 * fully-qualified. */
1689 bool set_number(uint32_t number, upb::Status* s); 2150 bool set_number(uint32_t number, upb::Status* s);
1690 bool set_name(const char* name, upb::Status* s); 2151 bool set_name(const char* name, upb::Status* s);
1691 bool set_name(const std::string& name, upb::Status* s); 2152 bool set_name(const std::string& name, upb::Status* s);
1692 2153
2154 /* Sets the JSON name to the given string. */
2155 /* TODO(haberman): implement. Right now only default json_name (camelCase)
2156 * is supported. */
2157 bool set_json_name(const char* json_name, upb::Status* s);
2158 bool set_json_name(const std::string& name, upb::Status* s);
2159
2160 /* Clears the JSON name. This will make it revert to its default, which is
2161 * a camelCased version of the regular field name. */
2162 void clear_json_name();
2163
1693 void set_integer_format(IntegerFormat format); 2164 void set_integer_format(IntegerFormat format);
1694 bool set_tag_delimited(bool tag_delimited, upb::Status* s); 2165 bool set_tag_delimited(bool tag_delimited, upb::Status* s);
1695 2166
1696 /* Sets default value for the field. The call must exactly match the type 2167 /* Sets default value for the field. The call must exactly match the type
1697 * of the field. Enum fields may use either setint32 or setstring to set 2168 * of the field. Enum fields may use either setint32 or setstring to set
1698 * the default numerically or symbolically, respectively, but symbolic 2169 * the default numerically or symbolically, respectively, but symbolic
1699 * defaults must be resolved before finalizing (see ResolveEnumDefault()). 2170 * defaults must be resolved before finalizing (see ResolveEnumDefault()).
1700 * 2171 *
1701 * Changing the type of a field will reset its default. */ 2172 * Changing the type of a field will reset its default. */
1702 void set_default_int64(int64_t val); 2173 void set_default_int64(int64_t val);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1747 2218
1748 bool upb_fielddef_typeisset(const upb_fielddef *f); 2219 bool upb_fielddef_typeisset(const upb_fielddef *f);
1749 upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f); 2220 upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f);
1750 upb_descriptortype_t upb_fielddef_descriptortype(const upb_fielddef *f); 2221 upb_descriptortype_t upb_fielddef_descriptortype(const upb_fielddef *f);
1751 upb_label_t upb_fielddef_label(const upb_fielddef *f); 2222 upb_label_t upb_fielddef_label(const upb_fielddef *f);
1752 uint32_t upb_fielddef_number(const upb_fielddef *f); 2223 uint32_t upb_fielddef_number(const upb_fielddef *f);
1753 const char *upb_fielddef_name(const upb_fielddef *f); 2224 const char *upb_fielddef_name(const upb_fielddef *f);
1754 bool upb_fielddef_isextension(const upb_fielddef *f); 2225 bool upb_fielddef_isextension(const upb_fielddef *f);
1755 bool upb_fielddef_lazy(const upb_fielddef *f); 2226 bool upb_fielddef_lazy(const upb_fielddef *f);
1756 bool upb_fielddef_packed(const upb_fielddef *f); 2227 bool upb_fielddef_packed(const upb_fielddef *f);
2228 size_t upb_fielddef_getjsonname(const upb_fielddef *f, char *buf, size_t len);
1757 const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f); 2229 const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f);
1758 const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f); 2230 const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f);
1759 upb_msgdef *upb_fielddef_containingtype_mutable(upb_fielddef *f); 2231 upb_msgdef *upb_fielddef_containingtype_mutable(upb_fielddef *f);
1760 const char *upb_fielddef_containingtypename(upb_fielddef *f); 2232 const char *upb_fielddef_containingtypename(upb_fielddef *f);
1761 upb_intfmt_t upb_fielddef_intfmt(const upb_fielddef *f); 2233 upb_intfmt_t upb_fielddef_intfmt(const upb_fielddef *f);
1762 uint32_t upb_fielddef_index(const upb_fielddef *f); 2234 uint32_t upb_fielddef_index(const upb_fielddef *f);
1763 bool upb_fielddef_istagdelim(const upb_fielddef *f); 2235 bool upb_fielddef_istagdelim(const upb_fielddef *f);
1764 bool upb_fielddef_issubmsg(const upb_fielddef *f); 2236 bool upb_fielddef_issubmsg(const upb_fielddef *f);
1765 bool upb_fielddef_isstring(const upb_fielddef *f); 2237 bool upb_fielddef_isstring(const upb_fielddef *f);
1766 bool upb_fielddef_isseq(const upb_fielddef *f); 2238 bool upb_fielddef_isseq(const upb_fielddef *f);
1767 bool upb_fielddef_isprimitive(const upb_fielddef *f); 2239 bool upb_fielddef_isprimitive(const upb_fielddef *f);
1768 bool upb_fielddef_ismap(const upb_fielddef *f); 2240 bool upb_fielddef_ismap(const upb_fielddef *f);
2241 bool upb_fielddef_haspresence(const upb_fielddef *f);
1769 int64_t upb_fielddef_defaultint64(const upb_fielddef *f); 2242 int64_t upb_fielddef_defaultint64(const upb_fielddef *f);
1770 int32_t upb_fielddef_defaultint32(const upb_fielddef *f); 2243 int32_t upb_fielddef_defaultint32(const upb_fielddef *f);
1771 uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f); 2244 uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f);
1772 uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f); 2245 uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f);
1773 bool upb_fielddef_defaultbool(const upb_fielddef *f); 2246 bool upb_fielddef_defaultbool(const upb_fielddef *f);
1774 float upb_fielddef_defaultfloat(const upb_fielddef *f); 2247 float upb_fielddef_defaultfloat(const upb_fielddef *f);
1775 double upb_fielddef_defaultdouble(const upb_fielddef *f); 2248 double upb_fielddef_defaultdouble(const upb_fielddef *f);
1776 const char *upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len); 2249 const char *upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len);
1777 bool upb_fielddef_enumhasdefaultint32(const upb_fielddef *f); 2250 bool upb_fielddef_enumhasdefaultint32(const upb_fielddef *f);
1778 bool upb_fielddef_enumhasdefaultstr(const upb_fielddef *f); 2251 bool upb_fielddef_enumhasdefaultstr(const upb_fielddef *f);
1779 bool upb_fielddef_hassubdef(const upb_fielddef *f); 2252 bool upb_fielddef_hassubdef(const upb_fielddef *f);
1780 const upb_def *upb_fielddef_subdef(const upb_fielddef *f); 2253 const upb_def *upb_fielddef_subdef(const upb_fielddef *f);
1781 const upb_msgdef *upb_fielddef_msgsubdef(const upb_fielddef *f); 2254 const upb_msgdef *upb_fielddef_msgsubdef(const upb_fielddef *f);
1782 const upb_enumdef *upb_fielddef_enumsubdef(const upb_fielddef *f); 2255 const upb_enumdef *upb_fielddef_enumsubdef(const upb_fielddef *f);
1783 const char *upb_fielddef_subdefname(const upb_fielddef *f); 2256 const char *upb_fielddef_subdefname(const upb_fielddef *f);
1784 2257
1785 void upb_fielddef_settype(upb_fielddef *f, upb_fieldtype_t type); 2258 void upb_fielddef_settype(upb_fielddef *f, upb_fieldtype_t type);
1786 void upb_fielddef_setdescriptortype(upb_fielddef *f, int type); 2259 void upb_fielddef_setdescriptortype(upb_fielddef *f, int type);
1787 void upb_fielddef_setlabel(upb_fielddef *f, upb_label_t label); 2260 void upb_fielddef_setlabel(upb_fielddef *f, upb_label_t label);
1788 bool upb_fielddef_setnumber(upb_fielddef *f, uint32_t number, upb_status *s); 2261 bool upb_fielddef_setnumber(upb_fielddef *f, uint32_t number, upb_status *s);
1789 bool upb_fielddef_setname(upb_fielddef *f, const char *name, upb_status *s); 2262 bool upb_fielddef_setname(upb_fielddef *f, const char *name, upb_status *s);
2263 bool upb_fielddef_setjsonname(upb_fielddef *f, const char *name, upb_status *s);
2264 bool upb_fielddef_clearjsonname(upb_fielddef *f);
1790 bool upb_fielddef_setcontainingtypename(upb_fielddef *f, const char *name, 2265 bool upb_fielddef_setcontainingtypename(upb_fielddef *f, const char *name,
1791 upb_status *s); 2266 upb_status *s);
1792 void upb_fielddef_setisextension(upb_fielddef *f, bool is_extension); 2267 void upb_fielddef_setisextension(upb_fielddef *f, bool is_extension);
1793 void upb_fielddef_setlazy(upb_fielddef *f, bool lazy); 2268 void upb_fielddef_setlazy(upb_fielddef *f, bool lazy);
1794 void upb_fielddef_setpacked(upb_fielddef *f, bool packed); 2269 void upb_fielddef_setpacked(upb_fielddef *f, bool packed);
1795 void upb_fielddef_setintfmt(upb_fielddef *f, upb_intfmt_t fmt); 2270 void upb_fielddef_setintfmt(upb_fielddef *f, upb_intfmt_t fmt);
1796 void upb_fielddef_settagdelim(upb_fielddef *f, bool tag_delim); 2271 void upb_fielddef_settagdelim(upb_fielddef *f, bool tag_delim);
1797 void upb_fielddef_setdefaultint64(upb_fielddef *f, int64_t val); 2272 void upb_fielddef_setdefaultint64(upb_fielddef *f, int64_t val);
1798 void upb_fielddef_setdefaultint32(upb_fielddef *f, int32_t val); 2273 void upb_fielddef_setdefaultint32(upb_fielddef *f, int32_t val);
1799 void upb_fielddef_setdefaultuint64(upb_fielddef *f, uint64_t val); 2274 void upb_fielddef_setdefaultuint64(upb_fielddef *f, uint64_t val);
(...skipping 20 matching lines...) Expand all
1820 bool upb_fielddef_checkintfmt(int32_t fmt); 2295 bool upb_fielddef_checkintfmt(int32_t fmt);
1821 2296
1822 UPB_END_EXTERN_C 2297 UPB_END_EXTERN_C
1823 2298
1824 2299
1825 /* upb::MessageDef ************************************************************/ 2300 /* upb::MessageDef ************************************************************/
1826 2301
1827 typedef upb_inttable_iter upb_msg_field_iter; 2302 typedef upb_inttable_iter upb_msg_field_iter;
1828 typedef upb_strtable_iter upb_msg_oneof_iter; 2303 typedef upb_strtable_iter upb_msg_oneof_iter;
1829 2304
2305 /* Well-known field tag numbers for map-entry messages. */
2306 #define UPB_MAPENTRY_KEY 1
2307 #define UPB_MAPENTRY_VALUE 2
2308
1830 #ifdef __cplusplus 2309 #ifdef __cplusplus
1831 2310
1832 /* Structure that describes a single .proto message type. 2311 /* Structure that describes a single .proto message type.
1833 * 2312 *
1834 * Its base class is upb::Def (use upb::upcast() to convert). */ 2313 * Its base class is upb::Def (use upb::upcast() to convert). */
1835 class upb::MessageDef { 2314 class upb::MessageDef {
1836 public: 2315 public:
1837 /* Returns NULL if memory allocation failed. */ 2316 /* Returns NULL if memory allocation failed. */
1838 static reffed_ptr<MessageDef> New(); 2317 static reffed_ptr<MessageDef> New();
1839 2318
1840 /* upb::RefCounted methods like Ref()/Unref(). */ 2319 /* upb::RefCounted methods like Ref()/Unref(). */
1841 UPB_REFCOUNTED_CPPMETHODS 2320 UPB_REFCOUNTED_CPPMETHODS
1842 2321
1843 /* Functionality from upb::Def. */ 2322 /* Functionality from upb::Def. */
1844 const char* full_name() const; 2323 const char* full_name() const;
2324 const char* name() const;
1845 bool set_full_name(const char* fullname, Status* s); 2325 bool set_full_name(const char* fullname, Status* s);
1846 bool set_full_name(const std::string& fullname, Status* s); 2326 bool set_full_name(const std::string& fullname, Status* s);
1847 2327
1848 /* Call to freeze this MessageDef. 2328 /* Call to freeze this MessageDef.
1849 * WARNING: this will fail if this message has any unfrozen submessages! 2329 * WARNING: this will fail if this message has any unfrozen submessages!
1850 * Messages with cycles must be frozen as a batch using upb::Def::Freeze(). */ 2330 * Messages with cycles must be frozen as a batch using upb::Def::Freeze(). */
1851 bool Freeze(Status* s); 2331 bool Freeze(Status* s);
1852 2332
1853 /* The number of fields that belong to the MessageDef. */ 2333 /* The number of fields that belong to the MessageDef. */
1854 int field_count() const; 2334 int field_count() const;
(...skipping 22 matching lines...) Expand all
1877 /* Adds a oneof (upb_oneofdef object) to a msgdef. Requires that the msgdef, 2357 /* Adds a oneof (upb_oneofdef object) to a msgdef. Requires that the msgdef,
1878 * oneof, and any fielddefs are mutable, that the fielddefs contained in the 2358 * oneof, and any fielddefs are mutable, that the fielddefs contained in the
1879 * oneof do not have any name or number conflicts with existing fields in the 2359 * oneof do not have any name or number conflicts with existing fields in the
1880 * msgdef, and that the oneof's name is unique among all oneofs in the msgdef. 2360 * msgdef, and that the oneof's name is unique among all oneofs in the msgdef.
1881 * If the oneof is added successfully, all of its fields will be added 2361 * If the oneof is added successfully, all of its fields will be added
1882 * directly to the msgdef as well. In error cases, false is returned and the 2362 * directly to the msgdef as well. In error cases, false is returned and the
1883 * msgdef is unchanged. */ 2363 * msgdef is unchanged. */
1884 bool AddOneof(OneofDef* o, Status* s); 2364 bool AddOneof(OneofDef* o, Status* s);
1885 bool AddOneof(const reffed_ptr<OneofDef>& o, Status* s); 2365 bool AddOneof(const reffed_ptr<OneofDef>& o, Status* s);
1886 2366
2367 upb_syntax_t syntax() const;
2368
2369 /* Returns false if we don't support this syntax value. */
2370 bool set_syntax(upb_syntax_t syntax);
2371
2372 /* Set this to false to indicate that primitive fields should not have
2373 * explicit presence information associated with them. This will affect all
2374 * fields added to this message. Defaults to true. */
2375 void SetPrimitivesHavePresence(bool have_presence);
2376
1887 /* These return NULL if the field is not found. */ 2377 /* These return NULL if the field is not found. */
1888 FieldDef* FindFieldByNumber(uint32_t number); 2378 FieldDef* FindFieldByNumber(uint32_t number);
1889 FieldDef* FindFieldByName(const char *name, size_t len); 2379 FieldDef* FindFieldByName(const char *name, size_t len);
1890 const FieldDef* FindFieldByNumber(uint32_t number) const; 2380 const FieldDef* FindFieldByNumber(uint32_t number) const;
1891 const FieldDef* FindFieldByName(const char* name, size_t len) const; 2381 const FieldDef* FindFieldByName(const char* name, size_t len) const;
1892 2382
1893 2383
1894 FieldDef* FindFieldByName(const char *name) { 2384 FieldDef* FindFieldByName(const char *name) {
1895 return FindFieldByName(name, strlen(name)); 2385 return FindFieldByName(name, strlen(name));
1896 } 2386 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 UPB_BEGIN_EXTERN_C 2552 UPB_BEGIN_EXTERN_C
2063 2553
2064 /* Returns NULL if memory allocation failed. */ 2554 /* Returns NULL if memory allocation failed. */
2065 upb_msgdef *upb_msgdef_new(const void *owner); 2555 upb_msgdef *upb_msgdef_new(const void *owner);
2066 2556
2067 /* Include upb_refcounted methods like upb_msgdef_ref(). */ 2557 /* Include upb_refcounted methods like upb_msgdef_ref(). */
2068 UPB_REFCOUNTED_CMETHODS(upb_msgdef, upb_msgdef_upcast2) 2558 UPB_REFCOUNTED_CMETHODS(upb_msgdef, upb_msgdef_upcast2)
2069 2559
2070 bool upb_msgdef_freeze(upb_msgdef *m, upb_status *status); 2560 bool upb_msgdef_freeze(upb_msgdef *m, upb_status *status);
2071 2561
2562 upb_msgdef *upb_msgdef_dup(const upb_msgdef *m, const void *owner);
2072 const char *upb_msgdef_fullname(const upb_msgdef *m); 2563 const char *upb_msgdef_fullname(const upb_msgdef *m);
2073 bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname, upb_status *s); 2564 const char *upb_msgdef_name(const upb_msgdef *m);
2565 int upb_msgdef_numoneofs(const upb_msgdef *m);
2566 upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m);
2074 2567
2075 upb_msgdef *upb_msgdef_dup(const upb_msgdef *m, const void *owner);
2076 bool upb_msgdef_addfield(upb_msgdef *m, upb_fielddef *f, const void *ref_donor, 2568 bool upb_msgdef_addfield(upb_msgdef *m, upb_fielddef *f, const void *ref_donor,
2077 upb_status *s); 2569 upb_status *s);
2078 bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor, 2570 bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor,
2079 upb_status *s); 2571 upb_status *s);
2572 bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname, upb_status *s);
2573 void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry);
2574 bool upb_msgdef_mapentry(const upb_msgdef *m);
2575 bool upb_msgdef_setsyntax(upb_msgdef *m, upb_syntax_t syntax);
2080 2576
2081 /* Field lookup in a couple of different variations: 2577 /* Field lookup in a couple of different variations:
2082 * - itof = int to field 2578 * - itof = int to field
2083 * - ntof = name to field 2579 * - ntof = name to field
2084 * - ntofz = name to field, null-terminated string. */ 2580 * - ntofz = name to field, null-terminated string. */
2085 const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i); 2581 const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i);
2086 const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name, 2582 const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name,
2087 size_t len); 2583 size_t len);
2088 int upb_msgdef_numfields(const upb_msgdef *m); 2584 int upb_msgdef_numfields(const upb_msgdef *m);
2089 2585
(...skipping 21 matching lines...) Expand all
2111 UPB_INLINE const upb_oneofdef *upb_msgdef_ntooz(const upb_msgdef *m, 2607 UPB_INLINE const upb_oneofdef *upb_msgdef_ntooz(const upb_msgdef *m,
2112 const char *name) { 2608 const char *name) {
2113 return upb_msgdef_ntoo(m, name, strlen(name)); 2609 return upb_msgdef_ntoo(m, name, strlen(name));
2114 } 2610 }
2115 2611
2116 UPB_INLINE upb_oneofdef *upb_msgdef_ntoo_mutable(upb_msgdef *m, 2612 UPB_INLINE upb_oneofdef *upb_msgdef_ntoo_mutable(upb_msgdef *m,
2117 const char *name, size_t len) { 2613 const char *name, size_t len) {
2118 return (upb_oneofdef *)upb_msgdef_ntoo(m, name, len); 2614 return (upb_oneofdef *)upb_msgdef_ntoo(m, name, len);
2119 } 2615 }
2120 2616
2121 void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry); 2617 /* Lookup of either field or oneof by name. Returns whether either was found.
2122 bool upb_msgdef_mapentry(const upb_msgdef *m); 2618 * If the return is true, then the found def will be set, and the non-found
2619 * one set to NULL. */
2620 bool upb_msgdef_lookupname(const upb_msgdef *m, const char *name, size_t len,
2621 const upb_fielddef **f, const upb_oneofdef **o);
2123 2622
2124 /* Well-known field tag numbers for map-entry messages. */ 2623 UPB_INLINE bool upb_msgdef_lookupnamez(const upb_msgdef *m, const char *name,
2125 #define UPB_MAPENTRY_KEY 1 2624 const upb_fielddef **f,
2126 #define UPB_MAPENTRY_VALUE 2 2625 const upb_oneofdef **o) {
2626 return upb_msgdef_lookupname(m, name, strlen(name), f, o);
2627 }
2127 2628
2128 const upb_oneofdef *upb_msgdef_findoneof(const upb_msgdef *m, 2629 /* Iteration over fields and oneofs. For example:
2129 const char *name); 2630 *
2130 int upb_msgdef_numoneofs(const upb_msgdef *m); 2631 * upb_msg_field_iter i;
2131
2132 /* upb_msg_field_iter i;
2133 * for(upb_msg_field_begin(&i, m); 2632 * for(upb_msg_field_begin(&i, m);
2134 * !upb_msg_field_done(&i); 2633 * !upb_msg_field_done(&i);
2135 * upb_msg_field_next(&i)) { 2634 * upb_msg_field_next(&i)) {
2136 * upb_fielddef *f = upb_msg_iter_field(&i); 2635 * upb_fielddef *f = upb_msg_iter_field(&i);
2137 * // ... 2636 * // ...
2138 * } 2637 * }
2139 * 2638 *
2140 * For C we don't have separate iterators for const and non-const. 2639 * For C we don't have separate iterators for const and non-const.
2141 * It is the caller's responsibility to cast the upb_fielddef* to 2640 * It is the caller's responsibility to cast the upb_fielddef* to
2142 * const if the upb_msgdef* is const. */ 2641 * const if the upb_msgdef* is const. */
(...skipping 25 matching lines...) Expand all
2168 class upb::EnumDef { 2667 class upb::EnumDef {
2169 public: 2668 public:
2170 /* Returns NULL if memory allocation failed. */ 2669 /* Returns NULL if memory allocation failed. */
2171 static reffed_ptr<EnumDef> New(); 2670 static reffed_ptr<EnumDef> New();
2172 2671
2173 /* upb::RefCounted methods like Ref()/Unref(). */ 2672 /* upb::RefCounted methods like Ref()/Unref(). */
2174 UPB_REFCOUNTED_CPPMETHODS 2673 UPB_REFCOUNTED_CPPMETHODS
2175 2674
2176 /* Functionality from upb::Def. */ 2675 /* Functionality from upb::Def. */
2177 const char* full_name() const; 2676 const char* full_name() const;
2677 const char* name() const;
2178 bool set_full_name(const char* fullname, Status* s); 2678 bool set_full_name(const char* fullname, Status* s);
2179 bool set_full_name(const std::string& fullname, Status* s); 2679 bool set_full_name(const std::string& fullname, Status* s);
2180 2680
2181 /* Call to freeze this EnumDef. */ 2681 /* Call to freeze this EnumDef. */
2182 bool Freeze(Status* s); 2682 bool Freeze(Status* s);
2183 2683
2184 /* The value that is used as the default when no field default is specified. 2684 /* The value that is used as the default when no field default is specified.
2185 * If not set explicitly, the first value that was added will be used. 2685 * If not set explicitly, the first value that was added will be used.
2186 * The default value must be a member of the enum. 2686 * The default value must be a member of the enum.
2187 * Requires that value_count() > 0. */ 2687 * Requires that value_count() > 0. */
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2242 upb_enumdef *upb_enumdef_new(const void *owner); 2742 upb_enumdef *upb_enumdef_new(const void *owner);
2243 upb_enumdef *upb_enumdef_dup(const upb_enumdef *e, const void *owner); 2743 upb_enumdef *upb_enumdef_dup(const upb_enumdef *e, const void *owner);
2244 2744
2245 /* Include upb_refcounted methods like upb_enumdef_ref(). */ 2745 /* Include upb_refcounted methods like upb_enumdef_ref(). */
2246 UPB_REFCOUNTED_CMETHODS(upb_enumdef, upb_enumdef_upcast2) 2746 UPB_REFCOUNTED_CMETHODS(upb_enumdef, upb_enumdef_upcast2)
2247 2747
2248 bool upb_enumdef_freeze(upb_enumdef *e, upb_status *status); 2748 bool upb_enumdef_freeze(upb_enumdef *e, upb_status *status);
2249 2749
2250 /* From upb_def. */ 2750 /* From upb_def. */
2251 const char *upb_enumdef_fullname(const upb_enumdef *e); 2751 const char *upb_enumdef_fullname(const upb_enumdef *e);
2752 const char *upb_enumdef_name(const upb_enumdef *e);
2252 bool upb_enumdef_setfullname(upb_enumdef *e, const char *fullname, 2753 bool upb_enumdef_setfullname(upb_enumdef *e, const char *fullname,
2253 upb_status *s); 2754 upb_status *s);
2254 2755
2255 int32_t upb_enumdef_default(const upb_enumdef *e); 2756 int32_t upb_enumdef_default(const upb_enumdef *e);
2256 bool upb_enumdef_setdefault(upb_enumdef *e, int32_t val, upb_status *s); 2757 bool upb_enumdef_setdefault(upb_enumdef *e, int32_t val, upb_status *s);
2257 int upb_enumdef_numvals(const upb_enumdef *e); 2758 int upb_enumdef_numvals(const upb_enumdef *e);
2258 bool upb_enumdef_addval(upb_enumdef *e, const char *name, int32_t num, 2759 bool upb_enumdef_addval(upb_enumdef *e, const char *name, int32_t num,
2259 upb_status *status); 2760 upb_status *status);
2260 2761
2261 /* Enum lookups: 2762 /* Enum lookups:
(...skipping 21 matching lines...) Expand all
2283 int32_t upb_enum_iter_number(upb_enum_iter *iter); 2784 int32_t upb_enum_iter_number(upb_enum_iter *iter);
2284 2785
2285 UPB_END_EXTERN_C 2786 UPB_END_EXTERN_C
2286 2787
2287 /* upb::OneofDef **************************************************************/ 2788 /* upb::OneofDef **************************************************************/
2288 2789
2289 typedef upb_inttable_iter upb_oneof_iter; 2790 typedef upb_inttable_iter upb_oneof_iter;
2290 2791
2291 #ifdef __cplusplus 2792 #ifdef __cplusplus
2292 2793
2293 /* Class that represents a oneof. Its base class is upb::Def (convert with 2794 /* Class that represents a oneof. */
2294 * upb::upcast()). */
2295 class upb::OneofDef { 2795 class upb::OneofDef {
2296 public: 2796 public:
2297 /* Returns NULL if memory allocation failed. */ 2797 /* Returns NULL if memory allocation failed. */
2298 static reffed_ptr<OneofDef> New(); 2798 static reffed_ptr<OneofDef> New();
2299 2799
2300 /* upb::RefCounted methods like Ref()/Unref(). */ 2800 /* upb::RefCounted methods like Ref()/Unref(). */
2301 UPB_REFCOUNTED_CPPMETHODS 2801 UPB_REFCOUNTED_CPPMETHODS
2302 2802
2303 /* Functionality from upb::Def. */
2304 const char* full_name() const;
2305
2306 /* Returns the MessageDef that owns this OneofDef. */ 2803 /* Returns the MessageDef that owns this OneofDef. */
2307 const MessageDef* containing_type() const; 2804 const MessageDef* containing_type() const;
2308 2805
2309 /* Returns the name of this oneof. This is the name used to look up the oneof 2806 /* Returns the name of this oneof. This is the name used to look up the oneof
2310 * by name once added to a message def. */ 2807 * by name once added to a message def. */
2311 const char* name() const; 2808 const char* name() const;
2312 bool set_name(const char* name, Status* s); 2809 bool set_name(const char* name, Status* s);
2810 bool set_name(const std::string& name, Status* s);
2313 2811
2314 /* Returns the number of fields currently defined in the oneof. */ 2812 /* Returns the number of fields currently defined in the oneof. */
2315 int field_count() const; 2813 int field_count() const;
2316 2814
2317 /* Adds a field to the oneof. The field must not have been added to any other 2815 /* Adds a field to the oneof. The field must not have been added to any other
2318 * oneof or msgdef. If the oneof is not yet part of a msgdef, then when the 2816 * oneof or msgdef. If the oneof is not yet part of a msgdef, then when the
2319 * oneof is eventually added to a msgdef, all fields added to the oneof will 2817 * oneof is eventually added to a msgdef, all fields added to the oneof will
2320 * also be added to the msgdef at that time. If the oneof is already part of a 2818 * also be added to the msgdef at that time. If the oneof is already part of a
2321 * msgdef, the field must either be a part of that msgdef already, or must not 2819 * msgdef, the field must either be a part of that msgdef already, or must not
2322 * be a part of any msgdef; in the latter case, the field is added to the 2820 * be a part of any msgdef; in the latter case, the field is added to the
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2396 2894
2397 #endif /* __cplusplus */ 2895 #endif /* __cplusplus */
2398 2896
2399 UPB_BEGIN_EXTERN_C 2897 UPB_BEGIN_EXTERN_C
2400 2898
2401 /* Native C API. */ 2899 /* Native C API. */
2402 upb_oneofdef *upb_oneofdef_new(const void *owner); 2900 upb_oneofdef *upb_oneofdef_new(const void *owner);
2403 upb_oneofdef *upb_oneofdef_dup(const upb_oneofdef *o, const void *owner); 2901 upb_oneofdef *upb_oneofdef_dup(const upb_oneofdef *o, const void *owner);
2404 2902
2405 /* Include upb_refcounted methods like upb_oneofdef_ref(). */ 2903 /* Include upb_refcounted methods like upb_oneofdef_ref(). */
2406 UPB_REFCOUNTED_CMETHODS(upb_oneofdef, upb_oneofdef_upcast2) 2904 UPB_REFCOUNTED_CMETHODS(upb_oneofdef, upb_oneofdef_upcast)
2407 2905
2408 const char *upb_oneofdef_name(const upb_oneofdef *o); 2906 const char *upb_oneofdef_name(const upb_oneofdef *o);
2409 bool upb_oneofdef_setname(upb_oneofdef *o, const char *name, upb_status *s); 2907 bool upb_oneofdef_setname(upb_oneofdef *o, const char *name, upb_status *s);
2410 2908
2411 const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o); 2909 const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o);
2412 int upb_oneofdef_numfields(const upb_oneofdef *o); 2910 int upb_oneofdef_numfields(const upb_oneofdef *o);
2413 bool upb_oneofdef_addfield(upb_oneofdef *o, upb_fielddef *f, 2911 bool upb_oneofdef_addfield(upb_oneofdef *o, upb_fielddef *f,
2414 const void *ref_donor, 2912 const void *ref_donor,
2415 upb_status *s); 2913 upb_status *s);
2416 2914
(...skipping 15 matching lines...) Expand all
2432 * } 2930 * }
2433 */ 2931 */
2434 void upb_oneof_begin(upb_oneof_iter *iter, const upb_oneofdef *o); 2932 void upb_oneof_begin(upb_oneof_iter *iter, const upb_oneofdef *o);
2435 void upb_oneof_next(upb_oneof_iter *iter); 2933 void upb_oneof_next(upb_oneof_iter *iter);
2436 bool upb_oneof_done(upb_oneof_iter *iter); 2934 bool upb_oneof_done(upb_oneof_iter *iter);
2437 upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter); 2935 upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter);
2438 void upb_oneof_iter_setdone(upb_oneof_iter *iter); 2936 void upb_oneof_iter_setdone(upb_oneof_iter *iter);
2439 2937
2440 UPB_END_EXTERN_C 2938 UPB_END_EXTERN_C
2441 2939
2940
2941 /* upb::FileDef ***************************************************************/
2942
2943 #ifdef __cplusplus
2944
2945 /* Class that represents a .proto file with some things defined in it.
2946 *
2947 * Many users won't care about FileDefs, but they are necessary if you want to
2948 * read the values of file-level options. */
2949 class upb::FileDef {
2950 public:
2951 /* Returns NULL if memory allocation failed. */
2952 static reffed_ptr<FileDef> New();
2953
2954 /* upb::RefCounted methods like Ref()/Unref(). */
2955 UPB_REFCOUNTED_CPPMETHODS
2956
2957 /* Get/set name of the file (eg. "foo/bar.proto"). */
2958 const char* name() const;
2959 bool set_name(const char* name, Status* s);
2960 bool set_name(const std::string& name, Status* s);
2961
2962 /* Package name for definitions inside the file (eg. "foo.bar"). */
2963 const char* package() const;
2964 bool set_package(const char* package, Status* s);
2965
2966 /* Syntax for the file. Defaults to proto2. */
2967 upb_syntax_t syntax() const;
2968 void set_syntax(upb_syntax_t syntax);
2969
2970 /* Get the list of defs from the file. These are returned in the order that
2971 * they were added to the FileDef. */
2972 int def_count() const;
2973 const Def* def(int index) const;
2974 Def* def(int index);
2975
2976 /* Get the list of dependencies from the file. These are returned in the
2977 * order that they were added to the FileDef. */
2978 int dependency_count() const;
2979 const FileDef* dependency(int index) const;
2980
2981 /* Adds defs to this file. The def must not already belong to another
2982 * file.
2983 *
2984 * Note: this does *not* ensure that this def's name is unique in this file!
2985 * Use a SymbolTable if you want to check this property. Especially since
2986 * properly checking uniqueness would require a check across *all* files
2987 * (including dependencies). */
2988 bool AddDef(Def* def, Status* s);
2989 bool AddMessage(MessageDef* m, Status* s);
2990 bool AddEnum(EnumDef* e, Status* s);
2991 bool AddExtension(FieldDef* f, Status* s);
2992
2993 /* Adds a dependency of this file. */
2994 bool AddDependency(const FileDef* file);
2995
2996 /* Freezes this FileDef and all messages/enums under it. All subdefs must be
2997 * resolved and all messages/enums must validate. Returns true if this
2998 * succeeded.
2999 *
3000 * TODO(haberman): should we care whether the file's dependencies are frozen
3001 * already? */
3002 bool Freeze(Status* s);
3003
3004 private:
3005 UPB_DISALLOW_POD_OPS(FileDef, upb::FileDef)
3006 };
3007
3008 #endif
3009
3010 UPB_BEGIN_EXTERN_C
3011
3012 upb_filedef *upb_filedef_new(const void *owner);
3013
3014 /* Include upb_refcounted methods like upb_msgdef_ref(). */
3015 UPB_REFCOUNTED_CMETHODS(upb_filedef, upb_filedef_upcast)
3016
3017 const char *upb_filedef_name(const upb_filedef *f);
3018 const char *upb_filedef_package(const upb_filedef *f);
3019 upb_syntax_t upb_filedef_syntax(const upb_filedef *f);
3020 size_t upb_filedef_defcount(const upb_filedef *f);
3021 size_t upb_filedef_depcount(const upb_filedef *f);
3022 const upb_def *upb_filedef_def(const upb_filedef *f, size_t i);
3023 const upb_filedef *upb_filedef_dep(const upb_filedef *f, size_t i);
3024
3025 bool upb_filedef_freeze(upb_filedef *f, upb_status *s);
3026 bool upb_filedef_setname(upb_filedef *f, const char *name, upb_status *s);
3027 bool upb_filedef_setpackage(upb_filedef *f, const char *package, upb_status *s);
3028 bool upb_filedef_setsyntax(upb_filedef *f, upb_syntax_t syntax, upb_status *s);
3029
3030 bool upb_filedef_adddef(upb_filedef *f, upb_def *def, const void *ref_donor,
3031 upb_status *s);
3032 bool upb_filedef_adddep(upb_filedef *f, const upb_filedef *dep);
3033
3034 UPB_INLINE bool upb_filedef_addmsg(upb_filedef *f, upb_msgdef *m,
3035 const void *ref_donor, upb_status *s) {
3036 return upb_filedef_adddef(f, upb_msgdef_upcast_mutable(m), ref_donor, s);
3037 }
3038
3039 UPB_INLINE bool upb_filedef_addenum(upb_filedef *f, upb_enumdef *e,
3040 const void *ref_donor, upb_status *s) {
3041 return upb_filedef_adddef(f, upb_enumdef_upcast_mutable(e), ref_donor, s);
3042 }
3043
3044 UPB_INLINE bool upb_filedef_addext(upb_filedef *file, upb_fielddef *f,
3045 const void *ref_donor, upb_status *s) {
3046 return upb_filedef_adddef(file, upb_fielddef_upcast_mutable(f), ref_donor, s);
3047 }
3048 UPB_INLINE upb_def *upb_filedef_mutabledef(upb_filedef *f, int i) {
3049 return (upb_def*)upb_filedef_def(f, i);
3050 }
3051
3052 UPB_END_EXTERN_C
3053
2442 #ifdef __cplusplus 3054 #ifdef __cplusplus
2443 3055
2444 UPB_INLINE const char* upb_safecstr(const std::string& str) { 3056 UPB_INLINE const char* upb_safecstr(const std::string& str) {
2445 assert(str.size() == std::strlen(str.c_str())); 3057 UPB_ASSERT(str.size() == std::strlen(str.c_str()));
2446 return str.c_str(); 3058 return str.c_str();
2447 } 3059 }
2448 3060
2449 /* Inline C++ wrappers. */ 3061 /* Inline C++ wrappers. */
2450 namespace upb { 3062 namespace upb {
2451 3063
2452 inline Def* Def::Dup(const void* owner) const { 3064 inline Def* Def::Dup(const void* owner) const {
2453 return upb_def_dup(this, owner); 3065 return upb_def_dup(this, owner);
2454 } 3066 }
2455 inline Def::Type Def::def_type() const { return upb_def_type(this); } 3067 inline Def::Type Def::def_type() const { return upb_def_type(this); }
2456 inline const char* Def::full_name() const { return upb_def_fullname(this); } 3068 inline const char* Def::full_name() const { return upb_def_fullname(this); }
3069 inline const char* Def::name() const { return upb_def_name(this); }
2457 inline bool Def::set_full_name(const char* fullname, Status* s) { 3070 inline bool Def::set_full_name(const char* fullname, Status* s) {
2458 return upb_def_setfullname(this, fullname, s); 3071 return upb_def_setfullname(this, fullname, s);
2459 } 3072 }
2460 inline bool Def::set_full_name(const std::string& fullname, Status* s) { 3073 inline bool Def::set_full_name(const std::string& fullname, Status* s) {
2461 return upb_def_setfullname(this, upb_safecstr(fullname), s); 3074 return upb_def_setfullname(this, upb_safecstr(fullname), s);
2462 } 3075 }
2463 inline bool Def::Freeze(Def* const* defs, int n, Status* status) { 3076 inline bool Def::Freeze(Def* const* defs, size_t n, Status* status) {
2464 return upb_def_freeze(defs, n, status); 3077 return upb_def_freeze(defs, n, status);
2465 } 3078 }
2466 inline bool Def::Freeze(const std::vector<Def*>& defs, Status* status) { 3079 inline bool Def::Freeze(const std::vector<Def*>& defs, Status* status) {
2467 return upb_def_freeze((Def* const*)&defs[0], defs.size(), status); 3080 return upb_def_freeze((Def* const*)&defs[0], defs.size(), status);
2468 } 3081 }
2469 3082
2470 inline bool FieldDef::CheckType(int32_t val) { 3083 inline bool FieldDef::CheckType(int32_t val) {
2471 return upb_fielddef_checktype(val); 3084 return upb_fielddef_checktype(val);
2472 } 3085 }
2473 inline bool FieldDef::CheckLabel(int32_t val) { 3086 inline bool FieldDef::CheckLabel(int32_t val) {
2474 return upb_fielddef_checklabel(val); 3087 return upb_fielddef_checklabel(val);
2475 } 3088 }
2476 inline bool FieldDef::CheckDescriptorType(int32_t val) { 3089 inline bool FieldDef::CheckDescriptorType(int32_t val) {
2477 return upb_fielddef_checkdescriptortype(val); 3090 return upb_fielddef_checkdescriptortype(val);
2478 } 3091 }
2479 inline bool FieldDef::CheckIntegerFormat(int32_t val) { 3092 inline bool FieldDef::CheckIntegerFormat(int32_t val) {
2480 return upb_fielddef_checkintfmt(val); 3093 return upb_fielddef_checkintfmt(val);
2481 } 3094 }
2482 inline FieldDef::Type FieldDef::ConvertType(int32_t val) { 3095 inline FieldDef::Type FieldDef::ConvertType(int32_t val) {
2483 assert(CheckType(val)); 3096 UPB_ASSERT(CheckType(val));
2484 return static_cast<FieldDef::Type>(val); 3097 return static_cast<FieldDef::Type>(val);
2485 } 3098 }
2486 inline FieldDef::Label FieldDef::ConvertLabel(int32_t val) { 3099 inline FieldDef::Label FieldDef::ConvertLabel(int32_t val) {
2487 assert(CheckLabel(val)); 3100 UPB_ASSERT(CheckLabel(val));
2488 return static_cast<FieldDef::Label>(val); 3101 return static_cast<FieldDef::Label>(val);
2489 } 3102 }
2490 inline FieldDef::DescriptorType FieldDef::ConvertDescriptorType(int32_t val) { 3103 inline FieldDef::DescriptorType FieldDef::ConvertDescriptorType(int32_t val) {
2491 assert(CheckDescriptorType(val)); 3104 UPB_ASSERT(CheckDescriptorType(val));
2492 return static_cast<FieldDef::DescriptorType>(val); 3105 return static_cast<FieldDef::DescriptorType>(val);
2493 } 3106 }
2494 inline FieldDef::IntegerFormat FieldDef::ConvertIntegerFormat(int32_t val) { 3107 inline FieldDef::IntegerFormat FieldDef::ConvertIntegerFormat(int32_t val) {
2495 assert(CheckIntegerFormat(val)); 3108 UPB_ASSERT(CheckIntegerFormat(val));
2496 return static_cast<FieldDef::IntegerFormat>(val); 3109 return static_cast<FieldDef::IntegerFormat>(val);
2497 } 3110 }
2498 3111
2499 inline reffed_ptr<FieldDef> FieldDef::New() { 3112 inline reffed_ptr<FieldDef> FieldDef::New() {
2500 upb_fielddef *f = upb_fielddef_new(&f); 3113 upb_fielddef *f = upb_fielddef_new(&f);
2501 return reffed_ptr<FieldDef>(f, &f); 3114 return reffed_ptr<FieldDef>(f, &f);
2502 } 3115 }
2503 inline FieldDef* FieldDef::Dup(const void* owner) const { 3116 inline FieldDef* FieldDef::Dup(const void* owner) const {
2504 return upb_fielddef_dup(this, owner); 3117 return upb_fielddef_dup(this, owner);
2505 } 3118 }
(...skipping 14 matching lines...) Expand all
2520 return upb_fielddef_descriptortype(this); 3133 return upb_fielddef_descriptortype(this);
2521 } 3134 }
2522 inline FieldDef::Label FieldDef::label() const { 3135 inline FieldDef::Label FieldDef::label() const {
2523 return upb_fielddef_label(this); 3136 return upb_fielddef_label(this);
2524 } 3137 }
2525 inline uint32_t FieldDef::number() const { return upb_fielddef_number(this); } 3138 inline uint32_t FieldDef::number() const { return upb_fielddef_number(this); }
2526 inline const char* FieldDef::name() const { return upb_fielddef_name(this); } 3139 inline const char* FieldDef::name() const { return upb_fielddef_name(this); }
2527 inline bool FieldDef::is_extension() const { 3140 inline bool FieldDef::is_extension() const {
2528 return upb_fielddef_isextension(this); 3141 return upb_fielddef_isextension(this);
2529 } 3142 }
3143 inline size_t FieldDef::GetJsonName(char* buf, size_t len) const {
3144 return upb_fielddef_getjsonname(this, buf, len);
3145 }
2530 inline bool FieldDef::lazy() const { 3146 inline bool FieldDef::lazy() const {
2531 return upb_fielddef_lazy(this); 3147 return upb_fielddef_lazy(this);
2532 } 3148 }
2533 inline void FieldDef::set_lazy(bool lazy) { 3149 inline void FieldDef::set_lazy(bool lazy) {
2534 upb_fielddef_setlazy(this, lazy); 3150 upb_fielddef_setlazy(this, lazy);
2535 } 3151 }
2536 inline bool FieldDef::packed() const { 3152 inline bool FieldDef::packed() const {
2537 return upb_fielddef_packed(this); 3153 return upb_fielddef_packed(this);
2538 } 3154 }
3155 inline uint32_t FieldDef::index() const {
3156 return upb_fielddef_index(this);
3157 }
2539 inline void FieldDef::set_packed(bool packed) { 3158 inline void FieldDef::set_packed(bool packed) {
2540 upb_fielddef_setpacked(this, packed); 3159 upb_fielddef_setpacked(this, packed);
2541 } 3160 }
2542 inline const MessageDef* FieldDef::containing_type() const { 3161 inline const MessageDef* FieldDef::containing_type() const {
2543 return upb_fielddef_containingtype(this); 3162 return upb_fielddef_containingtype(this);
2544 } 3163 }
2545 inline const OneofDef* FieldDef::containing_oneof() const { 3164 inline const OneofDef* FieldDef::containing_oneof() const {
2546 return upb_fielddef_containingoneof(this); 3165 return upb_fielddef_containingoneof(this);
2547 } 3166 }
2548 inline const char* FieldDef::containing_type_name() { 3167 inline const char* FieldDef::containing_type_name() {
2549 return upb_fielddef_containingtypename(this); 3168 return upb_fielddef_containingtypename(this);
2550 } 3169 }
2551 inline bool FieldDef::set_number(uint32_t number, Status* s) { 3170 inline bool FieldDef::set_number(uint32_t number, Status* s) {
2552 return upb_fielddef_setnumber(this, number, s); 3171 return upb_fielddef_setnumber(this, number, s);
2553 } 3172 }
2554 inline bool FieldDef::set_name(const char *name, Status* s) { 3173 inline bool FieldDef::set_name(const char *name, Status* s) {
2555 return upb_fielddef_setname(this, name, s); 3174 return upb_fielddef_setname(this, name, s);
2556 } 3175 }
2557 inline bool FieldDef::set_name(const std::string& name, Status* s) { 3176 inline bool FieldDef::set_name(const std::string& name, Status* s) {
2558 return upb_fielddef_setname(this, upb_safecstr(name), s); 3177 return upb_fielddef_setname(this, upb_safecstr(name), s);
2559 } 3178 }
3179 inline bool FieldDef::set_json_name(const char *name, Status* s) {
3180 return upb_fielddef_setjsonname(this, name, s);
3181 }
3182 inline bool FieldDef::set_json_name(const std::string& name, Status* s) {
3183 return upb_fielddef_setjsonname(this, upb_safecstr(name), s);
3184 }
3185 inline void FieldDef::clear_json_name() {
3186 upb_fielddef_clearjsonname(this);
3187 }
2560 inline bool FieldDef::set_containing_type_name(const char *name, Status* s) { 3188 inline bool FieldDef::set_containing_type_name(const char *name, Status* s) {
2561 return upb_fielddef_setcontainingtypename(this, name, s); 3189 return upb_fielddef_setcontainingtypename(this, name, s);
2562 } 3190 }
2563 inline bool FieldDef::set_containing_type_name(const std::string &name, 3191 inline bool FieldDef::set_containing_type_name(const std::string &name,
2564 Status *s) { 3192 Status *s) {
2565 return upb_fielddef_setcontainingtypename(this, upb_safecstr(name), s); 3193 return upb_fielddef_setcontainingtypename(this, upb_safecstr(name), s);
2566 } 3194 }
2567 inline void FieldDef::set_type(upb_fieldtype_t type) { 3195 inline void FieldDef::set_type(upb_fieldtype_t type) {
2568 upb_fielddef_settype(this, type); 3196 upb_fielddef_settype(this, type);
2569 } 3197 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2664 return upb_fielddef_setsubdefname(this, upb_safecstr(name), s); 3292 return upb_fielddef_setsubdefname(this, upb_safecstr(name), s);
2665 } 3293 }
2666 3294
2667 inline reffed_ptr<MessageDef> MessageDef::New() { 3295 inline reffed_ptr<MessageDef> MessageDef::New() {
2668 upb_msgdef *m = upb_msgdef_new(&m); 3296 upb_msgdef *m = upb_msgdef_new(&m);
2669 return reffed_ptr<MessageDef>(m, &m); 3297 return reffed_ptr<MessageDef>(m, &m);
2670 } 3298 }
2671 inline const char *MessageDef::full_name() const { 3299 inline const char *MessageDef::full_name() const {
2672 return upb_msgdef_fullname(this); 3300 return upb_msgdef_fullname(this);
2673 } 3301 }
3302 inline const char *MessageDef::name() const {
3303 return upb_msgdef_name(this);
3304 }
3305 inline upb_syntax_t MessageDef::syntax() const {
3306 return upb_msgdef_syntax(this);
3307 }
2674 inline bool MessageDef::set_full_name(const char* fullname, Status* s) { 3308 inline bool MessageDef::set_full_name(const char* fullname, Status* s) {
2675 return upb_msgdef_setfullname(this, fullname, s); 3309 return upb_msgdef_setfullname(this, fullname, s);
2676 } 3310 }
2677 inline bool MessageDef::set_full_name(const std::string& fullname, Status* s) { 3311 inline bool MessageDef::set_full_name(const std::string& fullname, Status* s) {
2678 return upb_msgdef_setfullname(this, upb_safecstr(fullname), s); 3312 return upb_msgdef_setfullname(this, upb_safecstr(fullname), s);
2679 } 3313 }
3314 inline bool MessageDef::set_syntax(upb_syntax_t syntax) {
3315 return upb_msgdef_setsyntax(this, syntax);
3316 }
2680 inline bool MessageDef::Freeze(Status* status) { 3317 inline bool MessageDef::Freeze(Status* status) {
2681 return upb_msgdef_freeze(this, status); 3318 return upb_msgdef_freeze(this, status);
2682 } 3319 }
2683 inline int MessageDef::field_count() const { 3320 inline int MessageDef::field_count() const {
2684 return upb_msgdef_numfields(this); 3321 return upb_msgdef_numfields(this);
2685 } 3322 }
2686 inline int MessageDef::oneof_count() const { 3323 inline int MessageDef::oneof_count() const {
2687 return upb_msgdef_numoneofs(this); 3324 return upb_msgdef_numoneofs(this);
2688 } 3325 }
2689 inline bool MessageDef::AddField(upb_fielddef* f, Status* s) { 3326 inline bool MessageDef::AddField(upb_fielddef* f, Status* s) {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
2851 return !(*this == other); 3488 return !(*this == other);
2852 } 3489 }
2853 3490
2854 inline reffed_ptr<EnumDef> EnumDef::New() { 3491 inline reffed_ptr<EnumDef> EnumDef::New() {
2855 upb_enumdef *e = upb_enumdef_new(&e); 3492 upb_enumdef *e = upb_enumdef_new(&e);
2856 return reffed_ptr<EnumDef>(e, &e); 3493 return reffed_ptr<EnumDef>(e, &e);
2857 } 3494 }
2858 inline const char* EnumDef::full_name() const { 3495 inline const char* EnumDef::full_name() const {
2859 return upb_enumdef_fullname(this); 3496 return upb_enumdef_fullname(this);
2860 } 3497 }
3498 inline const char* EnumDef::name() const {
3499 return upb_enumdef_name(this);
3500 }
2861 inline bool EnumDef::set_full_name(const char* fullname, Status* s) { 3501 inline bool EnumDef::set_full_name(const char* fullname, Status* s) {
2862 return upb_enumdef_setfullname(this, fullname, s); 3502 return upb_enumdef_setfullname(this, fullname, s);
2863 } 3503 }
2864 inline bool EnumDef::set_full_name(const std::string& fullname, Status* s) { 3504 inline bool EnumDef::set_full_name(const std::string& fullname, Status* s) {
2865 return upb_enumdef_setfullname(this, upb_safecstr(fullname), s); 3505 return upb_enumdef_setfullname(this, upb_safecstr(fullname), s);
2866 } 3506 }
2867 inline bool EnumDef::Freeze(Status* status) { 3507 inline bool EnumDef::Freeze(Status* status) {
2868 return upb_enumdef_freeze(this, status); 3508 return upb_enumdef_freeze(this, status);
2869 } 3509 }
2870 inline int32_t EnumDef::default_value() const { 3510 inline int32_t EnumDef::default_value() const {
(...skipping 29 matching lines...) Expand all
2900 inline const char* EnumDef::Iterator::name() { 3540 inline const char* EnumDef::Iterator::name() {
2901 return upb_enum_iter_name(&iter_); 3541 return upb_enum_iter_name(&iter_);
2902 } 3542 }
2903 inline bool EnumDef::Iterator::Done() { return upb_enum_done(&iter_); } 3543 inline bool EnumDef::Iterator::Done() { return upb_enum_done(&iter_); }
2904 inline void EnumDef::Iterator::Next() { return upb_enum_next(&iter_); } 3544 inline void EnumDef::Iterator::Next() { return upb_enum_next(&iter_); }
2905 3545
2906 inline reffed_ptr<OneofDef> OneofDef::New() { 3546 inline reffed_ptr<OneofDef> OneofDef::New() {
2907 upb_oneofdef *o = upb_oneofdef_new(&o); 3547 upb_oneofdef *o = upb_oneofdef_new(&o);
2908 return reffed_ptr<OneofDef>(o, &o); 3548 return reffed_ptr<OneofDef>(o, &o);
2909 } 3549 }
2910 inline const char* OneofDef::full_name() const {
2911 return upb_oneofdef_name(this);
2912 }
2913 3550
2914 inline const MessageDef* OneofDef::containing_type() const { 3551 inline const MessageDef* OneofDef::containing_type() const {
2915 return upb_oneofdef_containingtype(this); 3552 return upb_oneofdef_containingtype(this);
2916 } 3553 }
2917 inline const char* OneofDef::name() const { 3554 inline const char* OneofDef::name() const {
2918 return upb_oneofdef_name(this); 3555 return upb_oneofdef_name(this);
2919 } 3556 }
2920 inline bool OneofDef::set_name(const char* name, Status* s) { 3557 inline bool OneofDef::set_name(const char* name, Status* s) {
2921 return upb_oneofdef_setname(this, name, s); 3558 return upb_oneofdef_setname(this, name, s);
2922 } 3559 }
3560 inline bool OneofDef::set_name(const std::string& name, Status* s) {
3561 return upb_oneofdef_setname(this, upb_safecstr(name), s);
3562 }
2923 inline int OneofDef::field_count() const { 3563 inline int OneofDef::field_count() const {
2924 return upb_oneofdef_numfields(this); 3564 return upb_oneofdef_numfields(this);
2925 } 3565 }
2926 inline bool OneofDef::AddField(FieldDef* field, Status* s) { 3566 inline bool OneofDef::AddField(FieldDef* field, Status* s) {
2927 return upb_oneofdef_addfield(this, field, NULL, s); 3567 return upb_oneofdef_addfield(this, field, NULL, s);
2928 } 3568 }
2929 inline bool OneofDef::AddField(const reffed_ptr<FieldDef>& field, Status* s) { 3569 inline bool OneofDef::AddField(const reffed_ptr<FieldDef>& field, Status* s) {
2930 return upb_oneofdef_addfield(this, field.get(), NULL, s); 3570 return upb_oneofdef_addfield(this, field.get(), NULL, s);
2931 } 3571 }
2932 inline const FieldDef* OneofDef::FindFieldByName(const char* name, 3572 inline const FieldDef* OneofDef::FindFieldByName(const char* name,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2981 } 3621 }
2982 inline bool OneofDef::const_iterator::operator==( 3622 inline bool OneofDef::const_iterator::operator==(
2983 const const_iterator &other) const { 3623 const const_iterator &other) const {
2984 return upb_inttable_iter_isequal(&iter_, &other.iter_); 3624 return upb_inttable_iter_isequal(&iter_, &other.iter_);
2985 } 3625 }
2986 inline bool OneofDef::const_iterator::operator!=( 3626 inline bool OneofDef::const_iterator::operator!=(
2987 const const_iterator &other) const { 3627 const const_iterator &other) const {
2988 return !(*this == other); 3628 return !(*this == other);
2989 } 3629 }
2990 3630
3631 inline reffed_ptr<FileDef> FileDef::New() {
3632 upb_filedef *f = upb_filedef_new(&f);
3633 return reffed_ptr<FileDef>(f, &f);
3634 }
3635
3636 inline const char* FileDef::name() const {
3637 return upb_filedef_name(this);
3638 }
3639 inline bool FileDef::set_name(const char* name, Status* s) {
3640 return upb_filedef_setname(this, name, s);
3641 }
3642 inline bool FileDef::set_name(const std::string& name, Status* s) {
3643 return upb_filedef_setname(this, upb_safecstr(name), s);
3644 }
3645 inline const char* FileDef::package() const {
3646 return upb_filedef_package(this);
3647 }
3648 inline bool FileDef::set_package(const char* package, Status* s) {
3649 return upb_filedef_setpackage(this, package, s);
3650 }
3651 inline int FileDef::def_count() const {
3652 return upb_filedef_defcount(this);
3653 }
3654 inline const Def* FileDef::def(int index) const {
3655 return upb_filedef_def(this, index);
3656 }
3657 inline Def* FileDef::def(int index) {
3658 return const_cast<Def*>(upb_filedef_def(this, index));
3659 }
3660 inline int FileDef::dependency_count() const {
3661 return upb_filedef_depcount(this);
3662 }
3663 inline const FileDef* FileDef::dependency(int index) const {
3664 return upb_filedef_dep(this, index);
3665 }
3666 inline bool FileDef::AddDef(Def* def, Status* s) {
3667 return upb_filedef_adddef(this, def, NULL, s);
3668 }
3669 inline bool FileDef::AddMessage(MessageDef* m, Status* s) {
3670 return upb_filedef_addmsg(this, m, NULL, s);
3671 }
3672 inline bool FileDef::AddEnum(EnumDef* e, Status* s) {
3673 return upb_filedef_addenum(this, e, NULL, s);
3674 }
3675 inline bool FileDef::AddExtension(FieldDef* f, Status* s) {
3676 return upb_filedef_addext(this, f, NULL, s);
3677 }
3678 inline bool FileDef::AddDependency(const FileDef* file) {
3679 return upb_filedef_adddep(this, file);
3680 }
3681
2991 } /* namespace upb */ 3682 } /* namespace upb */
2992 #endif 3683 #endif
2993 3684
2994 #endif /* UPB_DEF_H_ */ 3685 #endif /* UPB_DEF_H_ */
2995 /* 3686 /*
2996 ** This file contains definitions of structs that should be considered private 3687 ** This file contains definitions of structs that should be considered private
2997 ** and NOT stable across versions of upb. 3688 ** and NOT stable across versions of upb.
2998 ** 3689 **
2999 ** The only reason they are declared here and not in .c files is to allow upb 3690 ** The only reason they are declared here and not in .c files is to allow upb
3000 ** and the application (if desired) to embed statically-initialized instances 3691 ** and the application (if desired) to embed statically-initialized instances
(...skipping 18 matching lines...) Expand all
3019 3710
3020 /* upb_refcounted *************************************************************/ 3711 /* upb_refcounted *************************************************************/
3021 3712
3022 3713
3023 /* upb_def ********************************************************************/ 3714 /* upb_def ********************************************************************/
3024 3715
3025 struct upb_def { 3716 struct upb_def {
3026 upb_refcounted base; 3717 upb_refcounted base;
3027 3718
3028 const char *fullname; 3719 const char *fullname;
3720 const upb_filedef* file;
3029 char type; /* A upb_deftype_t (char to save space) */ 3721 char type; /* A upb_deftype_t (char to save space) */
3030 3722
3031 /* Used as a flag during the def's mutable stage. Must be false unless 3723 /* Used as a flag during the def's mutable stage. Must be false unless
3032 * it is currently being used by a function on the stack. This allows 3724 * it is currently being used by a function on the stack. This allows
3033 * us to easily determine which defs were passed into the function's 3725 * us to easily determine which defs were passed into the function's
3034 * current invocation. */ 3726 * current invocation. */
3035 bool came_from_user; 3727 bool came_from_user;
3036 }; 3728 };
3037 3729
3038 #define UPB_DEF_INIT(name, type, refs, ref2s) \ 3730 #define UPB_DEF_INIT(name, type, vtbl, refs, ref2s) \
3039 { UPB_REFCOUNT_INIT(refs, ref2s), name, type, false } 3731 { UPB_REFCOUNT_INIT(vtbl, refs, ref2s), name, NULL, type, false }
3040 3732
3041 3733
3042 /* upb_fielddef ***************************************************************/ 3734 /* upb_fielddef ***************************************************************/
3043 3735
3044 struct upb_fielddef { 3736 struct upb_fielddef {
3045 upb_def base; 3737 upb_def base;
3046 3738
3047 union { 3739 union {
3048 int64_t sint; 3740 int64_t sint;
3049 uint64_t uint; 3741 uint64_t uint;
(...skipping 19 matching lines...) Expand all
3069 bool packed_; 3761 bool packed_;
3070 upb_intfmt_t intfmt; 3762 upb_intfmt_t intfmt;
3071 bool tagdelim; 3763 bool tagdelim;
3072 upb_fieldtype_t type_; 3764 upb_fieldtype_t type_;
3073 upb_label_t label_; 3765 upb_label_t label_;
3074 uint32_t number_; 3766 uint32_t number_;
3075 uint32_t selector_base; /* Used to index into a upb::Handlers table. */ 3767 uint32_t selector_base; /* Used to index into a upb::Handlers table. */
3076 uint32_t index_; 3768 uint32_t index_;
3077 }; 3769 };
3078 3770
3771 extern const struct upb_refcounted_vtbl upb_fielddef_vtbl;
3772
3079 #define UPB_FIELDDEF_INIT(label, type, intfmt, tagdelim, is_extension, lazy, \ 3773 #define UPB_FIELDDEF_INIT(label, type, intfmt, tagdelim, is_extension, lazy, \
3080 packed, name, num, msgdef, subdef, selector_base, \ 3774 packed, name, num, msgdef, subdef, selector_base, \
3081 index, defaultval, refs, ref2s) \ 3775 index, defaultval, refs, ref2s) \
3082 { \ 3776 { \
3083 UPB_DEF_INIT(name, UPB_DEF_FIELD, refs, ref2s), defaultval, {msgdef}, \ 3777 UPB_DEF_INIT(name, UPB_DEF_FIELD, &upb_fielddef_vtbl, refs, ref2s), \
3084 {subdef}, NULL, false, false, \ 3778 defaultval, {msgdef}, {subdef}, NULL, false, false, \
3085 type == UPB_TYPE_STRING || type == UPB_TYPE_BYTES, true, is_extension, \ 3779 type == UPB_TYPE_STRING || type == UPB_TYPE_BYTES, true, is_extension, \
3086 lazy, packed, intfmt, tagdelim, type, label, num, selector_base, index \ 3780 lazy, packed, intfmt, tagdelim, type, label, num, selector_base, index \
3087 } 3781 }
3088 3782
3089 3783
3090 /* upb_msgdef *****************************************************************/ 3784 /* upb_msgdef *****************************************************************/
3091 3785
3092 struct upb_msgdef { 3786 struct upb_msgdef {
3093 upb_def base; 3787 upb_def base;
3094 3788
3095 size_t selector_count; 3789 size_t selector_count;
3096 uint32_t submsg_field_count; 3790 uint32_t submsg_field_count;
3097 3791
3098 /* Tables for looking up fields by number and name. */ 3792 /* Tables for looking up fields by number and name. */
3099 upb_inttable itof; /* int to field */ 3793 upb_inttable itof; /* int to field */
3100 upb_strtable ntof; /* name to field */ 3794 upb_strtable ntof; /* name to field/oneof */
3101 3795
3102 /* Tables for looking up oneofs by name. */ 3796 /* Is this a map-entry message? */
3103 upb_strtable ntoo; /* name to oneof */ 3797 bool map_entry;
3104 3798
3105 /* Is this a map-entry message? 3799 /* Whether this message has proto2 or proto3 semantics. */
3106 * TODO: set this flag properly for static descriptors; regenerate 3800 upb_syntax_t syntax;
3107 * descriptor.upb.c. */
3108 bool map_entry;
3109 3801
3110 /* TODO(haberman): proper extension ranges (there can be multiple). */ 3802 /* TODO(haberman): proper extension ranges (there can be multiple). */
3111 }; 3803 };
3112 3804
3805 extern const struct upb_refcounted_vtbl upb_msgdef_vtbl;
3806
3113 /* TODO: also support static initialization of the oneofs table. This will be 3807 /* TODO: also support static initialization of the oneofs table. This will be
3114 * needed if we compile in descriptors that contain oneofs. */ 3808 * needed if we compile in descriptors that contain oneofs. */
3115 #define UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, \ 3809 #define UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, \
3116 refs, ref2s) \ 3810 map_entry, syntax, refs, ref2s) \
3117 { \ 3811 { \
3118 UPB_DEF_INIT(name, UPB_DEF_MSG, refs, ref2s), selector_count, \ 3812 UPB_DEF_INIT(name, UPB_DEF_MSG, &upb_fielddef_vtbl, refs, ref2s), \
3119 submsg_field_count, itof, ntof, \ 3813 selector_count, submsg_field_count, itof, ntof, map_entry, syntax \
3120 UPB_EMPTY_STRTABLE_INIT(UPB_CTYPE_PTR), false \
3121 } 3814 }
3122 3815
3123 3816
3124 /* upb_enumdef ****************************************************************/ 3817 /* upb_enumdef ****************************************************************/
3125 3818
3126 struct upb_enumdef { 3819 struct upb_enumdef {
3127 upb_def base; 3820 upb_def base;
3128 3821
3129 upb_strtable ntoi; 3822 upb_strtable ntoi;
3130 upb_inttable iton; 3823 upb_inttable iton;
3131 int32_t defaultval; 3824 int32_t defaultval;
3132 }; 3825 };
3133 3826
3827 extern const struct upb_refcounted_vtbl upb_enumdef_vtbl;
3828
3134 #define UPB_ENUMDEF_INIT(name, ntoi, iton, defaultval, refs, ref2s) \ 3829 #define UPB_ENUMDEF_INIT(name, ntoi, iton, defaultval, refs, ref2s) \
3135 { UPB_DEF_INIT(name, UPB_DEF_ENUM, refs, ref2s), ntoi, iton, defaultval } 3830 { UPB_DEF_INIT(name, UPB_DEF_ENUM, &upb_enumdef_vtbl, refs, ref2s), ntoi, \
3831 iton, defaultval }
3136 3832
3137 3833
3138 /* upb_oneofdef ***************************************************************/ 3834 /* upb_oneofdef ***************************************************************/
3139 3835
3140 struct upb_oneofdef { 3836 struct upb_oneofdef {
3141 upb_def base; 3837 upb_refcounted base;
3142 3838
3839 const char *name;
3143 upb_strtable ntof; 3840 upb_strtable ntof;
3144 upb_inttable itof; 3841 upb_inttable itof;
3145 const upb_msgdef *parent; 3842 const upb_msgdef *parent;
3146 }; 3843 };
3147 3844
3845 extern const struct upb_refcounted_vtbl upb_oneofdef_vtbl;
3846
3148 #define UPB_ONEOFDEF_INIT(name, ntof, itof, refs, ref2s) \ 3847 #define UPB_ONEOFDEF_INIT(name, ntof, itof, refs, ref2s) \
3149 { UPB_DEF_INIT(name, UPB_DEF_ENUM, refs, ref2s), ntof, itof } 3848 { UPB_REFCOUNT_INIT(&upb_oneofdef_vtbl, refs, ref2s), name, ntof, itof }
3150 3849
3151 3850
3152 /* upb_symtab *****************************************************************/ 3851 /* upb_symtab *****************************************************************/
3153 3852
3154 struct upb_symtab { 3853 struct upb_symtab {
3155 upb_refcounted base; 3854 upb_refcounted base;
3156 3855
3157 upb_strtable symtab; 3856 upb_strtable symtab;
3158 }; 3857 };
3159 3858
3160 #define UPB_SYMTAB_INIT(symtab, refs, ref2s) \ 3859 struct upb_filedef {
3161 { UPB_REFCOUNT_INIT(refs, ref2s), symtab } 3860 upb_refcounted base;
3162 3861
3862 const char *name;
3863 const char *package;
3864 upb_syntax_t syntax;
3865
3866 upb_inttable defs;
3867 upb_inttable deps;
3868 };
3869
3870 extern const struct upb_refcounted_vtbl upb_filedef_vtbl;
3163 3871
3164 #endif /* UPB_STATICINIT_H_ */ 3872 #endif /* UPB_STATICINIT_H_ */
3165 /* 3873 /*
3166 ** upb::Handlers (upb_handlers) 3874 ** upb::Handlers (upb_handlers)
3167 ** 3875 **
3168 ** A upb_handlers is like a virtual table for a upb_msgdef. Each field of the 3876 ** A upb_handlers is like a virtual table for a upb_msgdef. Each field of the
3169 ** message can have associated functions that will be called when we are 3877 ** message can have associated functions that will be called when we are
3170 ** parsing or visiting a stream of data. This is similar to how handlers work 3878 ** parsing or visiting a stream of data. This is similar to how handlers work
3171 ** in SAX (the Simple API for XML). 3879 ** in SAX (the Simple API for XML).
3172 ** 3880 **
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
3766 typedef T FuncPtr; 4474 typedef T FuncPtr;
3767 4475
3768 /* Intentionally implicit. */ 4476 /* Intentionally implicit. */
3769 template <class F> Handler(F func); 4477 template <class F> Handler(F func);
3770 ~Handler(); 4478 ~Handler();
3771 4479
3772 private: 4480 private:
3773 void AddCleanup(Handlers* h) const { 4481 void AddCleanup(Handlers* h) const {
3774 if (cleanup_func_) { 4482 if (cleanup_func_) {
3775 bool ok = h->AddCleanup(cleanup_data_, cleanup_func_); 4483 bool ok = h->AddCleanup(cleanup_data_, cleanup_func_);
3776 UPB_ASSERT_VAR(ok, ok); 4484 UPB_ASSERT(ok);
3777 } 4485 }
3778 } 4486 }
3779 4487
3780 UPB_DISALLOW_COPY_AND_ASSIGN(Handler) 4488 UPB_DISALLOW_COPY_AND_ASSIGN(Handler)
3781 friend class Handlers; 4489 friend class Handlers;
3782 FuncPtr handler_; 4490 FuncPtr handler_;
3783 mutable HandlerAttributes attr_; 4491 mutable HandlerAttributes attr_;
3784 mutable bool registered_; 4492 mutable bool registered_;
3785 void *cleanup_data_; 4493 void *cleanup_data_;
3786 upb_handlerfree *cleanup_func_; 4494 upb_handlerfree *cleanup_func_;
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
4786 /* utype/ltype are upper/lower-case, ctype is canonical C type, vtype is 5494 /* utype/ltype are upper/lower-case, ctype is canonical C type, vtype is
4787 * variant C type. */ 5495 * variant C type. */
4788 #define TYPE_METHODS(utype, ltype, ctype, vtype) \ 5496 #define TYPE_METHODS(utype, ltype, ctype, vtype) \
4789 template <> struct CanonicalType<vtype> { \ 5497 template <> struct CanonicalType<vtype> { \
4790 typedef ctype Type; \ 5498 typedef ctype Type; \
4791 }; \ 5499 }; \
4792 template <> \ 5500 template <> \
4793 inline bool Handlers::SetValueHandler<vtype>( \ 5501 inline bool Handlers::SetValueHandler<vtype>( \
4794 const FieldDef *f, \ 5502 const FieldDef *f, \
4795 const Handlers::utype ## Handler& handler) { \ 5503 const Handlers::utype ## Handler& handler) { \
4796 assert(!handler.registered_); \ 5504 UPB_ASSERT(!handler.registered_); \
4797 handler.AddCleanup(this); \ 5505 handler.AddCleanup(this); \
4798 handler.registered_ = true; \ 5506 handler.registered_ = true; \
4799 return upb_handlers_set##ltype(this, f, handler.handler_, &handler.attr_); \ 5507 return upb_handlers_set##ltype(this, f, handler.handler_, &handler.attr_); \
4800 } \ 5508 } \
4801 5509
4802 TYPE_METHODS(Double, double, double, double) 5510 TYPE_METHODS(Double, double, double, double)
4803 TYPE_METHODS(Float, float, float, float) 5511 TYPE_METHODS(Float, float, float, float)
4804 TYPE_METHODS(UInt64, uint64, uint64_t, UPB_UINT64_T) 5512 TYPE_METHODS(UInt64, uint64, uint64_t, UPB_UINT64_T)
4805 TYPE_METHODS(UInt32, uint32, uint32_t, UPB_UINT32_T) 5513 TYPE_METHODS(UInt32, uint32, uint32_t, UPB_UINT32_T)
4806 TYPE_METHODS(Int64, int64, int64_t, UPB_INT64_T) 5514 TYPE_METHODS(Int64, int64, int64_t, UPB_INT64_T)
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
4898 * This is all nonsense for non START* handlers, but it doesn't matter because 5606 * This is all nonsense for non START* handlers, but it doesn't matter because
4899 * in that case the value will be ignored. */ 5607 * in that case the value will be ignored. */
4900 typedef typename FirstUnlessVoidOrBool<typename F::FuncInfo::Return, 5608 typedef typename FirstUnlessVoidOrBool<typename F::FuncInfo::Return,
4901 typename F::FuncInfo::Closure>::value 5609 typename F::FuncInfo::Closure>::value
4902 EffectiveReturn; 5610 EffectiveReturn;
4903 attr_.SetReturnClosureType(UniquePtrForType<EffectiveReturn>()); 5611 attr_.SetReturnClosureType(UniquePtrForType<EffectiveReturn>());
4904 } 5612 }
4905 5613
4906 template <class T> 5614 template <class T>
4907 inline Handler<T>::~Handler() { 5615 inline Handler<T>::~Handler() {
4908 assert(registered_); 5616 UPB_ASSERT(registered_);
4909 } 5617 }
4910 5618
4911 inline HandlerAttributes::HandlerAttributes() { upb_handlerattr_init(this); } 5619 inline HandlerAttributes::HandlerAttributes() { upb_handlerattr_init(this); }
4912 inline HandlerAttributes::~HandlerAttributes() { upb_handlerattr_uninit(this); } 5620 inline HandlerAttributes::~HandlerAttributes() { upb_handlerattr_uninit(this); }
4913 inline bool HandlerAttributes::SetHandlerData(const void *hd) { 5621 inline bool HandlerAttributes::SetHandlerData(const void *hd) {
4914 return upb_handlerattr_sethandlerdata(this, hd); 5622 return upb_handlerattr_sethandlerdata(this, hd);
4915 } 5623 }
4916 inline const void* HandlerAttributes::handler_data() const { 5624 inline const void* HandlerAttributes::handler_data() const {
4917 return upb_handlerattr_handlerdata(this); 5625 return upb_handlerattr_handlerdata(this);
4918 } 5626 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
4984 return upb_handlers_freeze((Handlers* const*)&h[0], h.size(), status); 5692 return upb_handlers_freeze((Handlers* const*)&h[0], h.size(), status);
4985 } 5693 }
4986 inline const MessageDef *Handlers::message_def() const { 5694 inline const MessageDef *Handlers::message_def() const {
4987 return upb_handlers_msgdef(this); 5695 return upb_handlers_msgdef(this);
4988 } 5696 }
4989 inline bool Handlers::AddCleanup(void *p, upb_handlerfree *func) { 5697 inline bool Handlers::AddCleanup(void *p, upb_handlerfree *func) {
4990 return upb_handlers_addcleanup(this, p, func); 5698 return upb_handlers_addcleanup(this, p, func);
4991 } 5699 }
4992 inline bool Handlers::SetStartMessageHandler( 5700 inline bool Handlers::SetStartMessageHandler(
4993 const Handlers::StartMessageHandler &handler) { 5701 const Handlers::StartMessageHandler &handler) {
4994 assert(!handler.registered_); 5702 UPB_ASSERT(!handler.registered_);
4995 handler.registered_ = true; 5703 handler.registered_ = true;
4996 handler.AddCleanup(this); 5704 handler.AddCleanup(this);
4997 return upb_handlers_setstartmsg(this, handler.handler_, &handler.attr_); 5705 return upb_handlers_setstartmsg(this, handler.handler_, &handler.attr_);
4998 } 5706 }
4999 inline bool Handlers::SetEndMessageHandler( 5707 inline bool Handlers::SetEndMessageHandler(
5000 const Handlers::EndMessageHandler &handler) { 5708 const Handlers::EndMessageHandler &handler) {
5001 assert(!handler.registered_); 5709 UPB_ASSERT(!handler.registered_);
5002 handler.registered_ = true; 5710 handler.registered_ = true;
5003 handler.AddCleanup(this); 5711 handler.AddCleanup(this);
5004 return upb_handlers_setendmsg(this, handler.handler_, &handler.attr_); 5712 return upb_handlers_setendmsg(this, handler.handler_, &handler.attr_);
5005 } 5713 }
5006 inline bool Handlers::SetStartStringHandler(const FieldDef *f, 5714 inline bool Handlers::SetStartStringHandler(const FieldDef *f,
5007 const StartStringHandler &handler) { 5715 const StartStringHandler &handler) {
5008 assert(!handler.registered_); 5716 UPB_ASSERT(!handler.registered_);
5009 handler.registered_ = true; 5717 handler.registered_ = true;
5010 handler.AddCleanup(this); 5718 handler.AddCleanup(this);
5011 return upb_handlers_setstartstr(this, f, handler.handler_, &handler.attr_); 5719 return upb_handlers_setstartstr(this, f, handler.handler_, &handler.attr_);
5012 } 5720 }
5013 inline bool Handlers::SetEndStringHandler(const FieldDef *f, 5721 inline bool Handlers::SetEndStringHandler(const FieldDef *f,
5014 const EndFieldHandler &handler) { 5722 const EndFieldHandler &handler) {
5015 assert(!handler.registered_); 5723 UPB_ASSERT(!handler.registered_);
5016 handler.registered_ = true; 5724 handler.registered_ = true;
5017 handler.AddCleanup(this); 5725 handler.AddCleanup(this);
5018 return upb_handlers_setendstr(this, f, handler.handler_, &handler.attr_); 5726 return upb_handlers_setendstr(this, f, handler.handler_, &handler.attr_);
5019 } 5727 }
5020 inline bool Handlers::SetStringHandler(const FieldDef *f, 5728 inline bool Handlers::SetStringHandler(const FieldDef *f,
5021 const StringHandler& handler) { 5729 const StringHandler& handler) {
5022 assert(!handler.registered_); 5730 UPB_ASSERT(!handler.registered_);
5023 handler.registered_ = true; 5731 handler.registered_ = true;
5024 handler.AddCleanup(this); 5732 handler.AddCleanup(this);
5025 return upb_handlers_setstring(this, f, handler.handler_, &handler.attr_); 5733 return upb_handlers_setstring(this, f, handler.handler_, &handler.attr_);
5026 } 5734 }
5027 inline bool Handlers::SetStartSequenceHandler( 5735 inline bool Handlers::SetStartSequenceHandler(
5028 const FieldDef *f, const StartFieldHandler &handler) { 5736 const FieldDef *f, const StartFieldHandler &handler) {
5029 assert(!handler.registered_); 5737 UPB_ASSERT(!handler.registered_);
5030 handler.registered_ = true; 5738 handler.registered_ = true;
5031 handler.AddCleanup(this); 5739 handler.AddCleanup(this);
5032 return upb_handlers_setstartseq(this, f, handler.handler_, &handler.attr_); 5740 return upb_handlers_setstartseq(this, f, handler.handler_, &handler.attr_);
5033 } 5741 }
5034 inline bool Handlers::SetStartSubMessageHandler( 5742 inline bool Handlers::SetStartSubMessageHandler(
5035 const FieldDef *f, const StartFieldHandler &handler) { 5743 const FieldDef *f, const StartFieldHandler &handler) {
5036 assert(!handler.registered_); 5744 UPB_ASSERT(!handler.registered_);
5037 handler.registered_ = true; 5745 handler.registered_ = true;
5038 handler.AddCleanup(this); 5746 handler.AddCleanup(this);
5039 return upb_handlers_setstartsubmsg(this, f, handler.handler_, &handler.attr_); 5747 return upb_handlers_setstartsubmsg(this, f, handler.handler_, &handler.attr_);
5040 } 5748 }
5041 inline bool Handlers::SetEndSubMessageHandler(const FieldDef *f, 5749 inline bool Handlers::SetEndSubMessageHandler(const FieldDef *f,
5042 const EndFieldHandler &handler) { 5750 const EndFieldHandler &handler) {
5043 assert(!handler.registered_); 5751 UPB_ASSERT(!handler.registered_);
5044 handler.registered_ = true; 5752 handler.registered_ = true;
5045 handler.AddCleanup(this); 5753 handler.AddCleanup(this);
5046 return upb_handlers_setendsubmsg(this, f, handler.handler_, &handler.attr_); 5754 return upb_handlers_setendsubmsg(this, f, handler.handler_, &handler.attr_);
5047 } 5755 }
5048 inline bool Handlers::SetEndSequenceHandler(const FieldDef *f, 5756 inline bool Handlers::SetEndSequenceHandler(const FieldDef *f,
5049 const EndFieldHandler &handler) { 5757 const EndFieldHandler &handler) {
5050 assert(!handler.registered_); 5758 UPB_ASSERT(!handler.registered_);
5051 handler.registered_ = true; 5759 handler.registered_ = true;
5052 handler.AddCleanup(this); 5760 handler.AddCleanup(this);
5053 return upb_handlers_setendseq(this, f, handler.handler_, &handler.attr_); 5761 return upb_handlers_setendseq(this, f, handler.handler_, &handler.attr_);
5054 } 5762 }
5055 inline bool Handlers::SetSubHandlers(const FieldDef *f, const Handlers *sub) { 5763 inline bool Handlers::SetSubHandlers(const FieldDef *f, const Handlers *sub) {
5056 return upb_handlers_setsubhandlers(this, f, sub); 5764 return upb_handlers_setsubhandlers(this, f, sub);
5057 } 5765 }
5058 inline const Handlers *Handlers::GetSubHandlers(const FieldDef *f) const { 5766 inline const Handlers *Handlers::GetSubHandlers(const FieldDef *f) const {
5059 return upb_handlers_getsubhandlers(this, f); 5767 return upb_handlers_getsubhandlers(this, f);
5060 } 5768 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
5095 #undef UPB_UINT32ALT_T 5803 #undef UPB_UINT32ALT_T
5096 #undef UPB_INT64_T 5804 #undef UPB_INT64_T
5097 #undef UPB_UINT64_T 5805 #undef UPB_UINT64_T
5098 #undef UPB_INT64ALT_T 5806 #undef UPB_INT64ALT_T
5099 #undef UPB_UINT64ALT_T 5807 #undef UPB_UINT64ALT_T
5100 5808
5101 #endif /* UPB_HANDLERS_INL_H_ */ 5809 #endif /* UPB_HANDLERS_INL_H_ */
5102 5810
5103 #endif /* UPB_HANDLERS_H */ 5811 #endif /* UPB_HANDLERS_H */
5104 /* 5812 /*
5105 ** upb::Environment (upb_env)
5106 **
5107 ** A upb::Environment provides a means for injecting malloc and an
5108 ** error-reporting callback into encoders/decoders. This allows them to be
5109 ** independent of nearly all assumptions about their actual environment.
5110 **
5111 ** It is also a container for allocating the encoders/decoders themselves that
5112 ** insulates clients from knowing their actual size. This provides ABI
5113 ** compatibility even if the size of the objects change. And this allows the
5114 ** structure definitions to be in the .c files instead of the .h files, making
5115 ** the .h files smaller and more readable.
5116 */
5117
5118
5119 #ifndef UPB_ENV_H_
5120 #define UPB_ENV_H_
5121
5122 #ifdef __cplusplus
5123 namespace upb {
5124 class Environment;
5125 class SeededAllocator;
5126 }
5127 #endif
5128
5129 UPB_DECLARE_TYPE(upb::Environment, upb_env)
5130 UPB_DECLARE_TYPE(upb::SeededAllocator, upb_seededalloc)
5131
5132 typedef void *upb_alloc_func(void *ud, void *ptr, size_t oldsize, size_t size);
5133 typedef void upb_cleanup_func(void *ud);
5134 typedef bool upb_error_func(void *ud, const upb_status *status);
5135
5136 #ifdef __cplusplus
5137
5138 /* An environment is *not* thread-safe. */
5139 class upb::Environment {
5140 public:
5141 Environment();
5142 ~Environment();
5143
5144 /* Set a custom memory allocation function for the environment. May ONLY
5145 * be called before any calls to Malloc()/Realloc()/AddCleanup() below.
5146 * If this is not called, the system realloc() function will be used.
5147 * The given user pointer "ud" will be passed to the allocation function.
5148 *
5149 * The allocation function will not receive corresponding "free" calls. it
5150 * must ensure that the memory is valid for the lifetime of the Environment,
5151 * but it may be reclaimed any time thereafter. The likely usage is that
5152 * "ud" points to a stateful allocator, and that the allocator frees all
5153 * memory, arena-style, when it is destroyed. In this case the allocator must
5154 * outlive the Environment. Another possibility is that the allocation
5155 * function returns GC-able memory that is guaranteed to be GC-rooted for the
5156 * life of the Environment. */
5157 void SetAllocationFunction(upb_alloc_func* alloc, void* ud);
5158
5159 template<class T>
5160 void SetAllocator(T* allocator) {
5161 SetAllocationFunction(allocator->GetAllocationFunction(), allocator);
5162 }
5163
5164 /* Set a custom error reporting function. */
5165 void SetErrorFunction(upb_error_func* func, void* ud);
5166
5167 /* Set the error reporting function to simply copy the status to the given
5168 * status and abort. */
5169 void ReportErrorsTo(Status* status);
5170
5171 /* Returns true if all allocations and AddCleanup() calls have succeeded,
5172 * and no errors were reported with ReportError() (except ones that recovered
5173 * successfully). */
5174 bool ok() const;
5175
5176 /* Functions for use by encoders/decoders. **********************************/
5177
5178 /* Reports an error to this environment's callback, returning true if
5179 * the caller should try to recover. */
5180 bool ReportError(const Status* status);
5181
5182 /* Allocate memory. Uses the environment's allocation function.
5183 *
5184 * There is no need to free(). All memory will be freed automatically, but is
5185 * guaranteed to outlive the Environment. */
5186 void* Malloc(size_t size);
5187
5188 /* Reallocate memory. Preserves "oldsize" bytes from the existing buffer
5189 * Requires: oldsize <= existing_size.
5190 *
5191 * TODO(haberman): should we also enforce that oldsize <= size? */
5192 void* Realloc(void* ptr, size_t oldsize, size_t size);
5193
5194 /* Add a cleanup function to run when the environment is destroyed.
5195 * Returns false on out-of-memory.
5196 *
5197 * The first call to AddCleanup() after SetAllocationFunction() is guaranteed
5198 * to return true -- this makes it possible to robustly set a cleanup handler
5199 * for a custom allocation function. */
5200 bool AddCleanup(upb_cleanup_func* func, void* ud);
5201
5202 /* Total number of bytes that have been allocated. It is undefined what
5203 * Realloc() does to this counter. */
5204 size_t BytesAllocated() const;
5205
5206 private:
5207 UPB_DISALLOW_COPY_AND_ASSIGN(Environment)
5208
5209 #else
5210 struct upb_env {
5211 #endif /* __cplusplus */
5212
5213 bool ok_;
5214 size_t bytes_allocated;
5215
5216 /* Alloc function. */
5217 upb_alloc_func *alloc;
5218 void *alloc_ud;
5219
5220 /* Error-reporting function. */
5221 upb_error_func *err;
5222 void *err_ud;
5223
5224 /* Userdata for default alloc func. */
5225 void *default_alloc_ud;
5226
5227 /* Cleanup entries. Pointer to a cleanup_ent, defined in env.c */
5228 void *cleanup_head;
5229
5230 /* For future expansion, since the size of this struct is exposed to users. */
5231 void *future1;
5232 void *future2;
5233 };
5234
5235 UPB_BEGIN_EXTERN_C
5236
5237 void upb_env_init(upb_env *e);
5238 void upb_env_uninit(upb_env *e);
5239 void upb_env_setallocfunc(upb_env *e, upb_alloc_func *func, void *ud);
5240 void upb_env_seterrorfunc(upb_env *e, upb_error_func *func, void *ud);
5241 void upb_env_reporterrorsto(upb_env *e, upb_status *status);
5242 bool upb_env_ok(const upb_env *e);
5243 bool upb_env_reporterror(upb_env *e, const upb_status *status);
5244 void *upb_env_malloc(upb_env *e, size_t size);
5245 void *upb_env_realloc(upb_env *e, void *ptr, size_t oldsize, size_t size);
5246 bool upb_env_addcleanup(upb_env *e, upb_cleanup_func *func, void *ud);
5247 size_t upb_env_bytesallocated(const upb_env *e);
5248
5249 UPB_END_EXTERN_C
5250
5251 #ifdef __cplusplus
5252
5253 /* An allocator that allocates from an initial memory region (likely the stack)
5254 * before falling back to another allocator. */
5255 class upb::SeededAllocator {
5256 public:
5257 SeededAllocator(void *mem, size_t len);
5258 ~SeededAllocator();
5259
5260 /* Set a custom fallback memory allocation function for the allocator, to use
5261 * once the initial region runs out.
5262 *
5263 * May ONLY be called before GetAllocationFunction(). If this is not
5264 * called, the system realloc() will be the fallback allocator. */
5265 void SetFallbackAllocator(upb_alloc_func *alloc, void *ud);
5266
5267 /* Gets the allocation function for this allocator. */
5268 upb_alloc_func* GetAllocationFunction();
5269
5270 private:
5271 UPB_DISALLOW_COPY_AND_ASSIGN(SeededAllocator)
5272
5273 #else
5274 struct upb_seededalloc {
5275 #endif /* __cplusplus */
5276
5277 /* Fallback alloc function. */
5278 upb_alloc_func *alloc;
5279 upb_cleanup_func *alloc_cleanup;
5280 void *alloc_ud;
5281 bool need_cleanup;
5282 bool returned_allocfunc;
5283
5284 /* Userdata for default alloc func. */
5285 void *default_alloc_ud;
5286
5287 /* Pointers for the initial memory region. */
5288 char *mem_base;
5289 char *mem_ptr;
5290 char *mem_limit;
5291
5292 /* For future expansion, since the size of this struct is exposed to users. */
5293 void *future1;
5294 void *future2;
5295 };
5296
5297 UPB_BEGIN_EXTERN_C
5298
5299 void upb_seededalloc_init(upb_seededalloc *a, void *mem, size_t len);
5300 void upb_seededalloc_uninit(upb_seededalloc *a);
5301 void upb_seededalloc_setfallbackalloc(upb_seededalloc *a, upb_alloc_func *func,
5302 void *ud);
5303 upb_alloc_func *upb_seededalloc_getallocfunc(upb_seededalloc *a);
5304
5305 UPB_END_EXTERN_C
5306
5307 #ifdef __cplusplus
5308
5309 namespace upb {
5310
5311 inline Environment::Environment() {
5312 upb_env_init(this);
5313 }
5314 inline Environment::~Environment() {
5315 upb_env_uninit(this);
5316 }
5317 inline void Environment::SetAllocationFunction(upb_alloc_func *alloc,
5318 void *ud) {
5319 upb_env_setallocfunc(this, alloc, ud);
5320 }
5321 inline void Environment::SetErrorFunction(upb_error_func *func, void *ud) {
5322 upb_env_seterrorfunc(this, func, ud);
5323 }
5324 inline void Environment::ReportErrorsTo(Status* status) {
5325 upb_env_reporterrorsto(this, status);
5326 }
5327 inline bool Environment::ok() const {
5328 return upb_env_ok(this);
5329 }
5330 inline bool Environment::ReportError(const Status* status) {
5331 return upb_env_reporterror(this, status);
5332 }
5333 inline void *Environment::Malloc(size_t size) {
5334 return upb_env_malloc(this, size);
5335 }
5336 inline void *Environment::Realloc(void *ptr, size_t oldsize, size_t size) {
5337 return upb_env_realloc(this, ptr, oldsize, size);
5338 }
5339 inline bool Environment::AddCleanup(upb_cleanup_func *func, void *ud) {
5340 return upb_env_addcleanup(this, func, ud);
5341 }
5342 inline size_t Environment::BytesAllocated() const {
5343 return upb_env_bytesallocated(this);
5344 }
5345
5346 inline SeededAllocator::SeededAllocator(void *mem, size_t len) {
5347 upb_seededalloc_init(this, mem, len);
5348 }
5349 inline SeededAllocator::~SeededAllocator() {
5350 upb_seededalloc_uninit(this);
5351 }
5352 inline void SeededAllocator::SetFallbackAllocator(upb_alloc_func *alloc,
5353 void *ud) {
5354 upb_seededalloc_setfallbackalloc(this, alloc, ud);
5355 }
5356 inline upb_alloc_func *SeededAllocator::GetAllocationFunction() {
5357 return upb_seededalloc_getallocfunc(this);
5358 }
5359
5360 } /* namespace upb */
5361
5362 #endif /* __cplusplus */
5363
5364 #endif /* UPB_ENV_H_ */
5365 /*
5366 ** upb::Sink (upb_sink) 5813 ** upb::Sink (upb_sink)
5367 ** upb::BytesSink (upb_bytessink) 5814 ** upb::BytesSink (upb_bytessink)
5368 ** 5815 **
5369 ** A upb_sink is an object that binds a upb_handlers object to some runtime 5816 ** A upb_sink is an object that binds a upb_handlers object to some runtime
5370 ** state. It is the object that can actually receive data via the upb_handlers 5817 ** state. It is the object that can actually receive data via the upb_handlers
5371 ** interface. 5818 ** interface.
5372 ** 5819 **
5373 ** Unlike upb_def and upb_handlers, upb_sink is never frozen, immutable, or 5820 ** Unlike upb_def and upb_handlers, upb_sink is never frozen, immutable, or
5374 ** thread-safe. You can create as many of them as you want, but each one may 5821 ** thread-safe. You can create as many of them as you want, but each one may
5375 ** only be used in a single thread at a time. 5822 ** only be used in a single thread at a time.
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
6059 * leave the defs themselves partially resolved. Does this matter? If so we 6506 * leave the defs themselves partially resolved. Does this matter? If so we
6060 * could do a prepass that ensures that all symbols are resolvable and bail 6507 * could do a prepass that ensures that all symbols are resolvable and bail
6061 * if not, so we don't mutate anything until we know the operation will 6508 * if not, so we don't mutate anything until we know the operation will
6062 * succeed. 6509 * succeed.
6063 * 6510 *
6064 * TODO(haberman): since the defs must be mutable, refining a frozen def 6511 * TODO(haberman): since the defs must be mutable, refining a frozen def
6065 * requires making mutable copies of the entire tree. This is wasteful if 6512 * requires making mutable copies of the entire tree. This is wasteful if
6066 * only a few messages are changing. We may want to add a way of adding a 6513 * only a few messages are changing. We may want to add a way of adding a
6067 * tree of frozen defs to the symtab (perhaps an alternate constructor where 6514 * tree of frozen defs to the symtab (perhaps an alternate constructor where
6068 * you pass the root of the tree?) */ 6515 * you pass the root of the tree?) */
6069 bool Add(Def*const* defs, int n, void* ref_donor, upb_status* status); 6516 bool Add(Def*const* defs, size_t n, void* ref_donor, Status* status);
6070 6517
6071 bool Add(const std::vector<Def*>& defs, void *owner, Status* status) { 6518 bool Add(const std::vector<Def*>& defs, void *owner, Status* status) {
6072 return Add((Def*const*)&defs[0], defs.size(), owner, status); 6519 return Add((Def*const*)&defs[0], defs.size(), owner, status);
6073 } 6520 }
6074 6521
6522 /* Resolves all subdefs for messages in this file and attempts to freeze the
6523 * file. If this succeeds, adds all the symbols to this SymbolTable
6524 * (replacing any existing ones with the same names). */
6525 bool AddFile(FileDef* file, Status* s);
6526
6075 private: 6527 private:
6076 UPB_DISALLOW_POD_OPS(SymbolTable, upb::SymbolTable) 6528 UPB_DISALLOW_POD_OPS(SymbolTable, upb::SymbolTable)
6077 }; 6529 };
6078 6530
6079 #endif /* __cplusplus */ 6531 #endif /* __cplusplus */
6080 6532
6081 UPB_BEGIN_EXTERN_C 6533 UPB_BEGIN_EXTERN_C
6082 6534
6083 /* Native C API. */ 6535 /* Native C API. */
6084 6536
6085 /* Include refcounted methods like upb_symtab_ref(). */ 6537 /* Include refcounted methods like upb_symtab_ref(). */
6086 UPB_REFCOUNTED_CMETHODS(upb_symtab, upb_symtab_upcast) 6538 UPB_REFCOUNTED_CMETHODS(upb_symtab, upb_symtab_upcast)
6087 6539
6088 upb_symtab *upb_symtab_new(const void *owner); 6540 upb_symtab *upb_symtab_new(const void *owner);
6089 void upb_symtab_freeze(upb_symtab *s); 6541 void upb_symtab_freeze(upb_symtab *s);
6090 const upb_def *upb_symtab_resolve(const upb_symtab *s, const char *base, 6542 const upb_def *upb_symtab_resolve(const upb_symtab *s, const char *base,
6091 const char *sym); 6543 const char *sym);
6092 const upb_def *upb_symtab_lookup(const upb_symtab *s, const char *sym); 6544 const upb_def *upb_symtab_lookup(const upb_symtab *s, const char *sym);
6093 const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym); 6545 const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym);
6094 const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym); 6546 const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym);
6095 bool upb_symtab_add(upb_symtab *s, upb_def *const*defs, int n, void *ref_donor, 6547 bool upb_symtab_add(upb_symtab *s, upb_def *const*defs, size_t n,
6096 upb_status *status); 6548 void *ref_donor, upb_status *status);
6549 bool upb_symtab_addfile(upb_symtab *s, upb_filedef *file, upb_status* status);
6097 6550
6098 /* upb_symtab_iter i; 6551 /* upb_symtab_iter i;
6099 * for(upb_symtab_begin(&i, s, type); !upb_symtab_done(&i); 6552 * for(upb_symtab_begin(&i, s, type); !upb_symtab_done(&i);
6100 * upb_symtab_next(&i)) { 6553 * upb_symtab_next(&i)) {
6101 * const upb_def *def = upb_symtab_iter_def(&i); 6554 * const upb_def *def = upb_symtab_iter_def(&i);
6102 * // ... 6555 * // ...
6103 * } 6556 * }
6104 * 6557 *
6105 * For C we don't have separate iterators for const and non-const. 6558 * For C we don't have separate iterators for const and non-const.
6106 * It is the caller's responsibility to cast the upb_fielddef* to 6559 * It is the caller's responsibility to cast the upb_fielddef* to
(...skipping 21 matching lines...) Expand all
6128 const char *sym) const { 6581 const char *sym) const {
6129 return upb_symtab_resolve(this, base, sym); 6582 return upb_symtab_resolve(this, base, sym);
6130 } 6583 }
6131 inline const Def* SymbolTable::Lookup(const char *sym) const { 6584 inline const Def* SymbolTable::Lookup(const char *sym) const {
6132 return upb_symtab_lookup(this, sym); 6585 return upb_symtab_lookup(this, sym);
6133 } 6586 }
6134 inline const MessageDef *SymbolTable::LookupMessage(const char *sym) const { 6587 inline const MessageDef *SymbolTable::LookupMessage(const char *sym) const {
6135 return upb_symtab_lookupmsg(this, sym); 6588 return upb_symtab_lookupmsg(this, sym);
6136 } 6589 }
6137 inline bool SymbolTable::Add( 6590 inline bool SymbolTable::Add(
6138 Def*const* defs, int n, void* ref_donor, upb_status* status) { 6591 Def*const* defs, size_t n, void* ref_donor, Status* status) {
6139 return upb_symtab_add(this, (upb_def*const*)defs, n, ref_donor, status); 6592 return upb_symtab_add(this, (upb_def*const*)defs, n, ref_donor, status);
6140 } 6593 }
6594 inline bool SymbolTable::AddFile(FileDef* file, Status* s) {
6595 return upb_symtab_addfile(this, file, s);
6596 }
6141 } /* namespace upb */ 6597 } /* namespace upb */
6142 #endif 6598 #endif
6143 6599
6144 #endif /* UPB_SYMTAB_H_ */ 6600 #endif /* UPB_SYMTAB_H_ */
6145 /* 6601 /*
6146 ** upb::descriptor::Reader (upb_descreader) 6602 ** upb::descriptor::Reader (upb_descreader)
6147 ** 6603 **
6148 ** Provides a way of building upb::Defs from data in descriptor.proto format. 6604 ** Provides a way of building upb::Defs from data in descriptor.proto format.
6149 */ 6605 */
6150 6606
(...skipping 23 matching lines...) Expand all
6174 * TODO: generate the handlers statically (like we do with the 6630 * TODO: generate the handlers statically (like we do with the
6175 * descriptor.proto defs) so that there is no need to pass this parameter (or 6631 * descriptor.proto defs) so that there is no need to pass this parameter (or
6176 * to build/memory-manage the handlers at runtime at all). Unfortunately this 6632 * to build/memory-manage the handlers at runtime at all). Unfortunately this
6177 * is a bit tricky to implement for Handlers, but necessary to simplify this 6633 * is a bit tricky to implement for Handlers, but necessary to simplify this
6178 * interface. */ 6634 * interface. */
6179 static Reader* Create(Environment* env, const Handlers* handlers); 6635 static Reader* Create(Environment* env, const Handlers* handlers);
6180 6636
6181 /* The reader's input; this is where descriptor.proto data should be sent. */ 6637 /* The reader's input; this is where descriptor.proto data should be sent. */
6182 Sink* input(); 6638 Sink* input();
6183 6639
6184 /* Returns an array of all defs that have been parsed, and transfers ownership 6640 /* Use to get the FileDefs that have been parsed. */
6185 * of them to "owner". The number of defs is stored in *n. Ownership of the 6641 size_t file_count() const;
6186 * returned array is retained and is invalidated by any other call into 6642 FileDef* file(size_t i) const;
6187 * Reader.
6188 *
6189 * These defs are not frozen or resolved; they are ready to be added to a
6190 * symtab. */
6191 upb::Def** GetDefs(void* owner, int* n);
6192 6643
6193 /* Builds and returns handlers for the reader, owned by "owner." */ 6644 /* Builds and returns handlers for the reader, owned by "owner." */
6194 static Handlers* NewHandlers(const void* owner); 6645 static Handlers* NewHandlers(const void* owner);
6195 6646
6196 private: 6647 private:
6197 UPB_DISALLOW_POD_OPS(Reader, upb::descriptor::Reader) 6648 UPB_DISALLOW_POD_OPS(Reader, upb::descriptor::Reader)
6198 }; 6649 };
6199 6650
6200 #endif 6651 #endif
6201 6652
6202 UPB_BEGIN_EXTERN_C 6653 UPB_BEGIN_EXTERN_C
6203 6654
6204 /* C API. */ 6655 /* C API. */
6205 upb_descreader *upb_descreader_create(upb_env *e, const upb_handlers *h); 6656 upb_descreader *upb_descreader_create(upb_env *e, const upb_handlers *h);
6206 upb_sink *upb_descreader_input(upb_descreader *r); 6657 upb_sink *upb_descreader_input(upb_descreader *r);
6207 upb_def **upb_descreader_getdefs(upb_descreader *r, void *owner, int *n); 6658 size_t upb_descreader_filecount(const upb_descreader *r);
6659 upb_filedef *upb_descreader_file(const upb_descreader *r, size_t i);
6208 const upb_handlers *upb_descreader_newhandlers(const void *owner); 6660 const upb_handlers *upb_descreader_newhandlers(const void *owner);
6209 6661
6210 UPB_END_EXTERN_C 6662 UPB_END_EXTERN_C
6211 6663
6212 #ifdef __cplusplus 6664 #ifdef __cplusplus
6213 /* C++ implementation details. ************************************************/ 6665 /* C++ implementation details. ************************************************/
6214 namespace upb { 6666 namespace upb {
6215 namespace descriptor { 6667 namespace descriptor {
6216 inline Reader* Reader::Create(Environment* e, const Handlers *h) { 6668 inline Reader* Reader::Create(Environment* e, const Handlers *h) {
6217 return upb_descreader_create(e, h); 6669 return upb_descreader_create(e, h);
6218 } 6670 }
6219 inline Sink* Reader::input() { return upb_descreader_input(this); } 6671 inline Sink* Reader::input() { return upb_descreader_input(this); }
6220 inline upb::Def** Reader::GetDefs(void* owner, int* n) { 6672 inline size_t Reader::file_count() const {
6221 return upb_descreader_getdefs(this, owner, n); 6673 return upb_descreader_filecount(this);
6674 }
6675 inline FileDef* Reader::file(size_t i) const {
6676 return upb_descreader_file(this, i);
6222 } 6677 }
6223 } /* namespace descriptor */ 6678 } /* namespace descriptor */
6224 } /* namespace upb */ 6679 } /* namespace upb */
6225 #endif 6680 #endif
6226 6681
6227 #endif /* UPB_DESCRIPTOR_H */ 6682 #endif /* UPB_DESCRIPTOR_H */
6228 /* This file contains accessors for a set of compiled-in defs. 6683 /* This file contains accessors for a set of compiled-in defs.
6229 * Note that unlike Google's protobuf, it does *not* define 6684 * Note that unlike Google's protobuf, it does *not* define
6230 * generated classes or any other kind of data structure for 6685 * generated classes or any other kind of data structure for
6231 * actually storing protobufs. It only contains *defs* which 6686 * actually storing protobufs. It only contains *defs* which
6232 * let you reflect over a protobuf *schema*. 6687 * let you reflect over a protobuf *schema*.
6233 */ 6688 */
6234 /* This file was generated by upbc (the upb compiler). 6689 /* This file was generated by upbc (the upb compiler) from the input
6690 * file:
6691 *
6692 * upb/descriptor/descriptor.proto
6693 *
6235 * Do not edit -- your changes will be discarded when the file is 6694 * Do not edit -- your changes will be discarded when the file is
6236 * regenerated. */ 6695 * regenerated. */
6237 6696
6238 #ifndef GOOGLE_PROTOBUF_DESCRIPTOR_UPB_H_ 6697 #ifndef UPB_DESCRIPTOR_DESCRIPTOR_PROTO_UPB_H_
6239 #define GOOGLE_PROTOBUF_DESCRIPTOR_UPB_H_ 6698 #define UPB_DESCRIPTOR_DESCRIPTOR_PROTO_UPB_H_
6240 6699
6241 6700
6242 #ifdef __cplusplus
6243 UPB_BEGIN_EXTERN_C 6701 UPB_BEGIN_EXTERN_C
6244 #endif
6245 6702
6246 /* Enums */ 6703 /* Enums */
6247 6704
6248 typedef enum { 6705 typedef enum {
6249 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_LABEL_OPTIONAL = 1, 6706 google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1,
6250 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_LABEL_REQUIRED = 2, 6707 google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2,
6251 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_LABEL_REPEATED = 3 6708 google_protobuf_FieldDescriptorProto_LABEL_REPEATED = 3
6252 } google_protobuf_FieldDescriptorProto_Label; 6709 } google_protobuf_FieldDescriptorProto_Label;
6253 6710
6254 typedef enum { 6711 typedef enum {
6255 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_DOUBLE = 1, 6712 google_protobuf_FieldDescriptorProto_TYPE_DOUBLE = 1,
6256 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_FLOAT = 2, 6713 google_protobuf_FieldDescriptorProto_TYPE_FLOAT = 2,
6257 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_INT64 = 3, 6714 google_protobuf_FieldDescriptorProto_TYPE_INT64 = 3,
6258 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_UINT64 = 4, 6715 google_protobuf_FieldDescriptorProto_TYPE_UINT64 = 4,
6259 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_INT32 = 5, 6716 google_protobuf_FieldDescriptorProto_TYPE_INT32 = 5,
6260 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_FIXED64 = 6, 6717 google_protobuf_FieldDescriptorProto_TYPE_FIXED64 = 6,
6261 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_FIXED32 = 7, 6718 google_protobuf_FieldDescriptorProto_TYPE_FIXED32 = 7,
6262 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_BOOL = 8, 6719 google_protobuf_FieldDescriptorProto_TYPE_BOOL = 8,
6263 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_STRING = 9, 6720 google_protobuf_FieldDescriptorProto_TYPE_STRING = 9,
6264 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_GROUP = 10, 6721 google_protobuf_FieldDescriptorProto_TYPE_GROUP = 10,
6265 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_MESSAGE = 11, 6722 google_protobuf_FieldDescriptorProto_TYPE_MESSAGE = 11,
6266 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_BYTES = 12, 6723 google_protobuf_FieldDescriptorProto_TYPE_BYTES = 12,
6267 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_UINT32 = 13, 6724 google_protobuf_FieldDescriptorProto_TYPE_UINT32 = 13,
6268 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_ENUM = 14, 6725 google_protobuf_FieldDescriptorProto_TYPE_ENUM = 14,
6269 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_SFIXED32 = 15, 6726 google_protobuf_FieldDescriptorProto_TYPE_SFIXED32 = 15,
6270 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_SFIXED64 = 16, 6727 google_protobuf_FieldDescriptorProto_TYPE_SFIXED64 = 16,
6271 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_SINT32 = 17, 6728 google_protobuf_FieldDescriptorProto_TYPE_SINT32 = 17,
6272 GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_SINT64 = 18 6729 google_protobuf_FieldDescriptorProto_TYPE_SINT64 = 18
6273 } google_protobuf_FieldDescriptorProto_Type; 6730 } google_protobuf_FieldDescriptorProto_Type;
6274 6731
6275 typedef enum { 6732 typedef enum {
6276 GOOGLE_PROTOBUF_FIELDOPTIONS_STRING = 0, 6733 google_protobuf_FieldOptions_STRING = 0,
6277 GOOGLE_PROTOBUF_FIELDOPTIONS_CORD = 1, 6734 google_protobuf_FieldOptions_CORD = 1,
6278 GOOGLE_PROTOBUF_FIELDOPTIONS_STRING_PIECE = 2 6735 google_protobuf_FieldOptions_STRING_PIECE = 2
6279 } google_protobuf_FieldOptions_CType; 6736 } google_protobuf_FieldOptions_CType;
6280 6737
6281 typedef enum { 6738 typedef enum {
6282 GOOGLE_PROTOBUF_FILEOPTIONS_SPEED = 1, 6739 google_protobuf_FieldOptions_JS_NORMAL = 0,
6283 GOOGLE_PROTOBUF_FILEOPTIONS_CODE_SIZE = 2, 6740 google_protobuf_FieldOptions_JS_STRING = 1,
6284 GOOGLE_PROTOBUF_FILEOPTIONS_LITE_RUNTIME = 3 6741 google_protobuf_FieldOptions_JS_NUMBER = 2
6742 } google_protobuf_FieldOptions_JSType;
6743
6744 typedef enum {
6745 google_protobuf_FileOptions_SPEED = 1,
6746 google_protobuf_FileOptions_CODE_SIZE = 2,
6747 google_protobuf_FileOptions_LITE_RUNTIME = 3
6285 } google_protobuf_FileOptions_OptimizeMode; 6748 } google_protobuf_FileOptions_OptimizeMode;
6286 6749
6287 /* Selectors */ 6750 /* MessageDefs: call these functions to get a ref to a msgdef. */
6288 6751 const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_get(const void *owner) ;
6289 /* google.protobuf.DescriptorProto */ 6752 const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ExtensionRange_get(con st void *owner);
6290 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_FIELD_STARTSUBMSG 2 6753 const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ReservedRange_get(cons t void *owner);
6291 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NESTED_TYPE_STARTSUBMSG 3 6754 const upb_msgdef *upbdefs_google_protobuf_EnumDescriptorProto_get(const void *ow ner);
6292 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_ENUM_TYPE_STARTSUBMSG 4 6755 const upb_msgdef *upbdefs_google_protobuf_EnumOptions_get(const void *owner);
6293 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_RANGE_STARTSUBMSG 5 6756 const upb_msgdef *upbdefs_google_protobuf_EnumValueDescriptorProto_get(const voi d *owner);
6294 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_STARTSUBMSG 6 6757 const upb_msgdef *upbdefs_google_protobuf_EnumValueOptions_get(const void *owner );
6295 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_OPTIONS_STARTSUBMSG 7 6758 const upb_msgdef *upbdefs_google_protobuf_FieldDescriptorProto_get(const void *o wner);
6296 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_FIELD_STARTSEQ 8 6759 const upb_msgdef *upbdefs_google_protobuf_FieldOptions_get(const void *owner);
6297 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_FIELD_ENDSEQ 9 6760 const upb_msgdef *upbdefs_google_protobuf_FileDescriptorProto_get(const void *ow ner);
6298 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_FIELD_ENDSUBMSG 10 6761 const upb_msgdef *upbdefs_google_protobuf_FileDescriptorSet_get(const void *owne r);
6299 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NESTED_TYPE_STARTSEQ 11 6762 const upb_msgdef *upbdefs_google_protobuf_FileOptions_get(const void *owner);
6300 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NESTED_TYPE_ENDSEQ 12 6763 const upb_msgdef *upbdefs_google_protobuf_MessageOptions_get(const void *owner);
6301 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NESTED_TYPE_ENDSUBMSG 13 6764 const upb_msgdef *upbdefs_google_protobuf_MethodDescriptorProto_get(const void * owner);
6302 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_ENUM_TYPE_STARTSEQ 14 6765 const upb_msgdef *upbdefs_google_protobuf_MethodOptions_get(const void *owner);
6303 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_ENUM_TYPE_ENDSEQ 15 6766 const upb_msgdef *upbdefs_google_protobuf_OneofDescriptorProto_get(const void *o wner);
6304 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_ENUM_TYPE_ENDSUBMSG 16 6767 const upb_msgdef *upbdefs_google_protobuf_ServiceDescriptorProto_get(const void *owner);
6305 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_RANGE_STARTSEQ 17 6768 const upb_msgdef *upbdefs_google_protobuf_ServiceOptions_get(const void *owner);
6306 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_RANGE_ENDSEQ 18 6769 const upb_msgdef *upbdefs_google_protobuf_SourceCodeInfo_get(const void *owner);
6307 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_RANGE_ENDSUBMSG 19 6770 const upb_msgdef *upbdefs_google_protobuf_SourceCodeInfo_Location_get(const void *owner);
6308 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_STARTSEQ 20 6771 const upb_msgdef *upbdefs_google_protobuf_UninterpretedOption_get(const void *ow ner);
6309 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_ENDSEQ 21 6772 const upb_msgdef *upbdefs_google_protobuf_UninterpretedOption_NamePart_get(const void *owner);
6310 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSION_ENDSUBMSG 22 6773
6311 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_OPTIONS_ENDSUBMSG 23 6774 /* EnumDefs: call these functions to get a ref to an enumdef. */
6312 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NAME_STRING 24 6775 const upb_enumdef *upbdefs_google_protobuf_FieldDescriptorProto_Label_get(const void *owner);
6313 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NAME_STARTSTR 25 6776 const upb_enumdef *upbdefs_google_protobuf_FieldDescriptorProto_Type_get(const v oid *owner);
6314 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_NAME_ENDSTR 26 6777 const upb_enumdef *upbdefs_google_protobuf_FieldOptions_CType_get(const void *ow ner);
6315 6778 const upb_enumdef *upbdefs_google_protobuf_FieldOptions_JSType_get(const void *o wner);
6316 /* google.protobuf.DescriptorProto.ExtensionRange */ 6779 const upb_enumdef *upbdefs_google_protobuf_FileOptions_OptimizeMode_get(const vo id *owner);
6317 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSIONRANGE_START_INT32 2 6780
6318 #define SEL_GOOGLE_PROTOBUF_DESCRIPTORPROTO_EXTENSIONRANGE_END_INT32 3 6781 /* Functions to test whether this message is of a certain type. */
6319 6782 UPB_INLINE bool upbdefs_google_protobuf_DescriptorProto_is(const upb_msgdef *m) {
6320 /* google.protobuf.EnumDescriptorProto */ 6783 return strcmp(upb_msgdef_fullname(m), "google.protobuf.DescriptorProto") == 0;
6321 #define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_VALUE_STARTSUBMSG 2 6784 }
6322 #define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_OPTIONS_STARTSUBMSG 3 6785 UPB_INLINE bool upbdefs_google_protobuf_DescriptorProto_ExtensionRange_is(const upb_msgdef *m) {
6323 #define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_VALUE_STARTSEQ 4 6786 return strcmp(upb_msgdef_fullname(m), "google.protobuf.DescriptorProto.Extensi onRange") == 0;
6324 #define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_VALUE_ENDSEQ 5 6787 }
6325 #define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_VALUE_ENDSUBMSG 6 6788 UPB_INLINE bool upbdefs_google_protobuf_DescriptorProto_ReservedRange_is(const u pb_msgdef *m) {
6326 #define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_OPTIONS_ENDSUBMSG 7 6789 return strcmp(upb_msgdef_fullname(m), "google.protobuf.DescriptorProto.Reserve dRange") == 0;
6327 #define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_NAME_STRING 8 6790 }
6328 #define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_NAME_STARTSTR 9 6791 UPB_INLINE bool upbdefs_google_protobuf_EnumDescriptorProto_is(const upb_msgdef *m) {
6329 #define SEL_GOOGLE_PROTOBUF_ENUMDESCRIPTORPROTO_NAME_ENDSTR 10 6792 return strcmp(upb_msgdef_fullname(m), "google.protobuf.EnumDescriptorProto") = = 0;
6330 6793 }
6331 /* google.protobuf.EnumOptions */ 6794 UPB_INLINE bool upbdefs_google_protobuf_EnumOptions_is(const upb_msgdef *m) {
6332 #define SEL_GOOGLE_PROTOBUF_ENUMOPTIONS_UNINTERPRETED_OPTION_STARTSUBMSG 2 6795 return strcmp(upb_msgdef_fullname(m), "google.protobuf.EnumOptions") == 0;
6333 #define SEL_GOOGLE_PROTOBUF_ENUMOPTIONS_UNINTERPRETED_OPTION_STARTSEQ 3 6796 }
6334 #define SEL_GOOGLE_PROTOBUF_ENUMOPTIONS_UNINTERPRETED_OPTION_ENDSEQ 4 6797 UPB_INLINE bool upbdefs_google_protobuf_EnumValueDescriptorProto_is(const upb_ms gdef *m) {
6335 #define SEL_GOOGLE_PROTOBUF_ENUMOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 6798 return strcmp(upb_msgdef_fullname(m), "google.protobuf.EnumValueDescriptorProt o") == 0;
6336 #define SEL_GOOGLE_PROTOBUF_ENUMOPTIONS_ALLOW_ALIAS_BOOL 6 6799 }
6337 6800 UPB_INLINE bool upbdefs_google_protobuf_EnumValueOptions_is(const upb_msgdef *m) {
6338 /* google.protobuf.EnumValueDescriptorProto */ 6801 return strcmp(upb_msgdef_fullname(m), "google.protobuf.EnumValueOptions") == 0 ;
6339 #define SEL_GOOGLE_PROTOBUF_ENUMVALUEDESCRIPTORPROTO_OPTIONS_STARTSUBMSG 2 6802 }
6340 #define SEL_GOOGLE_PROTOBUF_ENUMVALUEDESCRIPTORPROTO_OPTIONS_ENDSUBMSG 3 6803 UPB_INLINE bool upbdefs_google_protobuf_FieldDescriptorProto_is(const upb_msgdef *m) {
6341 #define SEL_GOOGLE_PROTOBUF_ENUMVALUEDESCRIPTORPROTO_NAME_STRING 4 6804 return strcmp(upb_msgdef_fullname(m), "google.protobuf.FieldDescriptorProto") == 0;
6342 #define SEL_GOOGLE_PROTOBUF_ENUMVALUEDESCRIPTORPROTO_NAME_STARTSTR 5 6805 }
6343 #define SEL_GOOGLE_PROTOBUF_ENUMVALUEDESCRIPTORPROTO_NAME_ENDSTR 6 6806 UPB_INLINE bool upbdefs_google_protobuf_FieldOptions_is(const upb_msgdef *m) {
6344 #define SEL_GOOGLE_PROTOBUF_ENUMVALUEDESCRIPTORPROTO_NUMBER_INT32 7 6807 return strcmp(upb_msgdef_fullname(m), "google.protobuf.FieldOptions") == 0;
6345 6808 }
6346 /* google.protobuf.EnumValueOptions */ 6809 UPB_INLINE bool upbdefs_google_protobuf_FileDescriptorProto_is(const upb_msgdef *m) {
6347 #define SEL_GOOGLE_PROTOBUF_ENUMVALUEOPTIONS_UNINTERPRETED_OPTION_STARTSUBMSG 2 6810 return strcmp(upb_msgdef_fullname(m), "google.protobuf.FileDescriptorProto") = = 0;
6348 #define SEL_GOOGLE_PROTOBUF_ENUMVALUEOPTIONS_UNINTERPRETED_OPTION_STARTSEQ 3 6811 }
6349 #define SEL_GOOGLE_PROTOBUF_ENUMVALUEOPTIONS_UNINTERPRETED_OPTION_ENDSEQ 4 6812 UPB_INLINE bool upbdefs_google_protobuf_FileDescriptorSet_is(const upb_msgdef *m ) {
6350 #define SEL_GOOGLE_PROTOBUF_ENUMVALUEOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 6813 return strcmp(upb_msgdef_fullname(m), "google.protobuf.FileDescriptorSet") == 0;
6351 6814 }
6352 /* google.protobuf.FieldDescriptorProto */ 6815 UPB_INLINE bool upbdefs_google_protobuf_FileOptions_is(const upb_msgdef *m) {
6353 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_OPTIONS_STARTSUBMSG 2 6816 return strcmp(upb_msgdef_fullname(m), "google.protobuf.FileOptions") == 0;
6354 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_OPTIONS_ENDSUBMSG 3 6817 }
6355 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_NAME_STRING 4 6818 UPB_INLINE bool upbdefs_google_protobuf_MessageOptions_is(const upb_msgdef *m) {
6356 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_NAME_STARTSTR 5 6819 return strcmp(upb_msgdef_fullname(m), "google.protobuf.MessageOptions") == 0;
6357 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_NAME_ENDSTR 6 6820 }
6358 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_EXTENDEE_STRING 7 6821 UPB_INLINE bool upbdefs_google_protobuf_MethodDescriptorProto_is(const upb_msgde f *m) {
6359 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_EXTENDEE_STARTSTR 8 6822 return strcmp(upb_msgdef_fullname(m), "google.protobuf.MethodDescriptorProto") == 0;
6360 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_EXTENDEE_ENDSTR 9 6823 }
6361 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_NUMBER_INT32 10 6824 UPB_INLINE bool upbdefs_google_protobuf_MethodOptions_is(const upb_msgdef *m) {
6362 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_LABEL_INT32 11 6825 return strcmp(upb_msgdef_fullname(m), "google.protobuf.MethodOptions") == 0;
6363 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_INT32 12 6826 }
6364 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_NAME_STRING 13 6827 UPB_INLINE bool upbdefs_google_protobuf_OneofDescriptorProto_is(const upb_msgdef *m) {
6365 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_NAME_STARTSTR 14 6828 return strcmp(upb_msgdef_fullname(m), "google.protobuf.OneofDescriptorProto") == 0;
6366 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_NAME_ENDSTR 15 6829 }
6367 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_DEFAULT_VALUE_STRING 16 6830 UPB_INLINE bool upbdefs_google_protobuf_ServiceDescriptorProto_is(const upb_msgd ef *m) {
6368 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_DEFAULT_VALUE_STARTSTR 17 6831 return strcmp(upb_msgdef_fullname(m), "google.protobuf.ServiceDescriptorProto" ) == 0;
6369 #define SEL_GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_DEFAULT_VALUE_ENDSTR 18 6832 }
6370 6833 UPB_INLINE bool upbdefs_google_protobuf_ServiceOptions_is(const upb_msgdef *m) {
6371 /* google.protobuf.FieldOptions */ 6834 return strcmp(upb_msgdef_fullname(m), "google.protobuf.ServiceOptions") == 0;
6372 #define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_UNINTERPRETED_OPTION_STARTSUBMSG 2 6835 }
6373 #define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_UNINTERPRETED_OPTION_STARTSEQ 3 6836 UPB_INLINE bool upbdefs_google_protobuf_SourceCodeInfo_is(const upb_msgdef *m) {
6374 #define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_UNINTERPRETED_OPTION_ENDSEQ 4 6837 return strcmp(upb_msgdef_fullname(m), "google.protobuf.SourceCodeInfo") == 0;
6375 #define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 6838 }
6376 #define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_CTYPE_INT32 6 6839 UPB_INLINE bool upbdefs_google_protobuf_SourceCodeInfo_Location_is(const upb_msg def *m) {
6377 #define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_PACKED_BOOL 7 6840 return strcmp(upb_msgdef_fullname(m), "google.protobuf.SourceCodeInfo.Location ") == 0;
6378 #define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_DEPRECATED_BOOL 8 6841 }
6379 #define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_LAZY_BOOL 9 6842 UPB_INLINE bool upbdefs_google_protobuf_UninterpretedOption_is(const upb_msgdef *m) {
6380 #define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_EXPERIMENTAL_MAP_KEY_STRING 10 6843 return strcmp(upb_msgdef_fullname(m), "google.protobuf.UninterpretedOption") = = 0;
6381 #define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_EXPERIMENTAL_MAP_KEY_STARTSTR 11 6844 }
6382 #define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_EXPERIMENTAL_MAP_KEY_ENDSTR 12 6845 UPB_INLINE bool upbdefs_google_protobuf_UninterpretedOption_NamePart_is(const up b_msgdef *m) {
6383 #define SEL_GOOGLE_PROTOBUF_FIELDOPTIONS_WEAK_BOOL 13 6846 return strcmp(upb_msgdef_fullname(m), "google.protobuf.UninterpretedOption.Nam ePart") == 0;
6384 6847 }
6385 /* google.protobuf.FileDescriptorProto */ 6848
6386 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_MESSAGE_TYPE_STARTSUBMSG 2 6849 /* Functions to test whether this enum is of a certain type. */
6387 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_ENUM_TYPE_STARTSUBMSG 3 6850 UPB_INLINE bool upbdefs_google_protobuf_FieldDescriptorProto_Label_is(const upb_ enumdef *e) {
6388 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_SERVICE_STARTSUBMSG 4 6851 return strcmp(upb_enumdef_fullname(e), "google.protobuf.FieldDescriptorProto.L abel") == 0;
6389 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_EXTENSION_STARTSUBMSG 5 6852 }
6390 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_OPTIONS_STARTSUBMSG 6 6853 UPB_INLINE bool upbdefs_google_protobuf_FieldDescriptorProto_Type_is(const upb_e numdef *e) {
6391 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_SOURCE_CODE_INFO_STARTSUBMSG 7 6854 return strcmp(upb_enumdef_fullname(e), "google.protobuf.FieldDescriptorProto.T ype") == 0;
6392 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_MESSAGE_TYPE_STARTSEQ 8 6855 }
6393 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_MESSAGE_TYPE_ENDSEQ 9 6856 UPB_INLINE bool upbdefs_google_protobuf_FieldOptions_CType_is(const upb_enumdef *e) {
6394 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_MESSAGE_TYPE_ENDSUBMSG 10 6857 return strcmp(upb_enumdef_fullname(e), "google.protobuf.FieldOptions.CType") = = 0;
6395 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_ENUM_TYPE_STARTSEQ 11 6858 }
6396 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_ENUM_TYPE_ENDSEQ 12 6859 UPB_INLINE bool upbdefs_google_protobuf_FieldOptions_JSType_is(const upb_enumdef *e) {
6397 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_ENUM_TYPE_ENDSUBMSG 13 6860 return strcmp(upb_enumdef_fullname(e), "google.protobuf.FieldOptions.JSType") == 0;
6398 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_SERVICE_STARTSEQ 14 6861 }
6399 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_SERVICE_ENDSEQ 15 6862 UPB_INLINE bool upbdefs_google_protobuf_FileOptions_OptimizeMode_is(const upb_en umdef *e) {
6400 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_SERVICE_ENDSUBMSG 16 6863 return strcmp(upb_enumdef_fullname(e), "google.protobuf.FileOptions.OptimizeMo de") == 0;
6401 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_EXTENSION_STARTSEQ 17 6864 }
6402 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_EXTENSION_ENDSEQ 18 6865
6403 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_EXTENSION_ENDSUBMSG 19 6866
6404 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_OPTIONS_ENDSUBMSG 20 6867 /* Functions to get a fielddef from a msgdef reference. */
6405 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_SOURCE_CODE_INFO_ENDSUBMSG 21 6868 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_Extension Range_f_end(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_Descriptor Proto_ExtensionRange_is(m)); return upb_msgdef_itof(m, 2); }
6406 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_NAME_STRING 22 6869 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_Extension Range_f_start(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_Descript orProto_ExtensionRange_is(m)); return upb_msgdef_itof(m, 1); }
6407 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_NAME_STARTSTR 23 6870 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_ReservedR ange_f_end(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorP roto_ReservedRange_is(m)); return upb_msgdef_itof(m, 2); }
6408 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_NAME_ENDSTR 24 6871 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_ReservedR ange_f_start(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_Descripto rProto_ReservedRange_is(m)); return upb_msgdef_itof(m, 1); }
6409 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_PACKAGE_STRING 25 6872 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_enum_ty pe(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is( m)); return upb_msgdef_itof(m, 4); }
6410 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_PACKAGE_STARTSTR 26 6873 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_extensi on(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is( m)); return upb_msgdef_itof(m, 6); }
6411 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_PACKAGE_ENDSTR 27 6874 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_extensi on_range(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorPro to_is(m)); return upb_msgdef_itof(m, 5); }
6412 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_DEPENDENCY_STARTSEQ 28 6875 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_field(c onst upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
6413 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_DEPENDENCY_ENDSEQ 29 6876 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_name(co nst upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
6414 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_DEPENDENCY_STRING 30 6877 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_nested_ type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_i s(m)); return upb_msgdef_itof(m, 3); }
6415 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_DEPENDENCY_STARTSTR 31 6878 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_oneof_d ecl(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is (m)); return upb_msgdef_itof(m, 8); }
6416 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_DEPENDENCY_ENDSTR 32 6879 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_options (const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m) ); return upb_msgdef_itof(m, 7); }
6417 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_PUBLIC_DEPENDENCY_STARTSEQ 33 6880 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_reserve d_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto _is(m)); return upb_msgdef_itof(m, 10); }
6418 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_PUBLIC_DEPENDENCY_ENDSEQ 34 6881 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_reserve d_range(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProt o_is(m)); return upb_msgdef_itof(m, 9); }
6419 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_PUBLIC_DEPENDENCY_INT32 35 6882 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumDescriptorProto_f_nam e(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumDescriptorProto_ is(m)); return upb_msgdef_itof(m, 1); }
6420 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_WEAK_DEPENDENCY_STARTSEQ 36 6883 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumDescriptorProto_f_opt ions(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumDescriptorPro to_is(m)); return upb_msgdef_itof(m, 3); }
6421 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_WEAK_DEPENDENCY_ENDSEQ 37 6884 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumDescriptorProto_f_val ue(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumDescriptorProto _is(m)); return upb_msgdef_itof(m, 2); }
6422 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORPROTO_WEAK_DEPENDENCY_INT32 38 6885 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumOptions_f_allow_alias (const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumOptions_is(m)); r eturn upb_msgdef_itof(m, 2); }
6423 6886 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumOptions_f_deprecated( const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumOptions_is(m)); re turn upb_msgdef_itof(m, 3); }
6424 /* google.protobuf.FileDescriptorSet */ 6887 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumOptions_f_uninterpret ed_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumOptions_ is(m)); return upb_msgdef_itof(m, 999); }
6425 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORSET_FILE_STARTSUBMSG 2 6888 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueDescriptorProto_ f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueDescri ptorProto_is(m)); return upb_msgdef_itof(m, 1); }
6426 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORSET_FILE_STARTSEQ 3 6889 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueDescriptorProto_ f_number(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueDesc riptorProto_is(m)); return upb_msgdef_itof(m, 2); }
6427 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORSET_FILE_ENDSEQ 4 6890 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueDescriptorProto_ f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueDes criptorProto_is(m)); return upb_msgdef_itof(m, 3); }
6428 #define SEL_GOOGLE_PROTOBUF_FILEDESCRIPTORSET_FILE_ENDSUBMSG 5 6891 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueOptions_f_deprec ated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueOptions_ is(m)); return upb_msgdef_itof(m, 1); }
6429 6892 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueOptions_f_uninte rpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumVal ueOptions_is(m)); return upb_msgdef_itof(m, 999); }
6430 /* google.protobuf.FileOptions */ 6893 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_de fault_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescr iptorProto_is(m)); return upb_msgdef_itof(m, 7); }
6431 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_UNINTERPRETED_OPTION_STARTSUBMSG 2 6894 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_ex tendee(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptor Proto_is(m)); return upb_msgdef_itof(m, 2); }
6432 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_UNINTERPRETED_OPTION_STARTSEQ 3 6895 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_js on_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescripto rProto_is(m)); return upb_msgdef_itof(m, 10); }
6433 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_UNINTERPRETED_OPTION_ENDSEQ 4 6896 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_la bel(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorPro to_is(m)); return upb_msgdef_itof(m, 4); }
6434 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 6897 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_na me(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProt o_is(m)); return upb_msgdef_itof(m, 1); }
6435 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_PACKAGE_STRING 6 6898 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_nu mber(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorPr oto_is(m)); return upb_msgdef_itof(m, 3); }
6436 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_PACKAGE_STARTSTR 7 6899 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_on eof_index(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescrip torProto_is(m)); return upb_msgdef_itof(m, 9); }
6437 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_PACKAGE_ENDSTR 8 6900 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_op tions(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorP roto_is(m)); return upb_msgdef_itof(m, 8); }
6438 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_OUTER_CLASSNAME_STRING 9 6901 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_ty pe(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProt o_is(m)); return upb_msgdef_itof(m, 5); }
6439 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_OUTER_CLASSNAME_STARTSTR 10 6902 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_ty pe_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescripto rProto_is(m)); return upb_msgdef_itof(m, 6); }
6440 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_OUTER_CLASSNAME_ENDSTR 11 6903 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_ctype(cons t upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); retur n upb_msgdef_itof(m, 1); }
6441 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_OPTIMIZE_FOR_INT32 12 6904 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_deprecated (const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 3); }
6442 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_MULTIPLE_FILES_BOOL 13 6905 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_jstype(con st upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); retu rn upb_msgdef_itof(m, 6); }
6443 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_GO_PACKAGE_STRING 14 6906 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_lazy(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 5); }
6444 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_GO_PACKAGE_STARTSTR 15 6907 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_packed(con st upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); retu rn upb_msgdef_itof(m, 2); }
6445 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_GO_PACKAGE_ENDSTR 16 6908 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_uninterpre ted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOption s_is(m)); return upb_msgdef_itof(m, 999); }
6446 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_CC_GENERIC_SERVICES_BOOL 17 6909 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_weak(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 10); }
6447 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_GENERIC_SERVICES_BOOL 18 6910 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_dep endency(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptor Proto_is(m)); return upb_msgdef_itof(m, 3); }
6448 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_PY_GENERIC_SERVICES_BOOL 19 6911 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_enu m_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorP roto_is(m)); return upb_msgdef_itof(m, 5); }
6449 #define SEL_GOOGLE_PROTOBUF_FILEOPTIONS_JAVA_GENERATE_EQUALS_AND_HASH_BOOL 20 6912 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_ext ension(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorP roto_is(m)); return upb_msgdef_itof(m, 7); }
6450 6913 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_mes sage_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescript orProto_is(m)); return upb_msgdef_itof(m, 4); }
6451 /* google.protobuf.MessageOptions */ 6914 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_nam e(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_ is(m)); return upb_msgdef_itof(m, 1); }
6452 #define SEL_GOOGLE_PROTOBUF_MESSAGEOPTIONS_UNINTERPRETED_OPTION_STARTSUBMSG 2 6915 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_opt ions(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorPro to_is(m)); return upb_msgdef_itof(m, 8); }
6453 #define SEL_GOOGLE_PROTOBUF_MESSAGEOPTIONS_UNINTERPRETED_OPTION_STARTSEQ 3 6916 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_pac kage(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorPro to_is(m)); return upb_msgdef_itof(m, 2); }
6454 #define SEL_GOOGLE_PROTOBUF_MESSAGEOPTIONS_UNINTERPRETED_OPTION_ENDSEQ 4 6917 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_pub lic_dependency(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDes criptorProto_is(m)); return upb_msgdef_itof(m, 10); }
6455 #define SEL_GOOGLE_PROTOBUF_MESSAGEOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 6918 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_ser vice(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorPro to_is(m)); return upb_msgdef_itof(m, 6); }
6456 #define SEL_GOOGLE_PROTOBUF_MESSAGEOPTIONS_MESSAGE_SET_WIRE_FORMAT_BOOL 6 6919 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_sou rce_code_info(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDesc riptorProto_is(m)); return upb_msgdef_itof(m, 9); }
6457 #define SEL_GOOGLE_PROTOBUF_MESSAGEOPTIONS_NO_STANDARD_DESCRIPTOR_ACCESSOR_BOOL 7 6920 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_syn tax(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProt o_is(m)); return upb_msgdef_itof(m, 12); }
6458 6921 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_wea k_dependency(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescr iptorProto_is(m)); return upb_msgdef_itof(m, 11); }
6459 /* google.protobuf.MethodDescriptorProto */ 6922 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorSet_f_file( const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorSet_is(m )); return upb_msgdef_itof(m, 1); }
6460 #define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_OPTIONS_STARTSUBMSG 2 6923 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_cc_enable_a renas(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m )); return upb_msgdef_itof(m, 31); }
6461 #define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_OPTIONS_ENDSUBMSG 3 6924 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_cc_generic_ services(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_i s(m)); return upb_msgdef_itof(m, 16); }
6462 #define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_NAME_STRING 4 6925 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_csharp_name space(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m )); return upb_msgdef_itof(m, 37); }
6463 #define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_NAME_STARTSTR 5 6926 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_deprecated( const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); re turn upb_msgdef_itof(m, 23); }
6464 #define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_NAME_ENDSTR 6 6927 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_go_package( const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); re turn upb_msgdef_itof(m, 11); }
6465 #define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_INPUT_TYPE_STRING 7 6928 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_genera te_equals_and_hash(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_Fil eOptions_is(m)); return upb_msgdef_itof(m, 20); }
6466 #define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_INPUT_TYPE_STARTSTR 8 6929 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_generi c_services(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions _is(m)); return upb_msgdef_itof(m, 17); }
6467 #define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_INPUT_TYPE_ENDSTR 9 6930 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_multip le_files(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_i s(m)); return upb_msgdef_itof(m, 10); }
6468 #define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_OUTPUT_TYPE_STRING 10 6931 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_outer_ classname(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_ is(m)); return upb_msgdef_itof(m, 8); }
6469 #define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_OUTPUT_TYPE_STARTSTR 11 6932 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_packag e(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 1); }
6470 #define SEL_GOOGLE_PROTOBUF_METHODDESCRIPTORPROTO_OUTPUT_TYPE_ENDSTR 12 6933 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_string _check_utf8(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOption s_is(m)); return upb_msgdef_itof(m, 27); }
6471 6934 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_javanano_us e_deprecated_package(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_F ileOptions_is(m)); return upb_msgdef_itof(m, 38); }
6472 /* google.protobuf.MethodOptions */ 6935 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_objc_class_ prefix(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is( m)); return upb_msgdef_itof(m, 36); }
6473 #define SEL_GOOGLE_PROTOBUF_METHODOPTIONS_UNINTERPRETED_OPTION_STARTSUBMSG 2 6936 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_optimize_fo r(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 9); }
6474 #define SEL_GOOGLE_PROTOBUF_METHODOPTIONS_UNINTERPRETED_OPTION_STARTSEQ 3 6937 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_py_generic_ services(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_i s(m)); return upb_msgdef_itof(m, 18); }
6475 #define SEL_GOOGLE_PROTOBUF_METHODOPTIONS_UNINTERPRETED_OPTION_ENDSEQ 4 6938 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_uninterpret ed_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_ is(m)); return upb_msgdef_itof(m, 999); }
6476 #define SEL_GOOGLE_PROTOBUF_METHODOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 6939 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_deprecat ed(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m )); return upb_msgdef_itof(m, 3); }
6477 6940 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_map_entr y(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m) ); return upb_msgdef_itof(m, 7); }
6478 /* google.protobuf.ServiceDescriptorProto */ 6941 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_message_ set_wire_format(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_Messag eOptions_is(m)); return upb_msgdef_itof(m, 1); }
6479 #define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_METHOD_STARTSUBMSG 2 6942 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_no_stand ard_descriptor_accessor(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobu f_MessageOptions_is(m)); return upb_msgdef_itof(m, 2); }
6480 #define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_OPTIONS_STARTSUBMSG 3 6943 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_uninterp reted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOp tions_is(m)); return upb_msgdef_itof(m, 999); }
6481 #define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_METHOD_STARTSEQ 4 6944 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_c lient_streaming(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_Method DescriptorProto_is(m)); return upb_msgdef_itof(m, 5); }
6482 #define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_METHOD_ENDSEQ 5 6945 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_i nput_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescri ptorProto_is(m)); return upb_msgdef_itof(m, 2); }
6483 #define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_METHOD_ENDSUBMSG 6 6946 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_n ame(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorPr oto_is(m)); return upb_msgdef_itof(m, 1); }
6484 #define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_OPTIONS_ENDSUBMSG 7 6947 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_o ptions(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescripto rProto_is(m)); return upb_msgdef_itof(m, 4); }
6485 #define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_NAME_STRING 8 6948 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_o utput_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescr iptorProto_is(m)); return upb_msgdef_itof(m, 3); }
6486 #define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_NAME_STARTSTR 9 6949 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_s erver_streaming(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_Method DescriptorProto_is(m)); return upb_msgdef_itof(m, 6); }
6487 #define SEL_GOOGLE_PROTOBUF_SERVICEDESCRIPTORPROTO_NAME_ENDSTR 10 6950 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodOptions_f_deprecate d(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodOptions_is(m)) ; return upb_msgdef_itof(m, 33); }
6488 6951 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodOptions_f_uninterpr eted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodOpti ons_is(m)); return upb_msgdef_itof(m, 999); }
6489 /* google.protobuf.ServiceOptions */ 6952 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_OneofDescriptorProto_f_na me(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_OneofDescriptorProt o_is(m)); return upb_msgdef_itof(m, 1); }
6490 #define SEL_GOOGLE_PROTOBUF_SERVICEOPTIONS_UNINTERPRETED_OPTION_STARTSUBMSG 2 6953 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceDescriptorProto_f_ method(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceDescript orProto_is(m)); return upb_msgdef_itof(m, 2); }
6491 #define SEL_GOOGLE_PROTOBUF_SERVICEOPTIONS_UNINTERPRETED_OPTION_STARTSEQ 3 6954 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceDescriptorProto_f_ name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceDescriptor Proto_is(m)); return upb_msgdef_itof(m, 1); }
6492 #define SEL_GOOGLE_PROTOBUF_SERVICEOPTIONS_UNINTERPRETED_OPTION_ENDSEQ 4 6955 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceDescriptorProto_f_ options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceDescrip torProto_is(m)); return upb_msgdef_itof(m, 3); }
6493 #define SEL_GOOGLE_PROTOBUF_SERVICEOPTIONS_UNINTERPRETED_OPTION_ENDSUBMSG 5 6956 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceOptions_f_deprecat ed(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceOptions_is(m )); return upb_msgdef_itof(m, 33); }
6494 6957 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceOptions_f_uninterp reted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceOp tions_is(m)); return upb_msgdef_itof(m, 999); }
6495 /* google.protobuf.SourceCodeInfo */ 6958 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f _leading_comments(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_Sour ceCodeInfo_Location_is(m)); return upb_msgdef_itof(m, 3); }
6496 #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_STARTSUBMSG 2 6959 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f _leading_detached_comments(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_prot obuf_SourceCodeInfo_Location_is(m)); return upb_msgdef_itof(m, 6); }
6497 #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_STARTSEQ 3 6960 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f _path(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_L ocation_is(m)); return upb_msgdef_itof(m, 1); }
6498 #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_ENDSEQ 4 6961 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f _span(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_L ocation_is(m)); return upb_msgdef_itof(m, 2); }
6499 #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_ENDSUBMSG 5 6962 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f _trailing_comments(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_Sou rceCodeInfo_Location_is(m)); return upb_msgdef_itof(m, 4); }
6500 6963 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_f_location (const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_is(m)) ; return upb_msgdef_itof(m, 1); }
6501 /* google.protobuf.SourceCodeInfo.Location */ 6964 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_NameP art_f_is_extension(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_Uni nterpretedOption_NamePart_is(m)); return upb_msgdef_itof(m, 2); }
6502 #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_PATH_STARTSEQ 2 6965 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_NameP art_f_name_part(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_Uninte rpretedOption_NamePart_is(m)); return upb_msgdef_itof(m, 1); }
6503 #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_PATH_ENDSEQ 3 6966 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_agg regate_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_Uninterpr etedOption_is(m)); return upb_msgdef_itof(m, 8); }
6504 #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_PATH_INT32 4 6967 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_dou ble_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_Uninterprete dOption_is(m)); return upb_msgdef_itof(m, 6); }
6505 #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_SPAN_STARTSEQ 5 6968 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_ide ntifier_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_Uninterp retedOption_is(m)); return upb_msgdef_itof(m, 3); }
6506 #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_SPAN_ENDSEQ 6 6969 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_nam e(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_ is(m)); return upb_msgdef_itof(m, 2); }
6507 #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_SPAN_INT32 7 6970 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_neg ative_int_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_Uninte rpretedOption_is(m)); return upb_msgdef_itof(m, 5); }
6508 #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_LEADING_COMMENTS_STRING 8 6971 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_pos itive_int_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_Uninte rpretedOption_is(m)); return upb_msgdef_itof(m, 4); }
6509 #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_LEADING_COMMENTS_STARTSTR 9 6972 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_str ing_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_Uninterprete dOption_is(m)); return upb_msgdef_itof(m, 7); }
6510 #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_LEADING_COMMENTS_ENDSTR 10
6511 #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_TRAILING_COMMENTS_STRING 11
6512 #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_TRAILING_COMMENTS_STARTSTR 1 2
6513 #define SEL_GOOGLE_PROTOBUF_SOURCECODEINFO_LOCATION_TRAILING_COMMENTS_ENDSTR 13
6514
6515 /* google.protobuf.UninterpretedOption */
6516 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NAME_STARTSUBMSG 2
6517 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NAME_STARTSEQ 3
6518 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NAME_ENDSEQ 4
6519 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NAME_ENDSUBMSG 5
6520 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_IDENTIFIER_VALUE_STRING 6
6521 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_IDENTIFIER_VALUE_STARTSTR 7
6522 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_IDENTIFIER_VALUE_ENDSTR 8
6523 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_POSITIVE_INT_VALUE_UINT64 9
6524 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NEGATIVE_INT_VALUE_INT64 10
6525 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_DOUBLE_VALUE_DOUBLE 11
6526 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_STRING_VALUE_STRING 12
6527 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_STRING_VALUE_STARTSTR 13
6528 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_STRING_VALUE_ENDSTR 14
6529 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_AGGREGATE_VALUE_STRING 15
6530 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_AGGREGATE_VALUE_STARTSTR 16
6531 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_AGGREGATE_VALUE_ENDSTR 17
6532
6533 /* google.protobuf.UninterpretedOption.NamePart */
6534 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NAMEPART_NAME_PART_STRING 2
6535 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NAMEPART_NAME_PART_STARTSTR 3
6536 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NAMEPART_NAME_PART_ENDSTR 4
6537 #define SEL_GOOGLE_PROTOBUF_UNINTERPRETEDOPTION_NAMEPART_IS_EXTENSION_BOOL 5
6538
6539 const upb_symtab *upbdefs_google_protobuf_descriptor(const void *owner);
6540
6541 /* MessageDefs */
6542 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_DescriptorProto(const upb_s ymtab *s) {
6543 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.DescriptorProto ");
6544 assert(m);
6545 return m;
6546 }
6547 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ExtensionRa nge(const upb_symtab *s) {
6548 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.DescriptorProto .ExtensionRange");
6549 assert(m);
6550 return m;
6551 }
6552 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_EnumDescriptorProto(const u pb_symtab *s) {
6553 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.EnumDescriptorP roto");
6554 assert(m);
6555 return m;
6556 }
6557 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_EnumOptions(const upb_symta b *s) {
6558 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.EnumOptions");
6559 assert(m);
6560 return m;
6561 }
6562 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_EnumValueDescriptorProto(co nst upb_symtab *s) {
6563 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.EnumValueDescri ptorProto");
6564 assert(m);
6565 return m;
6566 }
6567 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_EnumValueOptions(const upb_ symtab *s) {
6568 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.EnumValueOption s");
6569 assert(m);
6570 return m;
6571 }
6572 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_FieldDescriptorProto(const upb_symtab *s) {
6573 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.FieldDescriptor Proto");
6574 assert(m);
6575 return m;
6576 }
6577 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_FieldOptions(const upb_symt ab *s) {
6578 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.FieldOptions");
6579 assert(m);
6580 return m;
6581 }
6582 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_FileDescriptorProto(const u pb_symtab *s) {
6583 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.FileDescriptorP roto");
6584 assert(m);
6585 return m;
6586 }
6587 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_FileDescriptorSet(const upb _symtab *s) {
6588 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.FileDescriptorS et");
6589 assert(m);
6590 return m;
6591 }
6592 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_FileOptions(const upb_symta b *s) {
6593 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.FileOptions");
6594 assert(m);
6595 return m;
6596 }
6597 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_MessageOptions(const upb_sy mtab *s) {
6598 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.MessageOptions" );
6599 assert(m);
6600 return m;
6601 }
6602 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_MethodDescriptorProto(const upb_symtab *s) {
6603 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.MethodDescripto rProto");
6604 assert(m);
6605 return m;
6606 }
6607 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_MethodOptions(const upb_sym tab *s) {
6608 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.MethodOptions") ;
6609 assert(m);
6610 return m;
6611 }
6612 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_ServiceDescriptorProto(cons t upb_symtab *s) {
6613 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.ServiceDescript orProto");
6614 assert(m);
6615 return m;
6616 }
6617 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_ServiceOptions(const upb_sy mtab *s) {
6618 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.ServiceOptions" );
6619 assert(m);
6620 return m;
6621 }
6622 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_SourceCodeInfo(const upb_sy mtab *s) {
6623 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.SourceCodeInfo" );
6624 assert(m);
6625 return m;
6626 }
6627 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_SourceCodeInfo_Location(con st upb_symtab *s) {
6628 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.SourceCodeInfo. Location");
6629 assert(m);
6630 return m;
6631 }
6632 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_UninterpretedOption(const u pb_symtab *s) {
6633 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.UninterpretedOp tion");
6634 assert(m);
6635 return m;
6636 }
6637 UPB_INLINE const upb_msgdef *upbdefs_google_protobuf_UninterpretedOption_NamePar t(const upb_symtab *s) {
6638 const upb_msgdef *m = upb_symtab_lookupmsg(s, "google.protobuf.UninterpretedOp tion.NamePart");
6639 assert(m);
6640 return m;
6641 }
6642
6643
6644 /* EnumDefs */
6645 UPB_INLINE const upb_enumdef *upbdefs_google_protobuf_FieldDescriptorProto_Label (const upb_symtab *s) {
6646 const upb_enumdef *e = upb_symtab_lookupenum(s, "google.protobuf.FieldDescript orProto.Label");
6647 assert(e);
6648 return e;
6649 }
6650 UPB_INLINE const upb_enumdef *upbdefs_google_protobuf_FieldDescriptorProto_Type( const upb_symtab *s) {
6651 const upb_enumdef *e = upb_symtab_lookupenum(s, "google.protobuf.FieldDescript orProto.Type");
6652 assert(e);
6653 return e;
6654 }
6655 UPB_INLINE const upb_enumdef *upbdefs_google_protobuf_FieldOptions_CType(const u pb_symtab *s) {
6656 const upb_enumdef *e = upb_symtab_lookupenum(s, "google.protobuf.FieldOptions. CType");
6657 assert(e);
6658 return e;
6659 }
6660 UPB_INLINE const upb_enumdef *upbdefs_google_protobuf_FileOptions_OptimizeMode(c onst upb_symtab *s) {
6661 const upb_enumdef *e = upb_symtab_lookupenum(s, "google.protobuf.FileOptions.O ptimizeMode");
6662 assert(e);
6663 return e;
6664 }
6665
6666 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_Extension Range_end(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_ DescriptorProto_ExtensionRange(s), 2); }
6667 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_Extension Range_start(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobu f_DescriptorProto_ExtensionRange(s), 1); }
6668 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_enum_type (const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Descripto rProto(s), 4); }
6669 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_extension (const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Descripto rProto(s), 6); }
6670 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_extension _range(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Des criptorProto(s), 5); }
6671 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_field(con st upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_DescriptorPro to(s), 2); }
6672 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_name(cons t upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_DescriptorProt o(s), 1); }
6673 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_nested_ty pe(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Descrip torProto(s), 3); }
6674 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_options(c onst upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_DescriptorP roto(s), 7); }
6675 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumDescriptorProto_name( const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_EnumDescri ptorProto(s), 1); }
6676 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumDescriptorProto_optio ns(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_EnumDes criptorProto(s), 3); }
6677 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumDescriptorProto_value (const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_EnumDescr iptorProto(s), 2); }
6678 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumOptions_allow_alias(c onst upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_EnumOptions (s), 2); }
6679 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumOptions_uninterpreted _option(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_En umOptions(s), 999); }
6680 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueDescriptorProto_ name(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_EnumV alueDescriptorProto(s), 1); }
6681 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueDescriptorProto_ number(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Enu mValueDescriptorProto(s), 2); }
6682 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueDescriptorProto_ options(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_En umValueDescriptorProto(s), 3); }
6683 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueOptions_uninterp reted_option(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protob uf_EnumValueOptions(s), 999); }
6684 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_defa ult_value(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_ FieldDescriptorProto(s), 7); }
6685 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_exte ndee(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Field DescriptorProto(s), 2); }
6686 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_labe l(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldDes criptorProto(s), 4); }
6687 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_name (const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldDesc riptorProto(s), 1); }
6688 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_numb er(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldDe scriptorProto(s), 3); }
6689 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_opti ons(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldD escriptorProto(s), 8); }
6690 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_type (const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldDesc riptorProto(s), 5); }
6691 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_type _name(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Fiel dDescriptorProto(s), 6); }
6692 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_ctype(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldOptions(s), 1); }
6693 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_deprecated(c onst upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldOption s(s), 3); }
6694 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_experimental _map_key(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_F ieldOptions(s), 9); }
6695 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_lazy(const u pb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldOptions(s), 5); }
6696 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_packed(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldOptions(s) , 2); }
6697 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_uninterprete d_option(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_F ieldOptions(s), 999); }
6698 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_weak(const u pb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FieldOptions(s), 10); }
6699 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_depen dency(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_File DescriptorProto(s), 3); }
6700 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_enum_ type(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileD escriptorProto(s), 5); }
6701 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_exten sion(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileD escriptorProto(s), 7); }
6702 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_messa ge_type(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Fi leDescriptorProto(s), 4); }
6703 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_name( const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileDescri ptorProto(s), 1); }
6704 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_optio ns(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileDes criptorProto(s), 8); }
6705 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_packa ge(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileDes criptorProto(s), 2); }
6706 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_publi c_dependency(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protob uf_FileDescriptorProto(s), 10); }
6707 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_servi ce(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileDes criptorProto(s), 6); }
6708 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_sourc e_code_info(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobu f_FileDescriptorProto(s), 9); }
6709 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_weak_ dependency(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf _FileDescriptorProto(s), 11); }
6710 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorSet_file(co nst upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileDescript orSet(s), 1); }
6711 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_cc_generic_se rvices(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Fil eOptions(s), 16); }
6712 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_go_package(co nst upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOptions( s), 11); }
6713 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_java_generate _equals_and_hash(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_pr otobuf_FileOptions(s), 20); }
6714 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_java_generic_ services(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_F ileOptions(s), 17); }
6715 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_java_multiple _files(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Fil eOptions(s), 10); }
6716 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_java_outer_cl assname(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Fi leOptions(s), 8); }
6717 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_java_package( const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOption s(s), 1); }
6718 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_optimize_for( const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_FileOption s(s), 9); }
6719 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_py_generic_se rvices(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Fil eOptions(s), 18); }
6720 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_uninterpreted _option(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Fi leOptions(s), 999); }
6721 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_message_se t_wire_format(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_proto buf_MessageOptions(s), 1); }
6722 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_no_standar d_descriptor_accessor(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_goog le_protobuf_MessageOptions(s), 2); }
6723 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_uninterpre ted_option(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf _MessageOptions(s), 999); }
6724 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_inp ut_type(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Me thodDescriptorProto(s), 2); }
6725 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_nam e(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_MethodDe scriptorProto(s), 1); }
6726 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_opt ions(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Metho dDescriptorProto(s), 4); }
6727 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_out put_type(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_M ethodDescriptorProto(s), 3); }
6728 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodOptions_uninterpret ed_option(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_ MethodOptions(s), 999); }
6729 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceDescriptorProto_me thod(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Servi ceDescriptorProto(s), 2); }
6730 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceDescriptorProto_na me(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Service DescriptorProto(s), 1); }
6731 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceDescriptorProto_op tions(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Serv iceDescriptorProto(s), 3); }
6732 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceOptions_uninterpre ted_option(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf _ServiceOptions(s), 999); }
6733 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_l eading_comments(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_pro tobuf_SourceCodeInfo_Location(s), 3); }
6734 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_p ath(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Source CodeInfo_Location(s), 1); }
6735 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_s pan(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Source CodeInfo_Location(s), 2); }
6736 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_t railing_comments(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_pr otobuf_SourceCodeInfo_Location(s), 4); }
6737 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_location(c onst upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_SourceCodeI nfo(s), 1); }
6738 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_NameP art_is_extension(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_pr otobuf_UninterpretedOption_NamePart(s), 2); }
6739 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_NameP art_name_part(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_proto buf_UninterpretedOption_NamePart(s), 1); }
6740 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_aggre gate_value(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf _UninterpretedOption(s), 8); }
6741 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_doubl e_value(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Un interpretedOption(s), 6); }
6742 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_ident ifier_value(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobu f_UninterpretedOption(s), 3); }
6743 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_name( const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Uninterpre tedOption(s), 2); }
6744 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_negat ive_int_value(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_proto buf_UninterpretedOption(s), 5); }
6745 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_posit ive_int_value(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_proto buf_UninterpretedOption(s), 4); }
6746 UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_strin g_value(const upb_symtab *s) { return upb_msgdef_itof(upbdefs_google_protobuf_Un interpretedOption(s), 7); }
6747 6973
6748 UPB_END_EXTERN_C 6974 UPB_END_EXTERN_C
6749 6975
6750 #ifdef __cplusplus 6976 #ifdef __cplusplus
6751 6977
6752 namespace upbdefs { 6978 namespace upbdefs {
6753 namespace google { 6979 namespace google {
6754 namespace protobuf { 6980 namespace protobuf {
6755 namespace descriptor { 6981
6756 inline upb::reffed_ptr<const upb::SymbolTable> SymbolTable() { 6982 class DescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
6757 const upb::SymbolTable* s = upbdefs_google_protobuf_descriptor(&s); 6983 public:
6758 return upb::reffed_ptr<const upb::SymbolTable>(s, &s); 6984 DescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
6759 } 6985 : reffed_ptr(m, ref_donor) {
6760 } /* namespace descriptor */ 6986 UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m));
6987 }
6988
6989 static DescriptorProto get() {
6990 const ::upb::MessageDef* m = upbdefs_google_protobuf_DescriptorProto_get(&m) ;
6991 return DescriptorProto(m, &m);
6992 }
6993
6994 class ExtensionRange : public ::upb::reffed_ptr<const ::upb::MessageDef> {
6995 public:
6996 ExtensionRange(const ::upb::MessageDef* m, const void *ref_donor = NULL)
6997 : reffed_ptr(m, ref_donor) {
6998 UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ExtensionRange_is(m));
6999 }
7000
7001 static ExtensionRange get() {
7002 const ::upb::MessageDef* m = upbdefs_google_protobuf_DescriptorProto_Exten sionRange_get(&m);
7003 return ExtensionRange(m, &m);
7004 }
7005 };
7006
7007 class ReservedRange : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7008 public:
7009 ReservedRange(const ::upb::MessageDef* m, const void *ref_donor = NULL)
7010 : reffed_ptr(m, ref_donor) {
7011 UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ReservedRange_is(m));
7012 }
7013
7014 static ReservedRange get() {
7015 const ::upb::MessageDef* m = upbdefs_google_protobuf_DescriptorProto_Reser vedRange_get(&m);
7016 return ReservedRange(m, &m);
7017 }
7018 };
7019 };
7020
7021 class EnumDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7022 public:
7023 EnumDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
7024 : reffed_ptr(m, ref_donor) {
7025 UPB_ASSERT(upbdefs_google_protobuf_EnumDescriptorProto_is(m));
7026 }
7027
7028 static EnumDescriptorProto get() {
7029 const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumDescriptorProto_get (&m);
7030 return EnumDescriptorProto(m, &m);
7031 }
7032 };
7033
7034 class EnumOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7035 public:
7036 EnumOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
7037 : reffed_ptr(m, ref_donor) {
7038 UPB_ASSERT(upbdefs_google_protobuf_EnumOptions_is(m));
7039 }
7040
7041 static EnumOptions get() {
7042 const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumOptions_get(&m);
7043 return EnumOptions(m, &m);
7044 }
7045 };
7046
7047 class EnumValueDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDe f> {
7048 public:
7049 EnumValueDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = N ULL)
7050 : reffed_ptr(m, ref_donor) {
7051 UPB_ASSERT(upbdefs_google_protobuf_EnumValueDescriptorProto_is(m));
7052 }
7053
7054 static EnumValueDescriptorProto get() {
7055 const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumValueDescriptorProt o_get(&m);
7056 return EnumValueDescriptorProto(m, &m);
7057 }
7058 };
7059
7060 class EnumValueOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7061 public:
7062 EnumValueOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
7063 : reffed_ptr(m, ref_donor) {
7064 UPB_ASSERT(upbdefs_google_protobuf_EnumValueOptions_is(m));
7065 }
7066
7067 static EnumValueOptions get() {
7068 const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumValueOptions_get(&m );
7069 return EnumValueOptions(m, &m);
7070 }
7071 };
7072
7073 class FieldDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7074 public:
7075 FieldDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
7076 : reffed_ptr(m, ref_donor) {
7077 UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m));
7078 }
7079
7080 static FieldDescriptorProto get() {
7081 const ::upb::MessageDef* m = upbdefs_google_protobuf_FieldDescriptorProto_ge t(&m);
7082 return FieldDescriptorProto(m, &m);
7083 }
7084
7085 class Label : public ::upb::reffed_ptr<const ::upb::EnumDef> {
7086 public:
7087 Label(const ::upb::EnumDef* e, const void *ref_donor = NULL)
7088 : reffed_ptr(e, ref_donor) {
7089 UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_Label_is(e));
7090 }
7091 static Label get() {
7092 const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldDescriptorProto_Lab el_get(&e);
7093 return Label(e, &e);
7094 }
7095 };
7096
7097 class Type : public ::upb::reffed_ptr<const ::upb::EnumDef> {
7098 public:
7099 Type(const ::upb::EnumDef* e, const void *ref_donor = NULL)
7100 : reffed_ptr(e, ref_donor) {
7101 UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_Type_is(e));
7102 }
7103 static Type get() {
7104 const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldDescriptorProto_Typ e_get(&e);
7105 return Type(e, &e);
7106 }
7107 };
7108 };
7109
7110 class FieldOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7111 public:
7112 FieldOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
7113 : reffed_ptr(m, ref_donor) {
7114 UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m));
7115 }
7116
7117 static FieldOptions get() {
7118 const ::upb::MessageDef* m = upbdefs_google_protobuf_FieldOptions_get(&m);
7119 return FieldOptions(m, &m);
7120 }
7121
7122 class CType : public ::upb::reffed_ptr<const ::upb::EnumDef> {
7123 public:
7124 CType(const ::upb::EnumDef* e, const void *ref_donor = NULL)
7125 : reffed_ptr(e, ref_donor) {
7126 UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_CType_is(e));
7127 }
7128 static CType get() {
7129 const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldOptions_CType_get(& e);
7130 return CType(e, &e);
7131 }
7132 };
7133
7134 class JSType : public ::upb::reffed_ptr<const ::upb::EnumDef> {
7135 public:
7136 JSType(const ::upb::EnumDef* e, const void *ref_donor = NULL)
7137 : reffed_ptr(e, ref_donor) {
7138 UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_JSType_is(e));
7139 }
7140 static JSType get() {
7141 const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldOptions_JSType_get( &e);
7142 return JSType(e, &e);
7143 }
7144 };
7145 };
7146
7147 class FileDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7148 public:
7149 FileDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
7150 : reffed_ptr(m, ref_donor) {
7151 UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m));
7152 }
7153
7154 static FileDescriptorProto get() {
7155 const ::upb::MessageDef* m = upbdefs_google_protobuf_FileDescriptorProto_get (&m);
7156 return FileDescriptorProto(m, &m);
7157 }
7158 };
7159
7160 class FileDescriptorSet : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7161 public:
7162 FileDescriptorSet(const ::upb::MessageDef* m, const void *ref_donor = NULL)
7163 : reffed_ptr(m, ref_donor) {
7164 UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorSet_is(m));
7165 }
7166
7167 static FileDescriptorSet get() {
7168 const ::upb::MessageDef* m = upbdefs_google_protobuf_FileDescriptorSet_get(& m);
7169 return FileDescriptorSet(m, &m);
7170 }
7171 };
7172
7173 class FileOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7174 public:
7175 FileOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
7176 : reffed_ptr(m, ref_donor) {
7177 UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m));
7178 }
7179
7180 static FileOptions get() {
7181 const ::upb::MessageDef* m = upbdefs_google_protobuf_FileOptions_get(&m);
7182 return FileOptions(m, &m);
7183 }
7184
7185 class OptimizeMode : public ::upb::reffed_ptr<const ::upb::EnumDef> {
7186 public:
7187 OptimizeMode(const ::upb::EnumDef* e, const void *ref_donor = NULL)
7188 : reffed_ptr(e, ref_donor) {
7189 UPB_ASSERT(upbdefs_google_protobuf_FileOptions_OptimizeMode_is(e));
7190 }
7191 static OptimizeMode get() {
7192 const ::upb::EnumDef* e = upbdefs_google_protobuf_FileOptions_OptimizeMode _get(&e);
7193 return OptimizeMode(e, &e);
7194 }
7195 };
7196 };
7197
7198 class MessageOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7199 public:
7200 MessageOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
7201 : reffed_ptr(m, ref_donor) {
7202 UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m));
7203 }
7204
7205 static MessageOptions get() {
7206 const ::upb::MessageDef* m = upbdefs_google_protobuf_MessageOptions_get(&m);
7207 return MessageOptions(m, &m);
7208 }
7209 };
7210
7211 class MethodDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7212 public:
7213 MethodDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL )
7214 : reffed_ptr(m, ref_donor) {
7215 UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m));
7216 }
7217
7218 static MethodDescriptorProto get() {
7219 const ::upb::MessageDef* m = upbdefs_google_protobuf_MethodDescriptorProto_g et(&m);
7220 return MethodDescriptorProto(m, &m);
7221 }
7222 };
7223
7224 class MethodOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7225 public:
7226 MethodOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
7227 : reffed_ptr(m, ref_donor) {
7228 UPB_ASSERT(upbdefs_google_protobuf_MethodOptions_is(m));
7229 }
7230
7231 static MethodOptions get() {
7232 const ::upb::MessageDef* m = upbdefs_google_protobuf_MethodOptions_get(&m);
7233 return MethodOptions(m, &m);
7234 }
7235 };
7236
7237 class OneofDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7238 public:
7239 OneofDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
7240 : reffed_ptr(m, ref_donor) {
7241 UPB_ASSERT(upbdefs_google_protobuf_OneofDescriptorProto_is(m));
7242 }
7243
7244 static OneofDescriptorProto get() {
7245 const ::upb::MessageDef* m = upbdefs_google_protobuf_OneofDescriptorProto_ge t(&m);
7246 return OneofDescriptorProto(m, &m);
7247 }
7248 };
7249
7250 class ServiceDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7251 public:
7252 ServiceDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NUL L)
7253 : reffed_ptr(m, ref_donor) {
7254 UPB_ASSERT(upbdefs_google_protobuf_ServiceDescriptorProto_is(m));
7255 }
7256
7257 static ServiceDescriptorProto get() {
7258 const ::upb::MessageDef* m = upbdefs_google_protobuf_ServiceDescriptorProto_ get(&m);
7259 return ServiceDescriptorProto(m, &m);
7260 }
7261 };
7262
7263 class ServiceOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7264 public:
7265 ServiceOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
7266 : reffed_ptr(m, ref_donor) {
7267 UPB_ASSERT(upbdefs_google_protobuf_ServiceOptions_is(m));
7268 }
7269
7270 static ServiceOptions get() {
7271 const ::upb::MessageDef* m = upbdefs_google_protobuf_ServiceOptions_get(&m);
7272 return ServiceOptions(m, &m);
7273 }
7274 };
7275
7276 class SourceCodeInfo : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7277 public:
7278 SourceCodeInfo(const ::upb::MessageDef* m, const void *ref_donor = NULL)
7279 : reffed_ptr(m, ref_donor) {
7280 UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_is(m));
7281 }
7282
7283 static SourceCodeInfo get() {
7284 const ::upb::MessageDef* m = upbdefs_google_protobuf_SourceCodeInfo_get(&m);
7285 return SourceCodeInfo(m, &m);
7286 }
7287
7288 class Location : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7289 public:
7290 Location(const ::upb::MessageDef* m, const void *ref_donor = NULL)
7291 : reffed_ptr(m, ref_donor) {
7292 UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m));
7293 }
7294
7295 static Location get() {
7296 const ::upb::MessageDef* m = upbdefs_google_protobuf_SourceCodeInfo_Locati on_get(&m);
7297 return Location(m, &m);
7298 }
7299 };
7300 };
7301
7302 class UninterpretedOption : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7303 public:
7304 UninterpretedOption(const ::upb::MessageDef* m, const void *ref_donor = NULL)
7305 : reffed_ptr(m, ref_donor) {
7306 UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m));
7307 }
7308
7309 static UninterpretedOption get() {
7310 const ::upb::MessageDef* m = upbdefs_google_protobuf_UninterpretedOption_get (&m);
7311 return UninterpretedOption(m, &m);
7312 }
7313
7314 class NamePart : public ::upb::reffed_ptr<const ::upb::MessageDef> {
7315 public:
7316 NamePart(const ::upb::MessageDef* m, const void *ref_donor = NULL)
7317 : reffed_ptr(m, ref_donor) {
7318 UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_NamePart_is(m));
7319 }
7320
7321 static NamePart get() {
7322 const ::upb::MessageDef* m = upbdefs_google_protobuf_UninterpretedOption_N amePart_get(&m);
7323 return NamePart(m, &m);
7324 }
7325 };
7326 };
7327
6761 } /* namespace protobuf */ 7328 } /* namespace protobuf */
6762 } /* namespace google */ 7329 } /* namespace google */
6763
6764 #define RETURN_REFFED(type, func) \
6765 const type* obj = func(upbdefs::google::protobuf::descriptor::SymbolTable(). get()); \
6766 return upb::reffed_ptr<const type>(obj);
6767
6768 namespace google {
6769 namespace protobuf {
6770 namespace DescriptorProto {
6771 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_DescriptorProto) }
6772 inline upb::reffed_ptr<const upb::FieldDef> enum_type() { RETURN_REFFED(upb::Fie ldDef, upbdefs_google_protobuf_DescriptorProto_enum_type) }
6773 inline upb::reffed_ptr<const upb::FieldDef> extension() { RETURN_REFFED(upb::Fie ldDef, upbdefs_google_protobuf_DescriptorProto_extension) }
6774 inline upb::reffed_ptr<const upb::FieldDef> extension_range() { RETURN_REFFED(up b::FieldDef, upbdefs_google_protobuf_DescriptorProto_extension_range) }
6775 inline upb::reffed_ptr<const upb::FieldDef> field() { RETURN_REFFED(upb::FieldDe f, upbdefs_google_protobuf_DescriptorProto_field) }
6776 inline upb::reffed_ptr<const upb::FieldDef> name() { RETURN_REFFED(upb::FieldDef , upbdefs_google_protobuf_DescriptorProto_name) }
6777 inline upb::reffed_ptr<const upb::FieldDef> nested_type() { RETURN_REFFED(upb::F ieldDef, upbdefs_google_protobuf_DescriptorProto_nested_type) }
6778 inline upb::reffed_ptr<const upb::FieldDef> options() { RETURN_REFFED(upb::Field Def, upbdefs_google_protobuf_DescriptorProto_options) }
6779 } /* namespace DescriptorProto */
6780 } /* namespace protobuf */
6781 } /* namespace google */
6782
6783 namespace google {
6784 namespace protobuf {
6785 namespace DescriptorProto {
6786 namespace ExtensionRange {
6787 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_DescriptorProto_ExtensionRange) }
6788 inline upb::reffed_ptr<const upb::FieldDef> end() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_DescriptorProto_ExtensionRange_end) }
6789 inline upb::reffed_ptr<const upb::FieldDef> start() { RETURN_REFFED(upb::FieldDe f, upbdefs_google_protobuf_DescriptorProto_ExtensionRange_start) }
6790 } /* namespace ExtensionRange */
6791 } /* namespace DescriptorProto */
6792 } /* namespace protobuf */
6793 } /* namespace google */
6794
6795 namespace google {
6796 namespace protobuf {
6797 namespace EnumDescriptorProto {
6798 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_EnumDescriptorProto) }
6799 inline upb::reffed_ptr<const upb::FieldDef> name() { RETURN_REFFED(upb::FieldDef , upbdefs_google_protobuf_EnumDescriptorProto_name) }
6800 inline upb::reffed_ptr<const upb::FieldDef> options() { RETURN_REFFED(upb::Field Def, upbdefs_google_protobuf_EnumDescriptorProto_options) }
6801 inline upb::reffed_ptr<const upb::FieldDef> value() { RETURN_REFFED(upb::FieldDe f, upbdefs_google_protobuf_EnumDescriptorProto_value) }
6802 } /* namespace EnumDescriptorProto */
6803 } /* namespace protobuf */
6804 } /* namespace google */
6805
6806 namespace google {
6807 namespace protobuf {
6808 namespace EnumOptions {
6809 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_EnumOptions) }
6810 inline upb::reffed_ptr<const upb::FieldDef> allow_alias() { RETURN_REFFED(upb::F ieldDef, upbdefs_google_protobuf_EnumOptions_allow_alias) }
6811 inline upb::reffed_ptr<const upb::FieldDef> uninterpreted_option() { RETURN_REFF ED(upb::FieldDef, upbdefs_google_protobuf_EnumOptions_uninterpreted_option) }
6812 } /* namespace EnumOptions */
6813 } /* namespace protobuf */
6814 } /* namespace google */
6815
6816 namespace google {
6817 namespace protobuf {
6818 namespace EnumValueDescriptorProto {
6819 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_EnumValueDescriptorProto) }
6820 inline upb::reffed_ptr<const upb::FieldDef> name() { RETURN_REFFED(upb::FieldDef , upbdefs_google_protobuf_EnumValueDescriptorProto_name) }
6821 inline upb::reffed_ptr<const upb::FieldDef> number() { RETURN_REFFED(upb::FieldD ef, upbdefs_google_protobuf_EnumValueDescriptorProto_number) }
6822 inline upb::reffed_ptr<const upb::FieldDef> options() { RETURN_REFFED(upb::Field Def, upbdefs_google_protobuf_EnumValueDescriptorProto_options) }
6823 } /* namespace EnumValueDescriptorProto */
6824 } /* namespace protobuf */
6825 } /* namespace google */
6826
6827 namespace google {
6828 namespace protobuf {
6829 namespace EnumValueOptions {
6830 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_EnumValueOptions) }
6831 inline upb::reffed_ptr<const upb::FieldDef> uninterpreted_option() { RETURN_REFF ED(upb::FieldDef, upbdefs_google_protobuf_EnumValueOptions_uninterpreted_option) }
6832 } /* namespace EnumValueOptions */
6833 } /* namespace protobuf */
6834 } /* namespace google */
6835
6836 namespace google {
6837 namespace protobuf {
6838 namespace FieldDescriptorProto {
6839 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_FieldDescriptorProto) }
6840 inline upb::reffed_ptr<const upb::FieldDef> default_value() { RETURN_REFFED(upb: :FieldDef, upbdefs_google_protobuf_FieldDescriptorProto_default_value) }
6841 inline upb::reffed_ptr<const upb::FieldDef> extendee() { RETURN_REFFED(upb::Fiel dDef, upbdefs_google_protobuf_FieldDescriptorProto_extendee) }
6842 inline upb::reffed_ptr<const upb::FieldDef> label() { RETURN_REFFED(upb::FieldDe f, upbdefs_google_protobuf_FieldDescriptorProto_label) }
6843 inline upb::reffed_ptr<const upb::FieldDef> name() { RETURN_REFFED(upb::FieldDef , upbdefs_google_protobuf_FieldDescriptorProto_name) }
6844 inline upb::reffed_ptr<const upb::FieldDef> number() { RETURN_REFFED(upb::FieldD ef, upbdefs_google_protobuf_FieldDescriptorProto_number) }
6845 inline upb::reffed_ptr<const upb::FieldDef> options() { RETURN_REFFED(upb::Field Def, upbdefs_google_protobuf_FieldDescriptorProto_options) }
6846 inline upb::reffed_ptr<const upb::FieldDef> type() { RETURN_REFFED(upb::FieldDef , upbdefs_google_protobuf_FieldDescriptorProto_type) }
6847 inline upb::reffed_ptr<const upb::FieldDef> type_name() { RETURN_REFFED(upb::Fie ldDef, upbdefs_google_protobuf_FieldDescriptorProto_type_name) }
6848 inline upb::reffed_ptr<const upb::EnumDef> Label() { RETURN_REFFED(upb::EnumDef, upbdefs_google_protobuf_FieldDescriptorProto_Label) }
6849 inline upb::reffed_ptr<const upb::EnumDef> Type() { RETURN_REFFED(upb::EnumDef, upbdefs_google_protobuf_FieldDescriptorProto_Type) }
6850 } /* namespace FieldDescriptorProto */
6851 } /* namespace protobuf */
6852 } /* namespace google */
6853
6854 namespace google {
6855 namespace protobuf {
6856 namespace FieldOptions {
6857 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_FieldOptions) }
6858 inline upb::reffed_ptr<const upb::FieldDef> ctype() { RETURN_REFFED(upb::FieldDe f, upbdefs_google_protobuf_FieldOptions_ctype) }
6859 inline upb::reffed_ptr<const upb::FieldDef> deprecated() { RETURN_REFFED(upb::Fi eldDef, upbdefs_google_protobuf_FieldOptions_deprecated) }
6860 inline upb::reffed_ptr<const upb::FieldDef> experimental_map_key() { RETURN_REFF ED(upb::FieldDef, upbdefs_google_protobuf_FieldOptions_experimental_map_key) }
6861 inline upb::reffed_ptr<const upb::FieldDef> lazy() { RETURN_REFFED(upb::FieldDef , upbdefs_google_protobuf_FieldOptions_lazy) }
6862 inline upb::reffed_ptr<const upb::FieldDef> packed() { RETURN_REFFED(upb::FieldD ef, upbdefs_google_protobuf_FieldOptions_packed) }
6863 inline upb::reffed_ptr<const upb::FieldDef> uninterpreted_option() { RETURN_REFF ED(upb::FieldDef, upbdefs_google_protobuf_FieldOptions_uninterpreted_option) }
6864 inline upb::reffed_ptr<const upb::FieldDef> weak() { RETURN_REFFED(upb::FieldDef , upbdefs_google_protobuf_FieldOptions_weak) }
6865 inline upb::reffed_ptr<const upb::EnumDef> CType() { RETURN_REFFED(upb::EnumDef, upbdefs_google_protobuf_FieldOptions_CType) }
6866 } /* namespace FieldOptions */
6867 } /* namespace protobuf */
6868 } /* namespace google */
6869
6870 namespace google {
6871 namespace protobuf {
6872 namespace FileDescriptorProto {
6873 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_FileDescriptorProto) }
6874 inline upb::reffed_ptr<const upb::FieldDef> dependency() { RETURN_REFFED(upb::Fi eldDef, upbdefs_google_protobuf_FileDescriptorProto_dependency) }
6875 inline upb::reffed_ptr<const upb::FieldDef> enum_type() { RETURN_REFFED(upb::Fie ldDef, upbdefs_google_protobuf_FileDescriptorProto_enum_type) }
6876 inline upb::reffed_ptr<const upb::FieldDef> extension() { RETURN_REFFED(upb::Fie ldDef, upbdefs_google_protobuf_FileDescriptorProto_extension) }
6877 inline upb::reffed_ptr<const upb::FieldDef> message_type() { RETURN_REFFED(upb:: FieldDef, upbdefs_google_protobuf_FileDescriptorProto_message_type) }
6878 inline upb::reffed_ptr<const upb::FieldDef> name() { RETURN_REFFED(upb::FieldDef , upbdefs_google_protobuf_FileDescriptorProto_name) }
6879 inline upb::reffed_ptr<const upb::FieldDef> options() { RETURN_REFFED(upb::Field Def, upbdefs_google_protobuf_FileDescriptorProto_options) }
6880 inline upb::reffed_ptr<const upb::FieldDef> package() { RETURN_REFFED(upb::Field Def, upbdefs_google_protobuf_FileDescriptorProto_package) }
6881 inline upb::reffed_ptr<const upb::FieldDef> public_dependency() { RETURN_REFFED( upb::FieldDef, upbdefs_google_protobuf_FileDescriptorProto_public_dependency) }
6882 inline upb::reffed_ptr<const upb::FieldDef> service() { RETURN_REFFED(upb::Field Def, upbdefs_google_protobuf_FileDescriptorProto_service) }
6883 inline upb::reffed_ptr<const upb::FieldDef> source_code_info() { RETURN_REFFED(u pb::FieldDef, upbdefs_google_protobuf_FileDescriptorProto_source_code_info) }
6884 inline upb::reffed_ptr<const upb::FieldDef> weak_dependency() { RETURN_REFFED(up b::FieldDef, upbdefs_google_protobuf_FileDescriptorProto_weak_dependency) }
6885 } /* namespace FileDescriptorProto */
6886 } /* namespace protobuf */
6887 } /* namespace google */
6888
6889 namespace google {
6890 namespace protobuf {
6891 namespace FileDescriptorSet {
6892 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_FileDescriptorSet) }
6893 inline upb::reffed_ptr<const upb::FieldDef> file() { RETURN_REFFED(upb::FieldDef , upbdefs_google_protobuf_FileDescriptorSet_file) }
6894 } /* namespace FileDescriptorSet */
6895 } /* namespace protobuf */
6896 } /* namespace google */
6897
6898 namespace google {
6899 namespace protobuf {
6900 namespace FileOptions {
6901 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_FileOptions) }
6902 inline upb::reffed_ptr<const upb::FieldDef> cc_generic_services() { RETURN_REFFE D(upb::FieldDef, upbdefs_google_protobuf_FileOptions_cc_generic_services) }
6903 inline upb::reffed_ptr<const upb::FieldDef> go_package() { RETURN_REFFED(upb::Fi eldDef, upbdefs_google_protobuf_FileOptions_go_package) }
6904 inline upb::reffed_ptr<const upb::FieldDef> java_generate_equals_and_hash() { RE TURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_java_generate_equ als_and_hash) }
6905 inline upb::reffed_ptr<const upb::FieldDef> java_generic_services() { RETURN_REF FED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_java_generic_services) }
6906 inline upb::reffed_ptr<const upb::FieldDef> java_multiple_files() { RETURN_REFFE D(upb::FieldDef, upbdefs_google_protobuf_FileOptions_java_multiple_files) }
6907 inline upb::reffed_ptr<const upb::FieldDef> java_outer_classname() { RETURN_REFF ED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_java_outer_classname) }
6908 inline upb::reffed_ptr<const upb::FieldDef> java_package() { RETURN_REFFED(upb:: FieldDef, upbdefs_google_protobuf_FileOptions_java_package) }
6909 inline upb::reffed_ptr<const upb::FieldDef> optimize_for() { RETURN_REFFED(upb:: FieldDef, upbdefs_google_protobuf_FileOptions_optimize_for) }
6910 inline upb::reffed_ptr<const upb::FieldDef> py_generic_services() { RETURN_REFFE D(upb::FieldDef, upbdefs_google_protobuf_FileOptions_py_generic_services) }
6911 inline upb::reffed_ptr<const upb::FieldDef> uninterpreted_option() { RETURN_REFF ED(upb::FieldDef, upbdefs_google_protobuf_FileOptions_uninterpreted_option) }
6912 inline upb::reffed_ptr<const upb::EnumDef> OptimizeMode() { RETURN_REFFED(upb::E numDef, upbdefs_google_protobuf_FileOptions_OptimizeMode) }
6913 } /* namespace FileOptions */
6914 } /* namespace protobuf */
6915 } /* namespace google */
6916
6917 namespace google {
6918 namespace protobuf {
6919 namespace MessageOptions {
6920 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_MessageOptions) }
6921 inline upb::reffed_ptr<const upb::FieldDef> message_set_wire_format() { RETURN_R EFFED(upb::FieldDef, upbdefs_google_protobuf_MessageOptions_message_set_wire_for mat) }
6922 inline upb::reffed_ptr<const upb::FieldDef> no_standard_descriptor_accessor() { RETURN_REFFED(upb::FieldDef, upbdefs_google_protobuf_MessageOptions_no_standard_ descriptor_accessor) }
6923 inline upb::reffed_ptr<const upb::FieldDef> uninterpreted_option() { RETURN_REFF ED(upb::FieldDef, upbdefs_google_protobuf_MessageOptions_uninterpreted_option) }
6924 } /* namespace MessageOptions */
6925 } /* namespace protobuf */
6926 } /* namespace google */
6927
6928 namespace google {
6929 namespace protobuf {
6930 namespace MethodDescriptorProto {
6931 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_MethodDescriptorProto) }
6932 inline upb::reffed_ptr<const upb::FieldDef> input_type() { RETURN_REFFED(upb::Fi eldDef, upbdefs_google_protobuf_MethodDescriptorProto_input_type) }
6933 inline upb::reffed_ptr<const upb::FieldDef> name() { RETURN_REFFED(upb::FieldDef , upbdefs_google_protobuf_MethodDescriptorProto_name) }
6934 inline upb::reffed_ptr<const upb::FieldDef> options() { RETURN_REFFED(upb::Field Def, upbdefs_google_protobuf_MethodDescriptorProto_options) }
6935 inline upb::reffed_ptr<const upb::FieldDef> output_type() { RETURN_REFFED(upb::F ieldDef, upbdefs_google_protobuf_MethodDescriptorProto_output_type) }
6936 } /* namespace MethodDescriptorProto */
6937 } /* namespace protobuf */
6938 } /* namespace google */
6939
6940 namespace google {
6941 namespace protobuf {
6942 namespace MethodOptions {
6943 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_MethodOptions) }
6944 inline upb::reffed_ptr<const upb::FieldDef> uninterpreted_option() { RETURN_REFF ED(upb::FieldDef, upbdefs_google_protobuf_MethodOptions_uninterpreted_option) }
6945 } /* namespace MethodOptions */
6946 } /* namespace protobuf */
6947 } /* namespace google */
6948
6949 namespace google {
6950 namespace protobuf {
6951 namespace ServiceDescriptorProto {
6952 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_ServiceDescriptorProto) }
6953 inline upb::reffed_ptr<const upb::FieldDef> method() { RETURN_REFFED(upb::FieldD ef, upbdefs_google_protobuf_ServiceDescriptorProto_method) }
6954 inline upb::reffed_ptr<const upb::FieldDef> name() { RETURN_REFFED(upb::FieldDef , upbdefs_google_protobuf_ServiceDescriptorProto_name) }
6955 inline upb::reffed_ptr<const upb::FieldDef> options() { RETURN_REFFED(upb::Field Def, upbdefs_google_protobuf_ServiceDescriptorProto_options) }
6956 } /* namespace ServiceDescriptorProto */
6957 } /* namespace protobuf */
6958 } /* namespace google */
6959
6960 namespace google {
6961 namespace protobuf {
6962 namespace ServiceOptions {
6963 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_ServiceOptions) }
6964 inline upb::reffed_ptr<const upb::FieldDef> uninterpreted_option() { RETURN_REFF ED(upb::FieldDef, upbdefs_google_protobuf_ServiceOptions_uninterpreted_option) }
6965 } /* namespace ServiceOptions */
6966 } /* namespace protobuf */
6967 } /* namespace google */
6968
6969 namespace google {
6970 namespace protobuf {
6971 namespace SourceCodeInfo {
6972 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_SourceCodeInfo) }
6973 inline upb::reffed_ptr<const upb::FieldDef> location() { RETURN_REFFED(upb::Fiel dDef, upbdefs_google_protobuf_SourceCodeInfo_location) }
6974 } /* namespace SourceCodeInfo */
6975 } /* namespace protobuf */
6976 } /* namespace google */
6977
6978 namespace google {
6979 namespace protobuf {
6980 namespace SourceCodeInfo {
6981 namespace Location {
6982 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_SourceCodeInfo_Location) }
6983 inline upb::reffed_ptr<const upb::FieldDef> leading_comments() { RETURN_REFFED(u pb::FieldDef, upbdefs_google_protobuf_SourceCodeInfo_Location_leading_comments) }
6984 inline upb::reffed_ptr<const upb::FieldDef> path() { RETURN_REFFED(upb::FieldDef , upbdefs_google_protobuf_SourceCodeInfo_Location_path) }
6985 inline upb::reffed_ptr<const upb::FieldDef> span() { RETURN_REFFED(upb::FieldDef , upbdefs_google_protobuf_SourceCodeInfo_Location_span) }
6986 inline upb::reffed_ptr<const upb::FieldDef> trailing_comments() { RETURN_REFFED( upb::FieldDef, upbdefs_google_protobuf_SourceCodeInfo_Location_trailing_comments ) }
6987 } /* namespace Location */
6988 } /* namespace SourceCodeInfo */
6989 } /* namespace protobuf */
6990 } /* namespace google */
6991
6992 namespace google {
6993 namespace protobuf {
6994 namespace UninterpretedOption {
6995 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_UninterpretedOption) }
6996 inline upb::reffed_ptr<const upb::FieldDef> aggregate_value() { RETURN_REFFED(up b::FieldDef, upbdefs_google_protobuf_UninterpretedOption_aggregate_value) }
6997 inline upb::reffed_ptr<const upb::FieldDef> double_value() { RETURN_REFFED(upb:: FieldDef, upbdefs_google_protobuf_UninterpretedOption_double_value) }
6998 inline upb::reffed_ptr<const upb::FieldDef> identifier_value() { RETURN_REFFED(u pb::FieldDef, upbdefs_google_protobuf_UninterpretedOption_identifier_value) }
6999 inline upb::reffed_ptr<const upb::FieldDef> name() { RETURN_REFFED(upb::FieldDef , upbdefs_google_protobuf_UninterpretedOption_name) }
7000 inline upb::reffed_ptr<const upb::FieldDef> negative_int_value() { RETURN_REFFED (upb::FieldDef, upbdefs_google_protobuf_UninterpretedOption_negative_int_value) }
7001 inline upb::reffed_ptr<const upb::FieldDef> positive_int_value() { RETURN_REFFED (upb::FieldDef, upbdefs_google_protobuf_UninterpretedOption_positive_int_value) }
7002 inline upb::reffed_ptr<const upb::FieldDef> string_value() { RETURN_REFFED(upb:: FieldDef, upbdefs_google_protobuf_UninterpretedOption_string_value) }
7003 } /* namespace UninterpretedOption */
7004 } /* namespace protobuf */
7005 } /* namespace google */
7006
7007 namespace google {
7008 namespace protobuf {
7009 namespace UninterpretedOption {
7010 namespace NamePart {
7011 inline upb::reffed_ptr<const upb::MessageDef> MessageDef() { RETURN_REFFED(upb:: MessageDef, upbdefs_google_protobuf_UninterpretedOption_NamePart) }
7012 inline upb::reffed_ptr<const upb::FieldDef> is_extension() { RETURN_REFFED(upb:: FieldDef, upbdefs_google_protobuf_UninterpretedOption_NamePart_is_extension) }
7013 inline upb::reffed_ptr<const upb::FieldDef> name_part() { RETURN_REFFED(upb::Fie ldDef, upbdefs_google_protobuf_UninterpretedOption_NamePart_name_part) }
7014 } /* namespace NamePart */
7015 } /* namespace UninterpretedOption */
7016 } /* namespace protobuf */
7017 } /* namespace google */
7018
7019 } /* namespace upbdefs */ 7330 } /* namespace upbdefs */
7020 7331
7021 7332 #endif /* __cplusplus */
7022 #undef RETURN_REFFED 7333
7023 #endif /* __cplusplus */ 7334 #endif /* UPB_DESCRIPTOR_DESCRIPTOR_PROTO_UPB_H_ */
7024
7025 #endif /* GOOGLE_PROTOBUF_DESCRIPTOR_UPB_H_ */
7026 /* 7335 /*
7027 ** Internal-only definitions for the decoder. 7336 ** Internal-only definitions for the decoder.
7028 */ 7337 */
7029 7338
7030 #ifndef UPB_DECODER_INT_H_ 7339 #ifndef UPB_DECODER_INT_H_
7031 #define UPB_DECODER_INT_H_ 7340 #define UPB_DECODER_INT_H_
7032 7341
7033 #include <stdlib.h>
7034 /* 7342 /*
7035 ** upb::pb::Decoder 7343 ** upb::pb::Decoder
7036 ** 7344 **
7037 ** A high performance, streaming, resumable decoder for the binary protobuf 7345 ** A high performance, streaming, resumable decoder for the binary protobuf
7038 ** format. 7346 ** format.
7039 ** 7347 **
7040 ** This interface works the same regardless of what decoder backend is being 7348 ** This interface works the same regardless of what decoder backend is being
7041 ** used. A client of this class does not need to know whether decoding is using 7349 ** used. A client of this class does not need to know whether decoding is using
7042 ** a JITted decoder (DynASM, LLVM, etc) or an interpreted decoder. By default, 7350 ** a JITted decoder (DynASM, LLVM, etc) or an interpreted decoder. By default,
7043 ** it will always use the fastest available decoder. However, you can call 7351 ** it will always use the fastest available decoder. However, you can call
(...skipping 16 matching lines...) Expand all
7060 } /* namespace upb */ 7368 } /* namespace upb */
7061 #endif 7369 #endif
7062 7370
7063 UPB_DECLARE_TYPE(upb::pb::CodeCache, upb_pbcodecache) 7371 UPB_DECLARE_TYPE(upb::pb::CodeCache, upb_pbcodecache)
7064 UPB_DECLARE_TYPE(upb::pb::Decoder, upb_pbdecoder) 7372 UPB_DECLARE_TYPE(upb::pb::Decoder, upb_pbdecoder)
7065 UPB_DECLARE_TYPE(upb::pb::DecoderMethodOptions, upb_pbdecodermethodopts) 7373 UPB_DECLARE_TYPE(upb::pb::DecoderMethodOptions, upb_pbdecodermethodopts)
7066 7374
7067 UPB_DECLARE_DERIVED_TYPE(upb::pb::DecoderMethod, upb::RefCounted, 7375 UPB_DECLARE_DERIVED_TYPE(upb::pb::DecoderMethod, upb::RefCounted,
7068 upb_pbdecodermethod, upb_refcounted) 7376 upb_pbdecodermethod, upb_refcounted)
7069 7377
7378 /* The maximum number of bytes we are required to buffer internally between
7379 * calls to the decoder. The value is 14: a 5 byte unknown tag plus ten-byte
7380 * varint, less one because we are buffering an incomplete value.
7381 *
7382 * Should only be used by unit tests. */
7383 #define UPB_DECODER_MAX_RESIDUAL_BYTES 14
7384
7070 #ifdef __cplusplus 7385 #ifdef __cplusplus
7071 7386
7072 /* The parameters one uses to construct a DecoderMethod. 7387 /* The parameters one uses to construct a DecoderMethod.
7073 * TODO(haberman): move allowjit here? Seems more convenient for users. 7388 * TODO(haberman): move allowjit here? Seems more convenient for users.
7074 * TODO(haberman): move this to be heap allocated for ABI stability. */ 7389 * TODO(haberman): move this to be heap allocated for ABI stability. */
7075 class upb::pb::DecoderMethodOptions { 7390 class upb::pb::DecoderMethodOptions {
7076 public: 7391 public:
7077 /* Parameter represents the destination handlers that this method will push 7392 /* Parameter represents the destination handlers that this method will push
7078 * to. */ 7393 * to. */
7079 explicit DecoderMethodOptions(const Handlers* dest_handlers); 7394 explicit DecoderMethodOptions(const Handlers* dest_handlers);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
7116 private: 7431 private:
7117 UPB_DISALLOW_POD_OPS(DecoderMethod, upb::pb::DecoderMethod) 7432 UPB_DISALLOW_POD_OPS(DecoderMethod, upb::pb::DecoderMethod)
7118 }; 7433 };
7119 7434
7120 #endif 7435 #endif
7121 7436
7122 /* Preallocation hint: decoder won't allocate more bytes than this when first 7437 /* Preallocation hint: decoder won't allocate more bytes than this when first
7123 * constructed. This hint may be an overestimate for some build configurations. 7438 * constructed. This hint may be an overestimate for some build configurations.
7124 * But if the decoder library is upgraded without recompiling the application, 7439 * But if the decoder library is upgraded without recompiling the application,
7125 * it may be an underestimate. */ 7440 * it may be an underestimate. */
7126 #define UPB_PB_DECODER_SIZE 4408 7441 #define UPB_PB_DECODER_SIZE 4416
7127 7442
7128 #ifdef __cplusplus 7443 #ifdef __cplusplus
7129 7444
7130 /* A Decoder receives binary protobuf data on its input sink and pushes the 7445 /* A Decoder receives binary protobuf data on its input sink and pushes the
7131 * decoded data to its output sink. */ 7446 * decoded data to its output sink. */
7132 class upb::pb::Decoder { 7447 class upb::pb::Decoder {
7133 public: 7448 public:
7134 /* Constructs a decoder instance for the given method, which must outlive this 7449 /* Constructs a decoder instance for the given method, which must outlive this
7135 * decoder. Any errors during parsing will be set on the given status, which 7450 * decoder. Any errors during parsing will be set on the given status, which
7136 * must also outlive this decoder. 7451 * must also outlive this decoder.
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
7534 7849
7535 /* End of the delimited region, relative to ptr, NULL if not in this buf. */ 7850 /* End of the delimited region, relative to ptr, NULL if not in this buf. */
7536 const char *delim_end; 7851 const char *delim_end;
7537 7852
7538 /* End of the delimited region, relative to ptr, end if not in this buf. */ 7853 /* End of the delimited region, relative to ptr, end if not in this buf. */
7539 const char *data_end; 7854 const char *data_end;
7540 7855
7541 /* Overall stream offset of "buf." */ 7856 /* Overall stream offset of "buf." */
7542 uint64_t bufstart_ofs; 7857 uint64_t bufstart_ofs;
7543 7858
7544 /* Buffer for residual bytes not parsed from the previous buffer. 7859 /* Buffer for residual bytes not parsed from the previous buffer. */
7545 * The maximum number of residual bytes we require is 12; a five-byte 7860 char residual[UPB_DECODER_MAX_RESIDUAL_BYTES];
7546 * unknown tag plus an eight-byte value, less one because the value
7547 * is only a partial value. */
7548 char residual[12];
7549 char *residual_end; 7861 char *residual_end;
7550 7862
7551 /* Bytes of data that should be discarded from the input beore we start 7863 /* Bytes of data that should be discarded from the input beore we start
7552 * parsing again. We set this when we internally determine that we can 7864 * parsing again. We set this when we internally determine that we can
7553 * safely skip the next N bytes, but this region extends past the current 7865 * safely skip the next N bytes, but this region extends past the current
7554 * user buffer. */ 7866 * user buffer. */
7555 size_t skip; 7867 size_t skip;
7556 7868
7557 /* Stores the user buffer passed to our decode function. */ 7869 /* Stores the user buffer passed to our decode function. */
7558 const char *buf_param; 7870 const char *buf_param;
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
7805 UPB_INLINE size_t upb_varint_size(uint64_t val) { 8117 UPB_INLINE size_t upb_varint_size(uint64_t val) {
7806 char buf[UPB_PB_VARINT_MAX_LEN]; 8118 char buf[UPB_PB_VARINT_MAX_LEN];
7807 return upb_vencode64(val, buf); 8119 return upb_vencode64(val, buf);
7808 } 8120 }
7809 8121
7810 /* Encodes a 32-bit varint, *not* sign-extended. */ 8122 /* Encodes a 32-bit varint, *not* sign-extended. */
7811 UPB_INLINE uint64_t upb_vencode32(uint32_t val) { 8123 UPB_INLINE uint64_t upb_vencode32(uint32_t val) {
7812 char buf[UPB_PB_VARINT_MAX_LEN]; 8124 char buf[UPB_PB_VARINT_MAX_LEN];
7813 size_t bytes = upb_vencode64(val, buf); 8125 size_t bytes = upb_vencode64(val, buf);
7814 uint64_t ret = 0; 8126 uint64_t ret = 0;
7815 assert(bytes <= 5); 8127 UPB_ASSERT(bytes <= 5);
7816 memcpy(&ret, buf, bytes); 8128 memcpy(&ret, buf, bytes);
7817 assert(ret <= 0xffffffffffU); 8129 UPB_ASSERT(ret <= 0xffffffffffU);
7818 return ret; 8130 return ret;
7819 } 8131 }
7820 8132
7821 #ifdef __cplusplus 8133 #ifdef __cplusplus
7822 } /* extern "C" */ 8134 } /* extern "C" */
7823 #endif 8135 #endif
7824 8136
7825 #endif /* UPB_VARINT_DECODER_H_ */ 8137 #endif /* UPB_VARINT_DECODER_H_ */
7826 /* 8138 /*
7827 ** upb::pb::Encoder (upb_pb_encoder) 8139 ** upb::pb::Encoder (upb_pb_encoder)
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
7932 ** of data and efficiency is an issue, these may not be the best functions to 8244 ** of data and efficiency is an issue, these may not be the best functions to
7933 ** use (though they are useful for prototyping, before optimizing). 8245 ** use (though they are useful for prototyping, before optimizing).
7934 */ 8246 */
7935 8247
7936 #ifndef UPB_GLUE_H 8248 #ifndef UPB_GLUE_H
7937 #define UPB_GLUE_H 8249 #define UPB_GLUE_H
7938 8250
7939 #include <stdbool.h> 8251 #include <stdbool.h>
7940 8252
7941 #ifdef __cplusplus 8253 #ifdef __cplusplus
8254 #include <vector>
8255
7942 extern "C" { 8256 extern "C" {
7943 #endif 8257 #endif
7944 8258
7945 /* Loads all defs from the given protobuf binary descriptor, setting default 8259 /* Loads a binary descriptor and returns a NULL-terminated array of unfrozen
7946 * accessors and a default layout on all messages. The caller owns the 8260 * filedefs. The caller owns the returned array, which must be freed with
7947 * returned array of defs, which will be of length *n. On error NULL is 8261 * upb_gfree(). */
7948 * returned and status is set (if non-NULL). */ 8262 upb_filedef **upb_loaddescriptor(const char *buf, size_t n, const void *owner,
7949 upb_def **upb_load_defs_from_descriptor(const char *str, size_t len, int *n, 8263 upb_status *status);
7950 void *owner, upb_status *status);
7951
7952 /* Like the previous but also adds the loaded defs to the given symtab. */
7953 bool upb_load_descriptor_into_symtab(upb_symtab *symtab, const char *str,
7954 size_t len, upb_status *status);
7955
7956 /* Like the previous but also reads the descriptor from the given filename. */
7957 bool upb_load_descriptor_file_into_symtab(upb_symtab *symtab, const char *fname,
7958 upb_status *status);
7959
7960 /* Reads the given filename into a character string, returning NULL if there
7961 * was an error. */
7962 char *upb_readfile(const char *filename, size_t *len);
7963 8264
7964 #ifdef __cplusplus 8265 #ifdef __cplusplus
7965 } /* extern "C" */ 8266 } /* extern "C" */
7966 8267
7967 namespace upb { 8268 namespace upb {
7968 8269
7969 /* All routines that load descriptors expect the descriptor to be a 8270 inline bool LoadDescriptor(const char* buf, size_t n, Status* status,
7970 * FileDescriptorSet. */ 8271 std::vector<reffed_ptr<FileDef> >* files) {
7971 inline bool LoadDescriptorFileIntoSymtab(SymbolTable* s, const char *fname, 8272 FileDef** parsed_files = upb_loaddescriptor(buf, n, &parsed_files, status);
7972 Status* status) {
7973 return upb_load_descriptor_file_into_symtab(s, fname, status);
7974 }
7975 8273
7976 inline bool LoadDescriptorIntoSymtab(SymbolTable* s, const char* str, 8274 if (parsed_files) {
7977 size_t len, Status* status) { 8275 FileDef** p = parsed_files;
7978 return upb_load_descriptor_into_symtab(s, str, len, status); 8276 while (*p) {
8277 files->push_back(reffed_ptr<FileDef>(*p, &parsed_files));
8278 ++p;
8279 }
8280 free(parsed_files);
8281 return true;
8282 } else {
8283 return false;
8284 }
7979 } 8285 }
7980 8286
7981 /* Templated so it can accept both string and std::string. */ 8287 /* Templated so it can accept both string and std::string. */
7982 template <typename T> 8288 template <typename T>
7983 bool LoadDescriptorIntoSymtab(SymbolTable* s, const T& desc, Status* status) { 8289 bool LoadDescriptor(const T& desc, Status* status,
7984 return upb_load_descriptor_into_symtab(s, desc.c_str(), desc.size(), status); 8290 std::vector<reffed_ptr<FileDef> >* files) {
8291 return LoadDescriptor(desc.c_str(), desc.size(), status, files);
7985 } 8292 }
7986 8293
7987 } /* namespace upb */ 8294 } /* namespace upb */
7988 8295
7989 #endif 8296 #endif
7990 8297
7991 #endif /* UPB_GLUE_H */ 8298 #endif /* UPB_GLUE_H */
7992 /* 8299 /*
7993 ** upb::pb::TextPrinter (upb_textprinter) 8300 ** upb::pb::TextPrinter (upb_textprinter)
7994 ** 8301 **
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
8076 */ 8383 */
8077 8384
8078 #ifndef UPB_JSON_PARSER_H_ 8385 #ifndef UPB_JSON_PARSER_H_
8079 #define UPB_JSON_PARSER_H_ 8386 #define UPB_JSON_PARSER_H_
8080 8387
8081 8388
8082 #ifdef __cplusplus 8389 #ifdef __cplusplus
8083 namespace upb { 8390 namespace upb {
8084 namespace json { 8391 namespace json {
8085 class Parser; 8392 class Parser;
8393 class ParserMethod;
8086 } /* namespace json */ 8394 } /* namespace json */
8087 } /* namespace upb */ 8395 } /* namespace upb */
8088 #endif 8396 #endif
8089 8397
8090 UPB_DECLARE_TYPE(upb::json::Parser, upb_json_parser) 8398 UPB_DECLARE_TYPE(upb::json::Parser, upb_json_parser)
8399 UPB_DECLARE_DERIVED_TYPE(upb::json::ParserMethod, upb::RefCounted,
8400 upb_json_parsermethod, upb_refcounted)
8091 8401
8092 /* upb::json::Parser **********************************************************/ 8402 /* upb::json::Parser **********************************************************/
8093 8403
8094 /* Preallocation hint: parser won't allocate more bytes than this when first 8404 /* Preallocation hint: parser won't allocate more bytes than this when first
8095 * constructed. This hint may be an overestimate for some build configurations. 8405 * constructed. This hint may be an overestimate for some build configurations.
8096 * But if the parser library is upgraded without recompiling the application, 8406 * But if the parser library is upgraded without recompiling the application,
8097 * it may be an underestimate. */ 8407 * it may be an underestimate. */
8098 #define UPB_JSON_PARSER_SIZE 3704 8408 #define UPB_JSON_PARSER_SIZE 4112
8099 8409
8100 #ifdef __cplusplus 8410 #ifdef __cplusplus
8101 8411
8102 /* Parses an incoming BytesStream, pushing the results to the destination 8412 /* Parses an incoming BytesStream, pushing the results to the destination
8103 * sink. */ 8413 * sink. */
8104 class upb::json::Parser { 8414 class upb::json::Parser {
8105 public: 8415 public:
8106 static Parser* Create(Environment* env, Sink* output); 8416 static Parser* Create(Environment* env, const ParserMethod* method,
8417 Sink* output);
8107 8418
8108 BytesSink* input(); 8419 BytesSink* input();
8109 8420
8110 private: 8421 private:
8111 UPB_DISALLOW_POD_OPS(Parser, upb::json::Parser) 8422 UPB_DISALLOW_POD_OPS(Parser, upb::json::Parser)
8112 }; 8423 };
8113 8424
8425 class upb::json::ParserMethod {
8426 public:
8427 /* Include base methods from upb::ReferenceCounted. */
8428 UPB_REFCOUNTED_CPPMETHODS
8429
8430 /* Returns handlers for parsing according to the specified schema. */
8431 static reffed_ptr<const ParserMethod> New(const upb::MessageDef* md);
8432
8433 /* The destination handlers that are statically bound to this method.
8434 * This method is only capable of outputting to a sink that uses these
8435 * handlers. */
8436 const Handlers* dest_handlers() const;
8437
8438 /* The input handlers for this decoder method. */
8439 const BytesHandler* input_handler() const;
8440
8441 private:
8442 UPB_DISALLOW_POD_OPS(ParserMethod, upb::json::ParserMethod)
8443 };
8444
8114 #endif 8445 #endif
8115 8446
8116 UPB_BEGIN_EXTERN_C 8447 UPB_BEGIN_EXTERN_C
8117 8448
8118 upb_json_parser *upb_json_parser_create(upb_env *e, upb_sink *output); 8449 upb_json_parser* upb_json_parser_create(upb_env* e,
8450 const upb_json_parsermethod* m,
8451 upb_sink* output);
8119 upb_bytessink *upb_json_parser_input(upb_json_parser *p); 8452 upb_bytessink *upb_json_parser_input(upb_json_parser *p);
8120 8453
8454 upb_json_parsermethod* upb_json_parsermethod_new(const upb_msgdef* md,
8455 const void* owner);
8456 const upb_handlers *upb_json_parsermethod_desthandlers(
8457 const upb_json_parsermethod *m);
8458 const upb_byteshandler *upb_json_parsermethod_inputhandler(
8459 const upb_json_parsermethod *m);
8460
8461 /* Include refcounted methods like upb_json_parsermethod_ref(). */
8462 UPB_REFCOUNTED_CMETHODS(upb_json_parsermethod, upb_json_parsermethod_upcast)
8463
8121 UPB_END_EXTERN_C 8464 UPB_END_EXTERN_C
8122 8465
8123 #ifdef __cplusplus 8466 #ifdef __cplusplus
8124 8467
8125 namespace upb { 8468 namespace upb {
8126 namespace json { 8469 namespace json {
8127 inline Parser* Parser::Create(Environment* env, Sink* output) { 8470 inline Parser* Parser::Create(Environment* env, const ParserMethod* method,
8128 return upb_json_parser_create(env, output); 8471 Sink* output) {
8472 return upb_json_parser_create(env, method, output);
8129 } 8473 }
8130 inline BytesSink* Parser::input() { 8474 inline BytesSink* Parser::input() {
8131 return upb_json_parser_input(this); 8475 return upb_json_parser_input(this);
8132 } 8476 }
8477
8478 inline const Handlers* ParserMethod::dest_handlers() const {
8479 return upb_json_parsermethod_desthandlers(this);
8480 }
8481 inline const BytesHandler* ParserMethod::input_handler() const {
8482 return upb_json_parsermethod_inputhandler(this);
8483 }
8484 /* static */
8485 inline reffed_ptr<const ParserMethod> ParserMethod::New(
8486 const MessageDef* md) {
8487 const upb_json_parsermethod *m = upb_json_parsermethod_new(md, &m);
8488 return reffed_ptr<const ParserMethod>(m, &m);
8489 }
8490
8133 } /* namespace json */ 8491 } /* namespace json */
8134 } /* namespace upb */ 8492 } /* namespace upb */
8135 8493
8136 #endif 8494 #endif
8137 8495
8138 8496
8139 #endif /* UPB_JSON_PARSER_H_ */ 8497 #endif /* UPB_JSON_PARSER_H_ */
8140 /* 8498 /*
8141 ** upb::json::Printer 8499 ** upb::json::Printer
8142 ** 8500 **
(...skipping 10 matching lines...) Expand all
8153 class Printer; 8511 class Printer;
8154 } /* namespace json */ 8512 } /* namespace json */
8155 } /* namespace upb */ 8513 } /* namespace upb */
8156 #endif 8514 #endif
8157 8515
8158 UPB_DECLARE_TYPE(upb::json::Printer, upb_json_printer) 8516 UPB_DECLARE_TYPE(upb::json::Printer, upb_json_printer)
8159 8517
8160 8518
8161 /* upb::json::Printer *********************************************************/ 8519 /* upb::json::Printer *********************************************************/
8162 8520
8163 #define UPB_JSON_PRINTER_SIZE 168 8521 #define UPB_JSON_PRINTER_SIZE 176
8164 8522
8165 #ifdef __cplusplus 8523 #ifdef __cplusplus
8166 8524
8167 /* Prints an incoming stream of data to a BytesSink in JSON format. */ 8525 /* Prints an incoming stream of data to a BytesSink in JSON format. */
8168 class upb::json::Printer { 8526 class upb::json::Printer {
8169 public: 8527 public:
8170 static Printer* Create(Environment* env, const upb::Handlers* handlers, 8528 static Printer* Create(Environment* env, const upb::Handlers* handlers,
8171 BytesSink* output); 8529 BytesSink* output);
8172 8530
8173 /* The input to the printer. */ 8531 /* The input to the printer. */
8174 Sink* input(); 8532 Sink* input();
8175 8533
8176 /* Returns handlers for printing according to the specified schema. */ 8534 /* Returns handlers for printing according to the specified schema.
8177 static reffed_ptr<const Handlers> NewHandlers(const upb::MessageDef* md); 8535 * If preserve_proto_fieldnames is true, the output JSON will use the
8536 * original .proto field names (ie. {"my_field":3}) instead of using
8537 * camelCased names, which is the default: (eg. {"myField":3}). */
8538 static reffed_ptr<const Handlers> NewHandlers(const upb::MessageDef* md,
8539 bool preserve_proto_fieldnames);
8178 8540
8179 static const size_t kSize = UPB_JSON_PRINTER_SIZE; 8541 static const size_t kSize = UPB_JSON_PRINTER_SIZE;
8180 8542
8181 private: 8543 private:
8182 UPB_DISALLOW_POD_OPS(Printer, upb::json::Printer) 8544 UPB_DISALLOW_POD_OPS(Printer, upb::json::Printer)
8183 }; 8545 };
8184 8546
8185 #endif 8547 #endif
8186 8548
8187 UPB_BEGIN_EXTERN_C 8549 UPB_BEGIN_EXTERN_C
8188 8550
8189 /* Native C API. */ 8551 /* Native C API. */
8190 upb_json_printer *upb_json_printer_create(upb_env *e, const upb_handlers *h, 8552 upb_json_printer *upb_json_printer_create(upb_env *e, const upb_handlers *h,
8191 upb_bytessink *output); 8553 upb_bytessink *output);
8192 upb_sink *upb_json_printer_input(upb_json_printer *p); 8554 upb_sink *upb_json_printer_input(upb_json_printer *p);
8193 const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md, 8555 const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md,
8556 bool preserve_fieldnames,
8194 const void *owner); 8557 const void *owner);
8195 8558
8196 UPB_END_EXTERN_C 8559 UPB_END_EXTERN_C
8197 8560
8198 #ifdef __cplusplus 8561 #ifdef __cplusplus
8199 8562
8200 namespace upb { 8563 namespace upb {
8201 namespace json { 8564 namespace json {
8202 inline Printer* Printer::Create(Environment* env, const upb::Handlers* handlers, 8565 inline Printer* Printer::Create(Environment* env, const upb::Handlers* handlers,
8203 BytesSink* output) { 8566 BytesSink* output) {
8204 return upb_json_printer_create(env, handlers, output); 8567 return upb_json_printer_create(env, handlers, output);
8205 } 8568 }
8206 inline Sink* Printer::input() { return upb_json_printer_input(this); } 8569 inline Sink* Printer::input() { return upb_json_printer_input(this); }
8207 inline reffed_ptr<const Handlers> Printer::NewHandlers( 8570 inline reffed_ptr<const Handlers> Printer::NewHandlers(
8208 const upb::MessageDef *md) { 8571 const upb::MessageDef *md, bool preserve_proto_fieldnames) {
8209 const Handlers* h = upb_json_printer_newhandlers(md, &h); 8572 const Handlers* h = upb_json_printer_newhandlers(
8573 md, preserve_proto_fieldnames, &h);
8210 return reffed_ptr<const Handlers>(h, &h); 8574 return reffed_ptr<const Handlers>(h, &h);
8211 } 8575 }
8212 } /* namespace json */ 8576 } /* namespace json */
8213 } /* namespace upb */ 8577 } /* namespace upb */
8214 8578
8215 #endif 8579 #endif
8216 8580
8217 #endif /* UPB_JSON_TYPED_PRINTER_H_ */ 8581 #endif /* UPB_JSON_TYPED_PRINTER_H_ */
OLDNEW
« no previous file with comments | « third_party/protobuf/php/ext/google/protobuf/type_check.c ('k') | third_party/protobuf/php/ext/google/protobuf/upb.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698