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
This allows FromWire implementations to bind any lifetimes in their definition to the Read<'a> the data comes from.
In practice, this is a problem: it means that Read<'a> needs to allocate memory to buffer its entire message, which is undesirable. This also makes Read<'a> implementations, often the purview of an integration, needlessly complicated.
An alternative solution to the above FromWire signature is the following:
The main upshot from this change is that an implementation of Read doesn't need to buffer entire messages, while implementations of FromWire can buffer only what they absolutely have to:
impl<'a>FromWire<'a>forFirmwareVersionResponse<'a>{fnfrom_wire<R:Read,A:Arena>(r:R,arena:&'a mutA) -> Result<Self>{let version = arena.alloc(32)?;
r.read_bytes(&mut*version)?;Self{ version }}}
While this does introduce a copy into FromWire, this is a copy any non-trivial Read implementation was already doing. Read implementations can now simply be think wrappers over syscalls, like they should have been in the first place.
The text was updated successfully, but these errors were encountered:
Currently,
manticore::io::Read<'a>
behaves like a "grant me parts of your buffer":This is kind of a weird interface, but it's informed by the design of
FromWire
:This allows
FromWire
implementations to bind any lifetimes in their definition to theRead<'a>
the data comes from.In practice, this is a problem: it means that
Read<'a>
needs to allocate memory to buffer its entire message, which is undesirable. This also makesRead<'a>
implementations, often the purview of an integration, needlessly complicated.An alternative solution to the above
FromWire
signature is the following:The new trait
Arena
can be imagined as a thin wrapper oversplit_at_mut
:Then, we would be able to change
Read
to look a lot more likestd
's version:The main upshot from this change is that an implementation of
Read
doesn't need to buffer entire messages, while implementations ofFromWire
can buffer only what they absolutely have to:While this does introduce a copy into
FromWire
, this is a copy any non-trivialRead
implementation was already doing.Read
implementations can now simply be think wrappers over syscalls, like they should have been in the first place.The text was updated successfully, but these errors were encountered: