Remove the "buf = NULL" => skip requirement from pb_istream_t callbacks.

Rationale: it's easy to implement the callback wrong. Doing so introduces
io errors when unknown fields are present in the input. If code is not
tested with unknown fields, these bugs can remain hidden for long time.

Added a special case for the memory buffer stream, where it gives a small
speed benefit.

Added testcase for skipping fields with test_decode2 implementation.

Update issue 37
Status: FixedInGit
This commit is contained in:
Petteri Aimonen
2012-10-18 19:45:28 +03:00
parent 900c8dd125
commit dcab39a41c
8 changed files with 36 additions and 34 deletions

View File

@@ -19,12 +19,10 @@
* 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),
* 2) 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.
*
* 4) Your callback may be used with substreams, in which case bytes_left
* 3) Your callback may be used with substreams, in which case bytes_left
* is different than from the main stream. Don't use bytes_left to compute
* any pointers.
*/