use crate::{
eio::{Read, Write},
io::{
err::{ReadError, WriteError},
read::Readable,
write::Writable,
},
};
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum PropertyType {
PayloadFormatIndicator = 0x01,
MessageExpiryInterval = 0x02,
ContentType = 0x03,
ResponseTopic = 0x08,
CorrelationData = 0x09,
SubscriptionIdentifier = 0x0B,
SessionExpiryInterval = 0x11,
AssignedClientIdentifier = 0x12,
ServerKeepAlive = 0x13,
AuthenticationMethod = 0x15,
AuthenticationData = 0x16,
RequestProblemInformation = 0x17,
WillDelayInterval = 0x18,
RequestResponseInformation = 0x19,
ResponseInformation = 0x1A,
ServerReference = 0x1C,
ReasonString = 0x1F,
ReceiveMaximum = 0x21,
TopicAliasMaximum = 0x22,
TopicAlias = 0x23,
MaximumQoS = 0x24,
RetainAvailable = 0x25,
UserProperty = 0x26,
MaximumPacketSize = 0x27,
WildcardSubscriptionAvailable = 0x28,
SubscriptionIdentifierAvailable = 0x29,
SharedSubscriptionAvailable = 0x2A,
}
impl PropertyType {
pub const fn from_identifier(identifier: u8) -> Option<Self> {
Some(match identifier {
0x01 => Self::PayloadFormatIndicator,
0x02 => Self::MessageExpiryInterval,
0x03 => Self::ContentType,
0x08 => Self::ResponseTopic,
0x09 => Self::CorrelationData,
0x0B => Self::SubscriptionIdentifier,
0x11 => Self::SessionExpiryInterval,
0x12 => Self::AssignedClientIdentifier,
0x13 => Self::ServerKeepAlive,
0x15 => Self::AuthenticationMethod,
0x16 => Self::AuthenticationData,
0x17 => Self::RequestProblemInformation,
0x18 => Self::WillDelayInterval,
0x19 => Self::RequestResponseInformation,
0x1A => Self::ResponseInformation,
0x1C => Self::ServerReference,
0x1F => Self::ReasonString,
0x21 => Self::ReceiveMaximum,
0x22 => Self::TopicAliasMaximum,
0x23 => Self::TopicAlias,
0x24 => Self::MaximumQoS,
0x25 => Self::RetainAvailable,
0x26 => Self::UserProperty,
0x27 => Self::MaximumPacketSize,
0x28 => Self::WildcardSubscriptionAvailable,
0x29 => Self::SubscriptionIdentifierAvailable,
0x2A => Self::SharedSubscriptionAvailable,
_ => return None,
})
}
pub const fn identifier(self) -> u8 {
self as u8
}
}
impl<R: Read> Readable<R> for PropertyType {
async fn read(net: &mut R) -> Result<Self, ReadError<R::Error>> {
let identifier = u8::read(net).await?;
Self::from_identifier(identifier).ok_or(ReadError::MalformedPacket)
}
}
impl Writable for PropertyType {
fn written_len(&self) -> usize {
1
}
async fn write<W: Write>(&self, write: &mut W) -> Result<(), WriteError<W::Error>> {
let identifier: u8 = self.identifier();
identifier.write(write).await
}
}