Zig 0.17.0-dev (Split by item)

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 library itself.

Output

blake3.Output
const Output = struct

File

lib/std/crypto/blake3.zig:907

Code

const Output = struct {
    input_cv: [8]u32 align(16),
    block: [Blake3.block_length]u8 align(16),
    block_len: u8,
    counter: u64,
    flags: Flags,

    fn chainingValue(self: *const Output) [8]u32 {
        var cv_words = self.input_cv;
        compressInPlace(&cv_words, &self.block, self.block_len, self.counter, self.flags);
        return cv_words;
    }

    fn rootBytes(self: *const Output, seek: u64, out: []u8) void {
        if (out.len == 0) return;

        var output_block_counter = seek / 64;
        const offset_within_block = @as(usize, @intCast(seek % 64));
        var out_remaining = out;

        if (offset_within_block > 0) {
            var wide_buf: [64]u8 = undefined;
            compressXof(&self.input_cv, &self.block, self.block_len, output_block_counter, self.flags.with(.{ .root = true }), &wide_buf);
            const available_bytes = 64 - offset_within_block;
            const bytes = @min(out_remaining.len, available_bytes);
            @memcpy(out_remaining[0..bytes], wide_buf[offset_within_block..][0..bytes]);
            out_remaining = out_remaining[bytes..];
            output_block_counter += 1;
        }

        while (out_remaining.len >= 64) {
            compressXof(&self.input_cv, &self.block, self.block_len, output_block_counter, self.flags.with(.{ .root = true }), out_remaining[0..64]);
            out_remaining = out_remaining[64..];
            output_block_counter += 1;
        }

        if (out_remaining.len > 0) {
            var wide_buf: [64]u8 = undefined;
            compressXof(&self.input_cv, &self.block, self.block_len, output_block_counter, self.flags.with(.{ .root = true }), &wide_buf);
            @memcpy(out_remaining, wide_buf[0..out_remaining.len]);
        }
    }
}