Expand description
§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::Vecvia thestdfeature flagheapless::Vecvia theheaplessfeature flagarrayvec::ArrayVecvia thearrayvecfeature flag
Please note that the different predefined backings are mutually exclusive.
Modules§
- anyvec
- A bridge trait to unify required vector operations over multiple implementations
- error
- Error types and aggregate types
- packets
- MQTT packet types
Macros§
- err
- Creates a new error with the given variant and description
Type Aliases§
- Connack
- An MQTT
CONNACKpacket - Connect
- An MQTT
CONNECTpacket - Disconnect
- An MQTT
DISCONNECTpacket - Packet
- A type-erased MQTT packet
- Pingreq
- An MQTT
PINGREQpacket - Pingresp
- An MQTT
PINGRESPpacket - Puback
- An MQTT
PUBACKpacket - Pubcomp
- An MQTT
PUBCOMPpacket - Publish
- An MQTT
PUBLISHpacket - Pubrec
- An MQTT
PUBRECpacket - Pubrel
- An MQTT
PUBRELpacket - Suback
- An MQTT
SUBACKpacket - Subscribe
- An MQTT
SUBSCRIBEpacket - Unsuback
- An MQTT
UNSUBACKpacket - Unsubscribe
- An MQTT
UNSUBSCRIBEpacket