1use thiserror::Error;
4
5pub type WireResult<T> = Result<T, WireError>;
7
8#[derive(Debug, Error)]
10pub enum WireError {
11 #[error("invalid magic: expected 0x56444220, got 0x{0:08x}")]
13 InvalidMagic(u32),
14
15 #[error("unsupported protocol version: {0}")]
17 UnsupportedVersion(u16),
18
19 #[error("payload too large: {size} bytes (max {max})")]
21 PayloadTooLarge { size: u32, max: u32 },
22
23 #[error("checksum mismatch: expected 0x{expected:08x}, got 0x{actual:08x}")]
25 ChecksumMismatch { expected: u32, actual: u32 },
26
27 #[error("incomplete frame: need {needed} bytes, have {available}")]
29 IncompleteFrame { needed: usize, available: usize },
30
31 #[error("serialization error: {0}")]
33 Serialization(String),
34
35 #[error("deserialization error: {0}")]
37 Deserialization(String),
38
39 #[error("i/o error: {0}")]
41 Io(#[from] std::io::Error),
42}
43
44impl From<postcard::Error> for WireError {
45 fn from(e: postcard::Error) -> Self {
46 WireError::Deserialization(e.to_string())
47 }
48}