aakash-sahai / nanopb

Automatically exported from code.google.com/p/nanopb
zlib License
0 stars 0 forks source link

Callback decode function argument #69

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi all.

In struct _pb_callback_t it could be better to have prototype of decoding 
callback like this:
bool (*decode)(pb_istream_t *stream, const pb_field_t *field, void **arg);

( Also in function decode_callback_field modify pCallback->arg to 
&(pCallback->arg) )

So in callback I could completely handle arg as storage to anything. 
I have not to inicialize it first. NULL return value is usefull - could 
signalize that optional field was not processed. 
Now I have to fill callback function, allocate some struct or pointer and store 
pointer of it to arg.
In callback I could only manage content of my struct.
It could be much better that i could create it inside callback and store only 
pointer to it.

This could be very usefull with strings. Decoding callback simply allocate new 
string and store it directly to arg pointer.

Thanks

Original issue reported on code.google.com by P.Sta...@gmail.com on 2 Apr 2013 at 3:53

GoogleCodeExporter commented 9 years ago
Hmm, this does seem like a good idea.

Only problem is backwards compatibility. It'll have to be optional in some way:

1) #ifdef could be the most straightforward. Only problem is that it would be 
project-wide.
2) It could be a new ATYPE, but this seems like unnecessary bloat.

Original comment by Petteri.Aimonen on 2 Apr 2013 at 3:59

GoogleCodeExporter commented 9 years ago
This issue was updated by revision 214b0eae8aa0.

Original comment by Petteri.Aimonen on 2 Apr 2013 at 5:02