How to create a proto file for short int and unsigned char params.

2,975 views
Skip to first unread message

Shiva Naidu

unread,
Jan 14, 2015, 9:18:48 AM1/14/15
to nan...@googlegroups.com
Hi All,
    struct A {
    int   a1;
    short a2;
    unsigned short a3;
    unsigned char a4;
    char a5;
   } AA;

  Can you please let me know how to define the proto file for parameters "short", "unsigned short", "char" and "unsigned char".

Regards,
Shiva

Petteri Aimonen

unread,
Jan 14, 2015, 11:16:10 AM1/14/15
to nan...@googlegroups.com
Hi,
The smallest datatype in .proto is int32. Nanopb 0.3.2 will have
int_size option for limiting the size in the struct, but that is only a
memory saving feature.

Why do you want to make them unsigned short / whatever?

--
Petteri

Shiva Naidu

unread,
Jan 15, 2015, 2:18:10 AM1/15/15
to nan...@googlegroups.com
Hi Petteri,

Why do you want to make them unsigned short / whatever?
 -> I am building a standard message structure, in which some of the parameters are "short int", "unsigned short int", "unsigned char", "char", "long long", "unsigned long long". I need to encode this structure using GPB.

-> Since the message structure is a standard message with parameters that has data types which i mentioned above. I can't change the data types of that structure, but want to encode them using GPB for that datatypes as-well. 

-> Do you have other suggestion on how to encode these types of parameters. Previously i used to use ASN encoder, now i am trying to integrate my code with GBP.

Regards,
Shiva

Petteri Aimonen

unread,
Jan 15, 2015, 3:07:47 AM1/15/15
to nan...@googlegroups.com
Hi,

> -> Since the message structure is a standard message with parameters that
> has data types which i mentioned above. I can't change the data types of
> that structure, but want to encode them using GPB for that datatypes
> as-well.

Currently there is no support for such very precise control of the
generated structure. You'll probably have to copy the data from your
"standard structure" which you cannot change to the nanopb generated
structure.

--
Petteri

Michael Haberler

unread,
Jan 15, 2015, 3:21:37 AM1/15/15
to nan...@googlegroups.com
Shiva,

well everybody is using 'their' structs but then you have a given protobuf type universe to encode these in - see https://developers.google.com/protocol-buffers/docs/proto

you are expected to map your types onto these - so find a protobuf type wide enough for each of your fields and use that in your proto

Those techniques are basic C and this is not a nanopb question afterall; maybe perusing some protobuf-using code and going through the google tutorial helps

- Michael
> --
> You received this message because you are subscribed to the Google Groups "nanopb" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to nanopb+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages