Comments (4)
@00imvj00 Please take a look at vincentdephily@71627f9
I've spent some time trying to convert to impl Trait
but have hit a few walls. We've got a few options:
- Stop trying to be flexible, and embrace BytesMut everywhere.
- Wait for (or help) the Bytes crate to switch the specified bugs.
- Use the
.bytes()
workaround and document that only continuous-memory backends may be used (or if upstream creates a Trait for that, use it). - Use a different crate altogether, or reinvent the wheel.
I'm currently leaning towards option 2, but would like some opinions. I'd also be ok with throwing that commit away and go with option 1.
Note that one thing we need to do to get toward zero-copy is convert some Packet
members (Connect.password
, Publish.payload
...) from Vec<u8>
to Bytes
(or use &[u8]
and deal with the shared lifetime between Packet
and its source/destination buffer). If that's where we're going, maybe it's silly to try to support other Buf
backends.
from mqttrs.
For Zero-copy, instead of this, how about we keep references of offset?
For example: If the overall packet length is 64 bytes, we store these bytes as byte-array internally and then for the password, instead of a string, we just store something like, from index to index, and build method get_password() -> &str, where we will return the reference.
from mqttrs.
A Bytes
struct obtained from Bytes::slice*()
or Bytes::split*()
is pretty-much just a reference inside a &[u8]
, with some refcounting to figure out when the actual data can be dropped. I'm just not sure how it handles references to old data. Is it viable to keep using the same BytesMut to receive data from the network and then decode(), yielding a stream of Packet ? Or would holding a Byte from the connect packet force the buffer to grow forever ? Should we change the API to decode(Bytes) -> Result<Packet,Error>
(forcing a .freeze()
) to avoid that footgun ?
I'm going to dogfood that in different contexts and see, but it's going to take a while.
from mqttrs.
Yup, at this point we can experiment with couple of approaches and see which feels ergonomic.
Again, the goal is to keep is simple and make it super performant.
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
- 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.
- Example in README file does not work, cannot find encode/decode in this scope HOT 2
- 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.