aakash-sahai / nanopb

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

pb_enc_varint() error #6

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi!

I have done one test as goes wrong.

doppio:~/tmp/nanopb/rkm> ./rkm
ERROR endian_copy #284 destsize:8 srcsize:16 EXIT
doppio:~/tmp/nanopb/rkm> 

Is this way to use the packet not OK?

In dir rkm you find my test and I have add some code lines in the pb_encode.c:

-----------------------pb_encode.c----------------------
static void endian_copy(void *dest, const void *src, size_t destsize, size_t 
srcsize)
{
    if (destsize < srcsize)
    {
        fprintf(stderr, "ERROR %s #%d destsize:%zu srcsize:%zu EXIT\n",__func__,__LINE__,destsize, srcsize);
        exit(1);
    }
.....
---------------------

MvH/roger@karlbom.ws

PS: I run on a 64 bit ubuntu 10.04

Original issue reported on code.google.com by roger.ka...@gmail.com on 1 Mar 2012 at 9:09

Attachments:

GoogleCodeExporter commented 9 years ago
This is related to Issue 2. I'm only now starting to see how confusing both the 
field encoder and the field decoder interfaces are.

The issue is that the "field" passed to your callback function describes a 
pb_callback_t type field, whereas the pb_enc_varint() expects an integer field. 
This distinction makes sense internally, but in the library API it is terribly 
confusing.

Please use pb_encode_varint() instead. It has a cleaner interface and functions 
identically (it takes a 64-bit parameter, but works for encoding 32-bit 
parameters also as the binary format does not care about field width). I'll 
have to add thin wrappers to make sint32, fixed32 etc. encoding easy also.

Original comment by Petteri.Aimonen on 1 Mar 2012 at 10:25

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 9fbe9a5de30c.

Original comment by Petteri.Aimonen on 1 Mar 2012 at 11:51