Convert pb_type_t to uint8_t.
PB_HTYPE_x | PB_LTYPE_x becomes an int according to C, and some compilers warn when assigning that to an enum value. Also correct an associated term in reference.rst. git-svn-id: https://svn.kapsi.fi/jpa/nanopb-dev@1006 e3a754e5-d11d-0410-8d38-ebb782a927b9
This commit is contained in:
committed by
Petteri Aimonen
parent
13b6988b64
commit
dcf43a6416
@@ -13,9 +13,9 @@ pb_type_t
|
|||||||
---------
|
---------
|
||||||
Defines the encoder/decoder behaviour that should be used for a field. ::
|
Defines the encoder/decoder behaviour that should be used for a field. ::
|
||||||
|
|
||||||
typedef enum { ... } pb_type_t;
|
typedef uint8_t pb_type_t;
|
||||||
|
|
||||||
The low-order byte of the enumeration values defines the function that can be used for encoding and decoding the field data:
|
The low-order nibble of the enumeration values defines the function that can be used for encoding and decoding the field data:
|
||||||
|
|
||||||
==================== ===== ================================================
|
==================== ===== ================================================
|
||||||
LTYPE identifier Value Storage format
|
LTYPE identifier Value Storage format
|
||||||
@@ -28,7 +28,7 @@ PB_LTYPE_STRING 0x04 Null-terminated string.
|
|||||||
PB_LTYPE_SUBMESSAGE 0x05 Submessage structure.
|
PB_LTYPE_SUBMESSAGE 0x05 Submessage structure.
|
||||||
==================== ===== ================================================
|
==================== ===== ================================================
|
||||||
|
|
||||||
The high-order byte defines whether the field is required, optional, repeated or callback:
|
The high-order nibble defines whether the field is required, optional, repeated or callback:
|
||||||
|
|
||||||
==================== ===== ================================================
|
==================== ===== ================================================
|
||||||
HTYPE identifier Value Field handling
|
HTYPE identifier Value Field handling
|
||||||
|
|||||||
78
pb.h
78
pb.h
@@ -27,56 +27,56 @@
|
|||||||
* SINT* is different, though, because it is zig-zag coded.
|
* SINT* is different, though, because it is zig-zag coded.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef enum {
|
/************************
|
||||||
/************************
|
* Field contents types *
|
||||||
* Field contents types *
|
************************/
|
||||||
************************/
|
|
||||||
|
|
||||||
/* Numeric types */
|
typedef uint8_t pb_type_t;
|
||||||
PB_LTYPE_VARINT = 0x00, /* int32, uint32, int64, uint64, bool, enum */
|
|
||||||
PB_LTYPE_SVARINT = 0x01, /* sint32, sint64 */
|
|
||||||
PB_LTYPE_FIXED32 = 0x02, /* fixed32, sfixed32, float */
|
|
||||||
PB_LTYPE_FIXED64 = 0x03, /* fixed64, sfixed64, double */
|
|
||||||
|
|
||||||
/* Marker for last packable field type. */
|
/* Numeric types */
|
||||||
PB_LTYPE_LAST_PACKABLE = 0x03,
|
#define PB_LTYPE_VARINT 0x00 /* int32, uint32, int64, uint64, bool, enum */
|
||||||
|
#define PB_LTYPE_SVARINT 0x01 /* sint32, sint64 */
|
||||||
|
#define PB_LTYPE_FIXED32 0x02 /* fixed32, sfixed32, float */
|
||||||
|
#define PB_LTYPE_FIXED64 0x03 /* fixed64, sfixed64, double */
|
||||||
|
|
||||||
/* Byte array with pre-allocated buffer.
|
/* Marker for last packable field type. */
|
||||||
* data_size is the length of the allocated PB_BYTES_ARRAY structure. */
|
#define PB_LTYPE_LAST_PACKABLE 0x03
|
||||||
PB_LTYPE_BYTES = 0x04,
|
|
||||||
|
|
||||||
/* String with pre-allocated buffer.
|
/* Byte array with pre-allocated buffer.
|
||||||
* data_size is the maximum length. */
|
* data_size is the length of the allocated PB_BYTES_ARRAY structure. */
|
||||||
PB_LTYPE_STRING = 0x05,
|
#define PB_LTYPE_BYTES 0x04
|
||||||
|
|
||||||
/* Submessage
|
/* String with pre-allocated buffer.
|
||||||
* submsg_fields is pointer to field descriptions */
|
* data_size is the maximum length. */
|
||||||
PB_LTYPE_SUBMESSAGE = 0x06,
|
#define PB_LTYPE_STRING 0x05
|
||||||
|
|
||||||
/* Number of declared LTYPES */
|
/* Submessage
|
||||||
PB_LTYPES_COUNT = 7,
|
* submsg_fields is pointer to field descriptions */
|
||||||
|
#define PB_LTYPE_SUBMESSAGE 0x06
|
||||||
|
|
||||||
/******************
|
/* Number of declared LTYPES */
|
||||||
* Modifier flags *
|
#define PB_LTYPES_COUNT 7
|
||||||
******************/
|
|
||||||
|
|
||||||
/* Just the basic, write data at data_offset */
|
/******************
|
||||||
PB_HTYPE_REQUIRED = 0x00,
|
* Modifier flags *
|
||||||
|
******************/
|
||||||
|
|
||||||
/* Write true at size_offset */
|
/* Just the basic, write data at data_offset */
|
||||||
PB_HTYPE_OPTIONAL = 0x10,
|
#define PB_HTYPE_REQUIRED 0x00
|
||||||
|
|
||||||
/* Read to pre-allocated array
|
/* Write true at size_offset */
|
||||||
* Maximum number of entries is array_size,
|
#define PB_HTYPE_OPTIONAL 0x10
|
||||||
* actual number is stored at size_offset */
|
|
||||||
PB_HTYPE_ARRAY = 0x20,
|
|
||||||
|
|
||||||
/* Works for all required/optional/repeated fields.
|
/* Read to pre-allocated array
|
||||||
* data_offset points to pb_callback_t structure.
|
* Maximum number of entries is array_size,
|
||||||
* LTYPE should be 0 (it is ignored, but sometimes
|
* actual number is stored at size_offset */
|
||||||
* used to speculatively index an array). */
|
#define PB_HTYPE_ARRAY 0x20
|
||||||
PB_HTYPE_CALLBACK = 0x30
|
|
||||||
} pb_packed pb_type_t;
|
/* Works for all required/optional/repeated fields.
|
||||||
|
* data_offset points to pb_callback_t structure.
|
||||||
|
* LTYPE should be 0 (it is ignored, but sometimes
|
||||||
|
* used to speculatively index an array). */
|
||||||
|
#define PB_HTYPE_CALLBACK 0x30
|
||||||
|
|
||||||
#define PB_HTYPE(x) ((x) & 0xF0)
|
#define PB_HTYPE(x) ((x) & 0xF0)
|
||||||
#define PB_LTYPE(x) ((x) & 0x0F)
|
#define PB_LTYPE(x) ((x) & 0x0F)
|
||||||
|
|||||||
Reference in New Issue
Block a user