HomeBlogProtobuf Without a Schema Is Guesswork

Protobuf Without a Schema Is Guesswork

Decoded 15 Protobuf payloads with protoc --decode_raw and a browser inspector: what raw bytes reveal without a .proto, and where both tools guess wrong.

DevKit is maintained by hcatree. I wrote the tools on this site and ran the compression benchmarks myself — the script and the raw data download from the benchmarks page.

2026-11-1712 min read

"Protobuf is not self-describing" is a sentence you have read a hundred times. It is almost always followed by a tutorial that dumps a raw message and lists the fields as if the answer were obvious.

It is not obvious. I fed the same 15 payloads to protoc --decode_raw and to the decoder that backs this site's Protobuf Wire Inspector, and the two agreed on every one — not because they are both correct, but because they are both guessing the same way. Then I pasted the matching .proto on top of the same bytes, and on the 71-byte example below the schema changed the value, not just the label, in 5 of the 11 field rows.

This article is about exactly where the information ends and the inference begins.

What raw bytes actually give you

Strip away the format guide and one sentence is doing all the work: every field on the wire starts with a key byte that packs the field number and the wire type together. Everything a schemaless decoder knows, it knows from that byte.

Question Answer without a .proto Why
Where does each field start and end? Known exactly The tag and, for length-delimited values, a length prefix make the framing unambiguous
Which field number is which? Known exactly The tag carries it
Which wire type? Known exactly The low 3 bits of the tag
Is it a string or a byte blob? Guessed Both are wire type 2 and encode identically
Is that blob a nested message? Guessed Also wire type 2 — resolved by trying to parse it
Is it a number, a boolean or an enum? Unknown All three are wire type 0
Is that integer negative? Unknown int32, sint32 and uint32 differ only in the schema
What is the field called? Unknown Names never travel on the wire
Was an unset field omitted, or is it zero? Unknown in proto3 Default values are not serialized at all

Four rows are facts. Five are guesses or blanks. Most writing on this topic presents nine rows of output and never says which four are load-bearing.

The tag byte is the only honest part

The official encoding guide defines the key as:

(field_number << 3) | wire_type

and lists six wire types: VARINT (0), I64 (1), LEN (2), SGROUP (3), EGROUP (4), I32 (5). Types 6 and 7 are not defined, which is why a decoder can reject them outright rather than guess.

That single byte is the entire self-describing part of the format. Here is the message the Inspector ships as its built-in example — 71 bytes:

08 e7 07 12 0e 68 65 6c 6c 6f 20 70 72 6f 74 6f 62 75 66 1a 0e 0a 08
53 68 61 6e 67 68 61 69 12 02 43 4e 20 53 2d fb 20 00 00 31 90 f7 aa
95 09 bf 05 40 3a 03 77 65 62 3a 03 6e 6f 76 42 04 03 2c e8 07 48 01
50 01

Slicing it requires no schema at all, and the slice is correct:

08        field 1, wire type 0  (varint)
12 0e     field 2, wire type 2, 14 bytes follow
1a 0e     field 3, wire type 2, 14 bytes follow
20        field 4, wire type 0
2d        field 5, wire type 5  (32-bit)
31        field 6, wire type 1  (64-bit)
3a 03     field 7, wire type 2, 3 bytes
3a 03     field 7 again — the same number appears twice
42 04     field 8, wire type 2, 4 bytes
48        field 9, wire type 0
50        field 10, wire type 0

11 field rows, 10 distinct field numbers, every byte accounted for, zero knowledge required. That framing is the part you can trust.

A Protobuf tag byte split into field number and wire type, and what a schemaless decoder can and cannot recover from it

Wire type 2 is four things wearing one coat

The encoding guide is blunt about what LEN can hold: string, bytes, embedded messages and packed repeated fields. It is equally blunt that a decoder needs the message definition to tell them apart — the wire carries nothing that distinguishes them.

So I built four messages whose payload is the same five ASCII characters, and one whose payload is three tiny integers:

