Comments (2)
encode
and decode
have changed to encode_slice
and decode_slice
since 1e6d843
The following changes to the example work for me:
use bytes::BytesMut;
use mqttrs::*;
fn main() {
// Allocate write buffer.
let mut buf = [0u8; 1024];
// Encode an MQTT Connect packet.
let pkt = Packet::Connect(Connect {
protocol: Protocol::MQTT311,
keep_alive: 30,
client_id: "doc_client".into(),
clean_session: true,
last_will: None,
username: None,
password: None,
});
let encoded = encode_slice(&pkt, &mut buf);
assert!(encoded.is_ok());
let mut buf = BytesMut::from(&buf[..encoded.unwrap()]);
assert_eq!(&buf[14..], "doc_client".as_bytes());
// Decode one packet. The buffer will advance to the next packet.
assert_eq!(Ok(Some(pkt)), decode_slice(&mut buf));
// Example decode failures.
let mut incomplete = buf.split_to(10);
assert_eq!(Ok(None), decode_slice(&mut incomplete));
let mut garbage = BytesMut::from(&[0u8, 0, 0, 0] as &[u8]);
assert_eq!(Err(Error::InvalidHeader), decode_slice(&mut garbage));
}
I suggest updating README.md
with this, if the repository owner is ok with this
from mqttrs.
In addition, I'll be forking the repository to try and work in some MQTTv5 features as I have a need for some of them (mainly Message Expiry and Maximum Packet Size)
from mqttrs.
Related Issues (20)
- `Connect.password` should be `Option<Vec<u8>>` instead of `Option<String>`.
- Refactor using a combined `QosPid` struct. HOT 1
- PacketIdentifier should be NonZeroU16
- Support MQTT5 HOT 8
- Add builder APIs
- Zero-copy encoding and decoding HOT 4
- Write good documentation. HOT 4
- Usage in no_std environments HOT 9
- New release on crates.io? HOT 2
- Support alloc-free operation HOT 3
- Serde feature enabled by default (through `std` feature) HOT 2
- Add `mqttrs::decode::check()` method, to see if the packet is decodable? HOT 2
- Proper way to extract packet length? HOT 2
- make every packet clonable.
- Purging 0.4.0 in favour of simplicity and little bit of performance cost. HOT 10
- Fresh crates.io release HOT 2
- Unable to implement tokio_util::codec::{Decoder, Encoder} with mqttrs version 0.4 HOT 4
- Trouble Implementing Tokio-util Decoder for MQTT Broker
- Add integration examples with other libraries and runtimes.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mqttrs.