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
Say I want to skip the next n bytes of input from a Reader. Currently, I can see two ways of doing this, neither of which are ideal.
Allocate a Vec<u8> of size n. Call read on it. Discard the Vec<u8>. This has the disadvantage of doing an unnecessary allocation and unnecessary copying. Note that calling read_exact is equivalent to this.
Call read_u8n times. This has this the disadvantage of doing n function calls, which may even translate to n syscalls. For any significant n this is going to be worse than the first option.
The solution.
Have Reader expose a method skip_exact that skips the next n bytes. For some readers such as MemReader and BufferedReader this just means advancing the cursor by n. For some other readers this could be implemented using seek. For other readers again this method can be given a default implementation that just calls read_exact.
Note that I can't just call seek(n, SeekCur). Not all readers implement Seek (socket streams for example) but all readers can be advanced from their current position by - in the worst case - just reading and throwing away data.
The text was updated successfully, but these errors were encountered:
The problem.
Say I want to skip the next
n
bytes of input from aReader
. Currently, I can see two ways of doing this, neither of which are ideal.Vec<u8>
of sizen
. Callread
on it. Discard theVec<u8>
. This has the disadvantage of doing an unnecessary allocation and unnecessary copying. Note that callingread_exact
is equivalent to this.read_u8
n
times. This has this the disadvantage of doingn
function calls, which may even translate ton
syscalls. For any significantn
this is going to be worse than the first option.The solution.
Have
Reader
expose a methodskip_exact
that skips the nextn
bytes. For some readers such asMemReader
andBufferedReader
this just means advancing the cursor byn
. For some other readers this could be implemented using seek. For other readers again this method can be given a default implementation that just callsread_exact
.Note that I can't just call
seek(n, SeekCur)
. Not all readers implementSeek
(socket streams for example) but all readers can be advanced from their current position by - in the worst case - just reading and throwing away data.The text was updated successfully, but these errors were encountered: