Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make receive_datagram return BytesMut #179

Open
TheButlah opened this issue May 5, 2024 · 4 comments
Open

Make receive_datagram return BytesMut #179

TheButlah opened this issue May 5, 2024 · 4 comments
Labels
enhancement New feature or request Investigation

Comments

@TheButlah
Copy link

TheButlah commented May 5, 2024

Some use cases, such as using datagrams with serde via tokio_serde::Framed, require that messages received from the peer are BytesMut instead of Bytes. Currently, Connection::receive_datagram() returns a Datagram which itself can only give you Bytes, so the user of the API first needs to clone the data to get exclusive access to a buffer.

It would be nice if receive_datagrams instead returned a BytesMut, providing more performance for use cases like mine where I actually need exclusive access to the buffer.

@BiagioFesta
Copy link
Owner

It there a way to get a BytesMut from Bytes without copying it?

I am on my phone atm, but considering the underlying QUIC library returns Bytes I am wondering if that's trivially feasible

@TheButlah
Copy link
Author

AFAIK, no, there isn't a way. There is a is_unique function, but I don't think it can be used for the purpose of converting to a BytesMut. I could be wrong though.

@BiagioFesta
Copy link
Owner

I am afraid so. Considering the QUIC connection returns a datagram as Bytes here, the only possibility is to copy the data (even if the Bytes is unique), I guess

@BiagioFesta BiagioFesta added enhancement New feature or request Investigation labels May 8, 2024
@pablosichert
Copy link

There's an adjacent issue for this in the Quinn repo: quinn-rs/quinn#1173

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Investigation
Projects
None yet
Development

No branches or pull requests

3 participants