Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nanopb/nanopb.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/pb.h
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-04-02 20:55:21 +0400
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-04-02 20:55:21 +0400
commit214b0eae8aa011fa8b3e8a3dcc784f8d423aeffb (patch)
tree8cdebc1ab067bca01d47eefcc9dcf43ce50048db /pb.h
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 'pb.h')
-rw-r--r--pb.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/pb.h b/pb.h
index b9c3f75..61649e9 100644
--- a/pb.h
+++ b/pb.h
@@ -203,10 +203,19 @@ typedef struct _pb_istream_t pb_istream_t;
typedef struct _pb_ostream_t pb_ostream_t;
typedef struct _pb_callback_t pb_callback_t;
struct _pb_callback_t {
+#ifdef PB_OLD_CALLBACK_STYLE
+ /* Deprecated since nanopb-0.2.1 */
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);
} funcs;
+#else
+ /* New function signature, which allows modifying arg contents in callback. */
+ 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, void * const *arg);
+ } funcs;
+#endif
/* Free arg for use by callback */
void *arg;