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