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.

Fields

context: Context,

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 slice

fn 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, returns error.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 exceed max_append_size, error.StreamTooLong is returned and the std.ArrayList has exactly max_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 than len 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-known

fn 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 order

fn readInt(self: Self, comptime T: type, endian: std.builtin.Endian) !T

No documentation provided.

fn readIntBig(self: Self, comptime T: type) !T

No documentation provided.

fn readIntForeign(self: Self, comptime T: type) Error || error{EndOfStream}!T

Reads a foreign-endian integer

fn readIntLittle(self: Self, comptime T: type) !T

No documentation provided.

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 to num_bytes, or the stream ends.

Reads bytes until bounded.len is equal to num_bytes, or the stream ends.

  • it is assumed that num_bytes will not exceed bounded.capacity()
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 readStruct(self: Self, comptime T: type) !T

No documentation provided.

fn readStructBig(self: Self, comptime T: type) !T

No documentation provided.

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 to buf.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 until delimiter. If the allocated memory would be greater than max_size, returns error.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 the std.ArrayList contents by reading from the stream until delimiter is found. Does not include the delimiter in the result. If the std.ArrayList length would exceed max_size, error.StreamTooLong is returned and the std.ArrayList is populated with max_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 to buf.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 until delimiter or end-of-stream. If the allocated memory would be greater than max_size, returns error.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 them

fn 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 until delimiter is…

Appends to the writer contents by reading from the stream until delimiter is found. Does not write the delimiter itself. If optional_max_size is not null and amount of written bytes exceeds optional_max_size, returns error.StreamTooLong and finishes appending. If optional_max_size is null, appending is unbounded.

Values

Error
undefined