summaryrefslogtreecommitdiffstats
path: root/pb_encode.c
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2017-02-22 21:06:32 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2017-02-22 21:10:26 +0200
commit07375a126337916f3a34ea94f8085b8f89d789a1 (patch)
treeef95d9138252d8ae4797e0a7092bc7417c1abefb /pb_encode.c
parentca74746e23b5a9e7916e8fde6632d71d61603f50 (diff)
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".
Diffstat (limited to 'pb_encode.c')
-rw-r--r--pb_encode.c11
1 files changed, 7 insertions, 4 deletions
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);
+}
+