summaryrefslogtreecommitdiffstats
path: root/pb.h
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-08-24 21:22:20 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-08-24 21:22:20 +0300
commit0fb5e5e068326b23493952619d7efb640cb37377 (patch)
tree3f3bbb7e05c6c17984b13ab87104c235a61f22fd /pb.h
parentea57f74741b5b5ab3ab4a3e81d8b61811417b4c6 (diff)
Implement error messages in the decoder side.
Update issue 7 Status: Started
Diffstat (limited to 'pb.h')
-rw-r--r--pb.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/pb.h b/pb.h
index 4983d069..85f4421c 100644
--- a/pb.h
+++ b/pb.h
@@ -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