1 use std::{io, string}; 2 3 use netio::bytes_errors::{BytesReadError, BytesWriteError}; 4 5 //#[derive(Debug, Fail)] 6 pub enum Amf0ReadErrorValue { 7 //#[fail(display = "Encountered unknown marker: {}", marker)] 8 UnknownMarker { marker: u8 }, 9 10 //#[fail(display = "Unexpected empty object property name")] 11 UnexpectedEmptyObjectPropertyName, 12 13 //#[fail(display = "Hit end of the byte buffer but was expecting more data")] 14 UnexpectedEof, 15 16 //#[fail(display = "Failed to read byte buffer: {}", _0)] 17 //BufferReadError(#[cause] io::Error), 18 19 //#[fail(display = "Failed to read a utf8 string from the byte buffer: {}", _0)] 20 StringParseError(string::FromUtf8Error), 21 22 //#[fail(display = "Failed to read a utf8 string from the byte buffer: {}", _0)] 23 BytesReadError(BytesReadError), 24 WrongType, 25 } 26 27 pub struct Amf0ReadError { 28 pub value: Amf0ReadErrorValue, 29 } 30 31 // Since an IO error can only be thrown while reading the buffer, auto-conversion should work 32 // impl From<io::Error> for Amf0ReadError { 33 // fn from(error: io::Error) -> Self { 34 // Amf0ReadError::BufferReadError(error) 35 // } 36 // } 37 38 impl From<string::FromUtf8Error> for Amf0ReadError { 39 fn from(error: string::FromUtf8Error) -> Self { 40 Amf0ReadError { 41 value: Amf0ReadErrorValue::StringParseError(error), 42 } 43 } 44 } 45 46 impl From<BytesReadError> for Amf0ReadError { 47 fn from(error: BytesReadError) -> Self { 48 Amf0ReadError { 49 value: Amf0ReadErrorValue::BytesReadError(error), 50 } 51 } 52 } 53 54 // impl From<u8> for Amf0ReadError { 55 // fn from(error: u8) -> Self { 56 // Amf0ReadError { 57 // value: Amf0ReadErrorValue::UnknownMarker(error), 58 // } 59 // } 60 // } 61 62 /// Errors raised during to the serialization process 63 64 pub enum Amf0WriteErrorValue { 65 NormalStringTooLong, 66 BufferWriteError(io::Error), 67 BytesWriteError(BytesWriteError), 68 } 69 70 pub struct Amf0WriteError { 71 pub value: Amf0WriteErrorValue, 72 } 73 74 impl From<io::Error> for Amf0WriteError { 75 fn from(error: io::Error) -> Self { 76 Amf0WriteError { 77 value: Amf0WriteErrorValue::BufferWriteError(error), 78 } 79 } 80 } 81 82 impl From<BytesWriteError> for Amf0WriteError { 83 fn from(error: BytesWriteError) -> Self { 84 Amf0WriteError { 85 value: Amf0WriteErrorValue::BytesWriteError(error), 86 } 87 } 88 } 89