Skip to main content

check_discriminators

Function check_discriminators 

Source
fn check_discriminators(message: &ControlMessage) -> Result<(), CodecError>
Expand description

Refuse a message whose discriminator disagrees with the fields beside it.

A discriminator is a field that says which of the fields after it are on the wire. This codec holds the alternatives in 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 Fetch 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.

FETCH is the only message on draft-16 with such a field. Drafts 07 through 14 have three: SUBSCRIBE’s Filter Type and SUBSCRIBE_OK’s ContentExists are the other two, and both are gone from draft-16 — the filter moved into the parameters as SUBSCRIPTION_FILTER, and SUBSCRIBE_OK’s optional largest location left with it.