use super::data_representation::{
properties::Properties,
qos::QoS,
reserved_flags::ReservedFlags,
UTF8EncodedString,
RemainingLength,
BinaryData
};
use super::error::MQTTParserError;
use packattack::*;
#[derive(Clone, Debug, PartialEq, FromBitReader)]
pub struct Connect
(
ReservedFlags,
RemainingLength,
Protocol,
ProtocolLevel,
#[expose = "c_flags"]
ConnectFlags,
KeepAlive,
Properties,
ClientID,
#[flag = "c_flags.WillFlag"]
Option<WillProperties>,
#[flag = "c_flags.WillFlag"]
Option<WillTopic>,
#[flag = "c_flags.WillFlag"]
Option<WillPayload>,
#[flag = "c_flags.UserNameFlag"]
Option<Username>,
#[flag = "c_flags.PasswordFlag"]
Option<Password>
);
#[derive(Clone, Debug, PartialEq)]
pub enum Protocol
{
MQTT,
MQIsdp }
#[async_trait]
impl<R> FromBitReader<MQTTParserError, R> for Protocol where Self : Sized, R : Read + std::marker::Unpin + std::marker::Send
{
async fn from_bitreader(reader : &mut bitreader_async::BitReader<R>) -> Result<Protocol, MQTTParserError>
{
let protocol = UTF8EncodedString::from_bitreader(reader).await?;
match protocol.as_str()
{
"MQTT" => Ok(Protocol::MQTT),
"MQIsdp" => Ok(Protocol::MQIsdp),
_ => panic!("Couldn't parse control packet because the client tried to use a protocol other than MQTT!")
}
}
}
pub type ProtocolLevel = u8;
pub type KeepAlive = u16;
#[allow(non_snake_case)]
#[derive(Clone, Copy, Debug, PartialEq, FromBitReader)]
pub struct ConnectFlags
{
pub UserNameFlag : bool,
pub PasswordFlag : bool,
pub WillRetain : bool,
pub WillQoS : QoS,
pub WillFlag : bool,
pub CleanStart: bool,
Reserve : bool
}
pub type ClientID = UTF8EncodedString;
pub type WillProperties = Properties;
pub type WillTopic = UTF8EncodedString;
pub type WillPayload = BinaryData;
pub type Username = UTF8EncodedString;
pub type Password = UTF8EncodedString;