moqtap_codec/draft14/types.rs
1//! Draft-14 specific types.
2//!
3//! Types in this module are specific to draft-14 wire values and are kept
4//! separate from the shared [`crate::types`] module so that other drafts
5//! can continue to use their own enums without collision.
6
7/// Object status values, from MoQ Transport draft-14 Section 10.2.1.1
8/// "Object Status".
9///
10/// Status is a varint on the wire. The draft assigns 0x0, 0x1, 0x3 and 0x4, and
11/// says of everything else: "Any other value SHOULD be treated as a protocol
12/// error and the session SHOULD be terminated with a PROTOCOL_VIOLATION".
13/// [`ObjectStatus::from_u64`] answers `None` for 0x2 and for every other
14/// unassigned value.
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16#[repr(u8)]
17pub enum ObjectStatus {
18 /// Normal object. Implicit for non-zero length; zero-length objects must
19 /// encode this explicitly.
20 Normal = 0x0,
21 /// This Object does not exist at any publisher.
22 ObjectDoesNotExist = 0x1,
23 /// End of Group. Object ID is one greater than the largest in the group
24 /// (or 0 if the group is empty).
25 EndOfGroup = 0x3,
26 /// End of Track.
27 EndOfTrack = 0x4,
28}
29
30impl ObjectStatus {
31 /// Every status draft-14 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 wire value to [`ObjectStatus`], or `None` if draft-14 does
43 /// not assign that value.
44 pub fn from_u64(v: u64) -> Option<Self> {
45 match v {
46 0x0 => Some(ObjectStatus::Normal),
47 0x1 => Some(ObjectStatus::ObjectDoesNotExist),
48 0x3 => Some(ObjectStatus::EndOfGroup),
49 0x4 => 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}