rumqttc: value returned by `v4::Connect.write` doesn't match reality
de-sh opened this issue · comments
let connect = v4::Connect {
protocol: Protocol::V4,
keep_alive: u16::MAX,
client_id: "".to_owned(),
clean_session: true,
last_will: Some(LastWill::new(
"".to_owned(),
Bytes::new(),
QoS::AtLeastOnce,
true,
)),
login: Some(Login::new("", "")),
};
let mut buf = BytesMut::new();
let written = connect.write(&mut buf);
assert_eq!(written, Ok(buf.len()));
Expected Behavior
written should be equal to 18
Current Behavior
It is equal to 16
Failure Information (for bugs)
This part of the code evaluates written as len, which doesn't account for the length of header fields of the packet, i.e. 1 + count.
I think the len()
method on any packet doesn't account for FixedHeader
( which is 2 bytes as per standards ).
But in write()
, as we write along with FixedHeader
, we are seeing that deviation.
this brings the question of whether len()
should return length of Connect
struct, or the actual Connect packet that will get sent.
i.e. 1 + count
can you please explain this a bit?
I believe len()
accounts for the size of payload, while size of serialized packets we account for with size()
we have fixed it in rumqttc with PR #818 , but this issue is also observed in rumqttd as well, will close this once it is fixed there.
done with PR #819 🚀 !