#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u64)]
pub enum SessionErrorCode {
NoError = 0x0,
InternalError = 0x1,
Unauthorized = 0x2,
ProtocolViolation = 0x3,
DuplicateTrackAlias = 0x4,
ParameterLengthMismatch = 0x5,
TooManySubscribes = 0x6,
GoawayTimeout = 0x10,
ControlMessageTimeout = 0x11,
DataStreamTimeout = 0x12,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u64)]
pub enum AnnounceErrorCode {
InternalError = 0x0,
Unauthorized = 0x1,
Timeout = 0x2,
NotSupported = 0x3,
Uninterested = 0x4,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u64)]
pub enum SubscribeErrorCode {
InternalError = 0x0,
Unauthorized = 0x1,
Timeout = 0x2,
NotSupported = 0x3,
TrackDoesNotExist = 0x4,
InvalidRange = 0x5,
RetryTrackAlias = 0x6,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u64)]
pub enum FetchErrorCode {
InternalError = 0x0,
Unauthorized = 0x1,
Timeout = 0x2,
NotSupported = 0x3,
TrackDoesNotExist = 0x4,
InvalidRange = 0x5,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u64)]
pub enum SubscribeDoneStatusCode {
InternalError = 0x0,
Unauthorized = 0x1,
TrackEnded = 0x2,
SubscriptionEnded = 0x3,
GoingAway = 0x4,
Expired = 0x5,
TooFarBehind = 0x6,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u64)]
pub enum SubscribeAnnouncesErrorCode {
InternalError = 0x0,
Unauthorized = 0x1,
Timeout = 0x2,
NotSupported = 0x3,
NamespacePrefixUnknown = 0x4,
}
impl SessionErrorCode {
pub const ALL: &[SessionErrorCode] = &[
SessionErrorCode::NoError,
SessionErrorCode::InternalError,
SessionErrorCode::Unauthorized,
SessionErrorCode::ProtocolViolation,
SessionErrorCode::DuplicateTrackAlias,
SessionErrorCode::ParameterLengthMismatch,
SessionErrorCode::TooManySubscribes,
SessionErrorCode::GoawayTimeout,
SessionErrorCode::ControlMessageTimeout,
SessionErrorCode::DataStreamTimeout,
];
pub fn from_u64(v: u64) -> Option<Self> {
match v {
0x0 => Some(SessionErrorCode::NoError),
0x1 => Some(SessionErrorCode::InternalError),
0x2 => Some(SessionErrorCode::Unauthorized),
0x3 => Some(SessionErrorCode::ProtocolViolation),
0x4 => Some(SessionErrorCode::DuplicateTrackAlias),
0x5 => Some(SessionErrorCode::ParameterLengthMismatch),
0x6 => Some(SessionErrorCode::TooManySubscribes),
0x10 => Some(SessionErrorCode::GoawayTimeout),
0x11 => Some(SessionErrorCode::ControlMessageTimeout),
0x12 => Some(SessionErrorCode::DataStreamTimeout),
_ => None,
}
}
pub fn as_u64(self) -> u64 {
self as u64
}
}
impl AnnounceErrorCode {
pub const ALL: &[AnnounceErrorCode] = &[
AnnounceErrorCode::InternalError,
AnnounceErrorCode::Unauthorized,
AnnounceErrorCode::Timeout,
AnnounceErrorCode::NotSupported,
AnnounceErrorCode::Uninterested,
];
pub fn from_u64(v: u64) -> Option<Self> {
match v {
0x0 => Some(AnnounceErrorCode::InternalError),
0x1 => Some(AnnounceErrorCode::Unauthorized),
0x2 => Some(AnnounceErrorCode::Timeout),
0x3 => Some(AnnounceErrorCode::NotSupported),
0x4 => Some(AnnounceErrorCode::Uninterested),
_ => None,
}
}
pub fn as_u64(self) -> u64 {
self as u64
}
}
impl SubscribeErrorCode {
pub const ALL: &[SubscribeErrorCode] = &[
SubscribeErrorCode::InternalError,
SubscribeErrorCode::Unauthorized,
SubscribeErrorCode::Timeout,
SubscribeErrorCode::NotSupported,
SubscribeErrorCode::TrackDoesNotExist,
SubscribeErrorCode::InvalidRange,
SubscribeErrorCode::RetryTrackAlias,
];
pub fn from_u64(v: u64) -> Option<Self> {
match v {
0x0 => Some(SubscribeErrorCode::InternalError),
0x1 => Some(SubscribeErrorCode::Unauthorized),
0x2 => Some(SubscribeErrorCode::Timeout),
0x3 => Some(SubscribeErrorCode::NotSupported),
0x4 => Some(SubscribeErrorCode::TrackDoesNotExist),
0x5 => Some(SubscribeErrorCode::InvalidRange),
0x6 => Some(SubscribeErrorCode::RetryTrackAlias),
_ => None,
}
}
pub fn as_u64(self) -> u64 {
self as u64
}
}
impl FetchErrorCode {
pub const ALL: &[FetchErrorCode] = &[
FetchErrorCode::InternalError,
FetchErrorCode::Unauthorized,
FetchErrorCode::Timeout,
FetchErrorCode::NotSupported,
FetchErrorCode::TrackDoesNotExist,
FetchErrorCode::InvalidRange,
];
pub fn from_u64(v: u64) -> Option<Self> {
match v {
0x0 => Some(FetchErrorCode::InternalError),
0x1 => Some(FetchErrorCode::Unauthorized),
0x2 => Some(FetchErrorCode::Timeout),
0x3 => Some(FetchErrorCode::NotSupported),
0x4 => Some(FetchErrorCode::TrackDoesNotExist),
0x5 => Some(FetchErrorCode::InvalidRange),
_ => None,
}
}
pub fn as_u64(self) -> u64 {
self as u64
}
}
impl SubscribeDoneStatusCode {
pub const ALL: &[SubscribeDoneStatusCode] = &[
SubscribeDoneStatusCode::InternalError,
SubscribeDoneStatusCode::Unauthorized,
SubscribeDoneStatusCode::TrackEnded,
SubscribeDoneStatusCode::SubscriptionEnded,
SubscribeDoneStatusCode::GoingAway,
SubscribeDoneStatusCode::Expired,
SubscribeDoneStatusCode::TooFarBehind,
];
pub fn from_u64(v: u64) -> Option<Self> {
match v {
0x0 => Some(SubscribeDoneStatusCode::InternalError),
0x1 => Some(SubscribeDoneStatusCode::Unauthorized),
0x2 => Some(SubscribeDoneStatusCode::TrackEnded),
0x3 => Some(SubscribeDoneStatusCode::SubscriptionEnded),
0x4 => Some(SubscribeDoneStatusCode::GoingAway),
0x5 => Some(SubscribeDoneStatusCode::Expired),
0x6 => Some(SubscribeDoneStatusCode::TooFarBehind),
_ => None,
}
}
pub fn as_u64(self) -> u64 {
self as u64
}
}
impl SubscribeAnnouncesErrorCode {
pub const ALL: &[SubscribeAnnouncesErrorCode] = &[
SubscribeAnnouncesErrorCode::InternalError,
SubscribeAnnouncesErrorCode::Unauthorized,
SubscribeAnnouncesErrorCode::Timeout,
SubscribeAnnouncesErrorCode::NotSupported,
SubscribeAnnouncesErrorCode::NamespacePrefixUnknown,
];
pub fn from_u64(v: u64) -> Option<Self> {
match v {
0x0 => Some(SubscribeAnnouncesErrorCode::InternalError),
0x1 => Some(SubscribeAnnouncesErrorCode::Unauthorized),
0x2 => Some(SubscribeAnnouncesErrorCode::Timeout),
0x3 => Some(SubscribeAnnouncesErrorCode::NotSupported),
0x4 => Some(SubscribeAnnouncesErrorCode::NamespacePrefixUnknown),
_ => None,
}
}
pub fn as_u64(self) -> u64 {
self as u64
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn session_error_code_roundtrip() {
for code in [
SessionErrorCode::NoError,
SessionErrorCode::InternalError,
SessionErrorCode::Unauthorized,
SessionErrorCode::ProtocolViolation,
SessionErrorCode::DuplicateTrackAlias,
SessionErrorCode::ParameterLengthMismatch,
SessionErrorCode::TooManySubscribes,
SessionErrorCode::GoawayTimeout,
SessionErrorCode::ControlMessageTimeout,
SessionErrorCode::DataStreamTimeout,
] {
assert_eq!(SessionErrorCode::from_u64(code.as_u64()), Some(code));
}
}
#[test]
fn unknown_codes_are_none() {
for code in 0x7..=0xF {
assert_eq!(SessionErrorCode::from_u64(code), None, "0x{code:x}");
}
assert_eq!(SessionErrorCode::from_u64(0x13), None);
assert_eq!(AnnounceErrorCode::from_u64(0x5), None);
assert_eq!(SubscribeErrorCode::from_u64(0x7), None);
assert_eq!(FetchErrorCode::from_u64(0x6), None);
assert_eq!(SubscribeDoneStatusCode::from_u64(0x7), None);
assert_eq!(SubscribeAnnouncesErrorCode::from_u64(0x5), None);
assert_eq!(SessionErrorCode::from_u64(u64::MAX), None);
}
#[test]
fn fetch_error_has_no_retry_track_alias() {
assert_eq!(SubscribeErrorCode::from_u64(0x6), Some(SubscribeErrorCode::RetryTrackAlias));
assert_eq!(FetchErrorCode::from_u64(0x6), None);
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u64)]
pub enum TrackStatusCode {
InProgress = 0x00,
TrackDoesNotExist = 0x01,
NotYetBegun = 0x02,
Finished = 0x03,
RelayStatusUnavailable = 0x04,
}
impl TrackStatusCode {
pub fn from_u64(v: u64) -> Option<Self> {
match v {
0x00 => Some(TrackStatusCode::InProgress),
0x01 => Some(TrackStatusCode::TrackDoesNotExist),
0x02 => Some(TrackStatusCode::NotYetBegun),
0x03 => Some(TrackStatusCode::Finished),
0x04 => Some(TrackStatusCode::RelayStatusUnavailable),
_ => None,
}
}
pub fn requires_zero_location(self) -> bool {
matches!(self, TrackStatusCode::TrackDoesNotExist | TrackStatusCode::NotYetBegun)
}
pub fn as_u64(self) -> u64 {
self as u64
}
}