在 protobuf 消息中存储单个字节 [英] Store a single byte in a protobuf message
问题描述
我使用什么数据类型在协议缓冲区消息中存储单个字节?在 https://developers.google.com/protocol-buffers/docs 查看列表/proto#scalar 似乎 *int32 类型之一是最合适的.有没有更有效的方式来存储单个字节?
好吧,您需要了解无论如何它至少需要两个字节 - 一个用于标记,一个用于数据.(如果字段编号较高,标记将占用更多空间.)如果您使用 uint32
,则对于高达 127 的值,数据将占用 1 个字节,对于任何更大的值,将占用 2 个字节.>
我认为没有比这更有效的方法了.
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?
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.
这篇关于在 protobuf 消息中存储单个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!