Protobuf Does Not Count Your Fields (and the Schema's repeated Is the Whole Difference)
Put the same field in a message twice and the bytes do not tell you it happened. I built one stream by hand: field 1 with the value 2, then field 1 with the value 5, then a string field twice, then a nested message twice. It is one continuous run of tags and payloads, and nothing in it counts anything. There is no length prefix saying how many of field 1 there are, and no flag on the tag that says this is a repeat. A tag is just a field number and a three bit wire type, and the very same tag that set field 1 to 2 is the one that then sets it to 5. The wire is a flat stream of assignments, and it is up to the reader to decide what a second assignment to the same number means.
I ran that exact stream through the tool's own engine twice, once with a schema that declares the fields plain and once with a schema that declares them repeated. The bytes were byte identical, I checked the hex. The plain decode came back as a: 5, s: there, m: {x: 10}. Only the last occurrence of each field survived, the earlier ones simply overwritten. The repeated decode of the same bytes came back as a: [2, 5], s: ["hi", "there"], m: [{x: 9}, {x: 10}]. Every occurrence is there, in the order it appeared on the wire. So the whole difference between a single value and a list is one word in the .proto, repeated, and the bytes never change. A tag does not carry a count. It carries a field number, and whether that number collects into a list or replaces the last value is a decision only the schema makes. This is the same shape as every other thing in the format, the bytes leave the door open and the .proto walks through it.
The descriptor is the only place the difference even exists. I compiled both files with protoc and diffed the descriptors. They are one byte apart per field: the field label is stored as the number 1 for a plain field and the number 3 for a repeated field, a single varint byte, and that is the entire footprint of the whole repeated versus not distinction. It is not in the data at all. And the decoder is the quiet one. I fed the same duplicated bytes to protoc's decoder and it gave me exactly what the JS engine gave me, last wins for the plain schema, the full list for the repeated one, with no warning either way. The loud moment is on the writing side: when you try to encode a duplicated plain field from protoc's text format, it refuses with the message that the non repeated field is specified multiple times. So a sender can be stopped from writing a duplicate it did not mean, but a receiver that gets one, from any sender, in any language, decodes it without a sound.
A few things fall out of that. A repeated field is not a set, it keeps duplicates: I sent 7, then 11, then 7 again and got back [7, 11, 7] in that order. A non repeated field with the same three values gives you back just the last, 7, because there is no list to hold the others. Order is the wire order, even when the field is interleaved with other fields: I sent a, then s, then a again, and the a list came back [2, 5] in the order they appeared, not sorted and not grouped. And the two physical forms of a repeated field can be mixed in one stream, the packed form where several values ride under a single length prefix and the unpacked form where each value has its own tag. The engine merges them into one list, no error, which is why a sender in one language and a receiver in another, one packing and one not, still read the same values. That mixed packed and unpacked case is the edge of the packed option post and it is one of the reasons a repeated field is the format's safest shape to evolve.
The part that is easy to miss is that the tool's decode tab does not warn you about a duplicate. It has a note for unknown fields, the numbers that are in the bytes but not in the .proto, and that note is the right one. But a duplicate is a known field, so it never reaches that note. A stream that sent field 1 twice decodes to the last value, full stop, and the tab will not tell you the first one was there. If you are debugging a message that looks shorter than the sender intended, this is a real place to look: the value is not missing because the schema is wrong, it is missing because the stream carried the field twice and you are looking at a non repeated field. You can watch it happen in the tool at proto.datajutsu.com: paste a .proto and a message, and if the same field is in the bytes twice the JSON shows you exactly which reading won. The tag math behind it, why a second occurrence of a field is indistinguishable from the first at the byte level, is in the wire format post, and what happens to fields the schema does not know at all, the case the note does cover, is in the unknown fields post.