summaryrefslogtreecommitdiffstats
path: root/pb.h
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-12-09 19:19:12 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-12-29 18:35:57 +0200
commit25516b059137be64735276bbe3a96029f4c926be (patch)
tree046dc037c96cf9b4243e2eba533d4a555bf15f1f /pb.h
parent414e637867c513ba9aa199e106c6d576e5b60287 (diff)
Organize allocation logic in generator, add pb_bytes_ptr_t.
Allocation decision is now made before the field data type is decided. This way the data type decisions can more cleanly account for the allocation type, i.e. FT_DEFAULT logic etc. Added pb_bytes_ptr_t for pointer-allocated bytes-fields. There is no point generating separate structs for these, as they would all be of the same type.
Diffstat (limited to 'pb.h')
-rw-r--r--pb.h14
1 files changed, 11 insertions, 3 deletions
diff --git a/pb.h b/pb.h
index d839be59..76980e4c 100644
--- a/pb.h
+++ b/pb.h
@@ -228,9 +228,17 @@ struct _pb_bytes_array_t {
size_t size;
uint8_t bytes[1];
};
-
typedef struct _pb_bytes_array_t pb_bytes_array_t;
+/* Same, except for pointer-type fields. There is no need to variable struct
+ * length in this case.
+ */
+struct _pb_bytes_ptr_t {
+ size_t size;
+ uint8_t *bytes;
+};
+typedef struct _pb_bytes_ptr_t pb_bytes_ptr_t;
+
/* This structure is used for giving the callback function.
* It is stored in the message structure and filled in by the method that
* calls pb_decode.
@@ -377,10 +385,10 @@ struct _pb_extension_t {
{tag, PB_ATYPE_POINTER | PB_HTYPE_OPTIONAL | ltype, \
fd, 0, pb_membersize(st, m[0]), 0, ptr}
+/* Repeated fields have a _count field and a pointer to array of pointers */
#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), \
+ fd, pb_delta(st, m ## _count, m), \
pb_membersize(st, m[0]), 0, ptr}
/* Callbacks are much like required fields except with special datatype. */