why 2^29-1 is the biggest key in protocol buffers

2019-09-20 11:57发布

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?

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

1条回答
该账号已被封号
2楼-- · 2019-09-20 12:48

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.

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.

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

查看更多
登录 后发表回答