Type Functionstd.io.GenericReader[src]

Parameters

Context: type
ReadError: type
readFn: fn (context: Context, buffer: []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

Values

ConstantError[src]

Source Code

Source code
pub const Error = ReadError

Error Sets

Error SetNoEofError[src]

Errors

anyerror means the error set is known only at runtime.

EndOfStream

Source Code

Source code
pub const NoEofError = ReadError || error{
    EndOfStream,
}

Error SetReadEnumError[src]

Errors

anyerror means the error set is known only at runtime.

EndOfStream NoEofError
InvalidValue

An integer was read, but it did not match any of the tags in the supplied enum.

Source Code

Source code
pub const ReadEnumError = NoEofError || error{
    /// An integer was read, but it did not match any of the tags in the supplied enum.
    InvalidValue,
}

Functions

Functionread[src]

pub inline fn read(self: Self, buffer: []u8) Error!usize

Parameters

self: Self
buffer: []u8

Source Code

Source code
pub inline fn read(self: Self, buffer: []u8) Error!usize {
    return readFn(self.context, buffer);
}

FunctionreadAll[src]

pub inline fn readAll(self: Self, buffer: []u8) Error!usize

Parameters

self: Self
buffer: []u8

Source Code

Source code
pub inline fn readAll(self: Self, buffer: []u8) Error!usize {
    return @errorCast(self.any().readAll(buffer));
}

FunctionreadAtLeast[src]

pub inline fn readAtLeast(self: Self, buffer: []u8, len: usize) Error!usize

Parameters

self: Self
buffer: []u8
len: usize

Source Code

Source code
pub inline fn readAtLeast(self: Self, buffer: []u8, len: usize) Error!usize {
    return @errorCast(self.any().readAtLeast(buffer, len));
}

FunctionreadNoEof[src]

pub inline fn readNoEof(self: Self, buf: []u8) NoEofError!void

Parameters

self: Self
buf: []u8

Source Code

Source code
pub inline fn readNoEof(self: Self, buf: []u8) NoEofError!void {
    return @errorCast(self.any().readNoEof(buf));
}

FunctionreadAllArrayList[src]

pub inline fn readAllArrayList( self: Self, array_list: *std.ArrayList(u8), max_append_size: usize, ) (error{StreamTooLong} || Allocator.Error || Error)!void

Parameters

self: Self
array_list: *std.ArrayList(u8)
max_append_size: usize

Source Code

Source code
pub inline fn readAllArrayList(
    self: Self,
    array_list: *std.ArrayList(u8),
    max_append_size: usize,
) (error{StreamTooLong} || Allocator.Error || Error)!void {
    return @errorCast(self.any().readAllArrayList(array_list, max_append_size));
}

FunctionreadAllArrayListAligned[src]

pub inline fn readAllArrayListAligned( self: Self, comptime alignment: ?u29, array_list: *std.ArrayListAligned(u8, alignment), max_append_size: usize, ) (error{StreamTooLong} || Allocator.Error || Error)!void

Parameters

self: Self
alignment: ?u29
array_list: *std.ArrayListAligned(u8, alignment)
max_append_size: usize

Source Code

Source code
pub inline fn readAllArrayListAligned(
    self: Self,
    comptime alignment: ?u29,
    array_list: *std.ArrayListAligned(u8, alignment),
    max_append_size: usize,
) (error{StreamTooLong} || Allocator.Error || Error)!void {
    return @errorCast(self.any().readAllArrayListAligned(
        alignment,
        array_list,
        max_append_size,
    ));
}

FunctionreadAllAlloc[src]

pub inline fn readAllAlloc( self: Self, allocator: Allocator, max_size: usize, ) (Error || Allocator.Error || error{StreamTooLong})![]u8

Parameters

self: Self
allocator: Allocator
max_size: usize

Source Code

Source code
pub inline fn readAllAlloc(
    self: Self,
    allocator: Allocator,
    max_size: usize,
) (Error || Allocator.Error || error{StreamTooLong})![]u8 {
    return @errorCast(self.any().readAllAlloc(allocator, max_size));
}

FunctionreadUntilDelimiterArrayList[src]

pub inline fn readUntilDelimiterArrayList( self: Self, array_list: *std.ArrayList(u8), delimiter: u8, max_size: usize, ) (NoEofError || Allocator.Error || error{StreamTooLong})!void

Parameters

self: Self
array_list: *std.ArrayList(u8)
delimiter: u8
max_size: usize

Source Code

Source code
pub inline fn readUntilDelimiterArrayList(
    self: Self,
    array_list: *std.ArrayList(u8),
    delimiter: u8,
    max_size: usize,
) (NoEofError || Allocator.Error || error{StreamTooLong})!void {
    return @errorCast(self.any().readUntilDelimiterArrayList(
        array_list,
        delimiter,
        max_size,
    ));
}

FunctionreadUntilDelimiterAlloc[src]

pub inline fn readUntilDelimiterAlloc( self: Self, allocator: Allocator, delimiter: u8, max_size: usize, ) (NoEofError || Allocator.Error || error{StreamTooLong})![]u8

Parameters

self: Self
allocator: Allocator
delimiter: u8
max_size: usize

Source Code

Source code
pub inline fn readUntilDelimiterAlloc(
    self: Self,
    allocator: Allocator,
    delimiter: u8,
    max_size: usize,
) (NoEofError || Allocator.Error || error{StreamTooLong})![]u8 {
    return @errorCast(self.any().readUntilDelimiterAlloc(
        allocator,
        delimiter,
        max_size,
    ));
}

FunctionreadUntilDelimiter[src]

pub inline fn readUntilDelimiter( self: Self, buf: []u8, delimiter: u8, ) (NoEofError || error{StreamTooLong})![]u8

Parameters

self: Self
buf: []u8
delimiter: u8

Source Code

Source code
pub inline fn readUntilDelimiter(
    self: Self,
    buf: []u8,
    delimiter: u8,
) (NoEofError || error{StreamTooLong})![]u8 {
    return @errorCast(self.any().readUntilDelimiter(buf, delimiter));
}

FunctionreadUntilDelimiterOrEofAlloc[src]

pub inline fn readUntilDelimiterOrEofAlloc( self: Self, allocator: Allocator, delimiter: u8, max_size: usize, ) (Error || Allocator.Error || error{StreamTooLong})!?[]u8

Parameters

self: Self
allocator: Allocator
delimiter: u8
max_size: usize

Source Code

Source code
pub inline fn readUntilDelimiterOrEofAlloc(
    self: Self,
    allocator: Allocator,
    delimiter: u8,
    max_size: usize,
) (Error || Allocator.Error || error{StreamTooLong})!?[]u8 {
    return @errorCast(self.any().readUntilDelimiterOrEofAlloc(
        allocator,
        delimiter,
        max_size,
    ));
}

FunctionreadUntilDelimiterOrEof[src]

pub inline fn readUntilDelimiterOrEof( self: Self, buf: []u8, delimiter: u8, ) (Error || error{StreamTooLong})!?[]u8

Parameters

self: Self
buf: []u8
delimiter: u8

Source Code

Source code
pub inline fn readUntilDelimiterOrEof(
    self: Self,
    buf: []u8,
    delimiter: u8,
) (Error || error{StreamTooLong})!?[]u8 {
    return @errorCast(self.any().readUntilDelimiterOrEof(buf, delimiter));
}

FunctionstreamUntilDelimiter[src]

pub inline fn streamUntilDelimiter( self: Self, writer: anytype, delimiter: u8, optional_max_size: ?usize, ) (NoEofError || error{StreamTooLong} || @TypeOf(writer).Error)!void

Parameters

self: Self
delimiter: u8
optional_max_size: ?usize

Source Code

Source code
pub inline fn streamUntilDelimiter(
    self: Self,
    writer: anytype,
    delimiter: u8,
    optional_max_size: ?usize,
) (NoEofError || error{StreamTooLong} || @TypeOf(writer).Error)!void {
    return @errorCast(self.any().streamUntilDelimiter(
        writer,
        delimiter,
        optional_max_size,
    ));
}

FunctionskipUntilDelimiterOrEof[src]

pub inline fn skipUntilDelimiterOrEof(self: Self, delimiter: u8) Error!void

Parameters

self: Self
delimiter: u8

Source Code

Source code
pub inline fn skipUntilDelimiterOrEof(self: Self, delimiter: u8) Error!void {
    return @errorCast(self.any().skipUntilDelimiterOrEof(delimiter));
}

FunctionreadByte[src]

pub inline fn readByte(self: Self) NoEofError!u8

Parameters

self: Self

Source Code

Source code
pub inline fn readByte(self: Self) NoEofError!u8 {
    return @errorCast(self.any().readByte());
}

FunctionreadByteSigned[src]

pub inline fn readByteSigned(self: Self) NoEofError!i8

Parameters

self: Self

Source Code

Source code
pub inline fn readByteSigned(self: Self) NoEofError!i8 {
    return @errorCast(self.any().readByteSigned());
}

FunctionreadBytesNoEof[src]

pub inline fn readBytesNoEof( self: Self, comptime num_bytes: usize, ) NoEofError![num_bytes]u8

Parameters

self: Self
num_bytes: usize

Source Code

Source code
pub inline fn readBytesNoEof(
    self: Self,
    comptime num_bytes: usize,
) NoEofError![num_bytes]u8 {
    return @errorCast(self.any().readBytesNoEof(num_bytes));
}

FunctionreadIntoBoundedBytes[src]

pub inline fn readIntoBoundedBytes( self: Self, comptime num_bytes: usize, bounded: *std.BoundedArray(u8, num_bytes), ) Error!void

Parameters

self: Self
num_bytes: usize
bounded: *std.BoundedArray(u8, num_bytes)

Source Code

Source code
pub inline fn readIntoBoundedBytes(
    self: Self,
    comptime num_bytes: usize,
    bounded: *std.BoundedArray(u8, num_bytes),
) Error!void {
    return @errorCast(self.any().readIntoBoundedBytes(num_bytes, bounded));
}

FunctionreadBoundedBytes[src]

pub inline fn readBoundedBytes( self: Self, comptime num_bytes: usize, ) Error!std.BoundedArray(u8, num_bytes)

Parameters

self: Self
num_bytes: usize

Source Code

Source code
pub inline fn readBoundedBytes(
    self: Self,
    comptime num_bytes: usize,
) Error!std.BoundedArray(u8, num_bytes) {
    return @errorCast(self.any().readBoundedBytes(num_bytes));
}

FunctionreadInt[src]

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

Parameters

self: Self
T: type

Source Code

Source code
pub inline fn readInt(self: Self, comptime T: type, endian: std.builtin.Endian) NoEofError!T {
    return @errorCast(self.any().readInt(T, endian));
}

FunctionreadVarInt[src]

pub inline fn readVarInt( self: Self, comptime ReturnType: type, endian: std.builtin.Endian, size: usize, ) NoEofError!ReturnType

Parameters

self: Self
ReturnType: type
size: usize

Source Code

Source code
pub inline fn readVarInt(
    self: Self,
    comptime ReturnType: type,
    endian: std.builtin.Endian,
    size: usize,
) NoEofError!ReturnType {
    return @errorCast(self.any().readVarInt(ReturnType, endian, size));
}

FunctionskipBytes[src]

pub inline fn skipBytes( self: Self, num_bytes: u64, comptime options: SkipBytesOptions, ) NoEofError!void

Parameters

self: Self
num_bytes: u64

Source Code

Source code
pub inline fn skipBytes(
    self: Self,
    num_bytes: u64,
    comptime options: SkipBytesOptions,
) NoEofError!void {
    return @errorCast(self.any().skipBytes(num_bytes, options));
}

FunctionisBytes[src]

pub inline fn isBytes(self: Self, slice: []const u8) NoEofError!bool

Parameters

self: Self
slice: []const u8

Source Code

Source code
pub inline fn isBytes(self: Self, slice: []const u8) NoEofError!bool {
    return @errorCast(self.any().isBytes(slice));
}

FunctionreadStruct[src]

pub inline fn readStruct(self: Self, comptime T: type) NoEofError!T

Parameters

self: Self
T: type

Source Code

Source code
pub inline fn readStruct(self: Self, comptime T: type) NoEofError!T {
    return @errorCast(self.any().readStruct(T));
}

FunctionreadStructEndian[src]

pub inline fn readStructEndian(self: Self, comptime T: type, endian: std.builtin.Endian) NoEofError!T

Parameters

self: Self
T: type

Source Code

Source code
pub inline fn readStructEndian(self: Self, comptime T: type, endian: std.builtin.Endian) NoEofError!T {
    return @errorCast(self.any().readStructEndian(T, endian));
}

FunctionreadEnum[src]

pub inline fn readEnum( self: Self, comptime Enum: type, endian: std.builtin.Endian, ) ReadEnumError!Enum

Parameters

self: Self
Enum: type

Source Code

Source code
pub inline fn readEnum(
    self: Self,
    comptime Enum: type,
    endian: std.builtin.Endian,
) ReadEnumError!Enum {
    return @errorCast(self.any().readEnum(Enum, endian));
}

Functionany[src]

pub inline fn any(self: *const Self) AnyReader

Parameters

self: *const Self

Source Code

Source code
pub inline fn any(self: *const Self) AnyReader {
    return .{
        .context = @ptrCast(&self.context),
        .readFn = typeErasedReadFn,
    };
}

Source Code

Source code
pub fn GenericReader(
    comptime Context: type,
    comptime ReadError: type,
    /// 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.
    comptime readFn: fn (context: Context, buffer: []u8) ReadError!usize,
) type {
    return struct {
        context: Context,

        pub const Error = ReadError;
        pub const NoEofError = ReadError || error{
            EndOfStream,
        };

        pub inline fn read(self: Self, buffer: []u8) Error!usize {
            return readFn(self.context, buffer);
        }

        pub inline fn readAll(self: Self, buffer: []u8) Error!usize {
            return @errorCast(self.any().readAll(buffer));
        }

        pub inline fn readAtLeast(self: Self, buffer: []u8, len: usize) Error!usize {
            return @errorCast(self.any().readAtLeast(buffer, len));
        }

        pub inline fn readNoEof(self: Self, buf: []u8) NoEofError!void {
            return @errorCast(self.any().readNoEof(buf));
        }

        pub inline fn readAllArrayList(
            self: Self,
            array_list: *std.ArrayList(u8),
            max_append_size: usize,
        ) (error{StreamTooLong} || Allocator.Error || Error)!void {
            return @errorCast(self.any().readAllArrayList(array_list, max_append_size));
        }

        pub inline fn readAllArrayListAligned(
            self: Self,
            comptime alignment: ?u29,
            array_list: *std.ArrayListAligned(u8, alignment),
            max_append_size: usize,
        ) (error{StreamTooLong} || Allocator.Error || Error)!void {
            return @errorCast(self.any().readAllArrayListAligned(
                alignment,
                array_list,
                max_append_size,
            ));
        }

        pub inline fn readAllAlloc(
            self: Self,
            allocator: Allocator,
            max_size: usize,
        ) (Error || Allocator.Error || error{StreamTooLong})![]u8 {
            return @errorCast(self.any().readAllAlloc(allocator, max_size));
        }

        pub inline fn readUntilDelimiterArrayList(
            self: Self,
            array_list: *std.ArrayList(u8),
            delimiter: u8,
            max_size: usize,
        ) (NoEofError || Allocator.Error || error{StreamTooLong})!void {
            return @errorCast(self.any().readUntilDelimiterArrayList(
                array_list,
                delimiter,
                max_size,
            ));
        }

        pub inline fn readUntilDelimiterAlloc(
            self: Self,
            allocator: Allocator,
            delimiter: u8,
            max_size: usize,
        ) (NoEofError || Allocator.Error || error{StreamTooLong})![]u8 {
            return @errorCast(self.any().readUntilDelimiterAlloc(
                allocator,
                delimiter,
                max_size,
            ));
        }

        pub inline fn readUntilDelimiter(
            self: Self,
            buf: []u8,
            delimiter: u8,
        ) (NoEofError || error{StreamTooLong})![]u8 {
            return @errorCast(self.any().readUntilDelimiter(buf, delimiter));
        }

        pub inline fn readUntilDelimiterOrEofAlloc(
            self: Self,
            allocator: Allocator,
            delimiter: u8,
            max_size: usize,
        ) (Error || Allocator.Error || error{StreamTooLong})!?[]u8 {
            return @errorCast(self.any().readUntilDelimiterOrEofAlloc(
                allocator,
                delimiter,
                max_size,
            ));
        }

        pub inline fn readUntilDelimiterOrEof(
            self: Self,
            buf: []u8,
            delimiter: u8,
        ) (Error || error{StreamTooLong})!?[]u8 {
            return @errorCast(self.any().readUntilDelimiterOrEof(buf, delimiter));
        }

        pub inline fn streamUntilDelimiter(
            self: Self,
            writer: anytype,
            delimiter: u8,
            optional_max_size: ?usize,
        ) (NoEofError || error{StreamTooLong} || @TypeOf(writer).Error)!void {
            return @errorCast(self.any().streamUntilDelimiter(
                writer,
                delimiter,
                optional_max_size,
            ));
        }

        pub inline fn skipUntilDelimiterOrEof(self: Self, delimiter: u8) Error!void {
            return @errorCast(self.any().skipUntilDelimiterOrEof(delimiter));
        }

        pub inline fn readByte(self: Self) NoEofError!u8 {
            return @errorCast(self.any().readByte());
        }

        pub inline fn readByteSigned(self: Self) NoEofError!i8 {
            return @errorCast(self.any().readByteSigned());
        }

        pub inline fn readBytesNoEof(
            self: Self,
            comptime num_bytes: usize,
        ) NoEofError![num_bytes]u8 {
            return @errorCast(self.any().readBytesNoEof(num_bytes));
        }

        pub inline fn readIntoBoundedBytes(
            self: Self,
            comptime num_bytes: usize,
            bounded: *std.BoundedArray(u8, num_bytes),
        ) Error!void {
            return @errorCast(self.any().readIntoBoundedBytes(num_bytes, bounded));
        }

        pub inline fn readBoundedBytes(
            self: Self,
            comptime num_bytes: usize,
        ) Error!std.BoundedArray(u8, num_bytes) {
            return @errorCast(self.any().readBoundedBytes(num_bytes));
        }

        pub inline fn readInt(self: Self, comptime T: type, endian: std.builtin.Endian) NoEofError!T {
            return @errorCast(self.any().readInt(T, endian));
        }

        pub inline fn readVarInt(
            self: Self,
            comptime ReturnType: type,
            endian: std.builtin.Endian,
            size: usize,
        ) NoEofError!ReturnType {
            return @errorCast(self.any().readVarInt(ReturnType, endian, size));
        }

        pub const SkipBytesOptions = AnyReader.SkipBytesOptions;

        pub inline fn skipBytes(
            self: Self,
            num_bytes: u64,
            comptime options: SkipBytesOptions,
        ) NoEofError!void {
            return @errorCast(self.any().skipBytes(num_bytes, options));
        }

        pub inline fn isBytes(self: Self, slice: []const u8) NoEofError!bool {
            return @errorCast(self.any().isBytes(slice));
        }

        pub inline fn readStruct(self: Self, comptime T: type) NoEofError!T {
            return @errorCast(self.any().readStruct(T));
        }

        pub inline fn readStructEndian(self: Self, comptime T: type, endian: std.builtin.Endian) NoEofError!T {
            return @errorCast(self.any().readStructEndian(T, endian));
        }

        pub const ReadEnumError = NoEofError || error{
            /// An integer was read, but it did not match any of the tags in the supplied enum.
            InvalidValue,
        };

        pub inline fn readEnum(
            self: Self,
            comptime Enum: type,
            endian: std.builtin.Endian,
        ) ReadEnumError!Enum {
            return @errorCast(self.any().readEnum(Enum, endian));
        }

        pub inline fn any(self: *const Self) AnyReader {
            return .{
                .context = @ptrCast(&self.context),
                .readFn = typeErasedReadFn,
            };
        }

        const Self = @This();

        fn typeErasedReadFn(context: *const anyopaque, buffer: []u8) anyerror!usize {
            const ptr: *const Context = @alignCast(@ptrCast(context));
            return readFn(ptr.*, buffer);
        }
    };
}