(breaking) rework stream abstractions
The main goal here is to make the function pointers comptime, so that we don't have to do the crazy stuff with async function frames. Since InStream, OutStream, and SeekableStream are already generic across error sets, it's not really worse to make them generic across the vtable as well. See #764 for the open issue acknowledging that using generics for these abstractions is a design flaw. See #130 for the efforts to make these abstractions non-generic. This commit also changes the OutStream API so that `write` returns number of bytes written, and `writeAll` is the one that loops until the whole buffer is written.
This commit is contained in:
@@ -632,11 +632,7 @@ const MsfStream = struct {
|
||||
blocks: []u32 = undefined,
|
||||
block_size: u32 = undefined,
|
||||
|
||||
/// Implementation of InStream trait for Pdb.MsfStream
|
||||
stream: Stream = undefined,
|
||||
|
||||
pub const Error = @TypeOf(read).ReturnType.ErrorSet;
|
||||
pub const Stream = io.InStream(Error);
|
||||
|
||||
fn init(block_size: u32, file: File, blocks: []u32) MsfStream {
|
||||
const stream = MsfStream{
|
||||
@@ -644,7 +640,6 @@ const MsfStream = struct {
|
||||
.pos = 0,
|
||||
.blocks = blocks,
|
||||
.block_size = block_size,
|
||||
.stream = Stream{ .readFn = readFn },
|
||||
};
|
||||
|
||||
return stream;
|
||||
@@ -715,8 +710,7 @@ const MsfStream = struct {
|
||||
return block * self.block_size + offset;
|
||||
}
|
||||
|
||||
fn readFn(in_stream: *Stream, buffer: []u8) Error!usize {
|
||||
const self = @fieldParentPtr(MsfStream, "stream", in_stream);
|
||||
return self.read(buffer);
|
||||
fn inStream(self: *MsfStream) std.io.InStream(*MsfStream, Error, read) {
|
||||
return .{ .context = self };
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user