Protobuf Encoding
Code
- Start with the integer you want to encode.
- Break it into 7-bit chunks. These chunks are extracted from the least significant bits of the number.
- Set the most significant bit (MSB) of each chunk to 1 if there are more chunks to follow, and to 0 for the last chunk.
- Combine these chunks into bytes and output them in order.
- Read bytes one by one.
- For each byte, strip the MSB and collect the remaining 7 bits.
- If the MSB is 1, continue to the next byte. If the MSB is 0, this is the last byte.
- Combine all 7-bit groups into the original number.