Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add an int array in a protobuf message

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?

like image 212
javaMan Avatar asked Sep 13 '11 20:09

javaMan


People also ask

How do I add comments to a proto file?

Adding Comments To add comments to your .proto files, use C/C++-style // and /* ... */ syntax.

How big can a protobuf message be?

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.

Does protobuf handle endianness?

Protocol buffers messages always use little-endian encoding.

How do you serialize an object in protobuf?

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.


1 Answers

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]; 
like image 100
Marc Gravell Avatar answered Sep 29 '22 02:09

Marc Gravell