Function takeVarInt [src]
Asserts the buffer was initialized with a capacity at least n.
Prototype
pub fn takeVarInt(r: *Reader, comptime Int: type, endian: std.builtin.Endian, n: usize) Error!Int
Parameters
r: *Reader
Int: type
endian: std.builtin.Endian
n: usize
Possible Errors
See the Reader
implementation for detailed diagnostics.
Example
test takeVarInt {
var r: Reader = .fixed(&.{ 0x12, 0x34, 0x56 });
try testing.expectEqual(0x123456, try r.takeVarInt(u64, .big, 3));
try testing.expectError(error.EndOfStream, r.takeVarInt(u16, .little, 1));
}
Source
pub fn takeVarInt(r: *Reader, comptime Int: type, endian: std.builtin.Endian, n: usize) Error!Int {
assert(n <= @sizeOf(Int));
return std.mem.readVarInt(Int, try r.take(n), endian);
}