diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2017-09-16 13:40:57 +0300 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2017-09-16 13:40:57 +0300 |
commit | e21e78c67cbd6566fe9d8368eeaf3298ae22b75d (patch) | |
tree | cb2a44a3a93b3d6b9fb049219adcf6dcd003235c /pb_decode.h | |
parent | 03a7f76ef6df8ecfdf493c732a67a8e2f687bb90 (diff) |
Add pb_en/decode_nullterminated() (part of #278)
Nanopb has traditionally supported messages to be terminated with a zero tag.
However, this is not really standard protobuf behaviour, so it makes sense
to separate it into a different function. Because it is a breaking change,
it will happen in 0.4.0 release. But I add the functions here early so that
new code can start using them now.
Also changed the network_server example to use en/decode_delimited(), which
is the more common protobuf method of simple message framing.
Diffstat (limited to 'pb_decode.h')
-rw-r--r-- | pb_decode.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/pb_decode.h b/pb_decode.h index 4fe7995..d51ce39 100644 --- a/pb_decode.h +++ b/pb_decode.h @@ -85,6 +85,13 @@ bool pb_decode_noinit(pb_istream_t *stream, const pb_field_t fields[], void *des */ bool pb_decode_delimited(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct); +/* Same as pb_decode, except allows the message to be terminated with a null byte. + * NOTE: Until nanopb-0.4.0, pb_decode() also allows null-termination. This behaviour + * is not supported in most other protobuf implementations, so pb_decode_delimited() + * is a better option for compatibility. + */ +bool pb_decode_nullterminated(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct); + #ifdef PB_ENABLE_MALLOC /* Release any allocated pointer fields. If you use dynamic allocation, you should * call this for any successfully decoded message when you are done with it. If |