Fix crash in pb_release() if called twice on same message.
[apps/agl-service-can-low-level.git] / pb.h
diff --git a/pb.h b/pb.h
index 8ddf30e..fc30147 100644 (file)
--- a/pb.h
+++ b/pb.h
@@ -2,8 +2,8 @@
  * stuff. For the high-level interface, see pb_encode.h and pb_decode.h.
  */
 
-#ifndef _PB_H_
-#define _PB_H_
+#ifndef PB_H_INCLUDED
+#define PB_H_INCLUDED
 
 /*****************************************************************
  * Nanopb compilation time options. You can change these here by *
@@ -46,7 +46,7 @@
 
 /* Version of the nanopb library. Just in case you want to check it in
  * your own program. */
-#define NANOPB_VERSION nanopb-0.3.0-dev
+#define NANOPB_VERSION nanopb-0.3.1-dev
 
 /* Include all the system headers needed by nanopb. You will need the
  * definitions of the following:
@@ -213,8 +213,8 @@ typedef uint8_t pb_type_t;
  * PB_FIELD_32BIT.
  */
 PB_PACKED_STRUCT_START
-typedef struct _pb_field_t pb_field_t;
-struct _pb_field_t {
+typedef struct pb_field_s pb_field_t;
+struct pb_field_s {
     pb_size_t tag;
     pb_type_t type;
     pb_size_t data_offset; /* Offset of field data, relative to previous field. */
@@ -251,11 +251,11 @@ PB_STATIC_ASSERT(sizeof(uint64_t) == 8, UINT64_T_WRONG_SIZE)
 #define PB_BYTES_ARRAY_T(n) struct { pb_size_t size; uint8_t bytes[n]; }
 #define PB_BYTES_ARRAY_T_ALLOCSIZE(n) ((size_t)n + offsetof(pb_bytes_array_t, bytes))
 
-struct _pb_bytes_array_t {
+struct pb_bytes_array_s {
     pb_size_t size;
     uint8_t bytes[1];
 };
-typedef struct _pb_bytes_array_t pb_bytes_array_t;
+typedef struct pb_bytes_array_s pb_bytes_array_t;
 
 /* This structure is used for giving the callback function.
  * It is stored in the message structure and filled in by the method that
@@ -275,10 +275,10 @@ typedef struct _pb_bytes_array_t pb_bytes_array_t;
  *
  * The callback can be null if you want to skip a field.
  */
-typedef struct _pb_istream_t pb_istream_t;
-typedef struct _pb_ostream_t pb_ostream_t;
-typedef struct _pb_callback_t pb_callback_t;
-struct _pb_callback_t {
+typedef struct pb_istream_s pb_istream_t;
+typedef struct pb_ostream_s pb_ostream_t;
+typedef struct pb_callback_s pb_callback_t;
+struct pb_callback_s {
 #ifdef PB_OLD_CALLBACK_STYLE
     /* Deprecated since nanopb-0.2.1 */
     union {
@@ -311,9 +311,9 @@ typedef enum {
  * if you want to catch all unknown fields, you can also create a custom
  * pb_extension_type_t with your own callback.
  */
-typedef struct _pb_extension_type_t pb_extension_type_t;
-typedef struct _pb_extension_t pb_extension_t;
-struct _pb_extension_type_t {
+typedef struct pb_extension_type_s pb_extension_type_t;
+typedef struct pb_extension_s pb_extension_t;
+struct pb_extension_type_s {
     /* Called for each unknown field in the message.
      * If you handle the field, read off all of its data and return true.
      * If you do not handle the field, do not read anything and return true.
@@ -335,7 +335,7 @@ struct _pb_extension_type_t {
     const void *arg;
 };
 
-struct _pb_extension_t {
+struct pb_extension_s {
     /* Type describing the extension field. Usually you'll initialize
      * this to a pointer to the automatically generated structure. */
     const pb_extension_type_t *type;
@@ -365,6 +365,9 @@ struct _pb_extension_t {
 #   endif
 #endif
 
+/* This is used to inform about need to regenerate .pb.h/.pb.c files. */
+#define PB_PROTO_HEADER_VERSION 30
+
 /* These macros are used to declare pb_field_t's in the constant array. */
 /* Size of a structure member, in bytes. */
 #define pb_membersize(st, m) (sizeof ((st*)0)->m)
@@ -476,26 +479,15 @@ struct _pb_extension_t {
  *                 SINT32, SINT64, STRING, UINT32, UINT64 or EXTENSION
  * - Field rules:  REQUIRED, OPTIONAL or REPEATED
  * - Allocation:   STATIC or CALLBACK
+ * - Placement: FIRST or OTHER, depending on if this is the first field in structure.
  * - Message name
  * - Field name
  * - Previous field name (or field name again for first field)
  * - Pointer to default value or submsg fields.
  */
 
-#define PB_FIELD(tag, type, rules, allocation, message, field, prevfield, ptr) \
-    PB_ ## rules ## _ ## allocation(tag, message, field, \
-        PB_DATAOFFSET_CHOOSE(message, field, prevfield), \
-        PB_LTYPE_MAP_ ## type, ptr)
-
-/* This is a new version of the macro used by nanopb generator from
- * version 0.2.3 onwards. It avoids the use of a ternary expression in
- * the initialization, which confused some compilers.
- *
- * - Placement: FIRST or OTHER, depending on if this is the first field in structure.
- *
- */
-#define PB_FIELD2(tag, type, rules, allocation, placement, message, field, prevfield, ptr) \
-    PB_ ## rules ## _ ## allocation(tag, message, field, \
+#define PB_FIELD(tag, type, rules, allocation, placement, message, field, prevfield, ptr) \
+        PB_ ## rules ## _ ## allocation(tag, message, field, \
         PB_DATAOFFSET_ ## placement(message, field, prevfield), \
         PB_LTYPE_MAP_ ## type, ptr)