Skip to main content

moqtap_codec/draft07/
types.rs

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