1use core::fmt;
2
3use umsh_core::{EncodeError as CoreEncodeError, PacketType, ParseError as CoreParseError};
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
6pub enum AppParseError {
7 Core(CoreParseError),
8 InvalidUtf8,
9 InvalidPayloadType(u8),
10 PayloadTypeNotAllowed {
11 payload_type: u8,
12 packet_type: PacketType,
13 },
14 InvalidRole(u8),
15 InvalidCommandId(u8),
16 InvalidOptionValue,
17 InvalidLength {
18 expected: usize,
19 actual: usize,
20 },
21}
22
23impl From<CoreParseError> for AppParseError {
24 fn from(value: CoreParseError) -> Self {
25 Self::Core(value)
26 }
27}
28
29impl fmt::Display for AppParseError {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 write!(f, "{self:?}")
32 }
33}
34
35#[derive(Clone, Copy, Debug, PartialEq, Eq)]
36pub enum AppEncodeError {
37 Core(CoreEncodeError),
38 BufferTooSmall,
39 InvalidField,
40}
41
42impl From<CoreEncodeError> for AppEncodeError {
43 fn from(value: CoreEncodeError) -> Self {
44 Self::Core(value)
45 }
46}
47
48impl fmt::Display for AppEncodeError {
49 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50 write!(f, "{self:?}")
51 }
52}
53
54#[cfg(feature = "std")]
55impl std::error::Error for AppParseError {}
56
57#[cfg(feature = "std")]
58impl std::error::Error for AppEncodeError {}