This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function
writeSignedFixed
Public Function
std.leb128.writeSignedFixed
pubfnwriteSignedFixed(comptimel: usize, ptr: *[l]u8, int: @Int(.signed, l * 7)) void
This is an "advanced" function. It allows one to use a fixed amount of memory to store an ILEB128. This defeats the entire purpose of using this data encoding; it will no longer use fewer bytes to store smaller numbers. The advantage of using a fixed width is that it makes fields have a predictable size and so depending on the use case this tradeoff can be worthwhile. An example use case of this is in emitting DWARF info where one wants to make a ILEB128 field "relocatable", meaning that it becomes possible to later go back and patch the number to be a different value without shifting all the following code.
Params
l: usize
ptr: *[l]u8
int: @Int(.signed, l * 7)
File
leb128.zig:68
68697071727374757677787980
pubfnwriteSignedFixed(comptimel: usize, ptr: *[l]u8, int: @Int(.signed, l * 7)) void {
constT = @TypeOf(int);
constU = if (@typeInfo(T).int.bits < 8) u8elseT;
varvalue: U = @intCast(int);
comptimevari = 0;
inlinewhile (i < (l - 1)) : (i += 1) {
constbyte: u8 = @bitCast(@as(i8, @truncate(value)) | -0b1000_0000);
value >>= 7;
ptr[i] = byte;
}
ptr[i] = @as(u7, @bitCast(@as(i7, @truncate(value))));
}
This is an "advanced" function. It allows one to use a fixed amount of memory to store an ILEB128. This defeats the entire purpose of using this data encoding; it will no longer use fewer bytes to store smaller numbers. The advantage of using a fixed width is that it makes fields have a predictable size and so depending on the use case this tradeoff can be worthwhile. An example use case of this is in emitting DWARF info where one wants to make a ILEB128 field "relocatable", meaning that it becomes possible to later go back and patch the number to be a different value without shifting all the following code.