A Protobuf Extension Is a Regular Field (and the Wire Has No Idea)
I encoded a field my schema did not define and read the bytes. It travels like any field, because it is any field. The extension gets a number out of a declared range, one hundred to two hundred here, and on the wire that number is the only thing that matters. I set a nickname extension at number one hundred on a message carrying a name and an age, and the stream came out with a two-byte tag, the length, the word. Nothing in those bytes says the field is an extension. The extension part is a fact about the schema, not about the stream. The tag is just the number one hundred with the wire type folded in, and one hundred needs two bytes to write, so the tag is two bytes where a small field would be one. That is the first place people get tripped up: the extra byte is not an extension marker, it is the number being large.
Because the wire does not carry the marker, a reader who does not have the extension definition gets a message with one fewer field and no error. The field is still in the stream, the bytes are intact, but the schema in hand does not list that number, so the decoder sets it aside as unknown and moves on. I decoded the same stream with a schema that had no extension and the nickname was gone, name and age intact, no warning. That is the whole risk in one sentence: a service ships an extension, an older version decodes the message, and the field is silently not there. It is the unknown-field behavior you would expect, except the field is new and real and somebody is writing it, so the data is lost on exactly the readers that are still out there, and the only symptom is a value that was supposed to arrive and did not. In production that reads as missing data, not as a schema version gap, and it points the debugging at the app instead of at the two .proto files disagreeing.
The JSON side has its own door, and it is narrower than the well-known types but the same species. The converter names the extension with a leading dot, so the object it hands you is the base fields plus a key that starts with a dot and then the name. The input side is the same dot, and that is the trap: feed the encoder the plain key without the dot and it does not recognize it, drops the value, and encodes the base fields alone. No error. The value left before it was written, and the round trip completes. It is the third variation of the pattern the Timestamp, Duration and Any posts each showed in a different way: the library and the spec do not agree on a shape, and the mismatch does not throw, it loses. For Any the loss was the whole payload; for an extension it is one field, which is less catastrophic and harder to notice because the field was optional to begin with.
The declaration side is quieter than you would guess. The range statement that reserves the numbers is what the generators care about, and it is what keeps two extensions from colliding, but the parser will take an extension even without the range line and encode it the same way, same tag, same bytes. The range is a bookkeeping promise between the files, and a file can break the promise and the wire will not tell. That is the part the diff view earns: two versions of the file, and the new extension is listed as an addition with its number, so the reader who is about to merge sees that an older decoder will drop it, without having to know what an extension is or to guess from the bytes.
All of it runs in the browser with no protoc. Paste a file with an extension, encode a message with the dot-prefixed key, and the bytes show the field exactly as a field, two-byte tag and all, with the word sitting in the clear at the end of the stream. Decode the same bytes with a file that has no extension and watch the field leave with no error, which is the behavior you want to have seen before it happens to you in production. The raw decode tab at proto.datajutsu.com shows the extension as a plain field number before the schema gets a vote, which is the fastest way to see that a stream you cannot fully explain is carrying fields your file does not know about. The sister post on how the tags are built is the wire format post, and the one on reading field numbers without the schema is the unknown fields post, the two halves of what an extension is on the wire.