DoxigAlpha

writeUnsignedExtended

Same as writeUnsignedFixed but with a runtime-known length. Asserts slice.len > 0.

Function parameters

Parameters

#
slice:[]u8
arg:anytype

Read a single unsigned LEB128 value from the given reader as type T,

Functions

#
readUleb128
Read a single unsigned LEB128 value from the given reader as type T,
writeUleb128
Write a single unsigned integer as unsigned LEB128 to the given writer.
readIleb128
Read a single signed LEB128 value from the given reader as type T,
writeIleb128
Write a single signed integer as signed LEB128 to the given writer.
writeUnsignedFixed
This is an "advanced" function.
writeUnsignedExtended
Same as `writeUnsignedFixed` but with a runtime-known length.
writeSignedFixed
This is an "advanced" function.

Source

Implementation

#
pub fn writeUnsignedExtended(slice: []u8, arg: anytype) void {
    const Arg = @TypeOf(arg);
    const Int = switch (Arg) {
        comptime_int => std.math.IntFittingRange(arg, arg),
        else => Arg,
    };
    const Value = if (@typeInfo(Int).int.bits < 8) u8 else Int;
    var value: Value = arg;

    for (slice[0 .. slice.len - 1]) |*byte| {
        byte.* = @truncate(0x80 | value);
        value >>= 7;
    }
    slice[slice.len - 1] = @as(u7, @intCast(value));
}