Protobuf Decoder

Protobuf Payload

Schema (optional .proto)

Decoded

What this tool does

Paste a protobuf message as hex or base64 and see what’s inside. Without a schema you get every field number with its value, read the way protoc --decode_raw reads it. Add the .proto file and you get field names, enum names and dates in canonical proto3 JSON. Everything runs in your browser, so the payload never leaves your computer.

It takes the forms protobuf bytes turn up in, and removes what’s wrapped around them:

  • hex with or without spaces, 0x prefixes or commas (0a 08 4f 52, 0x0a, 0x08), base64 and base64url;
  • Python bytes (b'\n\x08ORD-1042'), escaped strings from logs and protoc ("\n\010ORD-1042") and byte arrays ([10, 8, 79, 82]);
  • gRPC messages with their 5-byte length prefix, several messages in a row, gzip-compressed messages and gRPC-Web trailers;
  • Kafka records written with Confluent Schema Registry, which start with the schema’s ID.

Switch to Annotated to see how each field was read: its wire type, its size, and the other ways its bytes could be read.

How protobuf bytes are laid out

A protobuf message is a list of fields, one after another, in no fixed order. Each field starts with a tag: a varint holding the field number and the wire type (the field number times 8, plus the wire type). The wire type says how the value that follows is stored:

Wire type Name Used for
0 VARINT int32, int64, uint32, uint64, sint32, sint64, bool, enum
1 I64 fixed64, sfixed64, double
2 LEN string, bytes, nested messages, packed repeated fields, maps
3 and 4 SGROUP, EGROUP groups (proto2, deprecated)
5 I32 fixed32, sfixed32, float

The example payload above starts like this:

Bytes Read as
0a tag: field 1, wire type 2 (1 × 8 + 2 = 10)
08 length: the next 8 bytes
4f 52 44 2d 31 30 34 32 the text ORD-1042
10 tag: field 2, wire type 0 (2 × 8 + 0 = 16)
c9 d9 04 a varint: 7 bits from each byte, lowest first: 73 + 89 × 128 + 4 × 16,384 = 77,001

Decoding without a schema

The bytes carry field numbers and wire types, but never names or declared types, so a decoder has to make some guesses. This is how this one reads each wire type:

  • Varints are shown as integers. A negative int32 or int64 takes ten bytes and is shown as negative. sint32 and sint64 are zigzag-encoded, so −150 arrives as 299; the Annotated view gives the zigzag reading of every varint (as sint -150). bool and enum values are varints too.
  • Length-delimited fields are shown as text when the bytes are readable UTF-8, as a nested message when they parse as one, and as base64 otherwise. A packed repeated field of numbers looks like bytes, so the Annotated view adds its reading as packed varints.
  • Fixed-width values are shown as a double or float when that gives a sensible number, and as an integer otherwise. The Annotated view shows the other reading.

The example payload, read without its schema:

1: "ORD-1042"               // string · 8 bytes
2: 77001                    // varint · as sint -38501
3: 2                        // varint · as sint 1
4 {                         // message · 14 bytes
  1: "TEA-250"              // string · 7 bytes
  2: 2                      // varint · as sint 1
  3: 1299                   // varint · as sint -650
}
4 {                         // message · 13 bytes
  1: "MUG-01"               // string · 6 bytes
  2: 1                      // varint
  3: 899                    // varint · as sint -450
}
5 {                         // message · 6 bytes
  1: 1795858200             // varint · as sint 897929100
}
6: 34.97                    // fixed64 · as int 4630118407277285212
7 {                         // message · 14 bytes
  1: "channel"              // string · 7 bytes
  2: "web"                  // string · 3 bytes
}
8: "Bww="                   // bytes · 2 bytes · hex 07 0c · as packed varints [7, 12]
9: 299                      // varint · as sint -150

Field 9 is the one to watch: 299 is a sint32 holding −150, which the schema confirms.

Decoding with a .proto schema

Paste the schema into the Schema box. The tool picks the message type that fits the payload best (choose another in the list if it guessed wrong) and writes canonical proto3 JSON: field names in lowerCamelCase, enums by name, 64-bit integers as strings, bytes as base64, Timestamp and Duration as strings, and fields left at their default values left out. Press Use the example schema to see the example decoded with names.

The well-known types (google/protobuf/timestamp.proto and the rest) are built in. If your schema imports files of your own, paste their messages into the box as well. The schema is read by protobuf.js, which loads only when you add one.

Getting the bytes

  • A file: xxd -p message.bin prints it as hex and base64 message.bin as base64. In PowerShell: [Convert]::ToBase64String([IO.File]::ReadAllBytes("message.bin")).
  • gRPC: paste a captured request or response body as it is, such as Wireshark’s Copy › …as a Hex Stream or a gRPC-Web response from the browser’s developer tools. The length prefix is removed, and gzip-compressed messages are decompressed.
  • Kafka: save a record’s value with kcat -C -b localhost:9092 -t orders -c 1 -f '%s' > record.bin, then print it as hex. If the topic uses Confluent Schema Registry, the header is removed and its schema ID shown.
  • Logs: Python prints bytes as b'\n\x08ORD-1042…', and C++ and protoc escape them as "\n\010ORD-1042…". Paste either as it is.

The same with protoc

# hex to bytes, then decode without a schema
xxd -r -p message.hex | protoc --decode_raw

# base64, with the schema
base64 -d message.b64 | protoc --decode=shop.Order order.proto

FAQs

Is my payload sent anywhere? No. Decoding happens in your browser, and nothing you paste is uploaded. The only thing the page downloads is protobuf.js from cdnjs, the first time you add a schema.
Can I decode protobuf without the .proto file? Yes, up to a point. The bytes hold every field number, wire type and value, so you can see the structure and most values. Names aren’t in the bytes, and some types share a wire type, so a sint32 or a float may need the Annotated view’s other readings.
Why does a number look wrong? Usually because of a type the bytes can’t tell apart. sint32 and sint64 are zigzag-encoded (299 is −150), a negative int32 takes ten bytes, and a fixed32 could be a float or an integer. The Annotated view lists the readings, and a schema settles them.
Why is a field shown as a string when it’s a message? A short nested message can happen to be readable text, and text can happen to parse as a message. The tool prefers text, and the Annotated view says “also reads as a message” when both fit. With the schema, each field is read as its declared type.
How is this different from the Proto to JSON converter? Proto to JSON turns a .proto schema into sample JSON, without any data. This tool reads real protobuf bytes: the messages your services send.
Does it handle proto2 and groups? Yes. Groups (wire types 3 and 4) are decoded as nested fields, and proto2 schemas, with required, optional and default values, are read like proto3 ones.
What about Kafka messages from Confluent Schema Registry? Their value starts with a zero byte, a 4-byte schema ID and the index of the message type in its schema. The tool removes that header, shows the schema ID next to the byte count, and decodes the rest.

More Free Developer Tools