fn check_discriminators(message: &ControlMessage) -> Result<(), CodecError>Expand description
Refuse a message whose discriminator disagrees with the fields beside it.
Several draft-14 messages carry a field that says which of the following
fields are on the wire — FETCH’s Fetch Type, SUBSCRIBE’s Filter Type,
SUBSCRIBE_OK’s ContentExists. This codec holds the optional halves in
Options and an enum, so a value can say one thing in its discriminator and
another in its body, and the two sides of the codec resolve that differently:
the encoder writes whatever the body holds, and the decoder reads whatever
the discriminator announces.
The result is a message that does not survive its own round trip. A FETCH whose type says Standalone and whose body is a joining pair encodes to a request id and a start where a namespace and a name belong, and comes back as a Standalone fetch of a track named after two integers — or, more often, as an error, which at least is honest. Refusing at the encoder keeps the two readings from ever diverging on the wire.