summaryrefslogtreecommitdiffstats
path: root/pb.h
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-07-01 10:15:37 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-07-01 10:15:37 +0300
commit9b1e1b440ab6a21bacab939b9c7bef0fa4ca5c90 (patch)
tree9b40693e48350c83c07829cd6770088c49b204fc /pb.h
parent78086cc27d746a425f3f1130e822275bdb623090 (diff)
Replace PB_MANY_FIELDS with PB_FIELD_16BIT and PB_FIELD_32BIT.
This allows more precise control over the memory use vs. field size.
Diffstat (limited to 'pb.h')
-rw-r--r--pb.h19
1 files changed, 16 insertions, 3 deletions
diff --git a/pb.h b/pb.h
index a81e9ef4..d030d9e3 100644
--- a/pb.h
+++ b/pb.h
@@ -33,6 +33,11 @@
#define PB_MAX_REQUIRED_FIELDS 64
#endif
+#if PB_MAX_REQUIRED_FIELDS < 64
+#warning You should not lower PB_MAX_REQUIRED_FIELDS from the default value (64). \
+ The automatic checks against too low value will not be active.
+#endif
+
/* List of possible field types. These are used in the autogenerated code.
* Least-significant 4 bits tell the scalar type
* Most-significant 4 bits specify repeated/required/packed etc.
@@ -99,21 +104,29 @@ typedef enum {
/* This structure is used in auto-generated constants
* to specify struct fields.
- * You can change field sizes here if you need structures
+ * You can change field sizes if you need structures
* larger than 256 bytes or field tags larger than 256.
* The compiler should complain if your .proto has such
- * structures ("initializer too large for type").
+ * structures. Fix that by defining PB_FIELD_16BIT or
+ * PB_FIELD_32BIT.
*/
typedef struct _pb_field_t pb_field_t;
struct _pb_field_t {
-#ifndef PB_MANY_FIELDS
+#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT)
uint8_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;