7 /* Lightweight input stream.
8 * If buf is NULL, read but don't store bytes.
9 * You can to provide a callback function for reading or use
10 * pb_istream_from_buffer.
12 * You can use state to store your own data (e.g. buffer pointer),
13 * and rely on pb_read to verify that no-body reads past bytes_left.
14 * However, substreams may change bytes_left so don't use that to
15 * compute any pointers.
19 bool (*callback)(pb_istream_t *stream, uint8_t *buf, size_t count);
20 void *state; /* Free field for use by callback implementation */
24 pb_istream_t pb_istream_from_buffer(uint8_t *buf, size_t bufsize);
25 bool pb_read(pb_istream_t *stream, uint8_t *buf, size_t count);
27 /* Decode from stream to destination struct.
28 * The actual struct pointed to by dest must match the description in fields.
30 bool pb_decode(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct);
32 /* --- Helper functions ---
33 * You may want to use these from your caller or callbacks.
36 bool pb_decode_varint32(pb_istream_t *stream, uint32_t *dest);
37 bool pb_decode_varint64(pb_istream_t *stream, uint64_t *dest);
39 bool pb_skip_varint(pb_istream_t *stream);
40 bool pb_skip_string(pb_istream_t *stream);
42 /* --- Field decoders ---
43 * Each decoder takes stream and field description, and a pointer to the field
44 * in the destination struct (dest = struct_addr + field->data_offset).
45 * For arrays, these functions are called repeatedly.
48 bool pb_dec_uint32(pb_istream_t *stream, const pb_field_t *field, uint32_t *dest);
49 bool pb_dec_sint32(pb_istream_t *stream, const pb_field_t *field, int32_t *dest);
50 bool pb_dec_fixed32(pb_istream_t *stream, const pb_field_t *field, uint32_t *dest);
51 bool pb_dec_uint64(pb_istream_t *stream, const pb_field_t *field, uint64_t *dest);
52 bool pb_dec_sint64(pb_istream_t *stream, const pb_field_t *field, int64_t *dest);
53 bool pb_dec_fixed64(pb_istream_t *stream, const pb_field_t *field, uint64_t *dest);
54 bool pb_dec_bool(pb_istream_t *stream, const pb_field_t *field, bool *dest);
55 bool pb_dec_enum(pb_istream_t *stream, const pb_field_t *field, void *dest);
57 bool pb_dec_float(pb_istream_t *stream, const pb_field_t *field, float *dest);
58 bool pb_dec_double(pb_istream_t *stream, const pb_field_t *field, double *dest);
60 bool pb_dec_bytes(pb_istream_t *stream, const pb_field_t *field, uint8_t *dest);
61 bool pb_dec_string(pb_istream_t *stream, const pb_field_t *field, uint8_t *dest);
62 bool pb_dec_submessage(pb_istream_t *stream, const pb_field_t *field, void *dest);
64 typedef bool (*pb_decoder_t)(pb_istream_t *stream, const pb_field_t *field, void *dest);
66 /* --- Function pointers to field decoders ---
67 * Order in the array must match pb_action_t LTYPE numbering.
69 const pb_decoder_t PB_DECODERS[16];