Function takeLeb128 [src]

Read a single LEB128 value as type T, or error.Overflow if the value cannot fit.

Prototype

pub fn takeLeb128(r: *Reader, comptime Result: type) TakeLeb128Error!Result

Parameters

r: *ReaderResult: type

Possible Errors

EndOfStream Error
Overflow
ReadFailed Error

See the Reader implementation for detailed diagnostics.

Example

test takeLeb128 { var r: Reader = .fixed("\xc7\x9f\x7f\x80"); try testing.expectEqual(-12345, try r.takeLeb128(i64)); try testing.expectEqual(0x80, try r.peekByte()); try testing.expectError(error.EndOfStream, r.takeLeb128(i64)); }

Source

pub fn takeLeb128(r: *Reader, comptime Result: type) TakeLeb128Error!Result { const result_info = @typeInfo(Result).int; return std.math.cast(Result, try r.takeMultipleOf7Leb128(@Type(.{ .int = .{ .signedness = result_info.signedness, .bits = std.mem.alignForwardAnyAlign(u16, result_info.bits, 7), } }))) orelse error.Overflow; }