From 9b1e1b440ab6a21bacab939b9c7bef0fa4ca5c90 Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Sun, 1 Jul 2012 10:15:37 +0300 Subject: Replace PB_MANY_FIELDS with PB_FIELD_16BIT and PB_FIELD_32BIT. This allows more precise control over the memory use vs. field size. --- pb.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'pb.h') diff --git a/pb.h b/pb.h index a81e9ef..d030d9e 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; -- cgit 1.2.3-korg