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

Convenience API for skipping data? #154

Closed
Gankra opened this issue Apr 24, 2017 · 8 comments
Closed

Convenience API for skipping data? #154

Gankra opened this issue Apr 24, 2017 · 8 comments

Comments

@Gankra
Copy link
Contributor

Gankra commented Apr 24, 2017

I'm working on a format where I have several arrays in my data stream that I don't want to deserialize right away, but instead jump over and deserialize on demand later (element-by-element).

It would be nice if there was methods like:

// returns bytes skipped over
bincode::skip_over<T: Deserialize>(&mut Reader, count: usize) -> Result<usize>;

Bincode might be able to implement this better than I could naively, by using things like fixed-serialized-size info to skip over everything without any parsing in O(1). In general this API needs to parse (enums), but it can basically be like "it only parses as much as is needed to skip over the data".

@samlh
Copy link

samlh commented Apr 28, 2017

https://serde.rs/ignored-any.html may be relevant

@Gankra
Copy link
Contributor Author

Gankra commented Apr 28, 2017

I'm using bincode, so I need to give the fields a type.

@Xaeroxe
Copy link

Xaeroxe commented Apr 28, 2017

@gankro serde 1.0 introduces zero copy deserialization, so as soon support for 1.0 is finished you should be able to use that to similar effect.

@Gankra
Copy link
Contributor Author

Gankra commented Apr 28, 2017

Zero copy deserialization only works on bytes and strs; my slices contain actual types that need to be materialized into a new buffer.

@Xaeroxe
Copy link

Xaeroxe commented Apr 28, 2017

I see. Well in the mean time maybe you could use borrowed_bytes with a wrapper struct and interpret the bytes lazily when needed? I'm not sure if that's easy or doable I'm just thinking out loud.

@TyOverby
Copy link
Collaborator

@Xaeroxe: that's what I suggested in #serde a few days ago. Unfortunately it would require serializing extra "length" bytes into the output, so for lots of tiny structs this isn't an option.

@Xaeroxe
Copy link

Xaeroxe commented Apr 28, 2017

Hmm I wonder if it's possible to do this using generics so the length is coded into the executable rather than the memory representation. I might look into that.

@stale
Copy link

stale bot commented Jun 13, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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

4 participants