1use crate::types::PacketIdentifier;
2
3#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord)]
5#[cfg_attr(feature = "defmt", derive(defmt::Format))]
6pub enum QoS {
7 AtMostOnce = 0,
9 AtLeastOnce = 1,
11 ExactlyOnce = 2,
13}
14impl From<IdentifiedQoS> for QoS {
15 fn from(value: IdentifiedQoS) -> Self {
16 match value {
17 IdentifiedQoS::AtMostOnce => Self::AtMostOnce,
18 IdentifiedQoS::AtLeastOnce(_) => Self::AtLeastOnce,
19 IdentifiedQoS::ExactlyOnce(_) => Self::ExactlyOnce,
20 }
21 }
22}
23
24impl QoS {
25 pub(crate) const fn into_bits(self, left_shift: u8) -> u8 {
26 let bits = match self {
27 Self::AtMostOnce => 0x00,
28 Self::AtLeastOnce => 0x01,
29 Self::ExactlyOnce => 0x02,
30 };
31
32 bits << left_shift
33 }
34
35 pub(crate) const fn try_from_bits(bits: u8) -> Option<Self> {
36 match bits {
37 0x00 => Some(Self::AtMostOnce),
38 0x01 => Some(Self::AtLeastOnce),
39 0x02 => Some(Self::ExactlyOnce),
40 _ => None,
41 }
42 }
43}
44
45#[derive(Debug, Clone, Copy, PartialEq, Eq)]
48#[cfg_attr(feature = "defmt", derive(defmt::Format))]
49pub enum IdentifiedQoS {
50 AtMostOnce,
52 AtLeastOnce(PacketIdentifier),
54 ExactlyOnce(PacketIdentifier),
56}
57
58impl IdentifiedQoS {
59 #[inline]
62 #[must_use]
63 pub const fn packet_identifier(&self) -> Option<PacketIdentifier> {
64 match self {
65 Self::AtMostOnce => None,
66 Self::AtLeastOnce(pid) | Self::ExactlyOnce(pid) => Some(*pid),
67 }
68 }
69}