string  "hello"            -> 0a 05 68 65 6c 6c 6f
bytes   "hello"            -> 12 05 68 65 6c 6c 6f
message { city: "hello" }  -> 1a 07 0a 05 68 65 6c 6c 6f
packed  [1, 2, 3]          -> 22 03 01 02 03

The first two differ only in the field number. Same five payload bytes, same wire type, one declared as text and one as an opaque blob. No decoder on earth can separate them, because there is nothing to separate.

protoc --decode_raw prints them as:

1: "hello"
2: "hello"

The Inspector prints the same thing. The third case is where the guessing starts to look like knowledge: 1a 07 wraps 0a 05 68 65 6c 6c 6f, and both tools parse that inner blob as a message with one string field, so it renders as a tree. That is not detection. That is a parse that happened to succeed.

The fourth is the one people trip over. 22 03 01 02 03 is a packed list of three uint32. protoc --decode_raw prints it as a string with escapes:

4: "\001\002\003"

The Inspector refuses to call it a string — its UTF-8 check rejects bytes below 0x20 except tab, newline and carriage return — so it shows bytes · 3 B. Two honest tools, two different answers, and neither is 1, 2, 3. Only the schema knows those four bytes are a list.

The same length-delimited bytes read four different ways: string, bytes, nested message and packed repeated

15 payloads, two decoders, one table

Every row below is a real run on the same bytes: protoc 24.0 with --decode_raw, and the TypeScript decoder in this repository, with no schema supplied to either.

Bytes protoc --decode_raw Inspector, no schema What the schema later said
0a 05 68 65 6c 6c 6f 1: "hello" string "hello" string
12 05 68 65 6c 6c 6f 2: "hello" string "hello" bytes — indistinguishable
22 03 01 02 03 4: "\001\002\003" bytes · 3 B packed repeated uint32 = 1, 2, 3
1a 04 0a 02 68 69 3 { 1 { 13: 105 } } message → message → 105 3 { 1: "hi" } — both wrong
08 01 1: 1 varint 1 bool, enum, uint32, sint32 or int32
1d 00 00 a0 41 3: 0x41a00000 1101004800 and float 20 float = 20.0
19 00 00 00 00 00 00 f0 3f 3: 0x3ff0000000000000 4607182418800017408 and double 1 double = 1.0
0b 08 01 0c 1 { 1: 1 } group → varint 1 deprecated group, still parseable
08 ff ff ff ff ff ff ff ff ff 01 1: 18446744073709551615 same 20-digit integer int32 = -1
10 01 2: 1 varint 1 sint32 = -1
c0 a3 09 07 19000: 7 field 19000, varint 7 a reserved field number
08 80 Failed to parse input. truncated varint value · the two bytes are marked corrupt input
12 7f 41 Failed to parse input. length 127 overruns buffer corrupt input
0e 01 Failed to parse input. invalid tag (field=1, wire=6) impossible tag
(empty) (no output) 0 fields a proto3 message where every field is default

Three things in that table are worth more than the rest.

The two tools never disagree about structure. They disagree only about presentation: protoc prints a length-delimited blob as an escaped string, this decoder refuses to call unprintable bytes a string. Both are defensible; neither is information about the data.

The fixed-width rows are where a browser tool can actually beat --decode_raw. The four bytes 00 00 a0 41 are simultaneously the integer 1101004800 and the float 20.0. protoc hands you 0x41a00000 and leaves the conversion to you. The Inspector prints both readings side by side, because without a schema both are correct and picking one would be a lie.

The error rows are the only place one tool is clearly better. Failed to parse input. tells you nothing about where the message broke. Naming the failure — truncated varint, length overrun, undefined wire type — tells you whether you pasted the wrong encoding or the capture was cut off. That distinction decides whether you keep debugging or go back to the wire.

Where both decoders are wrong

1a 04 0a 02 68 69 deserves its own section, because it is the case that should make you distrust a schemaless dump in general.

The intended message is field 3, a nested message, containing field 1 with the string "hi". Here is what each decoder produced:

