You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Sometimes we want to serialize into a
Write
orAsyncWrite
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
andSubRecord
which returns anIterator<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 tostd::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
forRecord
types.The text was updated successfully, but these errors were encountered: