1use core::{
2 fmt::{Display, Formatter},
3 str::Utf8Error,
4};
5
6#[derive(Copy, Clone, Debug, PartialEq)]
28pub enum PacketReadError {
29 InsufficientData,
32
33 InvalidUtf8,
35
36 NullCharacterInString,
39
40 InvalidVariableByteIntegerEncoding,
44
45 IncorrectPacketType,
47
48 UnknownReasonCode,
50
51 InvalidBooleanValue,
53
54 TooManyProperties,
57
58 InvalidQosValue,
61
62 UnsupportedProtocolVersion,
66
67 TooManyRequests,
70
71 InvalidPacketType,
74
75 ConnectionReceive,
77
78 PacketTooLargeForBuffer,
80
81 UnexpectedPropertyIdentifier,
85
86 InvalidRetainHandlingValue,
89
90 InvalidConnectFlags,
92
93 IncorrectPacketLength,
96
97 SubscribeWithoutValidSubscriptionRequest,
99
100 SubackWithoutValidReasonCode,
103
104 UnsubscribeWithoutValidSubscriptionRequest,
106
107 UnsubackWithoutValidReasonCode,
110
111 WillQosSpecifiedWithoutWill,
113
114 WillRetainSpecifiedWithoutWill,
116
117 SubscriptionOptionsReservedBitsNonZero,
119}
120
121#[cfg(feature = "defmt")]
122impl defmt::Format for PacketReadError {
123 fn format(&self, f: defmt::Formatter) {
124 match self {
125 Self::InsufficientData => defmt::write!(f, "InsufficientData"),
126 Self::InvalidUtf8 => defmt::write!(f, "InvalidUtf8"),
127 Self::NullCharacterInString => defmt::write!(f, "NullCharacterInString"),
128 Self::InvalidVariableByteIntegerEncoding => {
129 defmt::write!(f, "InvalidVariableByteIntegerEncoding")
130 }
131 Self::IncorrectPacketType => defmt::write!(f, "IncorrectPacketType"),
132 Self::UnknownReasonCode => defmt::write!(f, "UnknownReasonCode"),
133 Self::InvalidBooleanValue => defmt::write!(f, "InvalidBooleanValue"),
134 Self::TooManyProperties => defmt::write!(f, "TooManyProperties"),
135 Self::InvalidQosValue => defmt::write!(f, "InvalidQosValue"),
136 Self::UnsupportedProtocolVersion => defmt::write!(f, "UnsupportedProtocolVersion"),
137 Self::TooManyRequests => defmt::write!(f, "TooManyRequests"),
138 Self::InvalidPacketType => defmt::write!(f, "InvalidPacketType"),
139 Self::ConnectionReceive => defmt::write!(f, "ConnectionReceive"),
140 Self::PacketTooLargeForBuffer => defmt::write!(f, "PacketTooLargeForBuffer"),
141 Self::UnexpectedPropertyIdentifier => defmt::write!(f, "UnexpectedPropertyIdentifier"),
142 Self::InvalidRetainHandlingValue => defmt::write!(f, "InvalidRetainHandlingValue"),
143 Self::InvalidConnectFlags => defmt::write!(f, "InvalidConnectFlags"),
144 Self::IncorrectPacketLength => defmt::write!(f, "IncorrectPacketLength"),
145 Self::SubscribeWithoutValidSubscriptionRequest => {
146 defmt::write!(f, "SubscribeWithoutValidSubscriptionRequest")
147 }
148 Self::SubackWithoutValidReasonCode => defmt::write!(f, "SubackWithoutValidReasonCode"),
149 Self::UnsubscribeWithoutValidSubscriptionRequest => {
150 defmt::write!(f, "UnsubscribeWithoutValidSubscriptionRequest")
151 }
152 Self::UnsubackWithoutValidReasonCode => {
153 defmt::write!(f, "UnsubackWithoutValidReasonCode")
154 }
155 Self::WillQosSpecifiedWithoutWill => defmt::write!(f, "WillQosSpecifiedWithoutWill"),
156 Self::WillRetainSpecifiedWithoutWill => {
157 defmt::write!(f, "WillRetainSpecifiedWithoutWill")
158 }
159 Self::SubscriptionOptionsReservedBitsNonZero => {
160 defmt::write!(f, "SubscriptionOptionsReservedBitsNonZero")
161 }
162 }
163 }
164}
165
166impl From<Utf8Error> for PacketReadError {
167 fn from(_e: Utf8Error) -> Self {
168 Self::InvalidUtf8
169 }
170}
171
172impl Display for PacketReadError {
173 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
174 match self {
175 Self::InsufficientData => write!(f, "InsufficientData"),
176 Self::InvalidUtf8 => write!(f, "InvalidUtf8"),
177 Self::NullCharacterInString => write!(f, "NullCharacterInString"),
178 Self::InvalidVariableByteIntegerEncoding => {
179 write!(f, "InvalidVariableByteIntegerEncoding")
180 }
181 Self::IncorrectPacketType => write!(f, "IncorrectPacketType"),
182 Self::UnknownReasonCode => write!(f, "UnknownReasonCode"),
183 Self::InvalidBooleanValue => write!(f, "InvalidBooleanValue"),
184 Self::TooManyProperties => write!(f, "TooManyProperties"),
185 Self::InvalidQosValue => write!(f, "InvalidQosValue"),
186 Self::UnsupportedProtocolVersion => write!(f, "UnsupportedProtocolVersion"),
187 Self::TooManyRequests => write!(f, "TooManyRequests"),
188 Self::InvalidPacketType => write!(f, "InvalidPacketType"),
189 Self::ConnectionReceive => write!(f, "ConnectionReceive"),
190 Self::PacketTooLargeForBuffer => write!(f, "PacketTooLargeForBuffer"),
191 Self::UnexpectedPropertyIdentifier => write!(f, "UnexpectedPropertyIdentifier"),
192 Self::InvalidRetainHandlingValue => write!(f, "InvalidRetainHandlingValue"),
193 Self::InvalidConnectFlags => write!(f, "InvalidConnectFlags"),
194 Self::IncorrectPacketLength => write!(f, "IncorrectPacketLength"),
195 Self::SubscribeWithoutValidSubscriptionRequest => {
196 write!(f, "SubscribeWithoutValidSubscriptionRequest")
197 }
198 Self::SubackWithoutValidReasonCode => write!(f, "SubackWithoutValidReasonCode"),
199 Self::UnsubscribeWithoutValidSubscriptionRequest => {
200 write!(f, "UnsubscribeWithoutValidSubscriptionRequest")
201 }
202 Self::UnsubackWithoutValidReasonCode => write!(f, "UnsubackWithoutValidReasonCode"),
203 Self::WillQosSpecifiedWithoutWill => write!(f, "WillQosSpecifiedWithoutWill"),
204 Self::WillRetainSpecifiedWithoutWill => write!(f, "WillRetainSpecifiedWithoutWill"),
205 Self::SubscriptionOptionsReservedBitsNonZero => {
206 write!(f, "ReservedBitsSetInSubscriptionOptions")
207 }
208 }
209 }
210}
211
212#[derive(Copy, Clone, Debug, PartialEq)]
213pub enum PacketWriteError {
214 Overflow,
216
217 NullCharacterInString,
219
220 VariableByteIntegerTooLarge,
222
223 DataTooLarge,
225
226 StringTooLarge,
228
229 ConnectionSend,
231}
232
233#[cfg(feature = "defmt")]
234impl defmt::Format for PacketWriteError {
235 fn format(&self, f: defmt::Formatter) {
236 match self {
237 Self::Overflow => defmt::write!(f, "Overflow"),
238 Self::NullCharacterInString => defmt::write!(f, "NullCharacterInString"),
239 Self::VariableByteIntegerTooLarge => defmt::write!(f, "VariableByteIntegerTooLarge"),
240 Self::DataTooLarge => defmt::write!(f, "DataTooLarge"),
241 Self::StringTooLarge => defmt::write!(f, "StringTooLarge"),
242 Self::ConnectionSend => defmt::write!(f, "ConnectionSend"),
243 }
244 }
245}
246
247impl Display for PacketWriteError {
248 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
249 match self {
250 Self::Overflow => write!(f, "Overflow"),
251 Self::NullCharacterInString => write!(f, "NullCharacterInString"),
252 Self::VariableByteIntegerTooLarge => write!(f, "VariableByteIntegerTooLarge"),
253 Self::DataTooLarge => write!(f, "DataTooLarge"),
254 Self::StringTooLarge => write!(f, "StringTooLarge"),
255 Self::ConnectionSend => write!(f, "ConnectionSend"),
256 }
257 }
258}