protoc --decode_raw        Inspector, no schema
3 {                        f3  LEN 4 B -> message
  1 {                        f1  LEN 2 B -> message
    13: 105                    f13 varint 105
  }                          }
}

Both, identically, destroyed a two-character string.

The reason is mechanical. 68 69 is "hi". It is also a perfectly legal message: 0x68 is a valid tag — field 13, wire type 0 — and 0x69 is a valid one-byte varint with value 105. Both decoders follow the same priority: try to parse length-delimited bytes as a nested message, and if that succeeds, treat it as one. Only if the parse fails do they fall back to text.

That priority is a reasonable default and a permanent source of false positives. A string is allowed to contain any bytes, so an infinite set of strings is also a valid message. The tools cannot tell you which one you have. Neither can you, until the .proto arrives and says field 1 is a string.

The practical rule: a nested message in a schemaless decode is a hypothesis, not a finding. If the "message" has one field with a round number and a wire type that matches nothing you expect, it is probably text you have just shredded.

A varint is not a number yet

Wire type 0 covers int32, int64, uint32, uint64, sint32, sint64, bool and enum. Eight declared types, one wire type.

The cost is not cosmetic. The same -1, declared two different ways:

int32  a = -1   -> 08 ff ff ff ff ff ff ff ff ff 01   (10 bytes)
sint32 c = -1   -> 10 01                               (1 byte)

int32 stores negatives as 64-bit two's complement, so -1 becomes a ten-byte varint. sint32 uses ZigZag, which the guide describes as mapping positive p to 2 * p and negative n to 2 * |n| - 1, so -1 fits in one byte.

Now the part that surprises people. protoc --decode_raw on that ten-byte row prints:

1: 18446744073709551615

That is the unsigned reading of the varint, and it is not wrong — it is the honest answer to a question nobody asked. The bytes do not say "negative". Only the declaration int32 a = 1 does, and only a decoder holding the schema can apply the 32-bit truncation that turns it back into -1.

Same for the one-byte case: 10 01 prints as 2: 1, and the ZigZag reading of -1 is available only once something tells the decoder that this field is sint, not int.

08 01 is the compressed version of the whole problem. One value byte, and every one of these is consistent with it: true, false, enum member 1, 1u, -1 as ZigZag, and the integer 1. A schemaless dump showing you 1 is not misleading — but a reader who types that into a bug report as "the flag was 1" may be reporting an enum.

proto3 deletes the field you most want to see

The encoding guide, explaining why absent fields simply are not there:

"we just leave out the record if it's not present"

In proto3, a field holding its default value is not serialized. I encoded a message where every field is at its default and measured the result: 0 bytes. Not a small message — nothing.

For a schemaless decoder that is the worst case in the format. An empty input is not a parse failure, it is a valid message, and there is no way to know whether the sender set ten fields to zero, false and empty string, or set nothing at all. protoc --decode_raw prints nothing. The Inspector reports 0 fields. Both are correct, and both will send you back to the sender's code.

This is also why counting fields in a raw dump tells you nothing about the shape of the schema. You are counting the fields that were not default.

What the schema still owns

Paste the .proto and the message type name, and the same 71 bytes become this. Verified against protoc --decode=demo.Order on the identical input:

id: 999
note: "hello protobuf"
ship {
  city: "Shanghai"
  country: "CN"
}
delta: -42
port: 8443
ratio: 2.71828
tags: "web"
tags: "nov"
nums: 3
nums: 44
nums: 1000
source: WEB
paid: true

Against the schemaless table above, the schema is doing five distinct jobs, and only one of them is naming:

  • Names. field 4 becomes delta. The presentation change everyone notices, and the least consequential one.
  • Width and signedness. 83 becomes -42, because the declaration says sint32. The 20-digit integer becomes -1, because the declaration says int32.
  • Which of the four LEN readings is real. bytes · 4 B becomes 3, 44, 1000, because nums is packed.
  • Grouping. Two separate field 7 rows become one repeated string with two elements. Repetition is invisible on the wire; only the schema groups it.
  • Vocabulary. 1 becomes WEB, because source names an enum.

