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
use std::io;
use thiserror::Error;
pub type DecodeResult<T> = Result<T, DecodeError>;
#[derive(Error, Debug)]
pub enum DecodeError {
#[error("decoder ran out of bytes to read on byte {index}")]
EndOfBuffer {
index: usize,
},
#[error("decoder checked_add failed")]
AddOverflow,
#[error("parser ran out of data-- not enough bytes")]
NotEnoughBytes,
#[error("error converting from slice {0}")]
SliceError(#[from] std::array::TryFromSliceError),
#[error("error getting null terminated string {0}")]
NulError(#[from] std::ffi::FromBytesWithNulError),
#[error("error converting to UTF-8 {0}")]
Utf8Error(#[from] std::str::Utf8Error),
#[error("io error {0}")]
IoError(#[from] io::Error),
}
#[derive(Error, Debug)]
pub enum EncodeError {
#[error("encoder checked_add failed")]
AddOverflow,
#[error(
"message is trying to write a string to the message that exceeds the max size of {len}"
)]
StringSizeTooBig {
len: usize,
},
#[error("io error {0}")]
IoError(#[from] io::Error),
}
pub type EncodeResult<T> = Result<T, EncodeError>;