#specification #client #message-broker #mqtt #service #middleware #pub-sub #negotiation

rmqtt-codec

MQTT protocol codec implementation with multi-version support and version negotiation

2 releases

new 0.1.1 Apr 19, 2025
0.1.0 Apr 17, 2025

#11 in #message-broker

Download history 67/week @ 2025-04-12

67 downloads per month
Used in rmqtt-net

MIT/Apache

225KB
5K SLoC

rmqtt-codec

crates.io page docs.rs page

🚀 rmqtt-codec is a high-performance MQTT protocol codec library designed for async environments. It provides full support for multiple MQTT versions with automatic negotiation and zero-copy efficiency, seamlessly integrating with the Tokio ecosystem.

✨ Core Features

  • Multi-Version Support: Full implementation of MQTT v3.1, v3.1.1, and v5.0 specifications
  • Automatic Protocol Negotiation: Smart version detection during the CONNECT handshake phase
  • Zero-Copy Encoding/Decoding: Efficient binary processing using bytes::BytesMut to minimize memory overhead
  • Tokio Integration: Built with tokio_util::codec for smooth async I/O operations
  • Memory Safety: Enforces strict message size limits (default 1MB) to prevent memory-related vulnerabilities

🧩 Architecture Components

  • MqttCodec: Main codec dispatcher for version-aware encoding and decoding
  • MqttPacket: Unified representation of all MQTT packet types across versions
  • version::ProtocolVersion: Handshake-based protocol version detection
  • EncodeError / DecodeError: Dedicated error types for robust error handling during encoding and decoding

📚 Crate Usage

Please add a dependency in 'Cargo. toml':

[dependencies]
rmqtt-codec = "0.1"

🔧 Use Cases

  • Embedded MQTT brokers or clients
  • High-performance message middleware
  • Protocol gateways or custom network services

Dependencies

~5–12MB
~120K SLoC