return pb_decode_noinit(stream, fields, dest_struct);
}
+bool pb_decode_delimited(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct)
+{
+ pb_istream_t substream;
+ bool status;
+
+ if (!pb_make_string_substream(stream, &substream))
+ return false;
+
+ status = pb_decode(&substream, fields, dest_struct);
+ pb_close_string_substream(stream, &substream);
+ return status;
+}
+
/* Field decoders */
bool pb_decode_svarint(pb_istream_t *stream, int64_t *dest)
*/
bool pb_decode_noinit(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct);
+/* Same as pb_decode, except expects the stream to start with the message size
+ * encoded as varint. Corresponds to parseDelimitedFrom() in Google's
+ * protobuf API.
+ */
+bool pb_decode_delimited(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct);
+
/**************************************
* Functions for manipulating streams *
return true;
}
+bool pb_encode_delimited(pb_ostream_t *stream, const pb_field_t fields[], const void *src_struct)
+{
+ return pb_encode_submessage(stream, fields, src_struct);
+}
+
/* Helper functions */
bool checkreturn pb_encode_varint(pb_ostream_t *stream, uint64_t value)
{
*/
bool pb_encode(pb_ostream_t *stream, const pb_field_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.
+ */
+bool pb_encode_delimited(pb_ostream_t *stream, const pb_field_t fields[], const void *src_struct);
/**************************************
* Functions for manipulating streams *
TEST((s = S("\x08"), !pb_decode(&s, IntegerArray_fields, &dest)))
}
+ {
+ pb_istream_t s;
+ IntegerContainer dest = {};
+
+ COMMENT("Testing pb_decode_delimited")
+ TEST((s = S("\x09\x0A\x07\x0A\x05\x01\x02\x03\x04\x05"),
+ pb_decode_delimited(&s, IntegerContainer_fields, &dest)) &&
+ dest.submsg.data_count == 5)
+ }
+
if (status != 0)
fprintf(stdout, "\n\nSome tests FAILED!\n");
"\x0A\x07\x0A\x05\x01\x02\x03\x04\x05"))
}
+ {
+ uint8_t buffer[20];
+ pb_ostream_t s;
+ IntegerContainer msg = {{5, {1,2,3,4,5}}};
+
+ COMMENT("Test pb_encode_delimited.")
+ TEST(WRITES(pb_encode_delimited(&s, IntegerContainer_fields, &msg),
+ "\x09\x0A\x07\x0A\x05\x01\x02\x03\x04\x05"))
+ }
+
{
uint8_t buffer[10];
pb_ostream_t s;