Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LinkNode-Test by
pb.h
00001 /* Common parts of the nanopb library. Most of these are quite low-level 00002 * stuff. For the high-level interface, see pb_encode.h and pb_decode.h. 00003 */ 00004 00005 #ifndef PB_H_INCLUDED 00006 #define PB_H_INCLUDED 00007 00008 /***************************************************************** 00009 * Nanopb compilation time options. You can change these here by * 00010 * uncommenting the lines, or on the compiler command line. * 00011 *****************************************************************/ 00012 00013 /* Enable support for dynamically allocated fields */ 00014 /* #define PB_ENABLE_MALLOC 1 */ 00015 00016 /* Define this if your CPU / compiler combination does not support 00017 * unaligned memory access to packed structures. */ 00018 /* #define PB_NO_PACKED_STRUCTS 1 */ 00019 00020 /* Increase the number of required fields that are tracked. 00021 * A compiler warning will tell if you need this. */ 00022 /* #define PB_MAX_REQUIRED_FIELDS 256 */ 00023 00024 /* Add support for tag numbers > 255 and fields larger than 255 bytes. */ 00025 /* #define PB_FIELD_16BIT 1 */ 00026 00027 /* Add support for tag numbers > 65536 and fields larger than 65536 bytes. */ 00028 #define PB_FIELD_32BIT 1 00029 00030 /* Disable support for error messages in order to save some code space. */ 00031 /* #define PB_NO_ERRMSG 1 */ 00032 00033 /* Disable support for custom streams (support only memory buffers). */ 00034 /* #define PB_BUFFER_ONLY 1 */ 00035 00036 /* Switch back to the old-style callback function signature. 00037 * This was the default until nanopb-0.2.1. */ 00038 /* #define PB_OLD_CALLBACK_STYLE */ 00039 00040 00041 /****************************************************************** 00042 * You usually don't need to change anything below this line. * 00043 * Feel free to look around and use the defined macros, though. * 00044 ******************************************************************/ 00045 00046 00047 /* Version of the nanopb library. Just in case you want to check it in 00048 * your own program. */ 00049 #define NANOPB_VERSION nanopb-0.3.6 00050 00051 /* Include all the system headers needed by nanopb. You will need the 00052 * definitions of the following: 00053 * - strlen, memcpy, memset functions 00054 * - [u]int_least8_t, uint_fast8_t, [u]int_least16_t, [u]int32_t, [u]int64_t 00055 * - size_t 00056 * - bool 00057 * 00058 * If you don't have the standard header files, you can instead provide 00059 * a custom header that defines or includes all this. In that case, 00060 * define PB_SYSTEM_HEADER to the path of this file. 00061 */ 00062 #ifdef PB_SYSTEM_HEADER 00063 #include PB_SYSTEM_HEADER 00064 #else 00065 #include <stdint.h> 00066 #include <stddef.h> 00067 #include <stdbool.h> 00068 #include <string.h> 00069 00070 #ifdef PB_ENABLE_MALLOC 00071 #include <stdlib.h> 00072 #endif 00073 #endif 00074 00075 /* Macro for defining packed structures (compiler dependent). 00076 * This just reduces memory requirements, but is not required. 00077 */ 00078 #if defined(PB_NO_PACKED_STRUCTS) 00079 /* Disable struct packing */ 00080 # define PB_PACKED_STRUCT_START 00081 # define PB_PACKED_STRUCT_END 00082 # define pb_packed 00083 #elif defined(__GNUC__) || defined(__clang__) 00084 /* For GCC and clang */ 00085 # define PB_PACKED_STRUCT_START 00086 # define PB_PACKED_STRUCT_END 00087 # define pb_packed __attribute__((packed)) 00088 #elif defined(__ICCARM__) || defined(__CC_ARM) 00089 /* For IAR ARM and Keil MDK-ARM compilers */ 00090 # define PB_PACKED_STRUCT_START _Pragma("pack(push, 1)") 00091 # define PB_PACKED_STRUCT_END _Pragma("pack(pop)") 00092 # define pb_packed 00093 #elif defined(_MSC_VER) && (_MSC_VER >= 1500) 00094 /* For Microsoft Visual C++ */ 00095 # define PB_PACKED_STRUCT_START __pragma(pack(push, 1)) 00096 # define PB_PACKED_STRUCT_END __pragma(pack(pop)) 00097 # define pb_packed 00098 #else 00099 /* Unknown compiler */ 00100 # define PB_PACKED_STRUCT_START 00101 # define PB_PACKED_STRUCT_END 00102 # define pb_packed 00103 #endif 00104 00105 /* Handly macro for suppressing unreferenced-parameter compiler warnings. */ 00106 #ifndef PB_UNUSED 00107 #define PB_UNUSED(x) (void)(x) 00108 #endif 00109 00110 /* Compile-time assertion, used for checking compatible compilation options. 00111 * If this does not work properly on your compiler, use 00112 * #define PB_NO_STATIC_ASSERT to disable it. 00113 * 00114 * But before doing that, check carefully the error message / place where it 00115 * comes from to see if the error has a real cause. Unfortunately the error 00116 * message is not always very clear to read, but you can see the reason better 00117 * in the place where the PB_STATIC_ASSERT macro was called. 00118 */ 00119 #ifndef PB_NO_STATIC_ASSERT 00120 #ifndef PB_STATIC_ASSERT 00121 #define PB_STATIC_ASSERT(COND,MSG) typedef char PB_STATIC_ASSERT_MSG(MSG, __LINE__, __COUNTER__)[(COND)?1:-1]; 00122 #define PB_STATIC_ASSERT_MSG(MSG, LINE, COUNTER) PB_STATIC_ASSERT_MSG_(MSG, LINE, COUNTER) 00123 #define PB_STATIC_ASSERT_MSG_(MSG, LINE, COUNTER) pb_static_assertion_##MSG##LINE##COUNTER 00124 #endif 00125 #else 00126 #define PB_STATIC_ASSERT(COND,MSG) 00127 #endif 00128 00129 /* Number of required fields to keep track of. */ 00130 #ifndef PB_MAX_REQUIRED_FIELDS 00131 #define PB_MAX_REQUIRED_FIELDS 64 00132 #endif 00133 00134 #if PB_MAX_REQUIRED_FIELDS < 64 00135 #error You should not lower PB_MAX_REQUIRED_FIELDS from the default value (64). 00136 #endif 00137 00138 /* List of possible field types. These are used in the autogenerated code. 00139 * Least-significant 4 bits tell the scalar type 00140 * Most-significant 4 bits specify repeated/required/packed etc. 00141 */ 00142 00143 typedef uint_least8_t pb_type_t; 00144 00145 /**** Field data types ****/ 00146 00147 /* Numeric types */ 00148 #define PB_LTYPE_VARINT 0x00 /* int32, int64, enum, bool */ 00149 #define PB_LTYPE_UVARINT 0x01 /* uint32, uint64 */ 00150 #define PB_LTYPE_SVARINT 0x02 /* sint32, sint64 */ 00151 #define PB_LTYPE_FIXED32 0x03 /* fixed32, sfixed32, float */ 00152 #define PB_LTYPE_FIXED64 0x04 /* fixed64, sfixed64, double */ 00153 00154 /* Marker for last packable field type. */ 00155 #define PB_LTYPE_LAST_PACKABLE 0x04 00156 00157 /* Byte array with pre-allocated buffer. 00158 * data_size is the length of the allocated PB_BYTES_ARRAY structure. */ 00159 #define PB_LTYPE_BYTES 0x05 00160 00161 /* String with pre-allocated buffer. 00162 * data_size is the maximum length. */ 00163 #define PB_LTYPE_STRING 0x06 00164 00165 /* Submessage 00166 * submsg_fields is pointer to field descriptions */ 00167 #define PB_LTYPE_SUBMESSAGE 0x07 00168 00169 /* Extension pseudo-field 00170 * The field contains a pointer to pb_extension_t */ 00171 #define PB_LTYPE_EXTENSION 0x08 00172 00173 /* Number of declared LTYPES */ 00174 #define PB_LTYPES_COUNT 9 00175 #define PB_LTYPE_MASK 0x0F 00176 00177 /**** Field repetition rules ****/ 00178 00179 #define PB_HTYPE_REQUIRED 0x00 00180 #define PB_HTYPE_OPTIONAL 0x10 00181 #define PB_HTYPE_REPEATED 0x20 00182 #define PB_HTYPE_ONEOF 0x30 00183 #define PB_HTYPE_MASK 0x30 00184 00185 /**** Field allocation types ****/ 00186 00187 #define PB_ATYPE_STATIC 0x00 00188 #define PB_ATYPE_POINTER 0x80 00189 #define PB_ATYPE_CALLBACK 0x40 00190 #define PB_ATYPE_MASK 0xC0 00191 00192 #define PB_ATYPE(x) ((x) & PB_ATYPE_MASK) 00193 #define PB_HTYPE(x) ((x) & PB_HTYPE_MASK) 00194 #define PB_LTYPE(x) ((x) & PB_LTYPE_MASK) 00195 00196 /* Data type used for storing sizes of struct fields 00197 * and array counts. 00198 */ 00199 #if defined(PB_FIELD_32BIT) 00200 typedef uint32_t pb_size_t; 00201 typedef int32_t pb_ssize_t; 00202 #elif defined(PB_FIELD_16BIT) 00203 typedef uint_least16_t pb_size_t; 00204 typedef int_least16_t pb_ssize_t; 00205 #else 00206 typedef uint_least8_t pb_size_t; 00207 typedef int_least8_t pb_ssize_t; 00208 #endif 00209 #define PB_SIZE_MAX ((pb_size_t)-1) 00210 00211 /* Data type for storing encoded data and other byte streams. 00212 * This typedef exists to support platforms where uint8_t does not exist. 00213 * You can regard it as equivalent on uint8_t on other platforms. 00214 */ 00215 typedef uint_least8_t pb_byte_t; 00216 00217 /* This structure is used in auto-generated constants 00218 * to specify struct fields. 00219 * You can change field sizes if you need structures 00220 * larger than 256 bytes or field tags larger than 256. 00221 * The compiler should complain if your .proto has such 00222 * structures. Fix that by defining PB_FIELD_16BIT or 00223 * PB_FIELD_32BIT. 00224 */ 00225 PB_PACKED_STRUCT_START 00226 typedef struct pb_field_s pb_field_t; 00227 struct pb_field_s { 00228 pb_size_t tag; 00229 pb_type_t type; 00230 pb_size_t data_offset; /* Offset of field data, relative to previous field. */ 00231 pb_ssize_t size_offset; /* Offset of array size or has-boolean, relative to data */ 00232 pb_size_t data_size; /* Data size in bytes for a single item */ 00233 pb_size_t array_size; /* Maximum number of entries in array */ 00234 00235 /* Field definitions for submessage 00236 * OR default value for all other non-array, non-callback types 00237 * If null, then field will zeroed. */ 00238 const void *ptr; 00239 } pb_packed; 00240 PB_PACKED_STRUCT_END 00241 00242 /* Make sure that the standard integer types are of the expected sizes. 00243 * Otherwise fixed32/fixed64 fields can break. 00244 * 00245 * If you get errors here, it probably means that your stdint.h is not 00246 * correct for your platform. 00247 */ 00248 PB_STATIC_ASSERT(sizeof(int64_t) == 2 * sizeof(int32_t), INT64_T_WRONG_SIZE) 00249 PB_STATIC_ASSERT(sizeof(uint64_t) == 2 * sizeof(uint32_t), UINT64_T_WRONG_SIZE) 00250 00251 /* This structure is used for 'bytes' arrays. 00252 * It has the number of bytes in the beginning, and after that an array. 00253 * Note that actual structs used will have a different length of bytes array. 00254 */ 00255 #define PB_BYTES_ARRAY_T(n) struct { pb_size_t size; pb_byte_t bytes[n]; } 00256 #define PB_BYTES_ARRAY_T_ALLOCSIZE(n) ((size_t)n + offsetof(pb_bytes_array_t, bytes)) 00257 00258 struct pb_bytes_array_s { 00259 pb_size_t size; 00260 pb_byte_t bytes[1]; 00261 }; 00262 typedef struct pb_bytes_array_s pb_bytes_array_t; 00263 00264 /* This structure is used for giving the callback function. 00265 * It is stored in the message structure and filled in by the method that 00266 * calls pb_decode. 00267 * 00268 * The decoding callback will be given a limited-length stream 00269 * If the wire type was string, the length is the length of the string. 00270 * If the wire type was a varint/fixed32/fixed64, the length is the length 00271 * of the actual value. 00272 * The function may be called multiple times (especially for repeated types, 00273 * but also otherwise if the message happens to contain the field multiple 00274 * times.) 00275 * 00276 * The encoding callback will receive the actual output stream. 00277 * It should write all the data in one call, including the field tag and 00278 * wire type. It can write multiple fields. 00279 * 00280 * The callback can be null if you want to skip a field. 00281 */ 00282 typedef struct pb_istream_s pb_istream_t; 00283 typedef struct pb_ostream_s pb_ostream_t; 00284 typedef struct pb_callback_s pb_callback_t; 00285 struct pb_callback_s { 00286 #ifdef PB_OLD_CALLBACK_STYLE 00287 /* Deprecated since nanopb-0.2.1 */ 00288 union { 00289 bool (*decode)(pb_istream_t *stream, const pb_field_t *field, void *arg); 00290 bool (*encode)(pb_ostream_t *stream, const pb_field_t *field, const void *arg); 00291 } funcs; 00292 #else 00293 /* New function signature, which allows modifying arg contents in callback. */ 00294 union { 00295 bool (*decode)(pb_istream_t *stream, const pb_field_t *field, void **arg); 00296 bool (*encode)(pb_ostream_t *stream, const pb_field_t *field, void * const *arg); 00297 } funcs; 00298 #endif 00299 00300 /* Free arg for use by callback */ 00301 void *arg; 00302 }; 00303 00304 /* Wire types. Library user needs these only in encoder callbacks. */ 00305 typedef enum { 00306 PB_WT_VARINT = 0, 00307 PB_WT_64BIT = 1, 00308 PB_WT_STRING = 2, 00309 PB_WT_32BIT = 5 00310 } pb_wire_type_t; 00311 00312 /* Structure for defining the handling of unknown/extension fields. 00313 * Usually the pb_extension_type_t structure is automatically generated, 00314 * while the pb_extension_t structure is created by the user. However, 00315 * if you want to catch all unknown fields, you can also create a custom 00316 * pb_extension_type_t with your own callback. 00317 */ 00318 typedef struct pb_extension_type_s pb_extension_type_t; 00319 typedef struct pb_extension_s pb_extension_t; 00320 struct pb_extension_type_s { 00321 /* Called for each unknown field in the message. 00322 * If you handle the field, read off all of its data and return true. 00323 * If you do not handle the field, do not read anything and return true. 00324 * If you run into an error, return false. 00325 * Set to NULL for default handler. 00326 */ 00327 bool (*decode)(pb_istream_t *stream, pb_extension_t *extension, 00328 uint32_t tag, pb_wire_type_t wire_type); 00329 00330 /* Called once after all regular fields have been encoded. 00331 * If you have something to write, do so and return true. 00332 * If you do not have anything to write, just return true. 00333 * If you run into an error, return false. 00334 * Set to NULL for default handler. 00335 */ 00336 bool (*encode)(pb_ostream_t *stream, const pb_extension_t *extension); 00337 00338 /* Free field for use by the callback. */ 00339 const void *arg; 00340 }; 00341 00342 struct pb_extension_s { 00343 /* Type describing the extension field. Usually you'll initialize 00344 * this to a pointer to the automatically generated structure. */ 00345 const pb_extension_type_t *type; 00346 00347 /* Destination for the decoded data. This must match the datatype 00348 * of the extension field. */ 00349 void *dest; 00350 00351 /* Pointer to the next extension handler, or NULL. 00352 * If this extension does not match a field, the next handler is 00353 * automatically called. */ 00354 pb_extension_t *next; 00355 00356 /* The decoder sets this to true if the extension was found. 00357 * Ignored for encoding. */ 00358 bool found; 00359 }; 00360 00361 /* Memory allocation functions to use. You can define pb_realloc and 00362 * pb_free to custom functions if you want. */ 00363 #ifdef PB_ENABLE_MALLOC 00364 # ifndef pb_realloc 00365 # define pb_realloc(ptr, size) realloc(ptr, size) 00366 # endif 00367 # ifndef pb_free 00368 # define pb_free(ptr) free(ptr) 00369 # endif 00370 #endif 00371 00372 /* This is used to inform about need to regenerate .pb.h/.pb.c files. */ 00373 #define PB_PROTO_HEADER_VERSION 30 00374 00375 /* These macros are used to declare pb_field_t's in the constant array. */ 00376 /* Size of a structure member, in bytes. */ 00377 #define pb_membersize(st, m) (sizeof ((st*)0)->m) 00378 /* Number of entries in an array. */ 00379 #define pb_arraysize(st, m) (pb_membersize(st, m) / pb_membersize(st, m[0])) 00380 /* Delta from start of one member to the start of another member. */ 00381 #define pb_delta(st, m1, m2) ((int)offsetof(st, m1) - (int)offsetof(st, m2)) 00382 /* Marks the end of the field list */ 00383 #define PB_LAST_FIELD {0,(pb_type_t) 0,0,0,0,0,0} 00384 00385 /* Macros for filling in the data_offset field */ 00386 /* data_offset for first field in a message */ 00387 #define PB_DATAOFFSET_FIRST(st, m1, m2) (offsetof(st, m1)) 00388 /* data_offset for subsequent fields */ 00389 #define PB_DATAOFFSET_OTHER(st, m1, m2) (offsetof(st, m1) - offsetof(st, m2) - pb_membersize(st, m2)) 00390 /* Choose first/other based on m1 == m2 (deprecated, remains for backwards compatibility) */ 00391 #define PB_DATAOFFSET_CHOOSE(st, m1, m2) (int)(offsetof(st, m1) == offsetof(st, m2) \ 00392 ? PB_DATAOFFSET_FIRST(st, m1, m2) \ 00393 : PB_DATAOFFSET_OTHER(st, m1, m2)) 00394 00395 /* Required fields are the simplest. They just have delta (padding) from 00396 * previous field end, and the size of the field. Pointer is used for 00397 * submessages and default values. 00398 */ 00399 #define PB_REQUIRED_STATIC(tag, st, m, fd, ltype, ptr) \ 00400 {tag, PB_ATYPE_STATIC | PB_HTYPE_REQUIRED | ltype, \ 00401 fd, 0, pb_membersize(st, m), 0, ptr} 00402 00403 /* Optional fields add the delta to the has_ variable. */ 00404 #define PB_OPTIONAL_STATIC(tag, st, m, fd, ltype, ptr) \ 00405 {tag, PB_ATYPE_STATIC | PB_HTYPE_OPTIONAL | ltype, \ 00406 fd, \ 00407 pb_delta(st, has_ ## m, m), \ 00408 pb_membersize(st, m), 0, ptr} 00409 00410 /* Repeated fields have a _count field and also the maximum number of entries. */ 00411 #define PB_REPEATED_STATIC(tag, st, m, fd, ltype, ptr) \ 00412 {tag, PB_ATYPE_STATIC | PB_HTYPE_REPEATED | ltype, \ 00413 fd, \ 00414 pb_delta(st, m ## _count, m), \ 00415 pb_membersize(st, m[0]), \ 00416 pb_arraysize(st, m), ptr} 00417 00418 /* Allocated fields carry the size of the actual data, not the pointer */ 00419 #define PB_REQUIRED_POINTER(tag, st, m, fd, ltype, ptr) \ 00420 {tag, PB_ATYPE_POINTER | PB_HTYPE_REQUIRED | ltype, \ 00421 fd, 0, pb_membersize(st, m[0]), 0, ptr} 00422 00423 /* Optional fields don't need a has_ variable, as information would be redundant */ 00424 #define PB_OPTIONAL_POINTER(tag, st, m, fd, ltype, ptr) \ 00425 {tag, PB_ATYPE_POINTER | PB_HTYPE_OPTIONAL | ltype, \ 00426 fd, 0, pb_membersize(st, m[0]), 0, ptr} 00427 00428 /* Repeated fields have a _count field and a pointer to array of pointers */ 00429 #define PB_REPEATED_POINTER(tag, st, m, fd, ltype, ptr) \ 00430 {tag, PB_ATYPE_POINTER | PB_HTYPE_REPEATED | ltype, \ 00431 fd, pb_delta(st, m ## _count, m), \ 00432 pb_membersize(st, m[0]), 0, ptr} 00433 00434 /* Callbacks are much like required fields except with special datatype. */ 00435 #define PB_REQUIRED_CALLBACK(tag, st, m, fd, ltype, ptr) \ 00436 {tag, PB_ATYPE_CALLBACK | PB_HTYPE_REQUIRED | ltype, \ 00437 fd, 0, pb_membersize(st, m), 0, ptr} 00438 00439 #define PB_OPTIONAL_CALLBACK(tag, st, m, fd, ltype, ptr) \ 00440 {tag, PB_ATYPE_CALLBACK | PB_HTYPE_OPTIONAL | ltype, \ 00441 fd, 0, pb_membersize(st, m), 0, ptr} 00442 00443 #define PB_REPEATED_CALLBACK(tag, st, m, fd, ltype, ptr) \ 00444 {tag, PB_ATYPE_CALLBACK | PB_HTYPE_REPEATED | ltype, \ 00445 fd, 0, pb_membersize(st, m), 0, ptr} 00446 00447 /* Optional extensions don't have the has_ field, as that would be redundant. */ 00448 #define PB_OPTEXT_STATIC(tag, st, m, fd, ltype, ptr) \ 00449 {tag, PB_ATYPE_STATIC | PB_HTYPE_OPTIONAL | ltype, \ 00450 0, \ 00451 0, \ 00452 pb_membersize(st, m), 0, ptr} 00453 00454 #define PB_OPTEXT_POINTER(tag, st, m, fd, ltype, ptr) \ 00455 PB_OPTIONAL_POINTER(tag, st, m, fd, ltype, ptr) 00456 00457 #define PB_OPTEXT_CALLBACK(tag, st, m, fd, ltype, ptr) \ 00458 PB_OPTIONAL_CALLBACK(tag, st, m, fd, ltype, ptr) 00459 00460 /* The mapping from protobuf types to LTYPEs is done using these macros. */ 00461 #define PB_LTYPE_MAP_BOOL PB_LTYPE_VARINT 00462 #define PB_LTYPE_MAP_BYTES PB_LTYPE_BYTES 00463 #define PB_LTYPE_MAP_DOUBLE PB_LTYPE_FIXED64 00464 #define PB_LTYPE_MAP_ENUM PB_LTYPE_VARINT 00465 #define PB_LTYPE_MAP_UENUM PB_LTYPE_UVARINT 00466 #define PB_LTYPE_MAP_FIXED32 PB_LTYPE_FIXED32 00467 #define PB_LTYPE_MAP_FIXED64 PB_LTYPE_FIXED64 00468 #define PB_LTYPE_MAP_FLOAT PB_LTYPE_FIXED32 00469 #define PB_LTYPE_MAP_INT32 PB_LTYPE_VARINT 00470 #define PB_LTYPE_MAP_INT64 PB_LTYPE_VARINT 00471 #define PB_LTYPE_MAP_MESSAGE PB_LTYPE_SUBMESSAGE 00472 #define PB_LTYPE_MAP_SFIXED32 PB_LTYPE_FIXED32 00473 #define PB_LTYPE_MAP_SFIXED64 PB_LTYPE_FIXED64 00474 #define PB_LTYPE_MAP_SINT32 PB_LTYPE_SVARINT 00475 #define PB_LTYPE_MAP_SINT64 PB_LTYPE_SVARINT 00476 #define PB_LTYPE_MAP_STRING PB_LTYPE_STRING 00477 #define PB_LTYPE_MAP_UINT32 PB_LTYPE_UVARINT 00478 #define PB_LTYPE_MAP_UINT64 PB_LTYPE_UVARINT 00479 #define PB_LTYPE_MAP_EXTENSION PB_LTYPE_EXTENSION 00480 00481 /* This is the actual macro used in field descriptions. 00482 * It takes these arguments: 00483 * - Field tag number 00484 * - Field type: BOOL, BYTES, DOUBLE, ENUM, UENUM, FIXED32, FIXED64, 00485 * FLOAT, INT32, INT64, MESSAGE, SFIXED32, SFIXED64 00486 * SINT32, SINT64, STRING, UINT32, UINT64 or EXTENSION 00487 * - Field rules: REQUIRED, OPTIONAL or REPEATED 00488 * - Allocation: STATIC or CALLBACK 00489 * - Placement: FIRST or OTHER, depending on if this is the first field in structure. 00490 * - Message name 00491 * - Field name 00492 * - Previous field name (or field name again for first field) 00493 * - Pointer to default value or submsg fields. 00494 */ 00495 00496 #define PB_FIELD(tag, type, rules, allocation, placement, message, field, prevfield, ptr) \ 00497 PB_ ## rules ## _ ## allocation(tag, message, field, \ 00498 PB_DATAOFFSET_ ## placement(message, field, prevfield), \ 00499 PB_LTYPE_MAP_ ## type, ptr) 00500 00501 /* Field description for oneof fields. This requires taking into account the 00502 * union name also, that's why a separate set of macros is needed. 00503 */ 00504 #define PB_ONEOF_STATIC(u, tag, st, m, fd, ltype, ptr) \ 00505 {tag, PB_ATYPE_STATIC | PB_HTYPE_ONEOF | ltype, \ 00506 fd, pb_delta(st, which_ ## u, u.m), \ 00507 pb_membersize(st, u.m), 0, ptr} 00508 00509 #define PB_ONEOF_POINTER(u, tag, st, m, fd, ltype, ptr) \ 00510 {tag, PB_ATYPE_POINTER | PB_HTYPE_ONEOF | ltype, \ 00511 fd, pb_delta(st, which_ ## u, u.m), \ 00512 pb_membersize(st, u.m[0]), 0, ptr} 00513 00514 #define PB_ONEOF_FIELD(union_name, tag, type, rules, allocation, placement, message, field, prevfield, ptr) \ 00515 PB_ONEOF_ ## allocation(union_name, tag, message, field, \ 00516 PB_DATAOFFSET_ ## placement(message, union_name.field, prevfield), \ 00517 PB_LTYPE_MAP_ ## type, ptr) 00518 00519 #define PB_ANONYMOUS_ONEOF_STATIC(u, tag, st, m, fd, ltype, ptr) \ 00520 {tag, PB_ATYPE_STATIC | PB_HTYPE_ONEOF | ltype, \ 00521 fd, pb_delta(st, which_ ## u, m), \ 00522 pb_membersize(st, m), 0, ptr} 00523 00524 #define PB_ANONYMOUS_ONEOF_POINTER(u, tag, st, m, fd, ltype, ptr) \ 00525 {tag, PB_ATYPE_POINTER | PB_HTYPE_ONEOF | ltype, \ 00526 fd, pb_delta(st, which_ ## u, m), \ 00527 pb_membersize(st, m[0]), 0, ptr} 00528 00529 #define PB_ANONYMOUS_ONEOF_FIELD(union_name, tag, type, rules, allocation, placement, message, field, prevfield, ptr) \ 00530 PB_ANONYMOUS_ONEOF_ ## allocation(union_name, tag, message, field, \ 00531 PB_DATAOFFSET_ ## placement(message, field, prevfield), \ 00532 PB_LTYPE_MAP_ ## type, ptr) 00533 00534 /* These macros are used for giving out error messages. 00535 * They are mostly a debugging aid; the main error information 00536 * is the true/false return value from functions. 00537 * Some code space can be saved by disabling the error 00538 * messages if not used. 00539 * 00540 * PB_SET_ERROR() sets the error message if none has been set yet. 00541 * msg must be a constant string literal. 00542 * PB_GET_ERROR() always returns a pointer to a string. 00543 * PB_RETURN_ERROR() sets the error and returns false from current 00544 * function. 00545 */ 00546 #ifdef PB_NO_ERRMSG 00547 #define PB_SET_ERROR(stream, msg) PB_UNUSED(stream) 00548 #define PB_GET_ERROR(stream) "(errmsg disabled)" 00549 #else 00550 #define PB_SET_ERROR(stream, msg) (stream->errmsg = (stream)->errmsg ? (stream)->errmsg : (msg)) 00551 #define PB_GET_ERROR(stream) ((stream)->errmsg ? (stream)->errmsg : "(none)") 00552 #endif 00553 00554 #define PB_RETURN_ERROR(stream, msg) return PB_SET_ERROR(stream, msg), false 00555 00556 #endif
Generated on Tue Jul 12 2022 16:00:21 by
