00imvj00/mqttrs

Decoding an incomplete packet can still consume some bytes of the buffer.

Closed this issue · 1 comments

Correct me if I'm wrong, but mqttrs::decoder::decode() follows the tokio FramedRead API so that you can write

use tokio::codec::Decoder;
pub struct Codec;
impl Decoder for Codec {
    type Item = Packet;
    type Error = Error;
    fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
        mqttrs::decoder::decode(src)
    }
}

which means that if the packet is incomplete it should return Ok(None) and not touch the buffer.

This is not currently the case, as the buffer advances if there's at least a header in it.

The fix is pretty trivial and you can cherry-pick it from vincentdephily@af590ce

Cheers.

thank you @vincentdephily . resolved.