Skip to main content

moqtap_codec/draft15/
types.rs

1//! Draft-15 specific types.
2
3/// Object status values, from MoQ Transport draft-15 Section 10.2.1.1
4/// "Object Status".
5///
6/// Draft-15 assigns 0x0, 0x1, 0x3 and 0x4. Of every other value the section
7/// says: "Any other value SHOULD be treated as a protocol error and the session
8/// SHOULD be terminated with a PROTOCOL_VIOLATION". [`ObjectStatus::from_u64`]
9/// answers `None` for 0x2 and for everything else the draft leaves unassigned.
10///
11/// Draft-15 is the last draft to assign 0x1; draft-16 drops Object Does Not
12/// Exist.
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14#[repr(u64)]
15pub enum ObjectStatus {
16    /// Normal object. Implicit for any non-zero length object; zero-length
17    /// objects encode it explicitly.
18    Normal = 0x00,
19    /// The object does not exist at any publisher and will not be published in
20    /// the future.
21    ObjectDoesNotExist = 0x01,
22    /// End of Group. Object ID is one greater than the largest object produced
23    /// in the group identified by the Group ID; 0 means the group is empty.
24    EndOfGroup = 0x03,
25    /// End of Track. Either Group ID is the largest group produced in the track
26    /// and Object ID is one greater than the largest object in that group, or
27    /// Group ID is one greater than the largest group produced and Object ID is
28    /// zero.
29    EndOfTrack = 0x04,
30}
31
32impl ObjectStatus {
33    /// Every status draft-15 assigns, in ascending wire order.
34    ///
35    /// This is exactly the set [`ObjectStatus::from_u64`] accepts. Any other
36    /// value is one the draft does not assign.
37    pub const ALL: &[ObjectStatus] = &[
38        ObjectStatus::Normal,
39        ObjectStatus::ObjectDoesNotExist,
40        ObjectStatus::EndOfGroup,
41        ObjectStatus::EndOfTrack,
42    ];
43
44    /// Convert a raw u64 to an `ObjectStatus`, or `None` if draft-15 does not
45    /// assign that value.
46    pub fn from_u64(v: u64) -> Option<Self> {
47        match v {
48            0x00 => Some(ObjectStatus::Normal),
49            0x01 => Some(ObjectStatus::ObjectDoesNotExist),
50            0x03 => Some(ObjectStatus::EndOfGroup),
51            0x04 => Some(ObjectStatus::EndOfTrack),
52            _ => None,
53        }
54    }
55
56    /// Return the wire value.
57    pub fn as_u64(self) -> u64 {
58        self as u64
59    }
60}