X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=pb.h;h=85f4421cbf711079e682bd7af6f3b0659019f3c8;hb=f1d7640fe1be0f150f604c72108ea516222c2505;hp=a81e9ef4487a45242dfcb1fd415e6ded756f10cc;hpb=78086cc27d746a425f3f1130e822275bdb623090;p=apps%2Fagl-service-can-low-level.git diff --git a/pb.h b/pb.h index a81e9ef4..85f4421c 100644 --- a/pb.h +++ b/pb.h @@ -33,6 +33,10 @@ #define PB_MAX_REQUIRED_FIELDS 64 #endif +#if PB_MAX_REQUIRED_FIELDS < 64 +#error You should not lower PB_MAX_REQUIRED_FIELDS from the default value (64). +#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 +103,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; @@ -182,7 +194,25 @@ typedef enum { #define pb_arraysize(st, m) (pb_membersize(st, m) / pb_membersize(st, m[0])) #define pb_delta(st, m1, m2) ((int)offsetof(st, m1) - (int)offsetof(st, m2)) #define pb_delta_end(st, m1, m2) (offsetof(st, m1) - offsetof(st, m2) - pb_membersize(st, m2)) -#define PB_LAST_FIELD {0,0,0,0} +#define PB_LAST_FIELD {0,(pb_type_t) 0,0,0} +/* These macros are used for giving out error messages. + * They are mostly a debugging aid; the main error information + * is the true/false return value from functions. + * Some code space can be saved by disabling the error + * messages if not used. + */ +#ifdef PB_NO_ERRMSG +#define PB_RETURN_ERROR(stream,msg) return false +#define PB_GET_ERROR(stream) "(errmsg disabled)" +#else +#define PB_RETURN_ERROR(stream,msg) \ + do {\ + if ((stream)->errmsg == NULL) \ + (stream)->errmsg = (msg); \ + return false; \ + } while(0) +#define PB_GET_ERROR(stream) ((stream)->errmsg ? (stream)->errmsg : "(none)") +#endif #endif