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

Iterable serialization for Rust #193

Open
mattiekat opened this issue Feb 16, 2022 · 0 comments
Open

Iterable serialization for Rust #193

mattiekat opened this issue Feb 16, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@mattiekat
Copy link
Contributor

mattiekat commented Feb 16, 2022

Is your feature request related to a problem? Please describe.
Sometimes we want to serialize into a Write or AsyncWrite type and to do so without allocating a buffer to store all the data in serialized form before passing it to write requires a way to serialize fields one at a time in a depth-first manner.

Describe the solution you'd like
A new function on Record and SubRecord which returns an Iterator<Item=usize> (saying how many bytes where written on each go) and takes a mutable reference to a [u8;1024] or something buffer which can be used to serialize some data into on each go.

This can either be accomplished with unsafe code (possibly some magic safe code that I can't think of ATM), but we could also pass the buffer to it mutably on the .next(&mut buf) call, but that would mean it no longer conforms to std::iter::Iterator.

We could also use a wrapping struct that is a true Iterator type and only goes 1 byte at a time, and an inner non-iterator type that get's the &mut buf on each call, which only happens when the outer type has exhausted what was written last time.

Describe alternatives you've considered
Write all data into a buffer to then pass to Write types as they can accept them. This requires an extra alloc and is non-ideal.

Additional context
This is useful for RPC and networking in general and would allow us to implement Read for Record types.

@mattiekat mattiekat added the enhancement New feature or request label Feb 16, 2022
@mattiekat mattiekat self-assigned this Feb 16, 2022
@mattiekat mattiekat removed their assignment May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant