Protobuf Decoder for Raw Hex, Base64 or Binary Files
Operator: Abdulla Al Fahad. How tools are built and checked
A protobuf blob in a trace or a database column carries no field names and no types, only numbers. The three bytes 08 96 01 are the tag 08, meaning field 1 as a varint, followed by the varint 96 01, which is 150. Paste bytes here as hex or base64, or open the file, and each field is listed with its number, its wire type and the values it could be: 150 unsigned, 150 as int64, 75 if it was a zigzag sint, and true or false when a value is 0 or 1.
Length-delimited fields are the ambiguous ones, because a string, a nested message, packed numbers and raw bytes all look the same on the wire. The page tries each reading in turn and picks the first that fits: valid printable UTF-8 as a string, then a well-formed nested message, then packed varints or fixed-width numbers, then bytes. A selector on every row lets you overrule the guess; the worked example below has a field that parses two ways.
With the .proto in hand, paste it and the same bytes decode to named JSON; the Encode tab goes the other way and writes JSON back into bytes.
Key features
- Hex (spaces, 0x, \x escapes, xxd dumps), base64, base64url or a binary file of up to 8 MB
- Varint, zigzag, int64, bool, fixed32 and fixed64 views for every scalar, with 64-bit values kept exact
- Per-field choice between string, nested message, packed numbers and bytes
- A mini .proto reader for messages, enums, nested types, repeated, optional, oneof and map fields
What the wire format tells you, and what it cannot
A field starts with a varint tag: the field number is the tag shifted right by 3 and the wire type is its low 3 bits. Wire type 0 is a varint, 1 a fixed 64-bit value, 2 a length-delimited payload, 3 and 4 the deprecated group start and end, and 5 a fixed 32-bit value. Types 6 and 7 do not exist, so a tag that uses them marks the message as malformed. A varint longer than 10 bytes, a length that runs past the end and a truncated fixed value do the same, and the message error names the offset where parsing broke.
A 5-byte gRPC or Connect frame header (a zero flag byte and a 4-byte length that equals the rest of the input) is removed automatically and noted. If the flag byte is 1 the payload is compressed, usually with gzip, and the page asks you to decompress it first. Nested guesses stop at 14 levels, and a message of more than 100,000 top-level fields is reported as too large, with the first 100,000 listed. Fields read while guessing whether a payload is a nested message have their own, larger allowance, so those guesses cannot make a valid message look malformed.
JSON from a schema follows the protobuf JSON mapping: 64-bit integers as strings, bytes as base64, enums by name (the number if the name is unknown), NaN and the infinities as strings, maps as objects. Fields the schema does not describe, or that arrive with the wrong wire type, are collected under _unknown_fields instead of being dropped.
How it works
The .proto text is tokenised and read for syntax, package, message, enum, oneof and map definitions, with type names resolved outward through the enclosing messages. import lines are noted but not followed, and services, options, extensions and proto2 groups are skipped, so paste dependent messages into the same box.
When this helps
- A support engineer copies a 58-byte message from a trace, pastes the 16-line .proto of the service, and reads name Alice, id 150, one email, a customer enum value, a city, a zip stored as a fixed32 and three zigzag scores of -1, 2 and 300.
- A developer finds a protobuf column in a database, has no schema, and sees field 5 decode as a nested message of two string fields while field 6 is a packed run of varints she recognises as timestamps.
- A mobile developer builds a test fixture by writing the JSON for a message, encoding it with the .proto, and copying the hex into a unit test.
Opening a file
- Paste hex or base64 into the Bytes box and press Decode, or drop a binary file.
- Read the Wire fields table and change any length-delimited row whose guess is wrong.
- Paste a .proto, press Read .proto, pick the message type and press Decode with schema.
Example
The built-in 58-byte demo.Person message, pasted as hex (7 fields, offsets start at 0)
0a 05 41 6c 69 63 65 10 96 01 1a 11 61 6c 69 63 65 40 65 78 61 6d 70 6c 65 2e 63 6f 6d 20 01 2a 0c 0a 05 50 61 72 69 73 15 61 1e 00 00 32 04 01 04 d8 04 3a 05 0a 01 61 10 05Wire fields table (offsets are start to end, end exclusive), then the JSON after pasting the 16-line demo.Person .proto
0-7 field 1 len "Alice"
7-10 field 2 varint 150 (zigzag 75)
10-29 field 3 len "alice@example.com"
29-31 field 4 varint 1 (true)
31-45 field 5 len message: 1 = "Paris", 2 = fixed32 7777
45-51 field 6 len packed varints 1, 4, 600 (zigzag -1, 2, 300)
51-58 field 7 len message {1 = "a", 2 = 5}, or packed varints 10, 1, 97, 16, 5
With the .proto: {"name": "Alice", "id": 150, "emails": ["alice@example.com"], "kind": "CUSTOMER", "address": {"city": "Paris", "zip": 7777}, "scores": [-1, 2, 300], "counters": {"a": "5"}}Tips for best results
- Use field-number JSON from the second view when you have no schema but want to change one value: edit it there, switch to Encode in field-number mode, and the bytes come back with every other field untouched.
- A varint whose unsigned view is a number near 1.8e19, such as 18446744073709551615, is a negative int32 or int64 in two's complement; the int64 column beside it shows the real value, -1.
- If a printable string is shown as a nested message, or the reverse, change the Read as selector on that row. A two-letter string such as hi (68 69) also reads as field 13 holding the varint 105, and field 7 of the example has the same split between a map entry and five packed varints; the schema decides which is right.
Limits
Without a schema, int32, uint32 and enum all look alike, and so do float and fixed32; the table shows each reading rather than choosing one, because the bytes cannot say.
A real parser merges a non-repeated message field that appears twice. The schema decoder here keeps the last occurrence instead, so a stream built from partial updates can show fewer fields than the application would see.
Common errors and how to fix them
- "The bytes are not a valid protobuf message: the field at offset 12 is malformed"
- The first 12 bytes parsed and the field after them did not. The fields before the break are still listed. Check that the payload was copied completely and that no framing, such as a length prefix or a gRPC header, sits in front of it.
- "$.id: 99999999999 is outside the range of int32 (-2147483648 to 2147483647)"
- Encoding checks every number against its declared type. Use an int64 field for that value, or a smaller number.
Frequently asked questions
Why is my text shown as a nested message?
Some byte strings are valid both as text and as a sequence of fields, so the guess can be wrong. The first interpretation is chosen by a fixed order and every other one that fits is offered in the Read as selector next to it.