9 /* This just reduces memory requirements, but is not required. */
10 #define pb_packed __attribute__((packed))
15 /* Wire types. Library user needs these only in encoder callbacks. */
23 /* List of possible field types
24 * Least-significant 4 bits tell the scalar type
25 * Most-significant 4 bits specify repeated/required/packed etc.
27 * INT32 and UINT32 are treated the same, as are (U)INT64 and (S)FIXED*
28 * These types are simply casted to correct field type when they are
29 * assigned to the memory pointer.
30 * SINT* is different, though, because it is zig-zag coded.
34 /************************
35 * Field contents types *
36 ************************/
39 PB_LTYPE_VARINT = 0x00, /* int32, uint32, int64, uint64, bool, enum */
40 PB_LTYPE_SVARINT = 0x01, /* sint32, sint64 */
41 PB_LTYPE_FIXED = 0x02, /* fixed32, sfixed32, fixed64, sfixed64, float, double */
43 /* Marker for last packable field type. */
44 PB_LTYPE_LAST_PACKABLE = 0x02,
46 /* Byte array with pre-allocated buffer.
47 * data_size is the length of the allocated PB_BYTES_ARRAY structure. */
48 PB_LTYPE_BYTES = 0x03,
50 /* String with pre-allocated buffer.
51 * data_size is the maximum length. */
52 PB_LTYPE_STRING = 0x04,
55 * submsg_fields is pointer to field descriptions */
56 PB_LTYPE_SUBMESSAGE = 0x05,
58 /* Number of declared LTYPES */
65 /* Just the basic, write data at data_offset */
66 PB_HTYPE_REQUIRED = 0x00,
68 /* Write true at size_offset */
69 PB_HTYPE_OPTIONAL = 0x10,
71 /* Read to pre-allocated array
72 * Maximum number of entries is array_size,
73 * actual number is stored at size_offset */
74 PB_HTYPE_ARRAY = 0x20,
76 /* Works for all required/optional/repeated fields.
77 * data_offset points to pb_callback_t structure.
78 * LTYPE should be 0 (it is ignored, but sometimes
79 * used to speculatively index an array). */
80 PB_HTYPE_CALLBACK = 0x30
81 } pb_packed pb_type_t;
83 #define PB_HTYPE(x) ((x) & 0xF0)
84 #define PB_LTYPE(x) ((x) & 0x0F)
86 /* This structure is used in auto-generated constants
87 * to specify struct fields.
88 * You can change field sizes here if you need structures
89 * larger than 256 bytes or field tags larger than 256.
90 * The compiler should complain if your .proto has such
91 * structures ("initializer too large for type").
93 typedef struct _pb_field_t pb_field_t;
97 uint8_t data_offset; /* Offset of field data, relative to previous field. */
98 int8_t size_offset; /* Offset of array size or has-boolean, relative to data */
99 uint8_t data_size; /* Data size in bytes for a single item */
100 uint8_t array_size; /* Maximum number of entries in array */
102 /* Field definitions for submessage
103 * OR default value for all other non-array, non-callback types
104 * If null, then field will zeroed. */
108 /* This structure is used for 'bytes' arrays.
109 * It has the number of bytes in the beginning, and after that an array.
110 * Note that actual structs used will have a different length of bytes array.
117 /* This structure is used for giving the callback function.
118 * It is stored in the message structure and filled in by the method that
121 * The decoding callback will be given a limited-length stream
122 * If the wire type was string, the length is the length of the string.
123 * If the wire type was a varint/fixed32/fixed64, the length is the length
124 * of the actual value.
125 * The function may be called multiple times (especially for repeated types,
126 * but also otherwise if the message happens to contain the field multiple
129 * The encoding callback will receive the actual output stream.
130 * It should write all the data in one call, including the field tag and
131 * wire type. It can write multiple fields.
133 typedef struct _pb_istream_t pb_istream_t;
134 typedef struct _pb_ostream_t pb_ostream_t;
135 typedef struct _pb_callback_t pb_callback_t;
136 struct _pb_callback_t {
138 bool (*decode)(pb_istream_t *stream, const pb_field_t *field, void *arg);
139 bool (*encode)(pb_ostream_t *stream, const pb_field_t *field, const void *arg);
142 /* Free arg for use by callback */
146 /* These macros are used to declare pb_field_t's in the constant array. */
147 #define pb_membersize(st, m) (sizeof ((st*)0)->m)
148 #define pb_arraysize(st, m) (pb_membersize(st, m) / pb_membersize(st, m[0]))
149 #define pb_delta(st, m1, m2) ((int)offsetof(st, m1) - (int)offsetof(st, m2))
150 #define PB_LAST_FIELD {0,0,0,0}