diff options
author | Petteri Aimonen <jpa@github.mail.kapsi.fi> | 2016-08-05 07:38:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-05 07:38:53 +0300 |
commit | 68a86e96481e6bea987df8de47027847b30c325b (patch) | |
tree | b96eaefeaeaacd123e8d7e2f033dda3ba1698681 /pb_encode.c | |
parent | 0198210f2cc349e7bc5199e8db7f4afc8208d843 (diff) | |
parent | 62afd54964528c1fbd5ab802134f7e9ad912d904 (diff) |
Merge pull request #211 from tmroeder/feat-inline-bytes
Add inline allocation of bytes fields
Diffstat (limited to 'pb_encode.c')
-rw-r--r-- | pb_encode.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/pb_encode.c b/pb_encode.c index 9f91c9d5..4685614c 100644 --- a/pb_encode.c +++ b/pb_encode.c @@ -49,7 +49,8 @@ static const pb_encoder_t PB_ENCODERS[PB_LTYPES_COUNT] = { &pb_enc_bytes, &pb_enc_string, &pb_enc_submessage, - NULL /* extensions */ + NULL, /* extensions */ + &pb_enc_bytes /* PB_LTYPE_FIXED_LENGTH_BYTES */ }; /******************************* @@ -498,6 +499,7 @@ bool checkreturn pb_encode_tag_for_field(pb_ostream_t *stream, const pb_field_t case PB_LTYPE_BYTES: case PB_LTYPE_STRING: case PB_LTYPE_SUBMESSAGE: + case PB_LTYPE_FIXED_LENGTH_BYTES: wiretype = PB_WT_STRING; break; @@ -636,11 +638,16 @@ static bool checkreturn pb_enc_fixed32(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) { - const pb_bytes_array_t *bytes = (const pb_bytes_array_t*)src; + 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) { - /* Threat null pointer as an empty bytes field */ + /* Treat null pointer as an empty bytes field */ return pb_encode_string(stream, NULL, 0); } @@ -664,7 +671,7 @@ static bool checkreturn pb_enc_string(pb_ostream_t *stream, const pb_field_t *fi if (src == NULL) { - size = 0; /* Threat null pointer as an empty string */ + size = 0; /* Treat null pointer as an empty string */ } else { |