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.

IconDir

ico.IconDir
pub const IconDir = struct

File

Code

pub const IconDir = struct {
    image_type: ImageType,
    /// Note: entries.len will always fit into a u16, since the field containing the
    /// number of images in an ico file is a u16.
    entries: []Entry,
    allocator: std.mem.Allocator,

    pub fn deinit(self: IconDir) void {
        self.allocator.free(self.entries);
    }

    pub const res_header_byte_len = 6;

    pub fn getResDataSize(self: IconDir) u32 {
        // maxInt(u16) * Entry.res_byte_len = 917,490 which is well within the u32 range.
        // Note: self.entries.len is limited to maxInt(u16)
        return @intCast(IconDir.res_header_byte_len + self.entries.len * Entry.res_byte_len);
    }

    pub fn writeResData(self: IconDir, writer: *std.Io.Writer, first_image_id: u16) !void {
        try writer.writeInt(u16, 0, .little);
        try writer.writeInt(u16, @backingInt(self.image_type), .little);
        // We know that entries.len must fit into a u16
        try writer.writeInt(u16, @as(u16, @intCast(self.entries.len)), .little);

        var image_id = first_image_id;
        for (self.entries) |entry| {
            try entry.writeResData(writer, image_id);
            image_id += 1;
        }
    }
}