summaryrefslogtreecommitdiffstats
path: root/pb_encode.c
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_encode.c
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_encode.c')
-rw-r--r--pb_encode.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/pb_encode.c b/pb_encode.c
index cbf7a667..8f01b10b 100644
--- a/pb_encode.c
+++ b/pb_encode.c
@@ -598,14 +598,14 @@ bool checkreturn pb_enc_fixed32(pb_ostream_t *stream, const pb_field_t *field, c
bool checkreturn pb_enc_bytes(pb_ostream_t *stream, const pb_field_t *field, const void *src)
{
- const pb_bytes_array_t *bytes = (const pb_bytes_array_t*)src;
-
if (PB_ATYPE(field->type) == PB_ATYPE_POINTER)
{
- return pb_encode_string(stream, *(const uint8_t**)bytes->bytes, bytes->size);
+ const pb_bytes_ptr_t *bytes = (const pb_bytes_ptr_t*)src;
+ return pb_encode_string(stream, bytes->bytes, bytes->size);
}
else
{
+ const pb_bytes_array_t *bytes = (const pb_bytes_array_t*)src;
if (bytes->size + offsetof(pb_bytes_array_t, bytes) > field->data_size)
PB_RETURN_ERROR(stream, "bytes size exceeded");