Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nanopb/nanopb.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2017-09-16 13:40:57 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2017-09-16 13:40:57 +0300
commite21e78c67cbd6566fe9d8368eeaf3298ae22b75d (patch)
treecb2a44a3a93b3d6b9fb049219adcf6dcd003235c /pb_encode.h
parent03a7f76ef6df8ecfdf493c732a67a8e2f687bb90 (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_encode.h')
-rw-r--r--pb_encode.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/pb_encode.h b/pb_encode.h
index d18a72d..8bf78dd 100644
--- a/pb_encode.h
+++ b/pb_encode.h
@@ -71,6 +71,12 @@ bool pb_encode(pb_ostream_t *stream, const pb_field_t fields[], const void *src_
*/
bool pb_encode_delimited(pb_ostream_t *stream, const pb_field_t fields[], const void *src_struct);
+/* Same as pb_encode, but appends a null byte to the message for termination.
+ * NOTE: This behaviour is not supported in most other protobuf implementations, so pb_encode_delimited()
+ * is a better option for compatibility.
+ */
+bool pb_encode_nullterminated(pb_ostream_t *stream, const pb_field_t fields[], const void *src_struct);
+
/* Encode the message to get the size of the encoded data, but do not store
* the data. */
bool pb_get_encoded_size(size_t *size, const pb_field_t fields[], const void *src_struct);