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