Protobuf Oneof: The Wire Format Has No Idea It Exists
You want three fields to mean the same thing: a message can carry an account number, an email, or an external ID, but never two at once. In proto3 you write that with oneof, and then something feels off, because the wire format has no oneof. That is the whole story, and it takes one test to see. Encode the message with the first member set to a known value, write the hex down, then decode a message where the second member is set. Look at the tags. A member of a oneof encodes exactly like any other field: field number shifted left three bits, wire type in the low three bits. The bytes for member one equal the bytes a plain field with the same number would produce, down to the last bit. There is no marker saying this belongs to a group.
The constraint lives in the schema, not in the bytes. A raw stream can contain the tags for two members of the same oneof back to back, and a decoder with the schema will happily return both of them. Nothing on the wire forces exclusivity; your runtime enforces it when it builds the object, keeping the last one it saw. Which means the same hex string can decode to different things under different schemas. Bytes that are oneof member one under schema A are just field one under a schema that has no oneof at all, and they decode to the same value. If you capture traffic and your schema says oneof while the sender built their object from a different schema, you are comparing interpretations of the same bytes, not comparing bytes.
This has a sharp edge for versioning. Renaming a oneof member is safe, because the number is what travels. Moving a field from one oneof group into another, or out of a group entirely, is also wire-safe for the same reason: identical number, identical wire type, identical bytes. The breaking change you actually have to watch for is renumbering a member, which is a field-number change wearing a costume. And because members are ordinary fields, the normal rules apply to them: never reuse a retired member's number, mark it reserved, and treat a retype across wire types the same as any other retype.
There is one shape that does carry a presence flag on the wire, and it looks like a oneof without being one. An explicitly marked optional field in proto3 gets the same treatment internally: it is a synthetic one-of-two where the second option is absence. On the wire it encodes as a plain field, identical to a non-optional one; the decoder just distinguishes was set from was not, which is why an explicit zero shows up in your JSON while a never-set field does not. So when you read generated code or a reflection API and see optional represented as a oneof, you are looking at that machinery, not at a real oneof field.
The practical takeaway is that oneof is a promise you make in the .proto, not a property of the data. If you are debugging a message that seems to violate it, start by decoding with no schema at all and counting how many of those tags are actually present in the stream. The raw decode tab at proto.datajutsu.com shows every field number and wire type, so you see the real contents of the bytes before the schema gets a vote. Then encode your own copy with the single member you expect and compare hex. Two bytes that should be exclusive in your model but both appear in the capture mean the sender is older or newer than the schema you are reading with, and the tag math tells you exactly which fields to chase. The tag math itself is in my post on how the wire format works, which this one is a direct follow-up to.
Everything here is checkable in the browser with the same tool: paste the .proto, encode each member, watch the tags, decode a stream that contains two of them, and see both come back. The JSON side follows the same rule, where only the set member gets a key in the output, so a JSON round trip looks exclusive even though the wire never was.