pb_istream_from_buffer: Update comments to avoid a common mistake
Previously it wasn't quite clear that bufsize should be the actual
length of the message, not full buffer size.
diff --git a/pb_decode.c b/pb_decode.c
index d4ad5a3..84b0f3e 100644
--- a/pb_decode.c
+++ b/pb_decode.c
@@ -139,7 +139,7 @@
return true;
}
-pb_istream_t pb_istream_from_buffer(const pb_byte_t *buf, size_t bufsize)
+pb_istream_t pb_istream_from_buffer(const pb_byte_t *buf, size_t msglen)
{
pb_istream_t stream;
/* Cast away the const from buf without a compiler error. We are
@@ -156,7 +156,7 @@
#endif
state.c_state = buf;
stream.state = state.state;
- stream.bytes_left = bufsize;
+ stream.bytes_left = msglen;
#ifndef PB_NO_ERRMSG
stream.errmsg = NULL;
#endif
diff --git a/pb_decode.h b/pb_decode.h
index b64d95a..9b70c8b 100644
--- a/pb_decode.h
+++ b/pb_decode.h
@@ -122,10 +122,13 @@
/* Create an input stream for reading from a memory buffer.
*
+ * msglen should be the actual length of the message, not the full size of
+ * allocated buffer.
+ *
* Alternatively, you can use a custom stream that reads directly from e.g.
* a file or a network socket.
*/
-pb_istream_t pb_istream_from_buffer(const pb_byte_t *buf, size_t bufsize);
+pb_istream_t pb_istream_from_buffer(const pb_byte_t *buf, size_t msglen);
/* Function to read from a pb_istream_t. You can use this if you need to
* read some custom header data, or to read data in field callbacks.