multiversx_sc_codec/
codec_err.rs

1#[derive(Debug, PartialEq, Eq)]
2pub struct EncodeError(&'static str);
3
4impl From<&'static str> for EncodeError {
5    #[inline]
6    fn from(message_bytes: &'static str) -> Self {
7        EncodeError(message_bytes)
8    }
9}
10
11impl EncodeError {
12    #[inline]
13    pub fn message_bytes(&self) -> &'static [u8] {
14        self.0.as_bytes()
15    }
16
17    #[inline]
18    pub fn message_str(&self) -> &'static str {
19        self.0
20    }
21
22    pub const UNSUPPORTED_OPERATION: EncodeError = EncodeError("unsupported operation");
23}
24
25#[derive(Debug, PartialEq, Eq)]
26pub struct DecodeError(&'static str);
27
28impl From<&'static str> for DecodeError {
29    #[inline]
30    fn from(message_bytes: &'static str) -> Self {
31        DecodeError(message_bytes)
32    }
33}
34
35impl DecodeError {
36    #[inline]
37    pub fn message_bytes(&self) -> &'static [u8] {
38        self.0.as_bytes()
39    }
40
41    #[inline]
42    pub fn message_str(&self) -> &'static str {
43        self.0
44    }
45
46    pub const INPUT_TOO_SHORT: DecodeError = DecodeError("input too short");
47    pub const INPUT_TOO_LONG: DecodeError = DecodeError("input too long");
48    pub const INPUT_OUT_OF_RANGE: DecodeError = DecodeError("input out of range");
49    pub const INVALID_VALUE: DecodeError = DecodeError("invalid value");
50    pub const UNSUPPORTED_OPERATION: DecodeError = DecodeError("unsupported operation");
51    pub const ARRAY_DECODE_ERROR: DecodeError = DecodeError("array decode error");
52    pub const UTF8_DECODE_ERROR: DecodeError = DecodeError("utf-8 decode error");
53    pub const CAPACITY_EXCEEDED_ERROR: DecodeError = DecodeError("capacity exceeded");
54
55    pub const MULTI_TOO_FEW_ARGS: DecodeError = DecodeError("too few arguments");
56    pub const MULTI_TOO_MANY_ARGS: DecodeError = DecodeError("too many arguments");
57}