protocol buffers 官方文档 https://developers.google.com/protocol-buffers/docs/proto3说 protobuf 消息中字段的最大字段数是 2^29-1。但为什么是这个限制?
请问谁能详细解释一下?我是新手。
我在 why 2^29-1 is the biggest key in protocol buffers 阅读了这个问题的答案.
但我没有澄清
最佳答案
编码 Protocol Buffer 中的每个字段都有一个 header (称为键或标签)作为实际编码值的前缀。 encoding spec定义这个键:
Each key in the streamed message is a varint with the value (field_number << 3) | wire_type – in other words, the last three bits of the number store the wire type.
这里的规范说标签是一个 varint,其中前 3 位用于对电线类型进行编码。 varint 可以编码一个 64 位的值,因此只要继续这个定义,限制就是
2^61-1
.除此之外,Language Guide将其缩小到最大 32 位值。
The smallest field number you can specify is 1, and the largest is 2^29 - 1, or 536,870,911.
没有给出原因。我只能推测这背后的原因:
关于protocol-buffers - protobuf 消息中的最大字段数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57520857/