Module codec

Source
Expand description

§Codec Implementation

Contains the core encoding/decoding logic for MQTT packets.

§Main Components

  • PacketCodec: The primary codec for encoding/decoding packets
  • RawPacket: Intermediate packet representation

§Example

use mqute_codec::codec::{PacketCodec, RawPacket, Encode, Decode, Encoded};
use tokio_util::codec::Decoder;
use bytes::BytesMut;
use mqute_codec::protocol::PacketType;

let mut codec = PacketCodec::new(Some(4096), Some(4096));
let mut buf = BytesMut::new();
buf.extend_from_slice(b"\x10\x29\x00\x04MQTT\x04\xd6\x00\x10\x00\x06client\x00\x04/abc\x00\x03bye\x00\x04user\x00\x04pass");

match codec.decode(&mut buf) {
    Ok(Some(packet)) => {
        assert_eq!(packet.header.packet_type(), PacketType::Connect);
    }
    _ => panic!("Decoding failed"),
}

Structs§

PacketCodec
A codec for encoding and decoding MQTT packets.
RawPacket
Represents a raw MQTT packet.

Traits§

Decode
A trait for decoding MQTT packets from their raw representation.
Encode
A trait for encoding MQTT packets into a buffer.
Encoded
A trait for calculating the total encoded length of an MQTT packet.