Function writeUnsignedExtended [src]
Same as writeUnsignedFixed but with a runtime-known length.
Asserts slice.len > 0.
Prototype
pub fn writeUnsignedExtended(slice: []u8, arg: anytype) void
Parameters
slice: []u8
Source
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));
}