Function takeInt [src]
Asserts the buffer was initialized with a capacity at least @bitSizeOf(T) / 8.
Prototype
pub inline fn takeInt(r: *Reader, comptime T: type, endian: std.builtin.Endian) Error!T
Parameters
r: *Reader
T: type
endian: std.builtin.Endian
Possible Errors
See the Reader
implementation for detailed diagnostics.
Example
test takeInt {
var r: Reader = .fixed(&.{ 0x12, 0x34, 0x56 });
try testing.expectEqual(0x1234, try r.takeInt(u16, .big));
try testing.expectError(error.EndOfStream, r.takeInt(u16, .little));
}
Source
pub inline fn takeInt(r: *Reader, comptime T: type, endian: std.builtin.Endian) Error!T {
const n = @divExact(@typeInfo(T).int.bits, 8);
return std.mem.readInt(T, try r.takeArray(n), endian);
}