A Protobuf Extension Is a Field Number on the Message It Extends (and the Report Path Carried a Package You Never Wrote There)

An extend block is the part of a .proto file that looks like it belongs to a different message, and for a while that is how the diff report drew it. I took a message, added an extension to it, and ran the change through the diff tab's real comparison function, not a copy, and the extension did not get its own special handling at all. It is registered on the message it extends, as an ordinary field with a field number, and the machinery that already knows how to add and remove and renumber and retype a field just applied that same machinery to it. Add the extension and it is a new field, a safe addition. Remove it and it is a removed field, a breaking change. Move its number from 100 to 200 and it is a field-number change, the one that silently lands old bytes in the wrong place. Re-type it from a string to bytes and it is a same-wire retype, the old bytes still decode and the values get re-read. None of it is special, which is the point.

The one place the extension is not an ordinary field is how the parser names it, and that name is what the report showed. A normal field on a message named Base in a package called demo is stored under the bare name, nickname. An extension of that same message is stored under a fully-qualified name with a leading dot, .demo.nickname, the package walked back into the field's own label. Without a package the leading dot is still there, .nickname. That label is not a mistake, it is how the library keeps an extension's key distinct, and it is also the key the JSON hand-off uses, the same leading-dot key the extensions post covers. But the report builds the path to each field by taking the message's path and appending the field's name with a dot in between. For a normal field that reads demo.Base.nickname. For the extension, with its name already carrying .demo.nickname, the same append produced demo.Base..demo.nickname. Two dots. The message path, and then the field's own package-qualified name, stacked on top of each other.

So the line in the breaking-changes report that was supposed to point at one field pointed at a path with a second dot in it, and the second dot was a package name the person writing the change never wrote in that place. You add an extension and the report lists it under a doubled-up path. You remove one and the breaking line carries the same doubled path. If you are scanning a long report for a field by its name you are reading demo.Base..demo.nickname, and half of what you see is the library's internal label, not your file. The fix is the small one, and it is already in the tool. The path builder now takes just the field's own name, nickname, off the leading-dot-qualified label and uses that, so the same field reads demo.Base.nickname, one dot, the message path and the name. I ran the real function over all four branches, add and remove and renumber and retype, and every line came back clean, and a normal field still reads M.a with nothing over-stripped, because the strip only fires on a name that actually starts with a dot.

This is the third time in a row the same underlying fact has shown up in a different tab, and it is worth saying plainly because it is the through-line of the whole format. An extension is a field with a number on the message it extends, nothing more, and every part of the tool that understands fields agrees, because they all walk the same fields list and the extension is in it. The decode tab shows it as a key, the explain tab lists it, the generated TypeScript interface gets a line for it, and the diff tab compares it by number. The leading dot is the parser's bookkeeping, it is not a different kind of field, and the only place it ever leaked into what a person reads was the report path, where it got appended to a path that already carried the package. That is the shape of the whole thing: one field, stored once, with a label longer than it needs to be, and four tabs that all do the right thing with it except the one that printed the label where it should have printed the name.

The consequence is the small one that compounds. You keep a message stable and grow it by extension, which is the whole point of extensions, other people add fields to your message without you changing it, and then you run the diff between two versions of the file that both use extensions. The report is correct about every change. The new extension is a safe addition, the renumbered one is breaking, the retyped one is a silent re-read, all of it right. The only thing that was wrong was the address of the field in the line, and the wrong address was a package name that belonged to the library's label, not your file, sitting in the middle of the path as a second dot. It is fixed now, so the address is the one you would write, and the rest of the line, the part that says what actually changed and why, was right all along.

That is where it lands. An extension is a field number on the message it extends, the wire does not treat it specially, the JSON hands it back under a leading-dot key, and the diff tab compares it by number like any other field, which is exactly correct. The only special thing was the label the parser gives it, a fully-qualified name with a leading dot, and the report printed that label where it should have printed the field's own name, so a package you never wrote in that place showed up as a second dot in the path. That is fixed in the tool now, and the line points at demo.Base.nickname instead of the doubled path. The wire story and the leading-dot JSON key are in the extensions post, the rest of how the diff report reads a change is in the diff report post, and the tab that does this comparison is in theprotobuf tool. If you paste a .proto that grows a message by extension into the diff tab and then change the extension, the report will treat it like the field it is, and the path will be the one you recognize.

Subscribe to Data Jutsu

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe