use crate::amf0::Amf0Value;
#[non_exhaustive]
#[derive(Debug, thiserror::Error, Clone, PartialEq)]
pub enum RtmpError {
#[error(transparent)]
BufferTooShort(#[from] broadcast_common::error::BufferTooShort),
#[error("malformed {what}")]
Malformed {
what: &'static str,
},
#[error("chunk size {value} is outside the range this engine accepts")]
ChunkSizeOutOfRange {
value: u32,
},
#[error("set peer bandwidth limit type {value} is not 0..=2")]
InvalidLimitType {
value: u8,
},
#[error("unsupported user control event type {value}")]
UnsupportedUserControlEvent {
value: u16,
},
#[error("unsupported AMF0 marker {marker:#04x}")]
UnsupportedAmf0Marker {
marker: u8,
},
#[error("AMF0 nesting depth exceeds {max}")]
Amf0DepthExceeded {
max: usize,
},
#[error("AMF0 value count exceeds {max}")]
Amf0TooManyValues {
max: usize,
},
#[error("command message is {len} bytes, above the {max}-byte limit")]
CommandTooLong {
len: usize,
max: usize,
},
#[error("{len} bytes do not fit the AMF0 string length prefix")]
Amf0StringTooLong {
len: usize,
},
#[error("command name is not an AMF0 string: {}", displayed(.value))]
CommandNameNotString {
value: Amf0Value,
},
#[error("command transaction id is not an AMF0 number: {}", displayed(.value))]
CommandTransactionIdNotNumber {
value: Amf0Value,
},
#[error("handshake version {value} is not {expected}")]
HandshakeVersion {
value: u8,
expected: u8,
},
#[error("AMF0 date reserved time zone is {value}, must be 0")]
Amf0DateTimeZone {
value: u16,
},
#[error("invalid AMF0 {what}")]
Amf0Utf8 {
what: &'static str,
},
#[error("more than {max} concurrent chunk streams")]
TooManyChunkStreams {
max: usize,
},
#[error("buffered input exceeds {max} bytes")]
InputBudgetExceeded {
max: usize,
},
#[error("inconsistent chunk stream {chunk_stream_id}: {what}")]
ChunkStreamState {
chunk_stream_id: u32,
what: &'static str,
},
#[error("unexpected state: {what}")]
UnexpectedState {
what: &'static str,
},
#[error("chunk stream id {chunk_stream_id} is outside the encodable range 2..=65599")]
InvalidChunkStreamId {
chunk_stream_id: u32,
},
#[error(transparent)]
FieldOverflow(#[from] broadcast_common::error::FieldOverflow),
#[error(transparent)]
OutputBufferTooSmall(#[from] broadcast_common::error::OutputBufferTooSmall),
}
fn displayed(value: &Amf0Value) -> alloc::string::String {
alloc::format!("{value:?}")
}
impl RtmpError {
pub(crate) const fn chunk_size_out_of_range(value: u32) -> Self {
RtmpError::ChunkSizeOutOfRange { value }
}
}