From 07375a126337916f3a34ea94f8085b8f89d789a1 Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Wed, 22 Feb 2017 21:06:32 +0200 Subject: Extend inline / fixed length bytes array support (issue #244) Adds support for proto3 and POINTER field types to have fixed length bytes arrays. Also changed the .proto option to a separate fixed_length:true, while also supporting the old FT_INLINE option. Restructured the generator and decoder logic to threat the inline bytes fields more like "just another field type". --- pb_encode.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'pb_encode.c') diff --git a/pb_encode.c b/pb_encode.c index cafe853c..cd731dcf 100644 --- a/pb_encode.c +++ b/pb_encode.c @@ -35,6 +35,7 @@ static bool checkreturn pb_enc_fixed64(pb_ostream_t *stream, const pb_field_t *f static bool checkreturn pb_enc_bytes(pb_ostream_t *stream, const pb_field_t *field, const void *src); static bool checkreturn pb_enc_string(pb_ostream_t *stream, const pb_field_t *field, const void *src); static bool checkreturn pb_enc_submessage(pb_ostream_t *stream, const pb_field_t *field, const void *src); +static bool checkreturn pb_enc_fixed_length_bytes(pb_ostream_t *stream, const pb_field_t *field, const void *src); /* --- Function pointers to field encoders --- * Order in the array must match pb_action_t LTYPE numbering. @@ -50,7 +51,7 @@ static const pb_encoder_t PB_ENCODERS[PB_LTYPES_COUNT] = { &pb_enc_string, &pb_enc_submessage, NULL, /* extensions */ - &pb_enc_bytes /* PB_LTYPE_FIXED_LENGTH_BYTES */ + &pb_enc_fixed_length_bytes }; /******************************* @@ -694,9 +695,6 @@ static bool checkreturn pb_enc_bytes(pb_ostream_t *stream, const pb_field_t *fie { const pb_bytes_array_t *bytes = NULL; - if (PB_LTYPE(field->type) == PB_LTYPE_FIXED_LENGTH_BYTES) - return pb_encode_string(stream, (const pb_byte_t*)src, field->data_size); - bytes = (const pb_bytes_array_t*)src; if (src == NULL) @@ -748,3 +746,8 @@ static bool checkreturn pb_enc_submessage(pb_ostream_t *stream, const pb_field_t return pb_encode_submessage(stream, (const pb_field_t*)field->ptr, src); } +static bool checkreturn pb_enc_fixed_length_bytes(pb_ostream_t *stream, const pb_field_t *field, const void *src) +{ + return pb_encode_string(stream, (const pb_byte_t*)src, field->data_size); +} + -- cgit 1.2.3-korg