I have to compose a protobuf message which should have 1 integer variables and a integer array.
package protobuf; message myProto { optional uint32 message_id =1; optional int update = 2; //here I have to add a array of integers //can I write like optional int[] array =3; //or should I use optional repeated array; //where array is another message with int variable }
Is my approach correct?
Adding Comments To add comments to your .proto files, use C/C++-style // and /* ... */ syntax.
Protobuf has a hard limit of 2GB, because many implementations use 32-bit signed arithmetic. For security reasons, many implementations (especially the Google-provided ones) impose a size limit of 64MB by default, although you can increase this limit manually if you need to.
Protocol buffers messages always use little-endian encoding.
Protobuf is create for serialize purpose so I recommend you no need to serialize it again to a Serializable or Parcelable object. Instead of, serialize it to byte array and put byte array to to bundle.
Array is mapped via "repeated":
repeated int32 data = 4;
Note you might want sint32/uint32. Also note that in all three cases "packed arrays" can be used, which are more efficient;
repeated int32 data = 4 [packed=true];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With