-1

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.

diwangkai
  • 1
  • 2

1 Answers1

1

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

jpa
  • 10,351
  • 1
  • 28
  • 45
  • the largest key 2^29 where the tag? – diwangkai Feb 26 '16 at 01:53
  • 7 bits per byte,one bit is tag,so 4*7 = 28 ,28 - lowest 3 = 25 is not 29 – diwangkai Feb 26 '16 at 01:55
  • @diwangkai Unfortunately I do not understand what you are trying to say. There is no reason to limit the 7-bit varint encoding to 4 bytes. And I have no idea what "one bit is tag" means. – jpa Feb 26 '16 at 05:34
  • numbers 1 -15 only one byte because 8 bits -1 bit tag - lowest 3 bits = 4 bits,2^4 = 16 ok,that's 1-15; numbers 2^29-1 four bytes ,32 bits - 4 bits tag - lowest 3 bits = 25 bits,is not 29 bits ,not 2^29-1 ,is 2^25-1 for largest. – diwangkai Feb 26 '16 at 06:06
  • There is no need to limit varints to 4 bytes. The uint32_t limit is for convenience for the in-memory representation, before encoding or after decoding. And also, in protobuf "tag" generally means the tag number specified in .proto. The usual term for the top bit in varints is "continuation bit" or just "msb". – jpa Feb 26 '16 at 15:32
  • I want to see the source code ...I want to know how to work.Can you show me where in source code? – diwangkai Feb 27 '16 at 05:51
  • I`m waiting for you~~ – diwangkai Mar 04 '16 at 09:05