Skip to main content

message_type_name

Function message_type_name 

Source
pub fn message_type_name(draft: u8, id: u64) -> Option<&'static str>
Expand description

The name draft draft gives control message type id, or None if that draft assigns the id nothing.

draft is the draft number as the IETF writes it — 7 through 20 — which is what a trace header’s moq-transport-NN carries and what crate::version::DraftVersion::number returns. A number outside the range this crate implements answers None, as does an id the named draft leaves unassigned, and so does a draft whose feature flag is off in this build.

Two drafts’ answers are not comparable just because they match: message_type_name(11, 0x0E) and message_type_name(14, 0x0D) both answer track_status and name opposite sides of an exchange. See the module docs.

use moqtap_codec::message_type_name;

// A draft left out of the build answers `None` for every id, which is the
// documented behaviour and also indistinguishable from a wrong table — so
// the per-draft half of this example runs only where all of the drafts it
// names are compiled in. The default feature set is `all-drafts`.
// 0x07 is three different messages across the range.
assert_eq!(message_type_name(7, 0x07), Some("announce_ok"));
assert_eq!(message_type_name(14, 0x07), Some("publish_namespace_ok"));
assert_eq!(message_type_name(19, 0x07), Some("request_ok"));
// 0x22 is PUBLISH_STATE_NOTIFY, and draft-20 is the first to assign it.
assert_eq!(message_type_name(19, 0x22), None);
assert_eq!(message_type_name(20, 0x22), Some("publish_state_notify"));

// The unified SETUP exists from draft-17 and nowhere before it.
assert_eq!(message_type_name(16, 0x2F00), None);
assert_eq!(message_type_name(17, 0x2F00), Some("setup"));

// A draft number outside the range answers `None` in every build.
assert_eq!(message_type_name(6, 0x03), None);