Skip to main content

moqtap_codec/draft08/
types.rs

1//! Draft-08 specific types.
2
3/// Object status values, from MoQ Transport draft-08 Section 8.1.1.1
4/// "Object Status".
5///
6/// The draft assigns 0x0, 0x1, 0x3, 0x4 and 0x5, and says of everything else
7/// that it "SHOULD be treated as a protocol error and terminate the session
8/// with a Protocol Violation". 0x2 is not assigned; [`ObjectStatus::from_u64`]
9/// answers `None` for it, and for every other unassigned value.
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11#[repr(u8)]
12pub enum ObjectStatus {
13    /// Object payload follows normally.
14    Normal = 0,
15    /// The referenced object does not exist.
16    ObjectDoesNotExist = 1,
17    /// Last object in the group.
18    EndOfGroup = 3,
19    /// Last object in the group AND the final group in the track.
20    EndOfTrackAndGroup = 4,
21    /// Last object in the track (group is not ending here).
22    EndOfTrack = 5,
23}
24
25impl ObjectStatus {
26    /// Every status draft-08 assigns, in ascending wire order.
27    ///
28    /// This is exactly the set [`ObjectStatus::from_u64`] accepts. Any other
29    /// value is one the draft does not assign.
30    pub const ALL: &[ObjectStatus] = &[
31        ObjectStatus::Normal,
32        ObjectStatus::ObjectDoesNotExist,
33        ObjectStatus::EndOfGroup,
34        ObjectStatus::EndOfTrackAndGroup,
35        ObjectStatus::EndOfTrack,
36    ];
37
38    /// Convert a raw u64 to an `ObjectStatus`, or `None` if draft-08 does not
39    /// assign that value.
40    pub fn from_u64(v: u64) -> Option<Self> {
41        match v {
42            0 => Some(ObjectStatus::Normal),
43            1 => Some(ObjectStatus::ObjectDoesNotExist),
44            3 => Some(ObjectStatus::EndOfGroup),
45            4 => Some(ObjectStatus::EndOfTrackAndGroup),
46            5 => Some(ObjectStatus::EndOfTrack),
47            _ => None,
48        }
49    }
50
51    /// Return the wire value.
52    pub fn as_u64(self) -> u64 {
53        self as u64
54    }
55}