use std::time::SystemTime;
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum QosLevel {
AtMostOnce,
AtLeastOnce,
ExactlyOnce,
}
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct MqttMessage {
pub topic: String,
pub payload: Vec<u8>,
pub qos: QosLevel,
pub retained: bool,
pub timestamp: SystemTime,
}
impl MqttMessage {
pub fn new(topic: impl Into<String>, payload: Vec<u8>) -> Self {
Self {
topic: topic.into(),
payload,
qos: QosLevel::AtMostOnce,
retained: false,
timestamp: SystemTime::now(),
}
}
pub fn with_qos(mut self, qos: QosLevel) -> Self {
self.qos = qos;
self
}
pub fn retained(mut self) -> Self {
self.retained = true;
self
}
}
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct BrokerConfig {
pub max_queue_depth: usize,
pub retain_messages: bool,
pub wildcard_enabled: bool,
}
impl Default for BrokerConfig {
fn default() -> Self {
Self {
max_queue_depth: 1000,
retain_messages: true,
wildcard_enabled: true,
}
}
}