diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2024-03-21 13:06:13 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2024-03-21 13:06:41 +0100 |
commit | b5bfdb3baaf81b57ff488c49c19700065c95a117 (patch) | |
tree | 66d25d58429f96d24566daff6128a6778809dc86 | |
parent | 90f398062f2bee2887c06d5d47fc8029bcfdcae4 (diff) |
Implement write() for all generated property types
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | mqtt-format/src/v5/properties.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/mqtt-format/src/v5/properties.rs b/mqtt-format/src/v5/properties.rs index 506deb5..ae48d77 100644 --- a/mqtt-format/src/v5/properties.rs +++ b/mqtt-format/src/v5/properties.rs @@ -123,6 +123,27 @@ macro_rules! define_properties { }) }).parse_next(input) } + + pub async fn write<W: crate::v5::write::WriteMqttPacket>(&self, buffer: &mut W) -> crate::v5::write::WResult<W> { + use crate::v5::variable_header::MqttProperties; + + let binary_size = { + 0 + $( + + self.$prop_name.as_ref().map(|p| p.binary_size()).unwrap_or(0) + )* + }; + + $crate::v5::integers::write_variable_u32(buffer, binary_size).await?; + + $( + if let Some(prop) = self.$prop_name.as_ref() { + prop.write(buffer).await?; + } + )* + + Ok(()) + } } }; } |