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

get_bytes for Buf trait #374

Closed
Diggsey opened this issue Feb 25, 2020 · 2 comments
Closed

get_bytes for Buf trait #374

Diggsey opened this issue Feb 25, 2020 · 2 comments
Milestone

Comments

@Diggsey
Copy link

Diggsey commented Feb 25, 2020

fn get_bytes(&mut self, size: usize) -> Bytes

This is somewhat similar to #228 but for reading from a Buf.

The idea is that a Buf implementation may already have an efficient way to get a "view" of some of its bytes that does not involve an expensive copy. The default implementation would just allocate a new Bytes object and then use copy_to_slice.

The Bytes type could have a specialized implementation that just calls split_to on itself. In the future it may be possible to specialize the implementation of Buf for &'static [u8] too, since Bytes can cope with that, or maybe Bytes will get an optional lifetime parameter allowing it to hold reference of any lifetime.

@danburkert
Copy link
Contributor

I think this is fixed by #439.

@Diggsey
Copy link
Author

Diggsey commented Nov 9, 2020

Yep 👍

@Diggsey Diggsey closed this as completed Nov 9, 2020
kbleeke added a commit to kbleeke/prost that referenced this issue Mar 19, 2021
I just noticed this while poking through the code. Fields of type `Bytes` can now be slices of a greater `Bytes` that is passed to Message::decode

The referenced issue tokio-rs/bytes#374 was implemented as Buf::copy_to_bytes and `Bytes` features the zero-copy implementation https://docs.rs/bytes/1.0.1/src/bytes/bytes.rs.html#526-560
danburkert pushed a commit to tokio-rs/prost that referenced this issue Mar 21, 2021
I just noticed this while poking through the code. Fields of type `Bytes` can now be slices of a greater `Bytes` that is passed to Message::decode

The referenced issue tokio-rs/bytes#374 was implemented as Buf::copy_to_bytes and `Bytes` features the zero-copy implementation https://docs.rs/bytes/1.0.1/src/bytes/bytes.rs.html#526-560
ryaminal pushed a commit to vivint-smarthome/prost that referenced this issue Apr 8, 2021
I just noticed this while poking through the code. Fields of type `Bytes` can now be slices of a greater `Bytes` that is passed to Message::decode

The referenced issue tokio-rs/bytes#374 was implemented as Buf::copy_to_bytes and `Bytes` features the zero-copy implementation https://docs.rs/bytes/1.0.1/src/bytes/bytes.rs.html#526-560
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

No branches or pull requests

3 participants