key/tag encoding when message types > 31

32 views
Skip to first unread message

emaz...@cisco.com

unread,
Jan 8, 2021, 7:47:34 AM1/8/21
to Protocol Buffers
Hello...

I appreciate the clear documentation on encoding here:

However it doesn't discuss how the key/tag is encoded when the number of message types exceeds 5 bits (31).

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.

What happens if the message type is 76 for example? That is 0x4c. If the data encoding is 000 for a varint then this is just  0x0260. Is that how it is represented in the data stream? Or is it encoded like a varint which I *think* is 0xe004?

Appreciate any information on this.

Thanks,

Ed Mazurek

Marc Gravell

unread,
Jan 8, 2021, 8:59:52 AM1/8/21
to emaz...@cisco.com, Protocol Buffers
The composed wire-type and field number are treated as a varint. And since the MSB is reserved for continuation, after the 3-bit wire type that only leaves 4 bits of field number, not 5, for single-byte field headers.

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/0f270391-fe31-4d0d-a736-874c0520a147n%40googlegroups.com.

emaz...@cisco.com

unread,
Jan 8, 2021, 9:05:44 AM1/8/21
to Protocol Buffers
Hi Marc,

OK thanks. 4 bits... Right. So for 76 it would look like 0xe004 in a wireshark trace ?

Thanks,
Ed

Marc Gravell

unread,
Jan 8, 2021, 1:51:13 PM1/8/21
to emaz...@cisco.com, Protocol Buffers
Field number 76 with which wire type? The lowest 3 bits are the wire-type, then the field number is whacked on the end. Then split into groups of 7 bits for varint encoding.

emaz...@cisco.com

unread,
Jan 8, 2021, 2:13:45 PM1/8/21
to Protocol Buffers
Ok yes... varint wire type so the 0x4c is 0x260. then it turns into 0xe004.

Thanks,

Ed
Reply all
Reply to author
Forward
0 new messages