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.

Several draft-13 messages carry a field that says which of the fields after it are on the wire — SUBSCRIBE’s and PUBLISH_OK’s Filter Type, SUBSCRIBE_OK’s and PUBLISH’s Content Exists, FETCH’s Fetch Type. 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 resolve that differently: the encoder writes whatever the body holds, the decoder reads whatever the discriminator announces.

The result is a message that does not survive its own round trip. A SUBSCRIBE_OK saying content exists with no location encodes to a frame whose own reader takes the parameter count for a Group ID. Refusing at the encoder keeps the two readings from diverging on the wire.

TRACK_STATUS is here because its format is the SUBSCRIBE format, so its Filter Type governs the same two optional fields.