summaryrefslogtreecommitdiffstats
path: root/pb.h
diff options
context:
space:
mode:
authorMartin Donath <scifish@gmail.com>2013-12-08 23:25:32 +0100
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-12-29 18:35:57 +0200
commit4ae3b2e5661b154cd1f7e545f6052d271306ff25 (patch)
tree90b8fb3619eedaf9c0f3e8a5ac7ffd494467b99c /pb.h
parent4f37c083d532a782e478b2cef6a02d028613564d (diff)
Generating and encoding messages with dynamic allocaiton
Diffstat (limited to 'pb.h')
-rw-r--r--pb.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/pb.h b/pb.h
index a8e95e59..d839be59 100644
--- a/pb.h
+++ b/pb.h
@@ -162,6 +162,7 @@ typedef uint8_t pb_type_t;
/**** Field allocation types ****/
#define PB_ATYPE_STATIC 0x00
+#define PB_ATYPE_POINTER 0x80
#define PB_ATYPE_CALLBACK 0x40
#define PB_ATYPE_MASK 0xC0
@@ -366,6 +367,22 @@ struct _pb_extension_t {
pb_membersize(st, m[0]), \
pb_arraysize(st, m), ptr}
+/* Allocated fields carry the size of the actual data, not the pointer */
+#define PB_REQUIRED_POINTER(tag, st, m, fd, ltype, ptr) \
+ {tag, PB_ATYPE_POINTER | PB_HTYPE_REQUIRED | ltype, \
+ fd, 0, pb_membersize(st, m[0]), 0, ptr}
+
+/* Optional fields don't need a has_ variable, as information would be redundant */
+#define PB_OPTIONAL_POINTER(tag, st, m, fd, ltype, ptr) \
+ {tag, PB_ATYPE_POINTER | PB_HTYPE_OPTIONAL | ltype, \
+ fd, 0, pb_membersize(st, m[0]), 0, ptr}
+
+#define PB_REPEATED_POINTER(tag, st, m, fd, ltype, ptr) \
+ {tag, PB_ATYPE_POINTER | PB_HTYPE_REPEATED | ltype, \
+ fd, \
+ pb_delta(st, m ## _count, m), \
+ pb_membersize(st, m[0]), 0, ptr}
+
/* Callbacks are much like required fields except with special datatype. */
#define PB_REQUIRED_CALLBACK(tag, st, m, fd, ltype, ptr) \
{tag, PB_ATYPE_CALLBACK | PB_HTYPE_REQUIRED | ltype, \