diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2012-08-24 21:22:20 +0300 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2012-08-24 21:22:20 +0300 |
commit | 0fb5e5e068326b23493952619d7efb640cb37377 (patch) | |
tree | 3f3bbb7e05c6c17984b13ab87104c235a61f22fd /pb.h | |
parent | ea57f74741b5b5ab3ab4a3e81d8b61811417b4c6 (diff) |
Implement error messages in the decoder side.
Update issue 7
Status: Started
Diffstat (limited to 'pb.h')
-rw-r--r-- | pb.h | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -196,5 +196,23 @@ typedef enum { #define pb_delta_end(st, m1, m2) (offsetof(st, m1) - offsetof(st, m2) - pb_membersize(st, m2)) #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 |