summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-08-24 21:22:20 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-08-24 21:22:20 +0300
commit0fb5e5e068326b23493952619d7efb640cb37377 (patch)
tree3f3bbb7e05c6c17984b13ab87104c235a61f22fd /docs
parentea57f74741b5b5ab3ab4a3e81d8b61811417b4c6 (diff)
Implement error messages in the decoder side.
Update issue 7 Status: Started
Diffstat (limited to 'docs')
-rw-r--r--docs/concepts.rst14
-rw-r--r--docs/reference.rst4
2 files changed, 8 insertions, 10 deletions
diff --git a/docs/concepts.rst b/docs/concepts.rst
index 1d0fe08f..122d29cf 100644
--- a/docs/concepts.rst
+++ b/docs/concepts.rst
@@ -258,18 +258,14 @@ generates this field description array for the structure *Person_PhoneNumber*::
Return values and error handling
================================
-Most functions in nanopb return bool: *true* means success, *false* means failure. If this is enough for you, skip this section.
+Most functions in nanopb return bool: *true* means success, *false* means failure. There is also some support for error messages for debugging purposes: the error messages go in *stream->errmsg*.
-For simplicity, nanopb doesn't define it's own error codes. This might be added if there is a compelling need for it. You can however deduce something about the error causes:
+The error messages help in guessing what is the underlying cause of the error. The most common error conditions are:
1) Running out of memory. Because everything is allocated from the stack, nanopb can't detect this itself. Encoding or decoding the same type of a message always takes the same amount of stack space. Therefore, if it works once, it works always.
2) Invalid field description. These are usually stored as constants, so if it works under the debugger, it always does.
-3) IO errors in your own stream callbacks. Because encoding/decoding stops at the first error, you can overwrite the *state* field in the struct and store your own error code there.
-4) Errors that happen in your callback functions. You can use the state field in the callback structure.
+3) IO errors in your own stream callbacks.
+4) Errors that happen in your callback functions.
5) Exceeding the max_size or bytes_left of a stream.
6) Exceeding the max_size of a string or array field
-7) Invalid protocol buffers binary message. It's not like you could recover from it anyway, so a simple failure should be enough.
-
-In my opinion, it is enough that 1. and 2. can be resolved using a debugger.
-
-However, you may be interested which of the remaining conditions caused the error. For 3. and 4., you can set and check the state. If you have to detect 5. and 6., you should convert the fields to callback type. Any remaining problem is of type 7.
+7) Invalid protocol buffers binary message.
diff --git a/docs/reference.rst b/docs/reference.rst
index 3a6e11a4..ec9aec5d 100644
--- a/docs/reference.rst
+++ b/docs/reference.rst
@@ -20,6 +20,8 @@ PB_FIELD_16BIT Add support for tag numbers > 255 and fields larg
Increases code size 3 bytes per each field. Compiler error will tell if you need this.
PB_FIELD_32BIT Add support for tag numbers > 65535 and fields larger than 65535 bytes or 65535 array entries.
Increases code size 9 bytes per each field. Compiler error will tell if you need this.
+PB_NO_ERRMSG Disables the support for error messages; only error information is the true/false return value.
+ Decreases the code size by a few hundred bytes.
============================ ================================================================================================
The PB_MAX_REQUIRED_FIELDS, PB_FIELD_16BIT and PB_FIELD_32BIT settings allow raising some datatype limits to suit larger messages.
@@ -431,7 +433,7 @@ Decode the length for a field with wire type *PB_WT_STRING* and create a substre
This function uses `pb_decode_varint`_ to read an integer from the stream. This is interpreted as a number of bytes, and the substream is set up so that its `bytes_left` is initially the same as the length, and its callback function and state the same as the parent stream.
pb_close_string_substream
-------------------------
+-------------------------
Close the substream created with `pb_make_string_substream`_. ::
void pb_close_string_substream(pb_istream_t *stream, pb_istream_t *substream);