moqtap_codec/draft12/types.rs
1//! Draft-12 types.
2
3/// Object status values, from MoQ Transport draft-12 Section 9.2.1.1
4/// "Object Status".
5///
6/// Draft-12 assigns 0x0, 0x1, 0x3 and 0x4, the same four as draft-11. Of every
7/// other value the section says: "Any other value SHOULD be treated as a
8/// protocol error and terminate the session with a Protocol Violation".
9/// [`ObjectStatus::from_u64`] answers `None` for 0x2, for 0x5, and for
10/// everything else the draft leaves unassigned.
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12#[repr(u8)]
13pub enum ObjectStatus {
14 /// Normal object. Implicit for any non-zero length object; zero-length
15 /// objects encode it explicitly.
16 Normal = 0,
17 /// The object does not exist at any publisher and will not be published in
18 /// the future.
19 ObjectDoesNotExist = 1,
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 = 3,
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 = 4,
28}
29
30impl ObjectStatus {
31 /// Every status draft-12 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,
37 ObjectStatus::ObjectDoesNotExist,
38 ObjectStatus::EndOfGroup,
39 ObjectStatus::EndOfTrack,
40 ];
41
42 /// Convert a raw u64 to an `ObjectStatus`, or `None` if draft-12 does not
43 /// assign that value.
44 pub fn from_u64(v: u64) -> Option<Self> {
45 match v {
46 0 => Some(ObjectStatus::Normal),
47 1 => Some(ObjectStatus::ObjectDoesNotExist),
48 3 => Some(ObjectStatus::EndOfGroup),
49 4 => Some(ObjectStatus::EndOfTrack),
50 _ => None,
51 }
52 }
53
54 /// Return the wire value.
55 pub fn as_u64(self) -> u64 {
56 self as u64
57 }
58}