-/* Lightweight input stream.
- * If buf is NULL, read but don't store bytes.
- * You have to provide a callback function for reading.
- * You can use state to store your own data (e.g. buffer pointer),
- * and rely on pb_read to verify that no-body reads past bytes_left.
- * However, substreams may change bytes_left so don't use that to
- * compute any pointers.
- */
-typedef struct _pb_istream_t pb_istream_t;
-struct _pb_istream_t
-{
- bool (*callback)(pb_istream_t *stream, uint8_t *buf, size_t count);
- void *state; // Free field for use by callback implementation
- size_t bytes_left;
-};
-
-static inline bool pb_read(pb_istream_t *stream, uint8_t *buf, size_t count)
-{
- if (stream->bytes_left < count)
- return false;
-
- bool status = stream->callback(stream, buf, count);
- stream->bytes_left -= count;
- return status;
-}
-
-/* Lightweight output stream. */
-typedef struct _pb_ostream_t pb_ostream_t;
-struct _pb_ostream_t
-{
- bool (*callback)(pb_ostream_t *stream, const uint8_t *buf, size_t count);
- void *state; // Free field for use by callback implementation
- size_t bytes_written;
-};
-
-static inline bool pb_write(pb_ostream_t *stream, const uint8_t *buf, size_t count)
-{
- bool status = stream->callback(stream, buf, count);
- stream->bytes_written += count;
- return status;
-}
-
-/* List of possible field types