Function fixed [src]
Constructs a Reader such that it will read from buffer and then end.
Prototype
pub fn fixed(buffer: []const u8) Reader Parameters
buffer: []const u8 Example
test fixed {
var r: Reader = .fixed("a\x02");
try testing.expect((try r.takeByte()) == 'a');
try testing.expect((try r.takeEnum(enum(u8) {
a = 0,
b = 99,
c = 2,
d = 3,
}, builtin.cpu.arch.endian())) == .c);
try testing.expectError(error.EndOfStream, r.takeByte());
} Source
pub fn fixed(buffer: []const u8) Reader {
return .{
.vtable = &.{
.stream = endingStream,
.discard = endingDiscard,
.readVec = endingReadVec,
.rebase = endingRebase,
},
// This cast is safe because all potential writes to it will instead
// return `error.EndOfStream`.
.buffer = @constCast(buffer),
.end = buffer.len,
.seek = 0,
};
}