18 releases (10 breaking)

0.11.1 Oct 20, 2021
0.11.0 Mar 29, 2021
0.10.0 Dec 24, 2020
0.9.0 Oct 18, 2020
0.2.0 Jul 23, 2016

#642 in Network programming

Download history 213/week @ 2021-09-27 283/week @ 2021-10-04 568/week @ 2021-10-11 630/week @ 2021-10-18 617/week @ 2021-10-25 500/week @ 2021-11-01 356/week @ 2021-11-08 295/week @ 2021-11-15 254/week @ 2021-11-22 496/week @ 2021-11-29 332/week @ 2021-12-06 357/week @ 2021-12-13 171/week @ 2021-12-20 79/week @ 2021-12-27 316/week @ 2022-01-03 320/week @ 2022-01-10

902 downloads per month
Used in 7 crates (3 directly)

MIT/Apache

115KB
2.5K SLoC

MQTT-rs

Build Status Build & Test License crates.io dependency status

MQTT protocol library for Rust

[dependencies]
mqtt-protocol = "0.11"

Usage

extern crate mqtt;

use std::io::Cursor;

use mqtt::{Encodable, Decodable};
use mqtt::packet::{VariablePacket, PublishPacket, QoSWithPacketIdentifier};
use mqtt::TopicName;

fn main() {
    // Create a new Publish packet
    let packet = PublishPacket::new(TopicName::new("mqtt/learning").unwrap(),
                                    QoSWithPacketIdentifier::Level2(10),
                                    "Hello MQTT!");

    // Encode
    let mut buf = Vec::new();
    packet.encode(&mut buf).unwrap();
    println!("Encoded: {:?}", buf);

    // Decode it with known type
    let mut dec_buf = Cursor::new(&buf[..]);
    let decoded = PublishPacket::decode(&mut dec_buf).unwrap();
    println!("Decoded: {:?}", decoded);
    assert_eq!(packet, decoded);

    // Auto decode by the fixed header
    let mut dec_buf = Cursor::new(&buf[..]);
    let auto_decode = VariablePacket::decode(&mut dec_buf).unwrap();
    println!("Variable packet decode: {:?}", auto_decode);
    assert_eq!(VariablePacket::PublishPacket(packet), auto_decode);
}

Note

Dependencies

~1.4–2.9MB
~68K SLoC