Expand description
tjiftjaf is a Rust library implementing MQTT 3.1.1.
§Features
MQTT Client
The crate provides a blocking Client
and an asynchronous Client.
The latter does not require a specific runtime executor.
Take a look at the examples:
- examples/client_with_smol.rs uses the executor smol
- examples/client_with_tokio.rs uses the executor tokio
- examples/blocking_client.rs does not use async.
§Do not use this crate
I created this project to learn more about MQTT, fuzzing, sans-io and zero-copy.
Do not rely on this crate for your own projects. It’s unstable. Consider using rumqttc instead.
§Fuzzer
Portions of the code are verified using fuzzing. Make sure to install
cargo fuzz before
running the examples.
cargo +nightly fuzz run subscribeList all fuzz targets using:
cargo +nightly fuzz list§Benchmarks
The project uses Criterion.rs to benchmark encoding and decoding speed of packets. Run all benchmarks using:
$ cargo benchTo list all benchmarks run:
$ cargo bench -- --listYou can plot a flamegraph of a benchmark. First build the benchmark into a binary.
$ cargo bench --no-run
...
Executable benches/decode-encode.rs (target/release/deps/decode_encode-9f10de3c0a084302)Then, invoke the binary with flamegraph. This example runs only 1 benchmark that matches the string ‘Publish’:
$ flamegraph -- target/release/deps/decode_encode-9f10de3c0a084302 --bench Publish
...
Benchmarking decode/encode Publish: Complete (Analysis Disabled)
...
[ perf record: Captured and wrote 1264.806 MB perf.data (79730 samples) ]
writing flamegraph to "flamegraph.svg"§License
This project is licensed under the Mozilla Public License.
Modules§
Structs§
- Client
Disconnected - An error indicating that the client terminated the connection with the server.
- ConnAck
- Connack
- Connect
- Connect is the first packet a client sends, after a connection has been established.
- Connection
Error - Type indicating that the connection between a handle and the Client is broken. It’s likely that the connection to the MQTT server broke.
- Disconnect
- The Disconnect Packet is sent from a Client to the Server.
- Mqtt
Binding - PingReq
- The PINGREQ Packet is sent from a Client to the Server. It can be used to:
- Ping
Resp - A PINGRESP Packet is sent by the Server to the Client in response to a PINGREQ Packet. It indicates that the Server is alive.
- PubAck
- A
PubAckpacket is the response to acrate::Publishpacket withcrate::QoS::AtLeastOnceDelivery. - PubComp
PubCompis the response to acrate::PubRelpacket withcrate::QoS::ExactlyOnceDelivery.- PubRec
- A
PubRecpacket is the response to acrate::Publishpacket withcrate::QoS::ExactlyOnceDelivery. - PubRel
- A
PubRelpacket is the response to acrate::PubRec. - Publish
- Publish is used by both clients and servers to emit a message for a specific topic.
- SubAck
- SubAck is emitted by a broker to confirm a
crate::Subscriberequest. - Subscribe
- Subscribe allows a client to express interest in one or more topics.
- Unsub
Ack - A
UnsubAckpacket is the response to acrate::Unsubscribe. - Unsubscribe
- Unsubscribe allows a client unsubscribe from one or more topics.
Enums§
- Decoding
Error - Packet
- A model for each MQTT packet.
- Packet
Type - Every packet type of MQTT 3.1.1.
- Protocol
Level - The revision of the MQTT protocol.
- QoS
- The delivery guarantee for packets
SubscribeandPublish.
Traits§
Functions§
- connect
- packet_
identifier - publish
- Construct a
Publishwith the given topic and payload. - subscribe
- Construct a
Subscribewith the given topic andQoS::AtMostOnceDelivery. - unsubscribe
- Construct a
Unsubscribewith the given topic.