TheNeikos / cloudmqtt

A simple and straightforward to use MQTT client/server
Other
5 stars 3 forks source link

Does not support Disconnect message #291

Open dscso opened 1 month ago

dscso commented 1 month ago

If using this command to publish a message the parser fails parsing the disconnect packet:

 mosquitto_pub -h 192.168.178.101 -t /test -m "mylittlemessage" -V mqttv5
Screenshot 2024-05-21 at 12 14 42
#[test]
fn test_disconnect_packet() {
    let buf = [0xe0, 0x00];
    let parsed = MqttPacket::parse_complete(&buf).unwrap();
}

this is not working unfortunately results in an error:

called `Result::unwrap()` on an `Err` value: Backtrack(ContextError { context: PhantomData<winnow::error::StrContext> })
thread 'v5::packets::disconnect::test::test_disconnect_packet' panicked at mqtt-format/src/v5/packets/disconnect.rs:144:55:
called `Result::unwrap()` on an `Err` value: Backtrack(ContextError { context: PhantomData<winnow::error::StrContext> })
stack backtrace:

The disconnect packet seems to be a special case. In the standard there is written:

The Client or Server sending the DISCONNECT packet MUST use one of the DISCONNECT Reason Code values [MQTT-3.14.2-1]. The Reason Code and Property Length can be omitted if the Reason Code is 0x00 (Normal disconnecton) and there are no Properties. In this case the DISCONNECT has a Remaining Length of 0.

PR incoming...

dscso commented 1 month ago

aaah maybe we have to add this on the serializing side as well to save traffic (2 bytes per disconnect idk if it is worth it)