Skip to main content

moqtap_codec/draft08/
types.rs

1//! Draft-08 specific types.
2
3/// SETUP ROLE parameter values (draft-08, key 0x00).
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5#[repr(u8)]
6pub enum Role {
7    /// Publisher only.
8    Publisher = 1,
9    /// Subscriber only.
10    Subscriber = 2,
11    /// Both publisher and subscriber.
12    PubSub = 3,
13}
14
15impl Role {
16    /// Convert a raw byte to a `Role`, if valid.
17    pub fn from_u8(v: u8) -> Option<Self> {
18        match v {
19            1 => Some(Role::Publisher),
20            2 => Some(Role::Subscriber),
21            3 => Some(Role::PubSub),
22            _ => None,
23        }
24    }
25}
26
27/// Object status values (draft-08).
28#[derive(Debug, Clone, Copy, PartialEq, Eq)]
29#[repr(u8)]
30pub enum ObjectStatus {
31    /// Object payload follows normally.
32    Normal = 0,
33    /// The referenced object does not exist.
34    ObjectDoesNotExist = 1,
35    /// Last object in the group.
36    EndOfGroup = 3,
37    /// Last object in the group AND the final group in the track.
38    EndOfTrackAndGroup = 4,
39    /// Last object in the track (group is not ending here).
40    EndOfTrack = 5,
41}
42
43impl ObjectStatus {
44    /// Convert a raw u64 to an `ObjectStatus`, if valid.
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::EndOfTrackAndGroup),
51            5 => Some(ObjectStatus::EndOfTrack),
52            _ => None,
53        }
54    }
55}