Skip to content

Commit

Permalink
fix wire_length and write length
Browse files Browse the repository at this point in the history
  • Loading branch information
GunnarMorrigan committed Nov 28, 2024
1 parent 621b517 commit 5caa701
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mqrstt/src/packets/macros/properties_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ macro_rules! define_properties {
impl<S> $crate::packets::mqtt_trait::MqttAsyncWrite<S> for $name where S: tokio::io::AsyncWrite + Unpin {
async fn async_write(&self, stream: &mut S) -> Result<usize, crate::packets::error::WriteError> {
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);
)*
Expand Down
4 changes: 3 additions & 1 deletion mqrstt/src/packets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion mqrstt/src/tests/test_packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5caa701

Please sign in to comment.