14#define PB_ENABLE_MALLOC 1
68#define NANOPB_VERSION "nanopb-0.4.6-dev"
81#ifdef PB_SYSTEM_HEADER
82#include PB_SYSTEM_HEADER
90#ifdef PB_ENABLE_MALLOC
102#if defined(PB_NO_PACKED_STRUCTS)
104# define PB_PACKED_STRUCT_START
105# define PB_PACKED_STRUCT_END
107#elif defined(__GNUC__) || defined(__clang__)
109# define PB_PACKED_STRUCT_START
110# define PB_PACKED_STRUCT_END
111# define pb_packed __attribute__((packed))
112#elif defined(__ICCARM__) || defined(__CC_ARM)
114# define PB_PACKED_STRUCT_START _Pragma("pack(push, 1)")
115# define PB_PACKED_STRUCT_END _Pragma("pack(pop)")
117#elif defined(_MSC_VER) && (_MSC_VER >= 1500)
119# define PB_PACKED_STRUCT_START __pragma(pack(push, 1))
120# define PB_PACKED_STRUCT_END __pragma(pack(pop))
124# define PB_PACKED_STRUCT_START
125# define PB_PACKED_STRUCT_END
130#ifndef PB_LITTLE_ENDIAN_8BIT
131#if ((defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN) || \
132 (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \
133 defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) || \
134 defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(_MIPSEL) || \
135 defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM)) \
137#define PB_LITTLE_ENDIAN_8BIT 1
143#define PB_UNUSED(x) (void)(x)
150#include <avr/pgmspace.h>
151#define PB_PROGMEM PROGMEM
152#define PB_PROGMEM_READU32(x) pgm_read_dword(&x)
155#define PB_PROGMEM_READU32(x) (x)
168#ifndef PB_NO_STATIC_ASSERT
169# ifndef PB_STATIC_ASSERT
170# if defined(__ICCARM__)
172# define PB_STATIC_ASSERT(COND, MSG) static_assert(COND,#MSG);
173# elif defined(PB_C99_STATIC_ASSERT)
175# define PB_STATIC_ASSERT(COND, MSG) typedef char PB_STATIC_ASSERT_MSG(MSG, __LINE__, __COUNTER__)[(COND)?1:-1];
176# define PB_STATIC_ASSERT_MSG(MSG, LINE, COUNTER) PB_STATIC_ASSERT_MSG_(MSG, LINE, COUNTER)
177# define PB_STATIC_ASSERT_MSG_(MSG, LINE, COUNTER) pb_static_assertion_ ## MSG ## _ ## LINE ## _ ## COUNTER
178# elif defined(__cplusplus)
180# define PB_STATIC_ASSERT(COND, MSG) static_assert(COND,#MSG);
183# define PB_STATIC_ASSERT(COND, MSG) _Static_assert(COND,#MSG);
188# define PB_STATIC_ASSERT(COND, MSG)
197PB_STATIC_ASSERT(1, STATIC_ASSERT_IS_NOT_WORKING)
200#ifndef PB_MAX_REQUIRED_FIELDS
201#define PB_MAX_REQUIRED_FIELDS 64
204#if PB_MAX_REQUIRED_FIELDS < 64
205#error You should not lower PB_MAX_REQUIRED_FIELDS from the default value (64).
208#ifdef PB_WITHOUT_64BIT
209#ifdef PB_CONVERT_DOUBLE_FLOAT
211#undef PB_CONVERT_DOUBLE_FLOAT
220typedef uint_least8_t pb_type_t;
225#define PB_LTYPE_BOOL 0x00U
226#define PB_LTYPE_VARINT 0x01U
227#define PB_LTYPE_UVARINT 0x02U
228#define PB_LTYPE_SVARINT 0x03U
229#define PB_LTYPE_FIXED32 0x04U
230#define PB_LTYPE_FIXED64 0x05U
233#define PB_LTYPE_LAST_PACKABLE 0x05U
237#define PB_LTYPE_BYTES 0x06U
241#define PB_LTYPE_STRING 0x07U
245#define PB_LTYPE_SUBMESSAGE 0x08U
250#define PB_LTYPE_SUBMSG_W_CB 0x09U
254#define PB_LTYPE_EXTENSION 0x0AU
260#define PB_LTYPE_FIXED_LENGTH_BYTES 0x0BU
263#define PB_LTYPES_COUNT 0x0CU
264#define PB_LTYPE_MASK 0x0FU
268#define PB_HTYPE_REQUIRED 0x00U
269#define PB_HTYPE_OPTIONAL 0x10U
270#define PB_HTYPE_SINGULAR 0x10U
271#define PB_HTYPE_REPEATED 0x20U
272#define PB_HTYPE_FIXARRAY 0x20U
273#define PB_HTYPE_ONEOF 0x30U
274#define PB_HTYPE_MASK 0x30U
278#define PB_ATYPE_STATIC 0x00U
279#define PB_ATYPE_POINTER 0x80U
280#define PB_ATYPE_CALLBACK 0x40U
281#define PB_ATYPE_MASK 0xC0U
283#define PB_ATYPE(x) ((x) & PB_ATYPE_MASK)
284#define PB_HTYPE(x) ((x) & PB_HTYPE_MASK)
285#define PB_LTYPE(x) ((x) & PB_LTYPE_MASK)
286#define PB_LTYPE_IS_SUBMSG(x) (PB_LTYPE(x) == PB_LTYPE_SUBMESSAGE || \
287 PB_LTYPE(x) == PB_LTYPE_SUBMSG_W_CB)
292#if defined(PB_FIELD_32BIT)
293typedef uint32_t pb_size_t;
294typedef int32_t pb_ssize_t;
296typedef uint_least16_t pb_size_t;
297typedef int_least16_t pb_ssize_t;
299#define PB_SIZE_MAX ((pb_size_t)-1)
305typedef uint_least8_t pb_byte_t;
317 const uint32_t * field_info;
319 const pb_byte_t * default_value;
323 pb_size_t field_count;
324 pb_size_t required_field_count;
325 pb_size_t largest_tag;
334 pb_size_t field_info_index;
335 pb_size_t required_field_index;
336 pb_size_t submessage_index;
340 pb_size_t array_size;
359#ifndef PB_WITHOUT_64BIT
360PB_STATIC_ASSERT(
sizeof(int64_t) == 2 *
sizeof(int32_t), INT64_T_WRONG_SIZE)
361PB_STATIC_ASSERT(
sizeof(uint64_t) == 2 *
sizeof(uint32_t), UINT64_T_WRONG_SIZE)
368#define PB_BYTES_ARRAY_T(n) struct { pb_size_t size; pb_byte_t bytes[n]; }
369#define PB_BYTES_ARRAY_T_ALLOCSIZE(n) ((size_t)n + offsetof(pb_bytes_array_t, bytes))
468#define pb_extension_init_zero { NULL, NULL, NULL, false }
472#ifdef PB_ENABLE_MALLOC
474# define pb_realloc(ptr, size) realloc(ptr, size)
477# define pb_free(ptr) free(ptr)
482#define PB_PROTO_HEADER_VERSION 40
486#define pb_membersize(st, m) (sizeof((st *)0)->m)
488#define pb_arraysize(st, m) (pb_membersize(st, m) / pb_membersize(st, m[0]))
490#define pb_delta(st, m1, m2) ((int)offsetof(st, m1) - (int)offsetof(st, m2))
493#define PB_EXPAND(x) x
496#define PB_BIND(msgname, structname, width) \
497 const uint32_t structname ## _field_info[] PB_PROGMEM = \
499 msgname ## _FIELDLIST(PB_GEN_FIELD_INFO_ ## width, structname) \
502 const pb_msgdesc_t *const structname ## _submsg_info[] = \
504 msgname ## _FIELDLIST(PB_GEN_SUBMSG_INFO, structname) \
507 const pb_msgdesc_t structname ## _msg = \
509 structname ## _field_info, \
510 structname ## _submsg_info, \
511 msgname ## _DEFAULT, \
512 msgname ## _CALLBACK, \
513 0 msgname ## _FIELDLIST(PB_GEN_FIELD_COUNT, structname), \
514 0 msgname ## _FIELDLIST(PB_GEN_REQ_FIELD_COUNT, structname), \
515 0 msgname ## _FIELDLIST(PB_GEN_LARGEST_TAG, structname), \
517 msgname ## _FIELDLIST(PB_GEN_FIELD_INFO_ASSERT_ ## width, structname)
519#define PB_GEN_FIELD_COUNT(structname, atype, htype, ltype, fieldname, tag) + 1
520#define PB_GEN_REQ_FIELD_COUNT(structname, atype, htype, ltype, fieldname, tag) \
521 + (PB_HTYPE_ ## htype == PB_HTYPE_REQUIRED)
522#define PB_GEN_LARGEST_TAG(structname, atype, htype, ltype, fieldname, tag) \
526#define PB_GEN_FIELD_INFO_1(structname, atype, htype, ltype, fieldname, tag) \
527 PB_FIELDINFO_1(tag, PB_ATYPE_ ## atype | PB_HTYPE_ ## htype | PB_LTYPE_MAP_ ## ltype, \
528 PB_DATA_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
529 PB_DATA_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
530 PB_SIZE_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
531 PB_ARRAY_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname))
533#define PB_GEN_FIELD_INFO_2(structname, atype, htype, ltype, fieldname, tag) \
534 PB_FIELDINFO_2(tag, PB_ATYPE_ ## atype | PB_HTYPE_ ## htype | PB_LTYPE_MAP_ ## ltype, \
535 PB_DATA_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
536 PB_DATA_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
537 PB_SIZE_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
538 PB_ARRAY_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname))
540#define PB_GEN_FIELD_INFO_4(structname, atype, htype, ltype, fieldname, tag) \
541 PB_FIELDINFO_4(tag, PB_ATYPE_ ## atype | PB_HTYPE_ ## htype | PB_LTYPE_MAP_ ## ltype, \
542 PB_DATA_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
543 PB_DATA_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
544 PB_SIZE_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
545 PB_ARRAY_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname))
547#define PB_GEN_FIELD_INFO_8(structname, atype, htype, ltype, fieldname, tag) \
548 PB_FIELDINFO_8(tag, PB_ATYPE_ ## atype | PB_HTYPE_ ## htype | PB_LTYPE_MAP_ ## ltype, \
549 PB_DATA_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
550 PB_DATA_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
551 PB_SIZE_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
552 PB_ARRAY_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname))
554#define PB_GEN_FIELD_INFO_AUTO(structname, atype, htype, ltype, fieldname, tag) \
555 PB_FIELDINFO_AUTO2(PB_FIELDINFO_WIDTH_AUTO(_PB_ATYPE_ ## atype, _PB_HTYPE_ ## htype, _PB_LTYPE_ ## ltype), \
556 tag, PB_ATYPE_ ## atype | PB_HTYPE_ ## htype | PB_LTYPE_MAP_ ## ltype, \
557 PB_DATA_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
558 PB_DATA_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
559 PB_SIZE_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
560 PB_ARRAY_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname))
562#define PB_FIELDINFO_AUTO2(width, tag, type, data_offset, data_size, size_offset, array_size) \
563 PB_FIELDINFO_AUTO3(width, tag, type, data_offset, data_size, size_offset, array_size)
565#define PB_FIELDINFO_AUTO3(width, tag, type, data_offset, data_size, size_offset, array_size) \
566 PB_FIELDINFO_ ## width(tag, type, data_offset, data_size, size_offset, array_size)
571#define PB_GEN_FIELD_INFO_ASSERT_1(structname, atype, htype, ltype, fieldname, tag) \
572 PB_FIELDINFO_ASSERT_1(tag, PB_ATYPE_ ## atype | PB_HTYPE_ ## htype | PB_LTYPE_MAP_ ## ltype, \
573 PB_DATA_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
574 PB_DATA_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
575 PB_SIZE_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
576 PB_ARRAY_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname))
578#define PB_GEN_FIELD_INFO_ASSERT_2(structname, atype, htype, ltype, fieldname, tag) \
579 PB_FIELDINFO_ASSERT_2(tag, PB_ATYPE_ ## atype | PB_HTYPE_ ## htype | PB_LTYPE_MAP_ ## ltype, \
580 PB_DATA_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
581 PB_DATA_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
582 PB_SIZE_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
583 PB_ARRAY_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname))
585#define PB_GEN_FIELD_INFO_ASSERT_4(structname, atype, htype, ltype, fieldname, tag) \
586 PB_FIELDINFO_ASSERT_4(tag, PB_ATYPE_ ## atype | PB_HTYPE_ ## htype | PB_LTYPE_MAP_ ## ltype, \
587 PB_DATA_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
588 PB_DATA_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
589 PB_SIZE_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
590 PB_ARRAY_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname))
592#define PB_GEN_FIELD_INFO_ASSERT_8(structname, atype, htype, ltype, fieldname, tag) \
593 PB_FIELDINFO_ASSERT_8(tag, PB_ATYPE_ ## atype | PB_HTYPE_ ## htype | PB_LTYPE_MAP_ ## ltype, \
594 PB_DATA_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
595 PB_DATA_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
596 PB_SIZE_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
597 PB_ARRAY_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname))
599#define PB_GEN_FIELD_INFO_ASSERT_AUTO(structname, atype, htype, ltype, fieldname, tag) \
600 PB_FIELDINFO_ASSERT_AUTO2(PB_FIELDINFO_WIDTH_AUTO(_PB_ATYPE_ ## atype, _PB_HTYPE_ ## htype, _PB_LTYPE_ ## ltype), \
601 tag, PB_ATYPE_ ## atype | PB_HTYPE_ ## htype | PB_LTYPE_MAP_ ## ltype, \
602 PB_DATA_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
603 PB_DATA_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
604 PB_SIZE_OFFSET_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname), \
605 PB_ARRAY_SIZE_ ## atype(_PB_HTYPE_ ## htype, structname, fieldname))
607#define PB_FIELDINFO_ASSERT_AUTO2(width, tag, type, data_offset, data_size, size_offset, array_size) \
608 PB_FIELDINFO_ASSERT_AUTO3(width, tag, type, data_offset, data_size, size_offset, array_size)
610#define PB_FIELDINFO_ASSERT_AUTO3(width, tag, type, data_offset, data_size, size_offset, array_size) \
611 PB_FIELDINFO_ASSERT_ ## width(tag, type, data_offset, data_size, size_offset, array_size)
613#define PB_DATA_OFFSET_STATIC(htype, structname, fieldname) PB_DO ## htype(structname, fieldname)
614#define PB_DATA_OFFSET_POINTER(htype, structname, fieldname) PB_DO ## htype(structname, fieldname)
615#define PB_DATA_OFFSET_CALLBACK(htype, structname, fieldname) PB_DO ## htype(structname, fieldname)
616#define PB_DO_PB_HTYPE_REQUIRED(structname, fieldname) offsetof(structname, fieldname)
617#define PB_DO_PB_HTYPE_SINGULAR(structname, fieldname) offsetof(structname, fieldname)
618#define PB_DO_PB_HTYPE_ONEOF(structname, fieldname) offsetof(structname, PB_ONEOF_NAME(FULL, fieldname))
619#define PB_DO_PB_HTYPE_OPTIONAL(structname, fieldname) offsetof(structname, fieldname)
620#define PB_DO_PB_HTYPE_REPEATED(structname, fieldname) offsetof(structname, fieldname)
621#define PB_DO_PB_HTYPE_FIXARRAY(structname, fieldname) offsetof(structname, fieldname)
623#define PB_SIZE_OFFSET_STATIC(htype, structname, fieldname) PB_SO ## htype(structname, fieldname)
624#define PB_SIZE_OFFSET_POINTER(htype, structname, fieldname) PB_SO_PTR ## htype(structname, fieldname)
625#define PB_SIZE_OFFSET_CALLBACK(htype, structname, fieldname) PB_SO_CB ## htype(structname, fieldname)
626#define PB_SO_PB_HTYPE_REQUIRED(structname, fieldname) 0
627#define PB_SO_PB_HTYPE_SINGULAR(structname, fieldname) 0
628#define PB_SO_PB_HTYPE_ONEOF(structname, fieldname) PB_SO_PB_HTYPE_ONEOF2(structname, PB_ONEOF_NAME(FULL, fieldname), PB_ONEOF_NAME(UNION, fieldname))
629#define PB_SO_PB_HTYPE_ONEOF2(structname, fullname, unionname) PB_SO_PB_HTYPE_ONEOF3(structname, fullname, unionname)
630#define PB_SO_PB_HTYPE_ONEOF3(structname, fullname, unionname) pb_delta(structname, fullname, which_ ## unionname)
631#define PB_SO_PB_HTYPE_OPTIONAL(structname, fieldname) pb_delta(structname, fieldname, has_ ## fieldname)
632#define PB_SO_PB_HTYPE_REPEATED(structname, fieldname) pb_delta(structname, fieldname, fieldname ## _count)
633#define PB_SO_PB_HTYPE_FIXARRAY(structname, fieldname) 0
634#define PB_SO_PTR_PB_HTYPE_REQUIRED(structname, fieldname) 0
635#define PB_SO_PTR_PB_HTYPE_SINGULAR(structname, fieldname) 0
636#define PB_SO_PTR_PB_HTYPE_ONEOF(structname, fieldname) PB_SO_PB_HTYPE_ONEOF(structname, fieldname)
637#define PB_SO_PTR_PB_HTYPE_OPTIONAL(structname, fieldname) 0
638#define PB_SO_PTR_PB_HTYPE_REPEATED(structname, fieldname) PB_SO_PB_HTYPE_REPEATED(structname, fieldname)
639#define PB_SO_PTR_PB_HTYPE_FIXARRAY(structname, fieldname) 0
640#define PB_SO_CB_PB_HTYPE_REQUIRED(structname, fieldname) 0
641#define PB_SO_CB_PB_HTYPE_SINGULAR(structname, fieldname) 0
642#define PB_SO_CB_PB_HTYPE_ONEOF(structname, fieldname) PB_SO_PB_HTYPE_ONEOF(structname, fieldname)
643#define PB_SO_CB_PB_HTYPE_OPTIONAL(structname, fieldname) 0
644#define PB_SO_CB_PB_HTYPE_REPEATED(structname, fieldname) 0
645#define PB_SO_CB_PB_HTYPE_FIXARRAY(structname, fieldname) 0
647#define PB_ARRAY_SIZE_STATIC(htype, structname, fieldname) PB_AS ## htype(structname, fieldname)
648#define PB_ARRAY_SIZE_POINTER(htype, structname, fieldname) PB_AS_PTR ## htype(structname, fieldname)
649#define PB_ARRAY_SIZE_CALLBACK(htype, structname, fieldname) 1
650#define PB_AS_PB_HTYPE_REQUIRED(structname, fieldname) 1
651#define PB_AS_PB_HTYPE_SINGULAR(structname, fieldname) 1
652#define PB_AS_PB_HTYPE_OPTIONAL(structname, fieldname) 1
653#define PB_AS_PB_HTYPE_ONEOF(structname, fieldname) 1
654#define PB_AS_PB_HTYPE_REPEATED(structname, fieldname) pb_arraysize(structname, fieldname)
655#define PB_AS_PB_HTYPE_FIXARRAY(structname, fieldname) pb_arraysize(structname, fieldname)
656#define PB_AS_PTR_PB_HTYPE_REQUIRED(structname, fieldname) 1
657#define PB_AS_PTR_PB_HTYPE_SINGULAR(structname, fieldname) 1
658#define PB_AS_PTR_PB_HTYPE_OPTIONAL(structname, fieldname) 1
659#define PB_AS_PTR_PB_HTYPE_ONEOF(structname, fieldname) 1
660#define PB_AS_PTR_PB_HTYPE_REPEATED(structname, fieldname) 1
661#define PB_AS_PTR_PB_HTYPE_FIXARRAY(structname, fieldname) pb_arraysize(structname, fieldname[0])
663#define PB_DATA_SIZE_STATIC(htype, structname, fieldname) PB_DS ## htype(structname, fieldname)
664#define PB_DATA_SIZE_POINTER(htype, structname, fieldname) PB_DS_PTR ## htype(structname, fieldname)
665#define PB_DATA_SIZE_CALLBACK(htype, structname, fieldname) PB_DS_CB ## htype(structname, fieldname)
666#define PB_DS_PB_HTYPE_REQUIRED(structname, fieldname) pb_membersize(structname, fieldname)
667#define PB_DS_PB_HTYPE_SINGULAR(structname, fieldname) pb_membersize(structname, fieldname)
668#define PB_DS_PB_HTYPE_OPTIONAL(structname, fieldname) pb_membersize(structname, fieldname)
669#define PB_DS_PB_HTYPE_ONEOF(structname, fieldname) pb_membersize(structname, PB_ONEOF_NAME(FULL, fieldname))
670#define PB_DS_PB_HTYPE_REPEATED(structname, fieldname) pb_membersize(structname, fieldname[0])
671#define PB_DS_PB_HTYPE_FIXARRAY(structname, fieldname) pb_membersize(structname, fieldname[0])
672#define PB_DS_PTR_PB_HTYPE_REQUIRED(structname, fieldname) pb_membersize(structname, fieldname[0])
673#define PB_DS_PTR_PB_HTYPE_SINGULAR(structname, fieldname) pb_membersize(structname, fieldname[0])
674#define PB_DS_PTR_PB_HTYPE_OPTIONAL(structname, fieldname) pb_membersize(structname, fieldname[0])
675#define PB_DS_PTR_PB_HTYPE_ONEOF(structname, fieldname) pb_membersize(structname, PB_ONEOF_NAME(FULL, fieldname)[0])
676#define PB_DS_PTR_PB_HTYPE_REPEATED(structname, fieldname) pb_membersize(structname, fieldname[0])
677#define PB_DS_PTR_PB_HTYPE_FIXARRAY(structname, fieldname) pb_membersize(structname, fieldname[0][0])
678#define PB_DS_CB_PB_HTYPE_REQUIRED(structname, fieldname) pb_membersize(structname, fieldname)
679#define PB_DS_CB_PB_HTYPE_SINGULAR(structname, fieldname) pb_membersize(structname, fieldname)
680#define PB_DS_CB_PB_HTYPE_OPTIONAL(structname, fieldname) pb_membersize(structname, fieldname)
681#define PB_DS_CB_PB_HTYPE_ONEOF(structname, fieldname) pb_membersize(structname, PB_ONEOF_NAME(FULL, fieldname))
682#define PB_DS_CB_PB_HTYPE_REPEATED(structname, fieldname) pb_membersize(structname, fieldname)
683#define PB_DS_CB_PB_HTYPE_FIXARRAY(structname, fieldname) pb_membersize(structname, fieldname)
685#define PB_ONEOF_NAME(type, tuple) PB_EXPAND(PB_ONEOF_NAME_ ## type tuple)
686#define PB_ONEOF_NAME_UNION(unionname, membername, fullname) unionname
687#define PB_ONEOF_NAME_MEMBER(unionname, membername, fullname) membername
688#define PB_ONEOF_NAME_FULL(unionname, membername, fullname) fullname
690#define PB_GEN_SUBMSG_INFO(structname, atype, htype, ltype, fieldname, tag) \
691 PB_SUBMSG_INFO_ ## htype(_PB_LTYPE_ ## ltype, structname, fieldname)
693#define PB_SUBMSG_INFO_REQUIRED(ltype, structname, fieldname) PB_SI ## ltype(structname ## _ ## fieldname ## _MSGTYPE)
694#define PB_SUBMSG_INFO_SINGULAR(ltype, structname, fieldname) PB_SI ## ltype(structname ## _ ## fieldname ## _MSGTYPE)
695#define PB_SUBMSG_INFO_OPTIONAL(ltype, structname, fieldname) PB_SI ## ltype(structname ## _ ## fieldname ## _MSGTYPE)
696#define PB_SUBMSG_INFO_ONEOF(ltype, structname, fieldname) PB_SUBMSG_INFO_ONEOF2(ltype, structname, PB_ONEOF_NAME(UNION, fieldname), PB_ONEOF_NAME(MEMBER, fieldname))
697#define PB_SUBMSG_INFO_ONEOF2(ltype, structname, unionname, membername) PB_SUBMSG_INFO_ONEOF3(ltype, structname, unionname, membername)
698#define PB_SUBMSG_INFO_ONEOF3(ltype, structname, unionname, membername) PB_SI ## ltype(structname ## _ ## unionname ## _ ## membername ## _MSGTYPE)
699#define PB_SUBMSG_INFO_REPEATED(ltype, structname, fieldname) PB_SI ## ltype(structname ## _ ## fieldname ## _MSGTYPE)
700#define PB_SUBMSG_INFO_FIXARRAY(ltype, structname, fieldname) PB_SI ## ltype(structname ## _ ## fieldname ## _MSGTYPE)
701#define PB_SI_PB_LTYPE_BOOL(t)
702#define PB_SI_PB_LTYPE_BYTES(t)
703#define PB_SI_PB_LTYPE_DOUBLE(t)
704#define PB_SI_PB_LTYPE_ENUM(t)
705#define PB_SI_PB_LTYPE_UENUM(t)
706#define PB_SI_PB_LTYPE_FIXED32(t)
707#define PB_SI_PB_LTYPE_FIXED64(t)
708#define PB_SI_PB_LTYPE_FLOAT(t)
709#define PB_SI_PB_LTYPE_INT32(t)
710#define PB_SI_PB_LTYPE_INT64(t)
711#define PB_SI_PB_LTYPE_MESSAGE(t) PB_SUBMSG_DESCRIPTOR(t)
712#define PB_SI_PB_LTYPE_MSG_W_CB(t) PB_SUBMSG_DESCRIPTOR(t)
713#define PB_SI_PB_LTYPE_SFIXED32(t)
714#define PB_SI_PB_LTYPE_SFIXED64(t)
715#define PB_SI_PB_LTYPE_SINT32(t)
716#define PB_SI_PB_LTYPE_SINT64(t)
717#define PB_SI_PB_LTYPE_STRING(t)
718#define PB_SI_PB_LTYPE_UINT32(t)
719#define PB_SI_PB_LTYPE_UINT64(t)
720#define PB_SI_PB_LTYPE_EXTENSION(t)
721#define PB_SI_PB_LTYPE_FIXED_LENGTH_BYTES(t)
722#define PB_SUBMSG_DESCRIPTOR(t) & (t ## _msg),
752#define PB_FIELDINFO_1(tag, type, data_offset, data_size, size_offset, array_size) \
753 (0 | (((tag) << 2) & 0xFF) | ((type) << 8) | (((uint32_t)(data_offset) & 0xFF) << 16) | \
754 (((uint32_t)(size_offset) & 0x0F) << 24) | (((uint32_t)(data_size) & 0x0F) << 28)),
756#define PB_FIELDINFO_2(tag, type, data_offset, data_size, size_offset, array_size) \
757 (1 | (((tag) << 2) & 0xFF) | ((type) << 8) | (((uint32_t)(array_size) & 0xFFF) << 16) | (((uint32_t)(size_offset) & 0x0F) << 28)), \
758 (((uint32_t)(data_offset) & 0xFFFF) | (((uint32_t)(data_size) & 0xFFF) << 16) | (((uint32_t)(tag) & 0x3c0) << 22)),
760#define PB_FIELDINFO_4(tag, type, data_offset, data_size, size_offset, array_size) \
761 (2 | (((tag) << 2) & 0xFF) | ((type) << 8) | (((uint32_t)(array_size) & 0xFFFF) << 16)), \
762 ((uint32_t)(int_least8_t)(size_offset) | (((uint32_t)(tag) << 2) & 0xFFFFFF00)), \
763 (data_offset), (data_size),
765#define PB_FIELDINFO_8(tag, type, data_offset, data_size, size_offset, array_size) \
766 (3 | (((tag) << 2) & 0xFF) | ((type) << 8)), \
767 ((uint32_t)(int_least8_t)(size_offset) | (((uint32_t)(tag) << 2) & 0xFFFFFF00)), \
768 (data_offset), (data_size), (array_size), 0, 0, 0,
777#define PB_FITS(value, bits) ((uint32_t)(value) < ((uint32_t)1 << bits))
778#define PB_FIELDINFO_ASSERT_1(tag, type, data_offset, data_size, size_offset, array_size) \
779 PB_STATIC_ASSERT(PB_FITS(tag, 6) && PB_FITS(data_offset, 8) && PB_FITS(size_offset, 4) && PB_FITS(data_size, 4) && PB_FITS(array_size, 1), FIELDINFO_DOES_NOT_FIT_width1_field ## tag)
781#define PB_FIELDINFO_ASSERT_2(tag, type, data_offset, data_size, size_offset, array_size) \
782 PB_STATIC_ASSERT(PB_FITS(tag, 10) && PB_FITS(data_offset, 16) && PB_FITS(size_offset, 4) && PB_FITS(data_size, 12) && PB_FITS(array_size, 12), FIELDINFO_DOES_NOT_FIT_width2_field ## tag)
784#ifndef PB_FIELD_32BIT
786#define PB_FIELDINFO_ASSERT_4(tag, type, data_offset, data_size, size_offset, array_size) \
787 PB_STATIC_ASSERT(PB_FITS(tag, 16) && PB_FITS(data_offset, 16) && PB_FITS((int_least8_t)size_offset, 8) && PB_FITS(data_size, 16) && PB_FITS(array_size, 16), FIELDINFO_DOES_NOT_FIT_width4_field ## tag)
789#define PB_FIELDINFO_ASSERT_8(tag, type, data_offset, data_size, size_offset, array_size) \
790 PB_STATIC_ASSERT(PB_FITS(tag, 16) && PB_FITS(data_offset, 16) && PB_FITS((int_least8_t)size_offset, 8) && PB_FITS(data_size, 16) && PB_FITS(array_size, 16), FIELDINFO_DOES_NOT_FIT_width8_field ## tag)
796#define PB_FIELDINFO_ASSERT_4(tag, type, data_offset, data_size, size_offset, array_size) \
797 PB_STATIC_ASSERT(PB_FITS(tag, 30) && PB_FITS(data_offset, 31) && PB_FITS(size_offset, 8) && PB_FITS(data_size, 31) && PB_FITS(array_size, 16), FIELDINFO_DOES_NOT_FIT_width4_field ## tag)
799#define PB_FIELDINFO_ASSERT_8(tag, type, data_offset, data_size, size_offset, array_size) \
800 PB_STATIC_ASSERT(PB_FITS(tag, 30) && PB_FITS(data_offset, 31) && PB_FITS(size_offset, 8) && PB_FITS(data_size, 31) && PB_FITS(array_size, 31), FIELDINFO_DOES_NOT_FIT_width8_field ## tag)
810#define PB_FIELDINFO_WIDTH_AUTO(atype, htype, ltype) PB_FI_WIDTH ## atype(htype, ltype)
811#define PB_FI_WIDTH_PB_ATYPE_STATIC(htype, ltype) PB_FI_WIDTH ## htype(ltype)
812#define PB_FI_WIDTH_PB_ATYPE_POINTER(htype, ltype) PB_FI_WIDTH ## htype(ltype)
813#define PB_FI_WIDTH_PB_ATYPE_CALLBACK(htype, ltype) 2
814#define PB_FI_WIDTH_PB_HTYPE_REQUIRED(ltype) PB_FI_WIDTH ## ltype
815#define PB_FI_WIDTH_PB_HTYPE_SINGULAR(ltype) PB_FI_WIDTH ## ltype
816#define PB_FI_WIDTH_PB_HTYPE_OPTIONAL(ltype) PB_FI_WIDTH ## ltype
817#define PB_FI_WIDTH_PB_HTYPE_ONEOF(ltype) PB_FI_WIDTH ## ltype
818#define PB_FI_WIDTH_PB_HTYPE_REPEATED(ltype) 2
819#define PB_FI_WIDTH_PB_HTYPE_FIXARRAY(ltype) 2
820#define PB_FI_WIDTH_PB_LTYPE_BOOL 1
821#define PB_FI_WIDTH_PB_LTYPE_BYTES 2
822#define PB_FI_WIDTH_PB_LTYPE_DOUBLE 1
823#define PB_FI_WIDTH_PB_LTYPE_ENUM 1
824#define PB_FI_WIDTH_PB_LTYPE_UENUM 1
825#define PB_FI_WIDTH_PB_LTYPE_FIXED32 1
826#define PB_FI_WIDTH_PB_LTYPE_FIXED64 1
827#define PB_FI_WIDTH_PB_LTYPE_FLOAT 1
828#define PB_FI_WIDTH_PB_LTYPE_INT32 1
829#define PB_FI_WIDTH_PB_LTYPE_INT64 1
830#define PB_FI_WIDTH_PB_LTYPE_MESSAGE 2
831#define PB_FI_WIDTH_PB_LTYPE_MSG_W_CB 2
832#define PB_FI_WIDTH_PB_LTYPE_SFIXED32 1
833#define PB_FI_WIDTH_PB_LTYPE_SFIXED64 1
834#define PB_FI_WIDTH_PB_LTYPE_SINT32 1
835#define PB_FI_WIDTH_PB_LTYPE_SINT64 1
836#define PB_FI_WIDTH_PB_LTYPE_STRING 2
837#define PB_FI_WIDTH_PB_LTYPE_UINT32 1
838#define PB_FI_WIDTH_PB_LTYPE_UINT64 1
839#define PB_FI_WIDTH_PB_LTYPE_EXTENSION 1
840#define PB_FI_WIDTH_PB_LTYPE_FIXED_LENGTH_BYTES 2
843#define PB_LTYPE_MAP_BOOL PB_LTYPE_BOOL
844#define PB_LTYPE_MAP_BYTES PB_LTYPE_BYTES
845#define PB_LTYPE_MAP_DOUBLE PB_LTYPE_FIXED64
846#define PB_LTYPE_MAP_ENUM PB_LTYPE_VARINT
847#define PB_LTYPE_MAP_UENUM PB_LTYPE_UVARINT
848#define PB_LTYPE_MAP_FIXED32 PB_LTYPE_FIXED32
849#define PB_LTYPE_MAP_FIXED64 PB_LTYPE_FIXED64
850#define PB_LTYPE_MAP_FLOAT PB_LTYPE_FIXED32
851#define PB_LTYPE_MAP_INT32 PB_LTYPE_VARINT
852#define PB_LTYPE_MAP_INT64 PB_LTYPE_VARINT
853#define PB_LTYPE_MAP_MESSAGE PB_LTYPE_SUBMESSAGE
854#define PB_LTYPE_MAP_MSG_W_CB PB_LTYPE_SUBMSG_W_CB
855#define PB_LTYPE_MAP_SFIXED32 PB_LTYPE_FIXED32
856#define PB_LTYPE_MAP_SFIXED64 PB_LTYPE_FIXED64
857#define PB_LTYPE_MAP_SINT32 PB_LTYPE_SVARINT
858#define PB_LTYPE_MAP_SINT64 PB_LTYPE_SVARINT
859#define PB_LTYPE_MAP_STRING PB_LTYPE_STRING
860#define PB_LTYPE_MAP_UINT32 PB_LTYPE_UVARINT
861#define PB_LTYPE_MAP_UINT64 PB_LTYPE_UVARINT
862#define PB_LTYPE_MAP_EXTENSION PB_LTYPE_EXTENSION
863#define PB_LTYPE_MAP_FIXED_LENGTH_BYTES PB_LTYPE_FIXED_LENGTH_BYTES
878#define PB_SET_ERROR(stream, msg) PB_UNUSED(stream)
879#define PB_GET_ERROR(stream) "(errmsg disabled)"
881#define PB_SET_ERROR(stream, msg) (stream->errmsg = (stream)->errmsg ? (stream)->errmsg : (msg))
882#define PB_GET_ERROR(stream) ((stream)->errmsg ? (stream)->errmsg : "(none)")
885#define PB_RETURN_ERROR(stream, msg) return PB_SET_ERROR(stream, msg), false
892#if __cplusplus >= 201103L
893#define PB_CONSTEXPR constexpr
898#if __cplusplus >= 201703L
899#define PB_INLINE_CONSTEXPR inline constexpr
901#define PB_INLINE_CONSTEXPR PB_CONSTEXPR
906template <
typename GenMessageT>
struct MessageDescriptor;