为什么 2^29-1 是协议缓冲区中最大的关键 [英] why 2^29-1 is the biggest key in protocol buffers

查看:62
本文介绍了为什么 2^29-1 是协议缓冲区中最大的关键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

2^29 -1 ?因为字段编号 1-15 有一个 1 字节的标签."
32字节没有标签?我知道 3 字节,但为什么没有标签?

2^29 -1 ? Because "Field numbers 1-15 have a 1-byte tag."
32-byte don't have the tag? I know the 3-byte,but why don`t have the tag?

那是varint吗?protobuf\descriptor.cc 源码看不懂.

Is that varint? I can`t understanding the protobuf\descriptor.cc source code.

推荐答案

所有字段都有一个标记,但对于编号为 16 及更高的字段,标记占用多个字节.因此字段编号 1 到 15 应该用于最常见的字段.是的,编码是 varint.

All fields have a tag, but for field numbers 16 and higher the tag takes multiple bytes. So field numbers 1 to 15 should be used for the most common fields. And yes, the encoding is varint.

最大的键是 2^29,因为最低 3 位用于存储字段数据类型.所以 29 + 3 = 32 正好适合 uint32_t.

The largest key is 2^29 because the lowest 3 bits are used to store the field datatype. So 29 + 3 = 32 fits neatly into uint32_t.

您会在此处找到更多信息:https://developers.google.com/protocol-buffers/docs/encoding#structure

You will find more information here: https://developers.google.com/protocol-buffers/docs/encoding#structure

这篇关于为什么 2^29-1 是协议缓冲区中最大的关键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