Add section in pb.h for changing compilation settings.

Update issue 76
Status: FixedInGit
This commit is contained in:
Petteri Aimonen
2013-07-06 15:27:31 +03:00
parent 4b705bf64b
commit 0ed3158560
2 changed files with 64 additions and 19 deletions

View File

@@ -11,9 +11,13 @@ Nanopb: API reference
Compilation options Compilation options
=================== ===================
The following options can be specified using -D switch given to the C compiler The following options can be specified in one of two ways:
when compiling the nanopb library and applications using it. You must have the
same settings for the nanopb library and all code that includes pb.h. 1. Using the -D switch on the C compiler command line.
2. By #defining them at the top of pb.h.
You must have the same settings for the nanopb library and all code that
includes pb.h.
============================ ================================================ ============================ ================================================
__BIG_ENDIAN__ Set this if your platform stores integers and __BIG_ENDIAN__ Set this if your platform stores integers and

73
pb.h
View File

@@ -1,13 +1,61 @@
/* Common parts of the nanopb library. Most of these are quite low-level
* stuff. For the high-level interface, see pb_encode.h and pb_decode.h.
*/
#ifndef _PB_H_ #ifndef _PB_H_
#define _PB_H_ #define _PB_H_
/* pb.h: Common parts for nanopb library. /*****************************************************************
* Most of these are quite low-level stuff. For the high-level interface, * Nanopb compilation time options. You can change these here by *
* see pb_encode.h or pb_decode.h * uncommenting the lines, or on the compiler command line. *
*/ *****************************************************************/
/* Define this if your CPU architecture is big endian, i.e. it
* stores the most-significant byte first. */
/* #define __BIG_ENDIAN__ 1 */
/* Increase the number of required fields that are tracked.
* A compiler warning will tell if you need this. */
/* #define PB_MAX_REQUIRED_FIELDS 256 */
/* Add support for tag numbers > 255 and fields larger than 255 bytes. */
/* #define PB_FIELD_16BIT 1 */
/* Add support for tag numbers > 65536 and fields larger than 65536 bytes. */
/* #define PB_FIELD_32BIT 1 */
/* Disable support for error messages in order to save some code space. */
/* #define PB_NO_ERRMSG 1 */
/* Disable support for custom streams (support only memory buffers). */
/* #define PB_BUFFER_ONLY 1 */
/* Switch back to the old-style callback function signature.
* This was the default until nanopb-0.2.1. */
/* #define PB_OLD_CALLBACK_STYLE */
/******************************************************************
* You usually don't need to change anything below this line. *
* Feel free to look around and use the defined macros, though. *
******************************************************************/
/* Version of the nanopb library. Just in case you want to check it in
* your own program. */
#define NANOPB_VERSION nanopb-0.2.2-dev #define NANOPB_VERSION nanopb-0.2.2-dev
/* Include all the system headers needed by nanopb. You will need the
* definitions of the following:
* - strlen, memcpy, memset functions
* - [u]int8_t, [u]int16_t, [u]int32_t, [u]int64_t
* - size_t
* - bool
*
* If you don't have the standard header files, you can instead provide
* a custom header that defines or includes all this. In that case,
* define PB_SYSTEM_HEADER to the path of this file.
*/
#ifdef PB_SYSTEM_HEADER #ifdef PB_SYSTEM_HEADER
#include PB_SYSTEM_HEADER #include PB_SYSTEM_HEADER
#else #else
@@ -42,7 +90,7 @@
# define pb_packed # define pb_packed
#endif #endif
/* Handly macro for suppressing unreferenced-parameter compiler warnings. */ /* Handly macro for suppressing unreferenced-parameter compiler warnings. */
#ifndef UNUSED #ifndef UNUSED
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)
#endif #endif
@@ -56,8 +104,7 @@
#define STATIC_ASSERT_MSG_(MSG, LINE, COUNTER) static_assertion_##MSG##LINE##COUNTER #define STATIC_ASSERT_MSG_(MSG, LINE, COUNTER) static_assertion_##MSG##LINE##COUNTER
#endif #endif
/* Number of required fields to keep track of /* Number of required fields to keep track of. */
* (change here or on compiler command line). */
#ifndef PB_MAX_REQUIRED_FIELDS #ifndef PB_MAX_REQUIRED_FIELDS
#define PB_MAX_REQUIRED_FIELDS 64 #define PB_MAX_REQUIRED_FIELDS 64
#endif #endif
@@ -78,9 +125,7 @@
typedef uint8_t pb_type_t; typedef uint8_t pb_type_t;
/************************ /**** Field data types ****/
* Field contents types *
************************/
/* Numeric types */ /* Numeric types */
#define PB_LTYPE_VARINT 0x00 /* int32, uint32, int64, uint64, bool, enum */ #define PB_LTYPE_VARINT 0x00 /* int32, uint32, int64, uint64, bool, enum */
@@ -107,18 +152,14 @@ typedef uint8_t pb_type_t;
#define PB_LTYPES_COUNT 7 #define PB_LTYPES_COUNT 7
#define PB_LTYPE_MASK 0x0F #define PB_LTYPE_MASK 0x0F
/************************** /**** Field repetition rules ****/
* Field repetition rules *
**************************/
#define PB_HTYPE_REQUIRED 0x00 #define PB_HTYPE_REQUIRED 0x00
#define PB_HTYPE_OPTIONAL 0x10 #define PB_HTYPE_OPTIONAL 0x10
#define PB_HTYPE_REPEATED 0x20 #define PB_HTYPE_REPEATED 0x20
#define PB_HTYPE_MASK 0x30 #define PB_HTYPE_MASK 0x30
/******************** /**** Field allocation types ****/
* Allocation types *
********************/
#define PB_ATYPE_STATIC 0x00 #define PB_ATYPE_STATIC 0x00
#define PB_ATYPE_CALLBACK 0x40 #define PB_ATYPE_CALLBACK 0x40