fn Reader(comptime Context: type, comptime ReadError: type, comptime readFn: fn (Context, []u8) ReadError!usize) type
Parameters
Context: type,
ReadError: type,
readFn: fn (Context, []u8) ReadError!usize,
Returns the number of bytes read. It may be less than buffer.len. If the number of bytes read is 0, it means end of stream. End of stream is not an error condition.
Functions
fn isBytes(self: Self, slice: []const u8) !bool
Reads
slice.len
bytes from the stream and returns if they are the same as the …Reads
slice.len
bytes from the stream and returns if they are the same as the passed slicefn read(self: Self, buffer: []u8) Error!usize
Returns the number of bytes read. It may be less than buffer.len. If the number…
Returns the number of bytes read. It may be less than buffer.len. If the number of bytes read is 0, it means end of stream. End of stream is not an error condition.
fn readAll(self: Self, buffer: []u8) Error!usize
Returns the number of bytes read. If the number read is smaller than `buffer.len…
Returns the number of bytes read. If the number read is smaller than
buffer.len
, it means the stream reached the end. Reaching the end of a stream is not an error condition.fn readAllAlloc(self: Self, allocator: mem.Allocator, max_size: usize) ![]u8
Allocates enough memory to hold all the contents of the stream. If the allocated…
Allocates enough memory to hold all the contents of the stream. If the allocated memory would be greater than
max_size
, returnserror.StreamTooLong
. Caller owns returned memory. If this function returns an error, the contents from the stream read so far are lost.fn readAllArrayList(self: Self, array_list: *field_call, max_append_size: usize) !void
Appends to the
std.ArrayList
contents by reading from the stream until end of…Appends to the
std.ArrayList
contents by reading from the stream until end of stream is found. If the number of bytes appended would exceedmax_append_size
,error.StreamTooLong
is returned and thestd.ArrayList
has exactlymax_append_size
bytes appended.fn readAllArrayListAligned(self: Self, comptime alignment: ?u29, array_list: *field_call, max_append_size: usize) !void
No documentation provided.
fn readAtLeast(self: Self, buffer: []u8, len: usize) Error!usize
Returns the number of bytes read, calling the underlying read function the mini…
Returns the number of bytes read, calling the underlying read function the minimal number of times until the buffer has at least
len
bytes filled. If the number read is less thanlen
it means the stream reached the end. Reaching the end of the stream is not an error condition.fn readBoundedBytes(self: Self, comptime num_bytes: usize) Error!field_call
Reads at most
num_bytes
and returns as a bounded array.fn readByte(self: Self) Error || error{EndOfStream}!u8
Reads 1 byte from the stream or returns
error.EndOfStream
.fn readByteSigned(self: Self) Error || error{EndOfStream}!i8
Same as
readByte
except the returned byte is signed.fn readBytesNoEof(self: Self, comptime num_bytes: usize) Error || error{EndOfStream}![num_bytes]u8
Reads exactly
num_bytes
bytes and returns as an array.num_bytes
must be co…Reads exactly
num_bytes
bytes and returns as an array.num_bytes
must be comptime-knownfn readEnum(self: Self, comptime Enum: type, endian: std.builtin.Endian) !Enum
Reads an integer with the same size as the given enum’s tag type. If the integer…
Reads an integer with the same size as the given enum’s tag type. If the integer matches an enum tag, casts the integer to the enum tag and returns it. Otherwise, returns an
error.InvalidValue
. TODO optimization taking advantage of most fields being in orderfn readIntForeign(self: Self, comptime T: type) Error || error{EndOfStream}!T
Reads a foreign-endian integer
fn readIntNative(self: Self, comptime T: type) Error || error{EndOfStream}!T
Reads a native-endian integer
fn readIntoBoundedBytes(self: Self, comptime num_bytes: usize, bounded: *field_call) Error!void
Reads bytes until
bounded.len
is equal tonum_bytes
, or the stream ends.Reads bytes until
bounded.len
is equal tonum_bytes
, or the stream ends.- it is assumed that
num_bytes
will not exceedbounded.capacity()
- it is assumed that
fn readNoEof(self: Self, buf: []u8) Error || error{EndOfStream}!void
If the number read would be smaller than
buf.len
,error.EndOfStream
is retur…If the number read would be smaller than
buf.len
,error.EndOfStream
is returned instead.fn readUntilDelimiter(self: Self, buf: []u8, delimiter: u8) ![]u8
Deprecated: use
streamUntilDelimiter
with FixedBufferStream’s writer instead. …Deprecated: use
streamUntilDelimiter
with FixedBufferStream’s writer instead. Reads from the stream until specified byte is found. If the buffer is not large enough to hold the entire contents,error.StreamTooLong
is returned. If end-of-stream is found,error.EndOfStream
is returned. Returns a slice of the stream data, with ptr equal tobuf.ptr
. The delimiter byte is written to the output buffer but is not included in the returned slice.fn readUntilDelimiterAlloc(self: Self, allocator: mem.Allocator, delimiter: u8, max_size: usize) ![]u8
Deprecated: use
streamUntilDelimiter
with ArrayList’s writer instead. Allocat…Deprecated: use
streamUntilDelimiter
with ArrayList’s writer instead. Allocates enough memory to read untildelimiter
. If the allocated memory would be greater thanmax_size
, returnserror.StreamTooLong
. Caller owns returned memory. If this function returns an error, the contents from the stream read so far are lost.fn readUntilDelimiterArrayList(self: Self, array_list: *field_call, delimiter: u8, max_size: usize) !void
Deprecated: use
streamUntilDelimiter
with ArrayList’s writer instead. Replace…Deprecated: use
streamUntilDelimiter
with ArrayList’s writer instead. Replaces thestd.ArrayList
contents by reading from the stream untildelimiter
is found. Does not include the delimiter in the result. If thestd.ArrayList
length would exceedmax_size
,error.StreamTooLong
is returned and thestd.ArrayList
is populated withmax_size
bytes from the stream.fn readUntilDelimiterOrEof(self: Self, buf: []u8, delimiter: u8) !?[]u8
Deprecated: use
streamUntilDelimiter
with FixedBufferStream’s writer instead. …Deprecated: use
streamUntilDelimiter
with FixedBufferStream’s writer instead. Reads from the stream until specified byte is found. If the buffer is not large enough to hold the entire contents,error.StreamTooLong
is returned. If end-of-stream is found, returns the rest of the stream. If this function is called again after that, returns null. Returns a slice of the stream data, with ptr equal tobuf.ptr
. The delimiter byte is written to the output buffer but is not included in the returned slice.fn readUntilDelimiterOrEofAlloc(self: Self, allocator: mem.Allocator, delimiter: u8, max_size: usize) !?[]u8
Deprecated: use
streamUntilDelimiter
with ArrayList’s (or any other’s) writer …Deprecated: use
streamUntilDelimiter
with ArrayList’s (or any other’s) writer instead. Allocates enough memory to read untildelimiter
or end-of-stream. If the allocated memory would be greater thanmax_size
, returnserror.StreamTooLong
. If end-of-stream is found, returns the rest of the stream. If this function is called again after that, returns null. Caller owns returned memory. If this function returns an error, the contents from the stream read so far are lost.fn readVarInt(self: Self, comptime ReturnType: type, endian: std.builtin.Endian, size: usize) !ReturnType
No documentation provided.
fn skipBytes(self: Self, num_bytes: u64, comptime options: SkipBytesOptions) !void
Reads
num_bytes
bytes from the stream and discards themfn skipUntilDelimiterOrEof(self: Self, delimiter: u8) Error!void
Reads from the stream until specified byte is found, discarding all data, inclu…
Reads from the stream until specified byte is found, discarding all data, including the delimiter. If end-of-stream is found, this function succeeds.
fn streamUntilDelimiter(self: Self, writer: anytype, delimiter: u8, optional_max_size: ?usize) Error || error{EndOfStream, StreamTooLong} || @TypeOf(writer).Error!void
Appends to the
writer
contents by reading from the stream untildelimiter
is…Appends to the
writer
contents by reading from the stream untildelimiter
is found. Does not write the delimiter itself. Ifoptional_max_size
is not null and amount of written bytes exceedsoptional_max_size
, returnserror.StreamTooLong
and finishes appending. Ifoptional_max_size
is null, appending is unbounded.