From e21e78c67cbd6566fe9d8368eeaf3298ae22b75d Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Sat, 16 Sep 2017 13:40:57 +0300 Subject: 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. --- pb_decode.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'pb_decode.h') 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 -- cgit v1.2.3