Start with one integer.
This proto3 definition has a single uint32 field numbered 1. Encoding the JSON object {"id":150} produces the three bytes 08 96 01. You can paste the definition into the schema workspace and reproduce the result.
syntax = "proto3";
message Example {
uint32 id = 1;
}
// JSON: {"id": 150}
// Hex: 08 96 01Read 96 01 as the integer 150.
A varint uses seven data bits per byte. The high bit says whether another byte follows. In 96, the high bit is set and the lower seven bits are 0x16, or 22. The next byte is 01, so the result is 22 + (1 << 7) = 150.
This interpretation is an unsigned integer. A schema is still needed to distinguish ordinary integers, bools, enums and ZigZag-encoded sint values. For example, a raw varint value of 1 represents -1 when its declared type is sint32.
96 01
10010110 00000001
0010110 0000001
22 + (1 * 128) = 150A length tells you where the next field begins.
For field 2 with wire type 2, the tag is 12 in Hex. The next varint gives the byte length. The bytes 12 02 48 69 therefore contain field 2 with a two-byte value, which can be interpreted as the UTF-8 text Hi.
A length counts bytes, not visible characters. UTF-8 characters may take multiple bytes. The same outer encoding is also used for embedded messages, raw bytes and packed scalar arrays.
syntax = "proto3";
message Greeting {
uint32 id = 1;
string text = 2;
}
// JSON: {"id":150,"text":"Hi"}
// Hex: 08 96 01 12 02 48 69Structure is observable. Meaning needs a schema.
Without a .proto definition, you can identify field numbers, wire types and encoded lengths. You cannot reliably recover names, choose among scalar types that share a wire type, or determine whether an arbitrary length-delimited value was meant to be a nested message.
Field order is not a reliable definition of meaning, and byte-for-byte equality is not a universal test of message equality. Different valid serializations can represent the same logical data. Use a schema-aware interpretation when correctness matters.
Reference material
Use the specifications for details beyond these examples.