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>2019-01-25 21:37:15 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2019-01-25 21:37:15 +0300
commite31fa8eb03774522ec1b3a46369b3669e944f59d (patch)
tree6c001326406a7ac0368c5c9b6cc657a411da3fe5 /pb_encode.h
parentb2d04dfceaac1dc35fcde2706e56d090222d2761 (diff)
Add pb_decode_ex(), pb_encode_ex() functions.
This should simplify specifying combinations, so that we don't need every variant of pb_decode_noinit_delimited() etc. Also disables zero-terminated decoding in pb_decode (issue #278).
Diffstat (limited to 'pb_encode.h')
-rw-r--r--pb_encode.h25
1 files changed, 17 insertions, 8 deletions
diff --git a/pb_encode.h b/pb_encode.h
index 0ba64fb..b8becc3 100644
--- a/pb_encode.h
+++ b/pb_encode.h
@@ -66,16 +66,25 @@ struct pb_ostream_s
*/
bool pb_encode(pb_ostream_t *stream, const pb_msgdesc_t *fields, const void *src_struct);
-/* Same as pb_encode, but prepends the length of the message as a varint.
- * Corresponds to writeDelimitedTo() in Google's protobuf API.
+/* Extended version of pb_encode, with several options to control the
+ * encoding process:
+ *
+ * PB_ENCODE_DELIMITED: Prepend the length of message as a varint.
+ * Corresponds to writeDelimitedTo() in Google's
+ * protobuf API.
+ *
+ * PB_ENCODE_NULLTERMINATED: Append 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_delimited(pb_ostream_t *stream, const pb_msgdesc_t *fields, const void *src_struct);
+#define PB_ENCODE_DELIMITED 0x02
+#define PB_ENCODE_NULLTERMINATED 0x04
+bool pb_encode_ex(pb_ostream_t *stream, const pb_msgdesc_t *fields, const void *src_struct, unsigned int flags);
-/* 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_msgdesc_t *fields, const void *src_struct);
+/* Defines for backwards compatibility with code written before nanopb-0.4.0 */
+#define pb_encode_delimited(s,f,d) pb_encode_ex(s,f,d, PB_ENCODE_DELIMITED)
+#define pb_encode_nullterminated(s,f,d) pb_encode_ex(s,f,d, PB_ENCODE_NULLTERMINATED)
/* Encode the message to get the size of the encoded data, but do not store
* the data. */