Agnel Kurian
Agnel Kurian

Reputation: 59466

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?

Upvotes: 4

Views: 4622

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500525

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.

Upvotes: 5

Related Questions