use std::io;
use std::num::TryFromIntError;
use std::str::Utf8Error;
use crate::Amf0Marker;
pub type Result<T> = std::result::Result<T, Amf0Error>;
#[derive(thiserror::Error, Debug)]
pub enum Amf0Error {
#[error("io error: {0}")]
Io(#[from] io::Error),
#[error("element is too long: {0}")]
TooLong(#[from] TryFromIntError),
#[error("cannot serialize sequence with unknown length")]
UnknownLength,
#[error("cannot serialize map with non-string key")]
MapKeyNotString,
#[error("unknown marker: {0}")]
UnknownMarker(u8),
#[error("this marker cannot be deserialized: {0:?}")]
UnsupportedMarker(Amf0Marker),
#[error("string parse error: {0}")]
StringParseError(#[from] Utf8Error),
#[error("unexpected type: expected one of {expected:?}, got {got:?}")]
UnexpectedType {
expected: &'static [Amf0Marker],
got: Amf0Marker,
},
#[error("wrong array length: expected {expected}, got {got}")]
WrongArrayLength {
expected: usize,
got: usize,
},
#[error("char deserialization is not supported")]
CharNotSupported,
#[cfg(feature = "serde")]
#[error("{0}")]
Custom(String),
}
#[cfg(feature = "serde")]
impl serde::ser::Error for Amf0Error {
fn custom<T: std::fmt::Display>(msg: T) -> Self {
Amf0Error::Custom(msg.to_string())
}
}
#[cfg(feature = "serde")]
impl serde::de::Error for Amf0Error {
fn custom<T: std::fmt::Display>(msg: T) -> Self {
Amf0Error::Custom(msg.to_string())
}
}