Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

protocol buffers : no notation for fixed size buffers?

Since I am not getting an answer on this question I gotta prototype and check myself, as my dataset headers need to be fixed size, I need fixed size strings. So, is it possible to specify fixed size strings or byte arrays in protocol buffers ? It is not readily apparent here, and I kinda feel bad about forcing fixed size strings into the header message. --i.e, std::string('\0', 128);

If not I'd rather use a #pragma pack(1) struct header {...};'

edit

Question indirectly answered here. Will answer and except

like image 671
Hassan Syed Avatar asked Apr 10 '12 15:04

Hassan Syed


1 Answers

protobuf does not have such a concept in the protocol, nor in the .proto schema language. In strings and blobs, the data is always technically variable length using a length prefix (which itself uses varint encoding, so even the length is variable length).

Of course, if you only ever store data of a particular length, then it will line up. Note also that since strings in protobuf are unicode using UTF-8 encoding, the length of the encoded data is not as simple as the number of characters (unless you are using only ASCII characters).

like image 136
Marc Gravell Avatar answered Sep 27 '22 19:09

Marc Gravell