1use std::io;
4use std::num::TryFromIntError;
5use std::str::Utf8Error;
6
7use crate::Amf0Marker;
8
9pub type Result<T> = std::result::Result<T, Amf0Error>;
11
12#[derive(thiserror::Error, Debug)]
14pub enum Amf0Error {
15 #[error("io error: {0}")]
17 Io(#[from] io::Error),
18 #[error("element is too long: {0}")]
20 TooLong(#[from] TryFromIntError),
21 #[error("cannot serialize sequence with unknown length")]
23 UnknownLength,
24 #[error("cannot serialize map with non-string key")]
26 MapKeyNotString,
27 #[error("unknown marker: {0}")]
29 UnknownMarker(u8),
30 #[error("this marker cannot be deserialized: {0:?}")]
32 UnsupportedMarker(Amf0Marker),
33 #[error("string parse error: {0}")]
35 StringParseError(#[from] Utf8Error),
36 #[error("unexpected type: expected one of {expected:?}, got {got:?}")]
38 UnexpectedType {
39 expected: &'static [Amf0Marker],
41 got: Amf0Marker,
43 },
44 #[error("wrong array length: expected {expected}, got {got}")]
46 WrongArrayLength {
47 expected: usize,
49 got: usize,
51 },
52 #[error("char deserialization is not supported")]
54 CharNotSupported,
55 #[cfg(feature = "serde")]
57 #[error("{0}")]
58 Custom(String),
59}
60
61#[cfg(feature = "serde")]
62impl serde::ser::Error for Amf0Error {
63 fn custom<T: std::fmt::Display>(msg: T) -> Self {
64 Amf0Error::Custom(msg.to_string())
65 }
66}
67
68#[cfg(feature = "serde")]
69impl serde::de::Error for Amf0Error {
70 fn custom<T: std::fmt::Display>(msg: T) -> Self {
71 Amf0Error::Custom(msg.to_string())
72 }
73}