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

Permit conversion into and creation from parts. #2

Merged
merged 3 commits into from
Feb 1, 2021
Merged

Permit conversion into and creation from parts. #2

merged 3 commits into from
Feb 1, 2021

Conversation

mxinden
Copy link
Owner

@mxinden mxinden commented Jan 31, 2021

Copy of matthunz/futures-codec#54 by @romanb.

This PR generalises Framed::release() et al to Framed::into_parts(), providing corresponding Framed::from_parts. This is pretty much analogous to tokio_util::codec::FramedParts. There are mainly two use-cases:

1. Resuing framed buffers with a new codec ([tokio-rs/tokio#717](https://github.com/tokio-rs/tokio/issues/717)).

2. Protocols that use a particular `Framed` only e.g. during a handshake phase after which they want to drop down to direct use of the underlying I/O stream. Since the `Framed` may have read and buffered data beyond the handshake frames, it is necessary to drain the remaining read buffer first when doing this. While one can already obtain the read buffer from `Framed::read_buffer()`, using it to capture the buffer before calling `Framed::into_inner()` requires to unnecessarily clone the `BytesMut`.

I also tweaked the documentation a bit to make it clearer that the into_inner() methods may discard buffered data. Since this PR removes / renames Framed::release() et al to into_parts, the API changes are not backward-compatible.

@romanb do you consent to your work being used in asynchronous-codec?

@romanb
Copy link
Contributor

romanb commented Jan 31, 2021

@romanb do you consent to your work being used in asynchronous-codec?

Sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants