summaryrefslogtreecommitdiffstats
path: root/pb.h
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-10-20 21:49:55 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-10-20 21:49:55 +0300
commit2bfd497eea857d19a09054c5c54f3718b08dc8c9 (patch)
tree18406647052239ca7de9dd66f2dd39a465fafdc4 /pb.h
parente83fbd18d3fa33af8a57198cddefe5fcef1b2f58 (diff)
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.
Diffstat (limited to 'pb.h')
-rw-r--r--pb.h41
1 files changed, 19 insertions, 22 deletions
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