1use std::fmt::Display;
2
3use serde::{de, ser};
4
5pub type Result<T> = std::result::Result<T, Error>;
6
7#[derive(Debug, thiserror::Error)]
9pub enum Error {
10 #[error("{0}")]
12 Message(String),
13
14 #[error("io::Error: {0}")]
16 Io(#[from] std::io::Error),
17
18 #[error("CDR is not self-describing format, cannot deserialize \'Any\' type: {0}")]
21 NotSelfDescribingFormat(String),
22
23 #[error("CDR serialization requires sequence length to be specified at the start.")]
26 SequenceLengthUnknown,
27
28 #[error("unexpected end of input")]
30 Eof,
31
32 #[error("Expected 0 or 1 as Boolean, got: {0}")]
34 BadBoolean(u8),
35
36 #[error("Bad Unicode character code: {0}")]
38 BadChar(u32), #[error("Option value must have discriminant 0 or 1, read: {0}")]
42 BadOption(u32), #[error("UTF-8 error: {0}")]
46 BadUTF8(std::str::Utf8Error),
47}
48
49impl ser::Error for Error {
50 fn custom<T: Display>(msg: T) -> Self {
51 Self::Message(msg.to_string())
52 }
53}
54
55impl de::Error for Error {
56 fn custom<T: Display>(msg: T) -> Self {
57 Self::Message(msg.to_string())
58 }
59}