diff --git a/mqrstt/src/packets/macros/properties_macros.rs b/mqrstt/src/packets/macros/properties_macros.rs index 33d80ba..b7b8438 100644 --- a/mqrstt/src/packets/macros/properties_macros.rs +++ b/mqrstt/src/packets/macros/properties_macros.rs @@ -36,7 +36,7 @@ macro_rules! define_properties { impl $crate::packets::mqtt_trait::MqttAsyncWrite for $name where S: tokio::io::AsyncWrite + Unpin { async fn async_write(&self, stream: &mut S) -> Result { let mut bytes_written = 0; - $crate::packets::VariableInteger::write_async_variable_integer(&self.wire_len(), stream).await?; + bytes_written += $crate::packets::VariableInteger::write_async_variable_integer(&self.wire_len(), stream).await?; $( $crate::packets::macros::properties_write!(self, bytes_written, stream, PropertyType::$prop_variant); )* diff --git a/mqrstt/src/packets/mod.rs b/mqrstt/src/packets/mod.rs index 8d6410e..7fd4a0a 100644 --- a/mqrstt/src/packets/mod.rs +++ b/mqrstt/src/packets/mod.rs @@ -278,10 +278,12 @@ impl Packet { Packet::PingReq => { stream.write_u8(0b1100_0000).await?; stream.write_u8(0).await?; // Variable header length. + written += 1; } Packet::PingResp => { stream.write_u8(0b1101_0000).await?; stream.write_u8(0).await?; // Variable header length. + written += 1; } Packet::Disconnect(p) => { stream.write_u8(0b1110_0000).await?; @@ -605,7 +607,7 @@ mod tests { let wire_len = packet.wire_len(); - assert_eq!(res, wire_len); + assert_eq!(res, buffer.len()); assert_eq!(wire_len, buffer.len()); let mut buf = buffer.as_slice(); diff --git a/mqrstt/src/tests/test_packets.rs b/mqrstt/src/tests/test_packets.rs index 2f9dac1..ffc8f18 100644 --- a/mqrstt/src/tests/test_packets.rs +++ b/mqrstt/src/tests/test_packets.rs @@ -324,7 +324,7 @@ pub fn unsubscribe_case() -> Packet { let expected = Unsubscribe { packet_identifier: 3, topics: vec!["test/topic".into()], - properties: UnsubscribeProperties { user_properties: vec![] }, + properties: UnsubscribeProperties { user_properties: vec![("written += 1;".into(), "value".into())] }, }; Packet::Unsubscribe(expected)