MQTT Frame
mqtt-frame is a lightweight, zero-copy, "Sans-I/O" MQTT v3.1.1 and v5.0 protocol codec and parser.
Features
- Sans-I/O Architecture: The library focuses entirely on framing and parsing MQTT packets over a byte stream.
- Tokio & Bytes Native: Built directly on top of
tokio_util::codec::Decoderand thebytescrate. It heavily utilizesBytesMut::split_to().freeze()to guarantee zero-copy slicing of payloads directly from the TCP network buffer. - Dual Protocol Support: Natively supports both MQTT 3.1.1 and MQTT 5.0.
- V5 Properties Extraction: Securely extracts MQTT v5.0 Properties (like
MessageExpiryInterval,ContentType,UserProperty) into a strongly typedPropertyenum.
Usage
Because mqtt-frame is built on tokio_util::codec, using it with Tokio's TCP streams is straightforward:
use MqttCodec;
use TcpListener;
use Framed;
use StreamExt;
async
Supported Packets
The parser fully implements the 14 standard packets required by the OASIS MQTT standard:
CONNECT/CONNACKPUBLISH/PUBACK/PUBREC/PUBREL/PUBCOMPSUBSCRIBE/SUBACKUNSUBSCRIBE/UNSUBACKPINGREQ/PINGRESPDISCONNECT
License
This project is licensed under the Apache License, Version 2.0.