Skip to main content

setup_option_name

Function setup_option_name 

Source
pub fn setup_option_name(draft: u8, param: &KeyValuePair) -> Option<String>
Expand description

The name draft draft gives param in a setup message, or None if that draft defines nothing for it.

draft is the draft number as the IETF writes it — 7 through 20 — matching crate::version::DraftVersion::number. A number outside the range this crate implements answers None, as does a draft whose feature flag is off in this build.

This is the setup parameter namespace, which is not the one non-setup messages use: 0x02 is max_request_id in a draft-14 SERVER_SETUP and delivery_timeout in a draft-14 SUBSCRIBE. Asking this about a parameter that arrived on a request would name the wrong thing.

use moqtap_codec::kvp::{KeyValuePair, KvpValue};
use moqtap_codec::setup_option_name;
use moqtap_codec::varint::VarInt;

let max = KeyValuePair {
    key: VarInt::from_u64(0x02).unwrap(),
    value: KvpValue::Varint(VarInt::from_u64(100).unwrap()),
};
// The same codepoint, renamed once and then retired.
assert_eq!(setup_option_name(10, &max).as_deref(), Some("max_subscribe_id"));
assert_eq!(setup_option_name(14, &max).as_deref(), Some("max_request_id"));
assert_eq!(setup_option_name(18, &max), None);