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