| author | |
| committer | |
| log | 3e18f16a27faad6344444685124d7a25c512b56b |
| tree | 6bd29fafe31d2c687d5ba25a7f0b7d3d433a3dd7 |
| parent | 784588b650abfc429124538b910bd0975ce09fe3 |
| signature |
7 files changed, 95 insertions(+), 8 deletions(-)
AnyReadable.zig+15-1| ... | ... | @@ -8,9 +8,23 @@ vtable: *const struct { |
| 8 | 8 | }, |
| 9 | 9 | state: *allowzero anyopaque, |
| 10 | 10 | |
| 11 | const R = nio.Readable(@This(), ._const); | |
| 12 | pub const readAll = R.readAll; | |
| 13 | pub const readAtLeast = R.readAtLeast; | |
| 14 | pub const readNoEof = R.readNoEof; | |
| 15 | pub const readAllAlloc = R.readAllAlloc; | |
| 16 | pub const readArray = R.readArray; | |
| 17 | pub const readByte = R.readByte; | |
| 18 | pub const readUntilDelimiterArrayList = R.readUntilDelimiterArrayList; | |
| 19 | pub const readUntilDelimiterAlloc = R.readUntilDelimiterAlloc; | |
| 20 | pub const readUntilDelimitersBuf = R.readUntilDelimitersBuf; | |
| 21 | pub const readUntilDelimitersArrayList = R.readUntilDelimitersArrayList; | |
| 22 | pub const readAlloc = R.readAlloc; | |
| 23 | pub const readInt = R.readInt; | |
| 24 | pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc; | |
| 25 | ||
| 11 | 26 | pub const Error = ReadError; // std compat |
| 12 | 27 | pub const ReadError = anyerror; |
| 13 | pub usingnamespace nio.Readable(@This(), ._const); | |
| 14 | 28 | pub fn read(r: AnyReadable, buffer: []u8) !usize { |
| 15 | 29 | return r.vtable.read(r.state, buffer); |
| 16 | 30 | } |
AnyWritable.zig+10-1| ... | ... | @@ -15,8 +15,17 @@ vtable: *const struct { |
| 15 | 15 | }, |
| 16 | 16 | state: *allowzero anyopaque, |
| 17 | 17 | |
| 18 | const W = nio.Writable(@This(), ._const); | |
| 19 | pub const writeAll = W.writeAll; | |
| 20 | pub const writevAll = W.writevAll; | |
| 21 | pub const writeByteNTimes = W.writeByteNTimes; | |
| 22 | pub const writeNTimes = W.writeNTimes; | |
| 23 | pub const writeInt = W.writeInt; | |
| 24 | pub const writeStruct = W.writeStruct; | |
| 25 | pub const writeIntPretty = W.writeIntPretty; | |
| 26 | pub const print = W.print; | |
| 27 | ||
| 18 | 28 | pub const WriteError = anyerror; |
| 19 | pub usingnamespace nio.Writable(@This(), ._const); | |
| 20 | 29 | pub fn write(r: AnyWritable, buffer: []const u8) !usize { |
| 21 | 30 | return r.vtable.write(r.state, buffer); |
| 22 | 31 | } |
buffered_reader.zig+15-1| ... | ... | @@ -19,8 +19,22 @@ pub fn BufferedReader(comptime buffer_size: usize, comptime ReaderType: type) ty |
| 19 | 19 | }; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | const R = nio.Readable(@This(), ._var); | |
| 23 | pub const readAll = R.readAll; | |
| 24 | pub const readAtLeast = R.readAtLeast; | |
| 25 | pub const readNoEof = R.readNoEof; | |
| 26 | pub const readAllAlloc = R.readAllAlloc; | |
| 27 | pub const readArray = R.readArray; | |
| 28 | pub const readByte = R.readByte; | |
| 29 | pub const readUntilDelimiterArrayList = R.readUntilDelimiterArrayList; | |
| 30 | pub const readUntilDelimiterAlloc = R.readUntilDelimiterAlloc; | |
| 31 | pub const readUntilDelimitersBuf = R.readUntilDelimitersBuf; | |
| 32 | pub const readUntilDelimitersArrayList = R.readUntilDelimitersArrayList; | |
| 33 | pub const readAlloc = R.readAlloc; | |
| 34 | pub const readInt = R.readInt; | |
| 35 | pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc; | |
| 36 | ||
| 22 | 37 | pub const ReadError = ReaderType.ReadError; |
| 23 | pub usingnamespace nio.Readable(@This(), ._var); | |
| 24 | 38 | pub fn read(self: *Self, dest: []u8) ReadError!usize { |
| 25 | 39 | // First try reading from the already buffered data onto the destination. |
| 26 | 40 | const current = self.buf[self.start..self.end]; |
buffered_writer.zig+10-1| ... | ... | @@ -25,8 +25,17 @@ pub fn BufferedWriter(comptime buffer_size: usize, comptime WriterType: type) ty |
| 25 | 25 | }; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | const W = nio.Writable(@This(), ._var); | |
| 29 | pub const writeAll = W.writeAll; | |
| 30 | pub const writevAll = W.writevAll; | |
| 31 | pub const writeByteNTimes = W.writeByteNTimes; | |
| 32 | pub const writeNTimes = W.writeNTimes; | |
| 33 | pub const writeInt = W.writeInt; | |
| 34 | pub const writeStruct = W.writeStruct; | |
| 35 | pub const writeIntPretty = W.writeIntPretty; | |
| 36 | pub const print = W.print; | |
| 37 | ||
| 28 | 38 | pub const WriteError = extras.Pointee(WriterType).WriteError; |
| 29 | pub usingnamespace nio.Writable(@This(), ._var); | |
| 30 | 39 | pub fn write(self: *Self, bytes: []const u8) WriteError!usize { |
| 31 | 40 | if (self.end + bytes.len > self.buf.len) { |
| 32 | 41 | try self.flush(); |
counting_writer.zig+10-1| ... | ... | @@ -16,8 +16,17 @@ pub fn CountingWriter(WriterType: type) type { |
| 16 | 16 | }; |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | const W = nio.Writable(@This(), ._var); | |
| 20 | pub const writeAll = W.writeAll; | |
| 21 | pub const writevAll = W.writevAll; | |
| 22 | pub const writeByteNTimes = W.writeByteNTimes; | |
| 23 | pub const writeNTimes = W.writeNTimes; | |
| 24 | pub const writeInt = W.writeInt; | |
| 25 | pub const writeStruct = W.writeStruct; | |
| 26 | pub const writeIntPretty = W.writeIntPretty; | |
| 27 | pub const print = W.print; | |
| 28 | ||
| 19 | 29 | pub const WriteError = extras.Pointee(WriterType).WriteError; |
| 20 | pub usingnamespace nio.Writable(@This(), ._var); | |
| 21 | 30 | pub fn write(self: *Self, bytes: []const u8) WriteError!usize { |
| 22 | 31 | const len = try self.backing_writer.write(bytes); |
| 23 | 32 | self.bytes_written += len; |
fixed_buffer_stream.zig+25-2| ... | ... | @@ -27,8 +27,22 @@ pub fn FixedBufferStream(comptime Buffer: type) type { |
| 27 | 27 | }; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | const R = nio.Readable(@This(), ._var); | |
| 31 | pub const readAll = R.readAll; | |
| 32 | pub const readAtLeast = R.readAtLeast; | |
| 33 | pub const readNoEof = R.readNoEof; | |
| 34 | pub const readAllAlloc = R.readAllAlloc; | |
| 35 | pub const readArray = R.readArray; | |
| 36 | pub const readByte = R.readByte; | |
| 37 | pub const readUntilDelimiterArrayList = R.readUntilDelimiterArrayList; | |
| 38 | pub const readUntilDelimiterAlloc = R.readUntilDelimiterAlloc; | |
| 39 | pub const readUntilDelimitersBuf = R.readUntilDelimitersBuf; | |
| 40 | pub const readUntilDelimitersArrayList = R.readUntilDelimitersArrayList; | |
| 41 | pub const readAlloc = R.readAlloc; | |
| 42 | pub const readInt = R.readInt; | |
| 43 | pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc; | |
| 44 | ||
| 30 | 45 | pub const ReadError = error{}; |
| 31 | pub usingnamespace nio.Readable(@This(), ._var); | |
| 32 | 46 | pub fn read(self: *Self, dest: []u8) ReadError!usize { |
| 33 | 47 | const size = @min(dest.len, self.buffer.len - self.pos); |
| 34 | 48 | const end = self.pos + size; |
| ... | ... | @@ -50,8 +64,17 @@ pub fn FixedBufferStream(comptime Buffer: type) type { |
| 50 | 64 | }; |
| 51 | 65 | } |
| 52 | 66 | |
| 67 | const W = nio.Writable(@This(), ._var); | |
| 68 | pub const writeAll = W.writeAll; | |
| 69 | pub const writevAll = W.writevAll; | |
| 70 | pub const writeByteNTimes = W.writeByteNTimes; | |
| 71 | pub const writeNTimes = W.writeNTimes; | |
| 72 | pub const writeInt = W.writeInt; | |
| 73 | pub const writeStruct = W.writeStruct; | |
| 74 | pub const writeIntPretty = W.writeIntPretty; | |
| 75 | pub const print = W.print; | |
| 76 | ||
| 53 | 77 | pub const WriteError = error{NoSpaceLeft}; |
| 54 | pub usingnamespace nio.Writable(@This(), ._var); | |
| 55 | 78 | /// If the returned number of bytes written is less than requested, the buffer is full. |
| 56 | 79 | /// Returns `error.NoSpaceLeft` when no bytes would be written. |
| 57 | 80 | pub fn write(self: *Self, bytes: []const u8) WriteError!usize { |
null_writer.zig+10-1| ... | ... | @@ -3,8 +3,17 @@ const extras = @import("extras"); |
| 3 | 3 | const nio = @import("./nio.zig"); |
| 4 | 4 | |
| 5 | 5 | pub const NullWriter = struct { |
| 6 | const W = nio.Writable(@This(), ._var); | |
| 7 | pub const writeAll = W.writeAll; | |
| 8 | pub const writevAll = W.writevAll; | |
| 9 | pub const writeByteNTimes = W.writeByteNTimes; | |
| 10 | pub const writeNTimes = W.writeNTimes; | |
| 11 | pub const writeInt = W.writeInt; | |
| 12 | pub const writeStruct = W.writeStruct; | |
| 13 | pub const writeIntPretty = W.writeIntPretty; | |
| 14 | pub const print = W.print; | |
| 15 | ||
| 6 | 16 | pub const WriteError = error{}; |
| 7 | pub usingnamespace nio.Writable(@This(), ._var); | |
| 8 | 17 | pub fn write(self: NullWriter, bytes: []const u8) WriteError!usize { |
| 9 | 18 | _ = self; |
| 10 | 19 | return bytes.len; |