1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
use { failure::{Backtrace, Fail}, networkio::bytes_errors::{BytesReadError, BytesWriteError}, std::{ fmt, {io, string}, }, }; #[derive(Debug, Fail)] pub enum Amf0ReadErrorValue { #[fail(display = "Encountered unknown marker: {}\n", marker)] UnknownMarker { marker: u8 }, #[fail(display = "parser string error: {}\n", _0)] StringParseError(#[cause] string::FromUtf8Error), #[fail(display = "bytes read error :{}\n", _0)] BytesReadError(BytesReadError), #[fail(display = "wrong type")] WrongType, } #[derive(Debug)] pub struct Amf0ReadError { pub value: Amf0ReadErrorValue, } impl From<string::FromUtf8Error> for Amf0ReadError { fn from(error: string::FromUtf8Error) -> Self { Amf0ReadError { value: Amf0ReadErrorValue::StringParseError(error), } } } impl From<BytesReadError> for Amf0ReadError { fn from(error: BytesReadError) -> Self { Amf0ReadError { value: Amf0ReadErrorValue::BytesReadError(error), } } } #[derive(Debug, Fail)] pub enum Amf0WriteErrorValue { #[fail(display = "normal string too long")] NormalStringTooLong, #[fail(display = "io error\n")] BufferWriteError(io::Error), #[fail(display = "bytes write error\n")] BytesWriteError(BytesWriteError), } #[derive(Debug)] pub struct Amf0WriteError { pub value: Amf0WriteErrorValue, } impl From<io::Error> for Amf0WriteError { fn from(error: io::Error) -> Self { Amf0WriteError { value: Amf0WriteErrorValue::BufferWriteError(error), } } } impl From<BytesWriteError> for Amf0WriteError { fn from(error: BytesWriteError) -> Self { Amf0WriteError { value: Amf0WriteErrorValue::BytesWriteError(error), } } } impl fmt::Display for Amf0ReadError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.value, f) } } impl Fail for Amf0ReadError { fn cause(&self) -> Option<&dyn Fail> { self.value.cause() } fn backtrace(&self) -> Option<&Backtrace> { self.value.backtrace() } } impl fmt::Display for Amf0WriteError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.value, f) } } impl Fail for Amf0WriteError { fn cause(&self) -> Option<&dyn Fail> { self.value.cause() } fn backtrace(&self) -> Option<&Backtrace> { self.value.backtrace() } }