summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2024-04-05 12:25:47 +0200
committerMatthias Beyer <mail@beyermatthias.de>2024-04-05 15:09:48 +0200
commit11e1f610e73158184a527ea02c89581b994f9f2f (patch)
tree71faf019206fa1ab6e744ad196d54275324812a5
parentc6296007528a595891c30a599aabf3d8d1aa71a9 (diff)
Add Puback packet type
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/packets/mod.rs2
-rw-r--r--src/packets/puback.rs29
2 files changed, 31 insertions, 0 deletions
diff --git a/src/packets/mod.rs b/src/packets/mod.rs
index 3b25e66..8e9e417 100644
--- a/src/packets/mod.rs
+++ b/src/packets/mod.rs
@@ -32,6 +32,8 @@ pub mod subscribe;
pub mod unsuback;
pub mod unsubscribe;
+pub use self::puback::Puback;
+
#[derive(Debug, thiserror::Error)]
#[error("Could not convert into the required packet type")]
pub struct InvalidPacketType;
diff --git a/src/packets/puback.rs b/src/packets/puback.rs
index cc001cf..54fc20b 100644
--- a/src/packets/puback.rs
+++ b/src/packets/puback.rs
@@ -4,6 +4,11 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
+use yoke::Yoke;
+
+use super::MqttPacket;
+use super::StableBytes;
+
crate::properties::define_properties! {
properties_type: mqtt_format::v5::packets::puback::PubackProperties,
anker: "_Toc3901125",
@@ -15,3 +20,27 @@ crate::properties::define_properties! {
user_properties: UserProperties<'i> with setter = crate::properties::UserProperty,
}
}
+
+#[derive(Clone, Debug)]
+pub struct Puback {
+ packet: Yoke<mqtt_format::v5::packets::puback::MPuback<'static>, StableBytes>,
+}
+
+impl Puback {
+ pub(crate) fn get(&self) -> &mqtt_format::v5::packets::puback::MPuback<'_> {
+ self.packet.get()
+ }
+}
+
+impl TryFrom<MqttPacket> for Puback {
+ type Error = ();
+
+ fn try_from(value: MqttPacket) -> Result<Self, Self::Error> {
+ let packet = value.packet.try_map_project(|p, _| match p {
+ mqtt_format::v5::packets::MqttPacket::Puback(puback) => Ok(puback),
+ _ => Err(()),
+ })?;
+
+ Ok(Puback { packet })
+ }
+}