Skip to main content

encode_parameters

Function encode_parameters 

Source
fn encode_parameters(
    params: &[KeyValuePair],
    buf: &mut impl BufMut,
) -> Result<(), CodecError>
Expand description

Encode a count-prefixed list of parameters with delta-encoded types.

Errors on every list decode_parameters would refuse, so the two directions accept the same set of frames. Three things are refused, and each of them is a frame this codec would otherwise emit and then decline to read back:

  • A list not in ascending order by type. The delta is a difference, so a descending pair wraps the subtraction into a nine-byte delta the peer resolves to an unrelated key.
  • A repeated type, except AUTHORIZATION_TOKEN (Section 9.3.2).
  • A uint8-valued parameter whose value does not fit one octet or lies outside the range its definition allows. Truncating instead is the worse outcome: GROUP_ORDER 258 goes out as the byte 0x02, a well-formed Descending indistinguishable on the wire from one the caller meant.
  • A value under a type that defines a structure which is not that structure: a Token, and a filter. Each is a value the receiver must close the session over, so writing one is not a way to send it — the sender’s first sign of trouble would be the session going.