From: Petteri Aimonen Date: Sun, 20 Oct 2013 18:49:55 +0000 (+0300) Subject: Define pb_size_t and pb_ssize_t data types. X-Git-Tag: 5.0.2~186^2~338 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=2bfd497eea857d19a09054c5c54f3718b08dc8c9;hp=e83fbd18d3fa33af8a57198cddefe5fcef1b2f58;p=apps%2Fagl-service-can-low-level.git Define pb_size_t and pb_ssize_t data types. Use these in pb_field_t definition to clean up some #ifs, and also to prepare for solving issue #82. --- diff --git a/pb.h b/pb.h index 8b501dec..04a8288b 100644 --- a/pb.h +++ b/pb.h @@ -173,6 +173,20 @@ typedef uint8_t pb_type_t; #define PB_HTYPE(x) ((x) & PB_HTYPE_MASK) #define PB_LTYPE(x) ((x) & PB_LTYPE_MASK) +/* Data type used for storing sizes of struct fields + * and array counts. + */ +#if defined(PB_FIELD_32BIT) + typedef uint32_t pb_size_t; + typedef int32_t pb_ssize_t; +#elif defined(PB_FIELD_16BIT) + typedef uint16_t pb_size_t; + typedef int16_t pb_ssize_t; +#else + typedef uint8_t pb_size_t; + typedef int8_t pb_ssize_t; +#endif + /* This structure is used in auto-generated constants * to specify struct fields. * You can change field sizes if you need structures @@ -184,29 +198,12 @@ typedef uint8_t pb_type_t; PB_PACKED_STRUCT_START typedef struct _pb_field_t pb_field_t; struct _pb_field_t { - -#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT) - uint8_t tag; + pb_size_t tag; pb_type_t type; - uint8_t data_offset; /* Offset of field data, relative to previous field. */ - int8_t size_offset; /* Offset of array size or has-boolean, relative to data */ - uint8_t data_size; /* Data size in bytes for a single item */ - uint8_t array_size; /* Maximum number of entries in array */ -#elif defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT) - uint16_t tag; - pb_type_t type; - uint8_t data_offset; - int8_t size_offset; - uint16_t data_size; - uint16_t array_size; -#else - uint32_t tag; - pb_type_t type; - uint8_t data_offset; - int8_t size_offset; - uint32_t data_size; - uint32_t array_size; -#endif + pb_size_t data_offset; /* Offset of field data, relative to previous field. */ + pb_ssize_t size_offset; /* Offset of array size or has-boolean, relative to data */ + pb_size_t data_size; /* Data size in bytes for a single item */ + pb_size_t array_size; /* Maximum number of entries in array */ /* Field definitions for submessage * OR default value for all other non-array, non-callback types