Protobuf Map Fields Are Just Repeated Key-Value Messages
You declare a map field in a .proto and you assume the wire format got a special thing to store it. It did not. A map from key to value is a repeated field, and each element is a small message with exactly two fields inside: the key, which is always field number one, and the value, which is always field number two. Encode a map with two entries and you get back a chain of length-delimited blocks, each one starting with the tag for the outer field, then its length, then the key as its own tagged field and the value as its own tagged field. Nothing in those bytes says the word map. The pair structure is the whole thing, and it looks exactly like any other repeated nested message.
Because it is a repeated message, two schemas that look nothing alike can be reading the same bytes. A schema that declares a repeated entry type with a key and a value field, and a schema that declares a map with the same outer field number and the same key and value numbers, decode one stream into the same values. That is why a raw decoder with no schema at all just shows you a run of nested messages, and it has no way to know it is looking at a map. The map is a label your schema puts on a list of pairs, not a property the bytes carry. The tag math is in my post on how the wire format works, and a map field is the case where the same bytes are two different things to two different readers.
The repeated-message shape also explains the edge behavior that surprises people. An empty map produces zero bytes, the field is simply absent, exactly like an empty repeated field. Order is not on the wire either, because the value is a dictionary keyed by the key, so a stream whose pairs arrive out of order decodes to the same object. And if the same key appears twice in one stream, the decoder takes the last one it saw and drops the earlier one silently, which is how a half-written retry can quietly overwrite a real entry.
The JSON side is where map fields actually bite. Every key serializes as a string in the JSON mapping, even when the key is an integer, so a key of one goes out as the string one, and a reader that only accepts numbers will reject data coming from your own service. Worse, an integer key past two to the fifty-third hits the same long-precision wall a value does: it encodes on the wire as a correct nine-byte varint, but when it is read back as JSON it comes out as a string of raw bytes instead of the decimal number you sent, so a thirteen-digit order ID used as a map key looks corrupted after a round trip with no error. That one is in my post on the JSON mapping rules, and it is the same failure wearing a key.
For versioning, the rule follows from the same fact. Converting a repeated message of key and value into a map, or a map into a repeated message, with the outer number and the two inner numbers unchanged, is wire safe, because the bytes were the same all along. Turning the field into a scalar, or renumbering the key or value inside the pair, is the break. The diff view on the tool calls map to field changes out by field number, so a migration that is really just a relabel of the same pairs shows up as a safe change, not a red line, and the one that actually moves a number is the line to argue about.
All of it is checkable in the browser. Paste the .proto, encode a map with two entries, and watch each one come out as its own length-delimited block. Decode a stream that carries the same key twice and see the last one win. Then switch to the JSON output and watch the integer keys turn into strings and a big integer key turn into a run of bytes. The raw decode tab at proto.datajutsu.com shows the pairs as plain nested messages before any schema gets a vote, which is the fastest way to see that the map was never in the bytes to begin with.