Skip to main content

moqtap_codec/draft14/
error_codes.rs

1/// Session termination error codes (draft-14).
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3#[repr(u64)]
4pub enum SessionErrorCode {
5    /// No error occurred.
6    NoError = 0x0,
7    /// Implementation-specific internal error.
8    InternalError = 0x1,
9    /// Authorization failed.
10    Unauthorized = 0x2,
11    /// Protocol rule violation detected.
12    ProtocolViolation = 0x3,
13    /// Request ID is invalid or unknown.
14    InvalidRequestId = 0x4,
15    /// Track alias already in use.
16    DuplicateTrackAlias = 0x5,
17    /// Key-value pair formatting error.
18    KeyValueFormattingError = 0x6,
19    /// Too many concurrent requests.
20    TooManyRequests = 0x7,
21    /// Requested path is invalid.
22    InvalidPath = 0x8,
23    /// Requested path is malformed.
24    MalformedPath = 0x9,
25    /// GOAWAY timeout elapsed.
26    GoawayTimeout = 0x10,
27    /// Control message timeout elapsed.
28    ControlMessageTimeout = 0x11,
29    /// Data stream timeout elapsed.
30    DataStreamTimeout = 0x12,
31    /// Auth token cache capacity exceeded.
32    AuthTokenCacheOverflow = 0x13,
33    /// Auth token alias already registered.
34    DuplicateAuthTokenAlias = 0x14,
35    /// No compatible version found during negotiation.
36    VersionNegotiationFailed = 0x15,
37    /// Auth token is malformed.
38    MalformedAuthToken = 0x16,
39    /// Auth token alias is not recognized.
40    UnknownAuthTokenAlias = 0x17,
41    /// Auth token has expired.
42    ExpiredAuthToken = 0x18,
43    /// Authority value is invalid.
44    InvalidAuthority = 0x19,
45    /// Authority value is malformed.
46    MalformedAuthority = 0x1A,
47}
48
49/// Request-level error codes (used in SUBSCRIBE_ERROR, PUBLISH_ERROR, etc.).
50#[derive(Debug, Clone, Copy, PartialEq, Eq)]
51#[repr(u64)]
52pub enum RequestErrorCode {
53    /// Implementation-specific internal error.
54    InternalError = 0x0,
55    /// Authorization failed for this request.
56    Unauthorized = 0x1,
57    /// Request timed out.
58    Timeout = 0x2,
59    /// Requested operation is not supported.
60    NotSupported = 0x3,
61    /// The requested track does not exist.
62    TrackDoesNotExist = 0x4,
63    /// The requested range is invalid.
64    InvalidRange = 0x5,
65    /// Auth token is malformed.
66    MalformedAuthToken = 0x10,
67    /// Auth token has expired.
68    ExpiredAuthToken = 0x12,
69}
70
71/// PUBLISH_DONE status codes.
72#[derive(Debug, Clone, Copy, PartialEq, Eq)]
73#[repr(u64)]
74pub enum PublishDoneStatusCode {
75    /// Publishing completed normally.
76    Normal = 0x0,
77    /// Subscriber unsubscribed.
78    Unsubscribed = 0x1,
79    /// Internal error during publishing.
80    InternalError = 0x2,
81    /// Authorization failed.
82    Unauthorized = 0x3,
83    /// Operation not supported.
84    Unsupported = 0x4,
85    /// Track not found.
86    NotFound = 0x5,
87}
88
89impl SessionErrorCode {
90    /// Convert a raw u64 to a `SessionErrorCode`, if valid.
91    pub fn from_u64(v: u64) -> Option<Self> {
92        match v {
93            0x0 => Some(SessionErrorCode::NoError),
94            0x1 => Some(SessionErrorCode::InternalError),
95            0x2 => Some(SessionErrorCode::Unauthorized),
96            0x3 => Some(SessionErrorCode::ProtocolViolation),
97            0x4 => Some(SessionErrorCode::InvalidRequestId),
98            0x5 => Some(SessionErrorCode::DuplicateTrackAlias),
99            0x6 => Some(SessionErrorCode::KeyValueFormattingError),
100            0x7 => Some(SessionErrorCode::TooManyRequests),
101            0x8 => Some(SessionErrorCode::InvalidPath),
102            0x9 => Some(SessionErrorCode::MalformedPath),
103            0x10 => Some(SessionErrorCode::GoawayTimeout),
104            0x11 => Some(SessionErrorCode::ControlMessageTimeout),
105            0x12 => Some(SessionErrorCode::DataStreamTimeout),
106            0x13 => Some(SessionErrorCode::AuthTokenCacheOverflow),
107            0x14 => Some(SessionErrorCode::DuplicateAuthTokenAlias),
108            0x15 => Some(SessionErrorCode::VersionNegotiationFailed),
109            0x16 => Some(SessionErrorCode::MalformedAuthToken),
110            0x17 => Some(SessionErrorCode::UnknownAuthTokenAlias),
111            0x18 => Some(SessionErrorCode::ExpiredAuthToken),
112            0x19 => Some(SessionErrorCode::InvalidAuthority),
113            0x1A => Some(SessionErrorCode::MalformedAuthority),
114            _ => None,
115        }
116    }
117
118    /// Return the raw u64 value of this error code.
119    pub fn as_u64(self) -> u64 {
120        self as u64
121    }
122}
123
124impl RequestErrorCode {
125    /// Convert a raw u64 to a `RequestErrorCode`, if valid.
126    pub fn from_u64(v: u64) -> Option<Self> {
127        match v {
128            0x0 => Some(RequestErrorCode::InternalError),
129            0x1 => Some(RequestErrorCode::Unauthorized),
130            0x2 => Some(RequestErrorCode::Timeout),
131            0x3 => Some(RequestErrorCode::NotSupported),
132            0x4 => Some(RequestErrorCode::TrackDoesNotExist),
133            0x5 => Some(RequestErrorCode::InvalidRange),
134            0x10 => Some(RequestErrorCode::MalformedAuthToken),
135            0x12 => Some(RequestErrorCode::ExpiredAuthToken),
136            _ => None,
137        }
138    }
139
140    /// Return the raw u64 value of this error code.
141    pub fn as_u64(self) -> u64 {
142        self as u64
143    }
144}
145
146impl PublishDoneStatusCode {
147    /// Convert a raw u64 to a `PublishDoneStatusCode`, if valid.
148    pub fn from_u64(v: u64) -> Option<Self> {
149        match v {
150            0x0 => Some(PublishDoneStatusCode::Normal),
151            0x1 => Some(PublishDoneStatusCode::Unsubscribed),
152            0x2 => Some(PublishDoneStatusCode::InternalError),
153            0x3 => Some(PublishDoneStatusCode::Unauthorized),
154            0x4 => Some(PublishDoneStatusCode::Unsupported),
155            0x5 => Some(PublishDoneStatusCode::NotFound),
156            _ => None,
157        }
158    }
159
160    /// Return the raw u64 value of this status code.
161    pub fn as_u64(self) -> u64 {
162        self as u64
163    }
164}