Open arkadiuszwojcik opened 5 months ago
are you perhaps looking for std.io.BufferedReader and std.io.BufferedWriter ?
There is a lot of similarities but this is a bit different. FixedBufferReader
don't relay on underlying Reader
as all data are already in fixed length memory slice. So in some sense all BufferedReader
implement FixedBufferReader
interface + additional operations to work with underlying reader. So this is something in between concept of slice and BufferedReader
/BufferedWriter
or it can be thought of as advance wrapper around slice that tracks current positions. Most of functions in std.mem
operate on slices but are stateless (no current position tracking), FixedBufferReader
adds state around slices.
in that case it sounds like std.BoundedArray and std.fifo.LinearFifo ?
Please take a look on FixedBufferReader it was made public in std
3 weeks ago. This is exactly what I am talking about. It should be promoted (with minor changes) to more generic namespace std.mem
instead of being part of specialized std.dwarf
namespace. Similar functionality is also impemented in Uri struct by SliceReader
Perhaps I'm missing something, but isn't FixedBufferStream
in std.io
what you're looking for? If not, can you describe why not? https://github.com/ziglang/zig/blob/master/lib/std/io/fixed_buffer_stream.zig
I'm quite new to the Zig community, so I may not have seen a lot, but recently, while submitting a PR to the MicroZig project, I had to implement BufferReader and BufferWriter types. This is quite common pattern (I think) and Zig also use it in one place where it is called
FixedBufferReader
. I think something like that is very useful and should be promoted tostd.mem
namespace, althoughFixedBufferReader
itself have some specyfic functions (like:readUleb128
) I would not expect in generic implementation.FixedBufferWriter
would be useful in cases when we have to join together a lot os small byte chunks while serializing. So togetherFixedBufferReader
andFixedBufferWriter
would be very nice addition tostd.mem
namespace in my opinion.