Skip to main content

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/// Draft-14 Object Status values (ยง10.2.1.1).
8///
9/// Status is a varint on the wire. Any other value is a protocol error.
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11#[repr(u8)]
12pub enum ObjectStatus {
13    /// Normal object. Implicit for non-zero length; zero-length objects must
14    /// encode this explicitly.
15    Normal = 0x0,
16    /// This Object does not exist at any publisher.
17    ObjectDoesNotExist = 0x1,
18    /// End of Group. Object ID is one greater than the largest in the group
19    /// (or 0 if the group is empty).
20    EndOfGroup = 0x3,
21    /// End of Track.
22    EndOfTrack = 0x4,
23}
24
25impl ObjectStatus {
26    /// Convert a raw wire value to [`ObjectStatus`].
27    pub fn from_u64(v: u64) -> Option<Self> {
28        match v {
29            0x0 => Some(ObjectStatus::Normal),
30            0x1 => Some(ObjectStatus::ObjectDoesNotExist),
31            0x3 => Some(ObjectStatus::EndOfGroup),
32            0x4 => Some(ObjectStatus::EndOfTrack),
33            _ => None,
34        }
35    }
36
37    /// Return the wire value.
38    pub fn as_u64(self) -> u64 {
39        self as u64
40    }
41}