Skip to main content

moqtap_codec/
error_codes.rs

1/// Session termination error codes (draft-14).
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3#[repr(u64)]
4pub enum SessionErrorCode {
5    NoError = 0x0,
6    InternalError = 0x1,
7    Unauthorized = 0x2,
8    ProtocolViolation = 0x3,
9    InvalidRequestId = 0x4,
10    DuplicateTrackAlias = 0x5,
11    KeyValueFormattingError = 0x6,
12    TooManyRequests = 0x7,
13    InvalidPath = 0x8,
14    MalformedPath = 0x9,
15    GoawayTimeout = 0x10,
16    ControlMessageTimeout = 0x11,
17    DataStreamTimeout = 0x12,
18    AuthTokenCacheOverflow = 0x13,
19    DuplicateAuthTokenAlias = 0x14,
20    VersionNegotiationFailed = 0x15,
21    MalformedAuthToken = 0x16,
22    UnknownAuthTokenAlias = 0x17,
23    ExpiredAuthToken = 0x18,
24    InvalidAuthority = 0x19,
25    MalformedAuthority = 0x1A,
26}
27
28/// Request-level error codes (used in SUBSCRIBE_ERROR, PUBLISH_ERROR, etc.).
29#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30#[repr(u64)]
31pub enum RequestErrorCode {
32    InternalError = 0x0,
33    Unauthorized = 0x1,
34    Timeout = 0x2,
35    NotSupported = 0x3,
36    TrackDoesNotExist = 0x4,
37    InvalidRange = 0x5,
38    MalformedAuthToken = 0x10,
39    ExpiredAuthToken = 0x12,
40}
41
42/// PUBLISH_DONE status codes.
43#[derive(Debug, Clone, Copy, PartialEq, Eq)]
44#[repr(u64)]
45pub enum PublishDoneStatusCode {
46    Normal = 0x0,
47    Unsubscribed = 0x1,
48    InternalError = 0x2,
49    Unauthorized = 0x3,
50    Unsupported = 0x4,
51    NotFound = 0x5,
52}
53
54impl SessionErrorCode {
55    pub fn from_u64(v: u64) -> Option<Self> {
56        match v {
57            0x0 => Some(SessionErrorCode::NoError),
58            0x1 => Some(SessionErrorCode::InternalError),
59            0x2 => Some(SessionErrorCode::Unauthorized),
60            0x3 => Some(SessionErrorCode::ProtocolViolation),
61            0x4 => Some(SessionErrorCode::InvalidRequestId),
62            0x5 => Some(SessionErrorCode::DuplicateTrackAlias),
63            0x6 => Some(SessionErrorCode::KeyValueFormattingError),
64            0x7 => Some(SessionErrorCode::TooManyRequests),
65            0x8 => Some(SessionErrorCode::InvalidPath),
66            0x9 => Some(SessionErrorCode::MalformedPath),
67            0x10 => Some(SessionErrorCode::GoawayTimeout),
68            0x11 => Some(SessionErrorCode::ControlMessageTimeout),
69            0x12 => Some(SessionErrorCode::DataStreamTimeout),
70            0x13 => Some(SessionErrorCode::AuthTokenCacheOverflow),
71            0x14 => Some(SessionErrorCode::DuplicateAuthTokenAlias),
72            0x15 => Some(SessionErrorCode::VersionNegotiationFailed),
73            0x16 => Some(SessionErrorCode::MalformedAuthToken),
74            0x17 => Some(SessionErrorCode::UnknownAuthTokenAlias),
75            0x18 => Some(SessionErrorCode::ExpiredAuthToken),
76            0x19 => Some(SessionErrorCode::InvalidAuthority),
77            0x1A => Some(SessionErrorCode::MalformedAuthority),
78            _ => None,
79        }
80    }
81
82    pub fn as_u64(self) -> u64 {
83        self as u64
84    }
85}
86
87impl RequestErrorCode {
88    pub fn from_u64(v: u64) -> Option<Self> {
89        match v {
90            0x0 => Some(RequestErrorCode::InternalError),
91            0x1 => Some(RequestErrorCode::Unauthorized),
92            0x2 => Some(RequestErrorCode::Timeout),
93            0x3 => Some(RequestErrorCode::NotSupported),
94            0x4 => Some(RequestErrorCode::TrackDoesNotExist),
95            0x5 => Some(RequestErrorCode::InvalidRange),
96            0x10 => Some(RequestErrorCode::MalformedAuthToken),
97            0x12 => Some(RequestErrorCode::ExpiredAuthToken),
98            _ => None,
99        }
100    }
101
102    pub fn as_u64(self) -> u64 {
103        self as u64
104    }
105}
106
107impl PublishDoneStatusCode {
108    pub fn from_u64(v: u64) -> Option<Self> {
109        match v {
110            0x0 => Some(PublishDoneStatusCode::Normal),
111            0x1 => Some(PublishDoneStatusCode::Unsubscribed),
112            0x2 => Some(PublishDoneStatusCode::InternalError),
113            0x3 => Some(PublishDoneStatusCode::Unauthorized),
114            0x4 => Some(PublishDoneStatusCode::Unsupported),
115            0x5 => Some(PublishDoneStatusCode::NotFound),
116            _ => None,
117        }
118    }
119
120    pub fn as_u64(self) -> u64 {
121        self as u64
122    }
123}