diff options
Diffstat (limited to 'src/packets/puback.rs')
-rw-r--r-- | src/packets/puback.rs | 29 |
1 files changed, 29 insertions, 0 deletions
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 }) + } +} |