-// Decode from stream to destination struct.
-// The actual struct pointed to by dest must match the description in fields.
+/* Lightweight input stream.
+ * You can provide a callback function for reading or use
+ * pb_istream_from_buffer.
+ *
+ * Rules for callback:
+ * 1) Return false on IO errors. This will cause decoding to abort.
+ *
+ * 2) If buf is NULL, read but don't store bytes ("skip input").
+ *
+ * 3) 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.
+ */
+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;
+};
+
+pb_istream_t pb_istream_from_buffer(uint8_t *buf, size_t bufsize);
+bool pb_read(pb_istream_t *stream, uint8_t *buf, size_t count);
+
+/* Decode from stream to destination struct.
+ * Returns true on success, false on any failure.
+ * The actual struct pointed to by dest must match the description in fields.
+ */