Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store a single byte in a protobuf message

What data type do I use to store a single byte in a protocol buffer message? Seeing the list at https://developers.google.com/protocol-buffers/docs/proto#scalar it seems like one of the *int32 types are the best fit. Is there a more efficient way to store a single byte?

like image 668
Agnel Kurian Avatar asked Oct 23 '25 14:10

Agnel Kurian


1 Answers

Well you need to understand that it will take at least two bytes anyway - one for the tag and one for the data. (The tag will take more space if the field number is high.) If you use uint32, it will take 1 byte for the data for values up to 127, and 2 bytes for anything larger.

I don't believe there's anything that will be more efficient than that.

like image 99
Jon Skeet Avatar answered Oct 27 '25 01:10

Jon Skeet