5 releases (3 breaking)

new 0.3.1 Apr 6, 2025
0.3.0 Apr 5, 2025
0.2.0 Feb 9, 2025
0.1.0 Oct 5, 2024
0.0.1 Dec 31, 2023

#1357 in Network programming

Download history 98/week @ 2025-02-05 22/week @ 2025-02-12 6/week @ 2025-02-26 217/week @ 2025-04-02

217 downloads per month

BSD-2-Clause OR MIT

81KB
1.5K SLoC

License BSD-2-Clause License MIT AppVeyor CI docs.rs crates.io Download numbers dependency status

mqtt-tiny

Welcome to mqtt-tiny 🎉

mqtt-tiny is a tiny, no-std-compatible MQTT 3.1.1 codec implementation. It is currently limited to packet en- and decoding, and does not handle state or transport-level stuff.

Example

use mqtt_tiny::{
    packets::{ToWriter, TryFromReader},
    Connack, Connect, Disconnect,
};
use std::{net::TcpStream, thread, time::Duration};

// Connect to a server
let mut connection = TcpStream::connect("127.0.0.1:1883").expect("failed to connect to server");
Connect::new(30, true, b"mqtttinyexamplesconnect").expect("failed to create CONNECT packet")
    .write(&mut connection).expect("failed to send CONNECT packet");

// Await CONNACK
let connack = Connack::try_read(&mut connection).expect("failed to read CONNACK packet");
assert_eq!(connack.return_code(), 0, "connection was refused");

// Sleep 3s
const PAUSE: Duration = Duration::from_secs(3);
thread::sleep(PAUSE);

// Disconnect
Disconnect::new().write(&mut connection).expect("failed to write DISCONNECT packet");

Storage Backings

You can configure different predefined storage backings via feature flags:

  • std::vec::Vec via the std feature flag
  • heapless::Vec via the heapless feature flag
  • arrayvec::ArrayVec via the arrayvec feature flag

Please note that the different predefined backings are mutually exclusive.

Dependencies

~125KB