One rule the schema owns but a decoder cannot enforce: field numbers must sit between 1 and 536,870,911, and the range 19000 to 19999 is reserved for the implementation. Both are compile-time facts. Feed c0 a3 09 07 to either tool and both print field 19000 without comment, because a raw message cannot be told it is using a forbidden number. Schemaless output is well-formed framing, not a valid schema.

The limits of guessing

The decoder here is not magic, and its limits are worth stating because they are the same limits every schemaless reader has:

  • Nesting is capped, and the two tools cap it in different places. I built a 40-level message — 80 bytes, one next field per level, a leaf int32 = 7. protoc --decode_raw opens 10 levels and then prints the last 30 bytes as an escaped string. The decoder here opens 24 levels (MAX_DEPTH) and leaves the same 30 bytes as an opaque LEN blob. Recursion on a guess has to stop somewhere; what matters is that neither tool says that it did, so a 10-level dump and a 24-level dump of one input both look complete.
  • A varint longer than 10 bytes is rejected, because that is the format's own maximum — the guide gives "one and ten bytes" as the range.
  • Deprecated groups still decode. Wire types 3 and 4 are described in the spec as "a deprecated feature that should not be used" but remain in the format, so a payload containing one is not corrupt.
  • Field 0 and wire types 6 and 7 are hard errors, not warnings. If you see invalid tag (field=1, wire=6), the input is almost certainly not Protobuf at all — it is compressed, encrypted, or you are looking at the HTTP framing rather than the body.

When to decode without a schema, and when to stop

Schemaless decoding is the right tool when the question is structural:

  • Is this blob Protobuf at all? If the first bytes slice into sane field numbers and the whole buffer is consumed, it is.
  • Did the field I care about get on the wire? Presence and absence are facts, not guesses.
  • Which field numbers does this API actually use? Enough to write a first .proto for an undocumented service.
  • Is my encoder emitting defaults it should not be?

It is the wrong tool when the question is semantic. Do not file a bug that says "the API returned 18446744073709551615" — that is an int32 of -1 seen without its schema. Do not conclude a nested message exists because the parser drew a tree. Do not treat a bytes · 3 B blob as binary when it is a packed list.

The workflow that survives contact with reality is two passes: read the framing schemalessly to confirm the shape and collect field numbers, then get the .proto and re-read the same bytes. If you cannot get the .proto, write one from the field numbers you collected and check your guesses against a second message. A schemaless dump is a hypothesis generator. The bug is in the hypothesis.

Try it in the browser

The Protobuf Wire Inspector on this site decodes Base64 or hex with no .proto — the same field tree as protoc --decode_raw, plus both readings of every fixed-width value, plus an error that says why the parse stopped and leaves the offending bytes highlighted in the byte map. Hovering any row highlights the bytes it came from. Paste a schema and the field names, signedness, enum labels and packed lists land on the same tree. The current input and schema are kept in the URL fragment, so a finding is shareable as one link — and a link that carries only bytes opens with no schema overlaid.

For the encoding side, the JSON ↔ Protobuf tool converts between JSON, Base64 and binary from uploaded .proto files with imports resolved, which is how to produce the test bytes in this article yourself.

The size and speed consequences of the format are measured in Protobuf vs JSON: Size, Speed and Trade-offs, which covers the wire rules behind the tag byte in more detail.


References:

Environment: libprotoc 24.0 and Node.js v24.22.0 on Windows x64, protobufjs 8.8.0. Every protoc output above came from protoc --decode_raw reading the payload on stdin; the Inspector column came from decodeWire() in this repository, the same function the tool page runs in your browser. Payloads were encoded with protobufjs from the schemas shown inline. The .proto-overlay column was produced by protoc --decode=demo.Order and cross-checked against the Inspector's own overlay path. Measured 2026-11-17.

Discuss this articleEchoForum · no sign-up, replies in any language

Related Tools

Protobuf Wire InspectorDecode Protobuf binary without a schema
JSON ↔ ProtobufConvert JSON and Protocol Buffers