test

Dependencies:   Nanopb iSerial mbed BaseJpegDecode FatFileSystem SDFileSystem RingBuffer Camera_LS_Y201

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pb.h Source File

pb.h

00001 /* Common parts of the nanopb library. Most of these are quite low-level
00002  * stuff. For the high-level interface, see pb_encode.h and pb_decode.h.
00003  */
00004 
00005 #ifndef _PB_H_
00006 #define _PB_H_
00007 
00008 /*****************************************************************
00009  * Nanopb compilation time options. You can change these here by *
00010  * uncommenting the lines, or on the compiler command line.      *
00011  *****************************************************************/
00012 
00013 /* Define this if your CPU architecture is big endian, i.e. it
00014  * stores the most-significant byte first. */
00015 /* #define __BIG_ENDIAN__ 1 */
00016 
00017 /* Increase the number of required fields that are tracked.
00018  * A compiler warning will tell if you need this. */
00019 /* #define PB_MAX_REQUIRED_FIELDS 256 */
00020 
00021 /* Add support for tag numbers > 255 and fields larger than 255 bytes. */
00022 /* #define PB_FIELD_16BIT 1 */
00023 
00024 /* Add support for tag numbers > 65536 and fields larger than 65536 bytes. */
00025 /* #define PB_FIELD_32BIT 1 */
00026 
00027 /* Disable support for error messages in order to save some code space. */
00028 /* #define PB_NO_ERRMSG 1 */
00029 
00030 /* Disable support for custom streams (support only memory buffers). */
00031 /* #define PB_BUFFER_ONLY 1 */
00032 
00033 /* Switch back to the old-style callback function signature.
00034  * This was the default until nanopb-0.2.1. */
00035 /* #define PB_OLD_CALLBACK_STYLE */
00036 
00037 
00038 /******************************************************************
00039  * You usually don't need to change anything below this line.     *
00040  * Feel free to look around and use the defined macros, though.   *
00041  ******************************************************************/
00042 
00043 
00044 /* Version of the nanopb library. Just in case you want to check it in
00045  * your own program. */
00046 #define NANOPB_VERSION nanopb-0.2.6
00047 
00048 /* Include all the system headers needed by nanopb. You will need the
00049  * definitions of the following:
00050  * - strlen, memcpy, memset functions
00051  * - [u]int8_t, [u]int16_t, [u]int32_t, [u]int64_t
00052  * - size_t
00053  * - bool
00054  *
00055  * If you don't have the standard header files, you can instead provide
00056  * a custom header that defines or includes all this. In that case,
00057  * define PB_SYSTEM_HEADER to the path of this file.
00058  */
00059 #ifdef PB_SYSTEM_HEADER
00060 #include PB_SYSTEM_HEADER
00061 #else
00062 #include <stdint.h>
00063 #include <stddef.h>
00064 #include <stdbool.h>
00065 #include <string.h>
00066 #endif
00067 
00068 #define PB_FIELD_32BIT 1
00069 
00070 /* Macro for defining packed structures (compiler dependent).
00071  * This just reduces memory requirements, but is not required.
00072  */
00073 #if defined(__GNUC__) || defined(__clang__)
00074     /* For GCC and clang */
00075 #   define PB_PACKED_STRUCT_START
00076 #   define PB_PACKED_STRUCT_END
00077 #   define pb_packed __attribute__((packed))
00078 #elif defined(__ICCARM__)
00079     /* For IAR ARM compiler */
00080 #   define PB_PACKED_STRUCT_START _Pragma("pack(push, 1)")
00081 #   define PB_PACKED_STRUCT_END _Pragma("pack(pop)")
00082 #   define pb_packed
00083 #elif defined(_MSC_VER) && (_MSC_VER >= 1500)
00084     /* For Microsoft Visual C++ */
00085 #   define PB_PACKED_STRUCT_START __pragma(pack(push, 1))
00086 #   define PB_PACKED_STRUCT_END __pragma(pack(pop))
00087 #   define pb_packed
00088 #else
00089     /* Unknown compiler */
00090 #   define PB_PACKED_STRUCT_START
00091 #   define PB_PACKED_STRUCT_END
00092 #   define pb_packed
00093 #endif
00094 
00095 /* Handly macro for suppressing unreferenced-parameter compiler warnings. */
00096 #ifndef UNUSED
00097 #define UNUSED(x) (void)(x)
00098 #endif
00099 
00100 /* Compile-time assertion, used for checking compatible compilation options.
00101  * If this does not work properly on your compiler, use #define STATIC_ASSERT
00102  * to disable it.
00103  *
00104  * But before doing that, check carefully the error message / place where it
00105  * comes from to see if the error has a real cause. Unfortunately the error
00106  * message is not always very clear to read, but you can see the reason better
00107  * in the place where the STATIC_ASSERT macro was called.
00108  */
00109 #ifndef STATIC_ASSERT
00110 #define STATIC_ASSERT(COND,MSG) typedef char STATIC_ASSERT_MSG(MSG, __LINE__, __COUNTER__)[(COND)?1:-1];
00111 #define STATIC_ASSERT_MSG(MSG, LINE, COUNTER) STATIC_ASSERT_MSG_(MSG, LINE, COUNTER)
00112 #define STATIC_ASSERT_MSG_(MSG, LINE, COUNTER) static_assertion_##MSG##LINE##COUNTER
00113 #endif
00114 
00115 /* Number of required fields to keep track of. */
00116 #ifndef PB_MAX_REQUIRED_FIELDS
00117 #define PB_MAX_REQUIRED_FIELDS 64
00118 #endif
00119 
00120 #if PB_MAX_REQUIRED_FIELDS < 64
00121 #error You should not lower PB_MAX_REQUIRED_FIELDS from the default value (64).
00122 #endif
00123 
00124 /* List of possible field types. These are used in the autogenerated code.
00125  * Least-significant 4 bits tell the scalar type
00126  * Most-significant 4 bits specify repeated/required/packed etc.
00127  */
00128 
00129 typedef uint8_t pb_type_t;
00130 
00131 /**** Field data types ****/
00132 
00133 /* Numeric types */
00134 #define PB_LTYPE_VARINT  0x00 /* int32, int64, enum, bool */
00135 #define PB_LTYPE_UVARINT 0x01 /* uint32, uint64 */
00136 #define PB_LTYPE_SVARINT 0x02 /* sint32, sint64 */
00137 #define PB_LTYPE_FIXED32 0x03 /* fixed32, sfixed32, float */
00138 #define PB_LTYPE_FIXED64 0x04 /* fixed64, sfixed64, double */
00139 
00140 /* Marker for last packable field type. */
00141 #define PB_LTYPE_LAST_PACKABLE 0x04
00142 
00143 /* Byte array with pre-allocated buffer.
00144  * data_size is the length of the allocated PB_BYTES_ARRAY structure. */
00145 #define PB_LTYPE_BYTES 0x05
00146 
00147 /* String with pre-allocated buffer.
00148  * data_size is the maximum length. */
00149 #define PB_LTYPE_STRING 0x06
00150 
00151 /* Submessage
00152  * submsg_fields is pointer to field descriptions */
00153 #define PB_LTYPE_SUBMESSAGE 0x07
00154 
00155 /* Extension pseudo-field
00156  * The field contains a pointer to pb_extension_t */
00157 #define PB_LTYPE_EXTENSION 0x08
00158 
00159 /* Number of declared LTYPES */
00160 #define PB_LTYPES_COUNT 9
00161 #define PB_LTYPE_MASK 0x0F
00162 
00163 /**** Field repetition rules ****/
00164 
00165 #define PB_HTYPE_REQUIRED 0x00
00166 #define PB_HTYPE_OPTIONAL 0x10
00167 #define PB_HTYPE_REPEATED 0x20
00168 #define PB_HTYPE_MASK     0x30
00169 
00170 /**** Field allocation types ****/
00171  
00172 #define PB_ATYPE_STATIC   0x00
00173 #define PB_ATYPE_POINTER  0x80
00174 #define PB_ATYPE_CALLBACK 0x40
00175 #define PB_ATYPE_MASK     0xC0
00176 
00177 #define PB_ATYPE(x) ((x) & PB_ATYPE_MASK)
00178 #define PB_HTYPE(x) ((x) & PB_HTYPE_MASK)
00179 #define PB_LTYPE(x) ((x) & PB_LTYPE_MASK)
00180 
00181 /* Data type used for storing sizes of struct fields
00182  * and array counts.
00183  */
00184 #if defined(PB_FIELD_32BIT)
00185     typedef uint32_t pb_size_t;
00186     typedef int32_t pb_ssize_t;
00187 #elif defined(PB_FIELD_16BIT)
00188     typedef uint16_t pb_size_t;
00189     typedef int16_t pb_ssize_t;
00190 #else
00191     typedef uint8_t pb_size_t;
00192     typedef int8_t pb_ssize_t;
00193 #endif
00194 
00195 /* This structure is used in auto-generated constants
00196  * to specify struct fields.
00197  * You can change field sizes if you need structures
00198  * larger than 256 bytes or field tags larger than 256.
00199  * The compiler should complain if your .proto has such
00200  * structures. Fix that by defining PB_FIELD_16BIT or
00201  * PB_FIELD_32BIT.
00202  */
00203 PB_PACKED_STRUCT_START
00204 typedef struct _pb_field_t pb_field_t;
00205 struct _pb_field_t {
00206     pb_size_t tag;
00207     pb_type_t type;
00208     pb_size_t data_offset; /* Offset of field data, relative to previous field. */
00209     pb_ssize_t size_offset; /* Offset of array size or has-boolean, relative to data */
00210     pb_size_t data_size; /* Data size in bytes for a single item */
00211     pb_size_t array_size; /* Maximum number of entries in array */
00212     
00213     /* Field definitions for submessage
00214      * OR default value for all other non-array, non-callback types
00215      * If null, then field will zeroed. */
00216     const void *ptr;
00217 } pb_packed;
00218 PB_PACKED_STRUCT_END
00219 
00220 /* Make sure that the standard integer types are of the expected sizes.
00221  * All kinds of things may break otherwise.. atleast all fixed* types.
00222  *
00223  * If you get errors here, it probably means that your stdint.h is not
00224  * correct for your platform.
00225  */
00226 STATIC_ASSERT(sizeof(int8_t) == 1, INT8_T_WRONG_SIZE)
00227 STATIC_ASSERT(sizeof(uint8_t) == 1, UINT8_T_WRONG_SIZE)
00228 STATIC_ASSERT(sizeof(int16_t) == 2, INT16_T_WRONG_SIZE)
00229 STATIC_ASSERT(sizeof(uint16_t) == 2, UINT16_T_WRONG_SIZE)
00230 STATIC_ASSERT(sizeof(int32_t) == 4, INT32_T_WRONG_SIZE)
00231 STATIC_ASSERT(sizeof(uint32_t) == 4, UINT32_T_WRONG_SIZE)
00232 STATIC_ASSERT(sizeof(int64_t) == 8, INT64_T_WRONG_SIZE)
00233 STATIC_ASSERT(sizeof(uint64_t) == 8, UINT64_T_WRONG_SIZE)
00234 
00235 /* This structure is used for 'bytes' arrays.
00236  * It has the number of bytes in the beginning, and after that an array.
00237  * Note that actual structs used will have a different length of bytes array.
00238  */
00239 struct _pb_bytes_array_t {
00240     size_t size;
00241     uint8_t bytes[1];
00242 };
00243 typedef struct _pb_bytes_array_t pb_bytes_array_t;
00244 
00245 /* Same, except for pointer-type fields. There is no need to variable struct
00246  * length in this case.
00247  */
00248 struct _pb_bytes_ptr_t {
00249     size_t size;
00250     uint8_t *bytes;
00251 };
00252 typedef struct _pb_bytes_ptr_t pb_bytes_ptr_t;
00253 
00254 /* This structure is used for giving the callback function.
00255  * It is stored in the message structure and filled in by the method that
00256  * calls pb_decode.
00257  *
00258  * The decoding callback will be given a limited-length stream
00259  * If the wire type was string, the length is the length of the string.
00260  * If the wire type was a varint/fixed32/fixed64, the length is the length
00261  * of the actual value.
00262  * The function may be called multiple times (especially for repeated types,
00263  * but also otherwise if the message happens to contain the field multiple
00264  * times.)
00265  *
00266  * The encoding callback will receive the actual output stream.
00267  * It should write all the data in one call, including the field tag and
00268  * wire type. It can write multiple fields.
00269  *
00270  * The callback can be null if you want to skip a field.
00271  */
00272 typedef struct _pb_istream_t pb_istream_t;
00273 typedef struct _pb_ostream_t pb_ostream_t;
00274 typedef struct _pb_callback_t pb_callback_t;
00275 struct _pb_callback_t {
00276 #ifdef PB_OLD_CALLBACK_STYLE
00277     /* Deprecated since nanopb-0.2.1 */
00278     union {
00279         bool (*decode)(pb_istream_t *stream, const pb_field_t *field, void *arg);
00280         bool (*encode)(pb_ostream_t *stream, const pb_field_t *field, const void *arg);
00281     } funcs;
00282 #else
00283     /* New function signature, which allows modifying arg contents in callback. */
00284     union {
00285         bool (*decode)(pb_istream_t *stream, const pb_field_t *field, void **arg);
00286         bool (*encode)(pb_ostream_t *stream, const pb_field_t *field, void * const *arg);
00287     } funcs;
00288 #endif    
00289     
00290     /* Free arg for use by callback */
00291     void *arg;
00292 };
00293 
00294 /* Wire types. Library user needs these only in encoder callbacks. */
00295 typedef enum {
00296     PB_WT_VARINT = 0,
00297     PB_WT_64BIT  = 1,
00298     PB_WT_STRING = 2,
00299     PB_WT_32BIT  = 5
00300 } pb_wire_type_t;
00301 
00302 /* Structure for defining the handling of unknown/extension fields.
00303  * Usually the pb_extension_type_t structure is automatically generated,
00304  * while the pb_extension_t structure is created by the user. However,
00305  * if you want to catch all unknown fields, you can also create a custom
00306  * pb_extension_type_t with your own callback.
00307  */
00308 typedef struct _pb_extension_type_t pb_extension_type_t;
00309 typedef struct _pb_extension_t pb_extension_t;
00310 struct _pb_extension_type_t {
00311     /* Called for each unknown field in the message.
00312      * If you handle the field, read off all of its data and return true.
00313      * If you do not handle the field, do not read anything and return true.
00314      * If you run into an error, return false.
00315      * Set to NULL for default handler.
00316      */
00317     bool (*decode)(pb_istream_t *stream, pb_extension_t *extension,
00318                    uint32_t tag, pb_wire_type_t wire_type);
00319     
00320     /* Called once after all regular fields have been encoded.
00321      * If you have something to write, do so and return true.
00322      * If you do not have anything to write, just return true.
00323      * If you run into an error, return false.
00324      * Set to NULL for default handler.
00325      */
00326     bool (*encode)(pb_ostream_t *stream, const pb_extension_t *extension);
00327     
00328     /* Free field for use by the callback. */
00329     const void *arg;
00330 };
00331 
00332 struct _pb_extension_t {
00333     /* Type describing the extension field. Usually you'll initialize
00334      * this to a pointer to the automatically generated structure. */
00335     const pb_extension_type_t *type;
00336     
00337     /* Destination for the decoded data. This must match the datatype
00338      * of the extension field. */
00339     void *dest;
00340     
00341     /* Pointer to the next extension handler, or NULL.
00342      * If this extension does not match a field, the next handler is
00343      * automatically called. */
00344     pb_extension_t *next;
00345 };
00346 
00347 /* These macros are used to declare pb_field_t's in the constant array. */
00348 /* Size of a structure member, in bytes. */
00349 #define pb_membersize(st, m) (sizeof ((st*)0)->m)
00350 /* Number of entries in an array. */
00351 #define pb_arraysize(st, m) (pb_membersize(st, m) / pb_membersize(st, m[0]))
00352 /* Delta from start of one member to the start of another member. */
00353 #define pb_delta(st, m1, m2) ((int)offsetof(st, m1) - (int)offsetof(st, m2))
00354 /* Marks the end of the field list */
00355 #define PB_LAST_FIELD {0,(pb_type_t) 0,0,0,0,0,0}
00356 
00357 /* Macros for filling in the data_offset field */
00358 /* data_offset for first field in a message */
00359 #define PB_DATAOFFSET_FIRST(st, m1, m2) (offsetof(st, m1))
00360 /* data_offset for subsequent fields */
00361 #define PB_DATAOFFSET_OTHER(st, m1, m2) (offsetof(st, m1) - offsetof(st, m2) - pb_membersize(st, m2))
00362 /* Choose first/other based on m1 == m2 (deprecated, remains for backwards compatibility) */
00363 #define PB_DATAOFFSET_CHOOSE(st, m1, m2) (int)(offsetof(st, m1) == offsetof(st, m2) \
00364                                   ? PB_DATAOFFSET_FIRST(st, m1, m2) \
00365                                   : PB_DATAOFFSET_OTHER(st, m1, m2))
00366 
00367 /* Required fields are the simplest. They just have delta (padding) from
00368  * previous field end, and the size of the field. Pointer is used for
00369  * submessages and default values.
00370  */
00371 #define PB_REQUIRED_STATIC(tag, st, m, fd, ltype, ptr) \
00372     {tag, PB_ATYPE_STATIC | PB_HTYPE_REQUIRED | ltype, \
00373     fd, 0, pb_membersize(st, m), 0, ptr}
00374 
00375 /* Optional fields add the delta to the has_ variable. */
00376 #define PB_OPTIONAL_STATIC(tag, st, m, fd, ltype, ptr) \
00377     {tag, PB_ATYPE_STATIC | PB_HTYPE_OPTIONAL | ltype, \
00378     fd, \
00379     pb_delta(st, has_ ## m, m), \
00380     pb_membersize(st, m), 0, ptr}
00381 
00382 /* Repeated fields have a _count field and also the maximum number of entries. */
00383 #define PB_REPEATED_STATIC(tag, st, m, fd, ltype, ptr) \
00384     {tag, PB_ATYPE_STATIC | PB_HTYPE_REPEATED | ltype, \
00385     fd, \
00386     pb_delta(st, m ## _count, m), \
00387     pb_membersize(st, m[0]), \
00388     pb_arraysize(st, m), ptr}
00389 
00390 /* Allocated fields carry the size of the actual data, not the pointer */
00391 #define PB_REQUIRED_POINTER(tag, st, m, fd, ltype, ptr) \
00392     {tag, PB_ATYPE_POINTER | PB_HTYPE_REQUIRED | ltype, \
00393     fd, 0, pb_membersize(st, m[0]), 0, ptr}
00394 
00395 /* Optional fields don't need a has_ variable, as information would be redundant */
00396 #define PB_OPTIONAL_POINTER(tag, st, m, fd, ltype, ptr) \
00397     {tag, PB_ATYPE_POINTER | PB_HTYPE_OPTIONAL | ltype, \
00398     fd, 0, pb_membersize(st, m[0]), 0, ptr}
00399 
00400 /* Repeated fields have a _count field and a pointer to array of pointers */
00401 #define PB_REPEATED_POINTER(tag, st, m, fd, ltype, ptr) \
00402     {tag, PB_ATYPE_POINTER | PB_HTYPE_REPEATED | ltype, \
00403     fd, pb_delta(st, m ## _count, m), \
00404     pb_membersize(st, m[0]), 0, ptr}
00405 
00406 /* Callbacks are much like required fields except with special datatype. */
00407 #define PB_REQUIRED_CALLBACK(tag, st, m, fd, ltype, ptr) \
00408     {tag, PB_ATYPE_CALLBACK | PB_HTYPE_REQUIRED | ltype, \
00409     fd, 0, pb_membersize(st, m), 0, ptr}
00410 
00411 #define PB_OPTIONAL_CALLBACK(tag, st, m, fd, ltype, ptr) \
00412     {tag, PB_ATYPE_CALLBACK | PB_HTYPE_OPTIONAL | ltype, \
00413     fd, 0, pb_membersize(st, m), 0, ptr}
00414     
00415 #define PB_REPEATED_CALLBACK(tag, st, m, fd, ltype, ptr) \
00416     {tag, PB_ATYPE_CALLBACK | PB_HTYPE_REPEATED | ltype, \
00417     fd, 0, pb_membersize(st, m), 0, ptr}
00418 
00419 /* Optional extensions don't have the has_ field, as that would be redundant. */
00420 #define PB_OPTEXT_STATIC(tag, st, m, fd, ltype, ptr) \
00421     {tag, PB_ATYPE_STATIC | PB_HTYPE_OPTIONAL | ltype, \
00422     0, \
00423     0, \
00424     pb_membersize(st, m), 0, ptr}
00425 
00426 #define PB_OPTEXT_CALLBACK(tag, st, m, fd, ltype, ptr) \
00427     {tag, PB_ATYPE_CALLBACK | PB_HTYPE_OPTIONAL | ltype, \
00428     0, 0, pb_membersize(st, m), 0, ptr}
00429 
00430 /* The mapping from protobuf types to LTYPEs is done using these macros. */
00431 #define PB_LTYPE_MAP_BOOL       PB_LTYPE_VARINT
00432 #define PB_LTYPE_MAP_BYTES      PB_LTYPE_BYTES
00433 #define PB_LTYPE_MAP_DOUBLE     PB_LTYPE_FIXED64
00434 #define PB_LTYPE_MAP_ENUM       PB_LTYPE_VARINT
00435 #define PB_LTYPE_MAP_FIXED32    PB_LTYPE_FIXED32
00436 #define PB_LTYPE_MAP_FIXED64    PB_LTYPE_FIXED64
00437 #define PB_LTYPE_MAP_FLOAT      PB_LTYPE_FIXED32
00438 #define PB_LTYPE_MAP_INT32      PB_LTYPE_VARINT
00439 #define PB_LTYPE_MAP_INT64      PB_LTYPE_VARINT
00440 #define PB_LTYPE_MAP_MESSAGE    PB_LTYPE_SUBMESSAGE
00441 #define PB_LTYPE_MAP_SFIXED32   PB_LTYPE_FIXED32
00442 #define PB_LTYPE_MAP_SFIXED64   PB_LTYPE_FIXED64
00443 #define PB_LTYPE_MAP_SINT32     PB_LTYPE_SVARINT
00444 #define PB_LTYPE_MAP_SINT64     PB_LTYPE_SVARINT
00445 #define PB_LTYPE_MAP_STRING     PB_LTYPE_STRING
00446 #define PB_LTYPE_MAP_UINT32     PB_LTYPE_UVARINT
00447 #define PB_LTYPE_MAP_UINT64     PB_LTYPE_UVARINT
00448 #define PB_LTYPE_MAP_EXTENSION  PB_LTYPE_EXTENSION
00449 
00450 /* This is the actual macro used in field descriptions.
00451  * It takes these arguments:
00452  * - Field tag number
00453  * - Field type:   BOOL, BYTES, DOUBLE, ENUM, FIXED32, FIXED64,
00454  *                 FLOAT, INT32, INT64, MESSAGE, SFIXED32, SFIXED64
00455  *                 SINT32, SINT64, STRING, UINT32, UINT64 or EXTENSION
00456  * - Field rules:  REQUIRED, OPTIONAL or REPEATED
00457  * - Allocation:   STATIC or CALLBACK
00458  * - Message name
00459  * - Field name
00460  * - Previous field name (or field name again for first field)
00461  * - Pointer to default value or submsg fields.
00462  */
00463 
00464 #define PB_FIELD(tag, type, rules, allocation, message, field, prevfield, ptr) \
00465     PB_ ## rules ## _ ## allocation(tag, message, field, \
00466         PB_DATAOFFSET_CHOOSE(message, field, prevfield), \
00467         PB_LTYPE_MAP_ ## type, ptr)
00468 
00469 /* This is a new version of the macro used by nanopb generator from
00470  * version 0.2.3 onwards. It avoids the use of a ternary expression in
00471  * the initialization, which confused some compilers.
00472  *
00473  * - Placement: FIRST or OTHER, depending on if this is the first field in structure.
00474  *
00475  */
00476 #define PB_FIELD2(tag, type, rules, allocation, placement, message, field, prevfield, ptr) \
00477     PB_ ## rules ## _ ## allocation(tag, message, field, \
00478         PB_DATAOFFSET_ ## placement(message, field, prevfield), \
00479         PB_LTYPE_MAP_ ## type, ptr)
00480 
00481 
00482 /* These macros are used for giving out error messages.
00483  * They are mostly a debugging aid; the main error information
00484  * is the true/false return value from functions.
00485  * Some code space can be saved by disabling the error
00486  * messages if not used.
00487  */
00488 #ifdef PB_NO_ERRMSG
00489 #define PB_RETURN_ERROR(stream,msg) return false
00490 #define PB_GET_ERROR(stream) "(errmsg disabled)"
00491 #else
00492 #define PB_RETURN_ERROR(stream,msg) \
00493     do {\
00494         if ((stream)->errmsg == NULL) \
00495             (stream)->errmsg = (msg); \
00496         return false; \
00497     } while(0)
00498 #define PB_GET_ERROR(stream) ((stream)->errmsg ? (stream)->errmsg : "(none)")
00499 #endif
00500 
00501 #endif