summaryrefslogtreecommitdiffstats
path: root/docs/reference.rst
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-04-02 19:55:21 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-04-02 19:55:21 +0300
commit214b0eae8aa011fa8b3e8a3dcc784f8d423aeffb (patch)
tree8cdebc1ab067bca01d47eefcc9dcf43ce50048db /docs/reference.rst
parent6f3740f74ed48daf51908676b203f1889455c17d (diff)
Change the callback function to use void**.
NOTE: This change breaks backwards-compatibility by default. If you have old callback functions, you can define PB_OLD_CALLBACK_STYLE to retain the old behaviour. If you want to convert your old callbacks to new signature, you need to do the following: 1) Change decode callback argument to void **arg and encode callback argument to void * const *arg. 2) Change any reference to arg into *arg. The rationale for making the new behaviour the default is that it simplifies the common case of "allocate some memory in decode callback". Update issue 69 Status: FixedInGit
Diffstat (limited to 'docs/reference.rst')
-rw-r--r--docs/reference.rst10
1 files changed, 7 insertions, 3 deletions
diff --git a/docs/reference.rst b/docs/reference.rst
index 93aae8b0..0db8e43e 100644
--- a/docs/reference.rst
+++ b/docs/reference.rst
@@ -24,6 +24,8 @@ PB_NO_ERRMSG Disables the support for error messages; only err
Decreases the code size by a few hundred bytes.
PB_BUFFER_ONLY Disables the support for custom streams. Only supports encoding to memory buffers.
Speeds up execution and decreases code size slightly.
+PB_OLD_CALLBACK_STYLE Use the old function signature (void\* instead of void\*\*) for callback fields. This was the
+ default until nanopb-0.2.1.
============================ ================================================================================================
The PB_MAX_REQUIRED_FIELDS, PB_FIELD_16BIT and PB_FIELD_32BIT settings allow raising some datatype limits to suit larger messages.
@@ -122,14 +124,16 @@ Part of a message structure, for fields with type PB_HTYPE_CALLBACK::
typedef struct _pb_callback_t pb_callback_t;
struct _pb_callback_t {
union {
- bool (*decode)(pb_istream_t *stream, const pb_field_t *field, void *arg);
- bool (*encode)(pb_ostream_t *stream, const pb_field_t *field, const void *arg);
+ bool (*decode)(pb_istream_t *stream, const pb_field_t *field, void **arg);
+ bool (*encode)(pb_ostream_t *stream, const pb_field_t *field, void * const *arg);
} funcs;
void *arg;
};
-The *arg* is passed to the callback when calling. It can be used to store any information that the callback might need.
+A pointer to the *arg* is passed to the callback when calling. It can be used to store any information that the callback might need.
+
+Previously the function received just the value of *arg* instead of a pointer to it. This old behaviour can be enabled by defining *PB_OLD_CALLBACK_STYLE*.
When calling `pb_encode`_, *funcs.encode* is used, and similarly when calling `pb_decode`_, *funcs.decode* is used. The function pointers are stored in the same memory location but are of incompatible types. You can set the function pointer to NULL to skip the field.