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.

allocErrorBundle

Server.allocErrorBundle
pub fn allocErrorBundle(gpa: Allocator, body: []const u8) error

File

lib/std/zig/Server.zig:267

Code

pub fn allocErrorBundle(gpa: Allocator, body: []const u8) error{ OutOfMemory, EndOfStream }!std.zig.ErrorBundle {
    var r: Reader = .fixed(body);
    const hdr = r.takeStruct(OutMessage.ErrorBundle, .little) catch |err| switch (err) {
        error.EndOfStream => |e| return e,
        error.ReadFailed => unreachable,
    };

    var eb: std.zig.ErrorBundle = .{
        .string_bytes = &.{},
        .extra = &.{},
    };
    errdefer eb.deinit(gpa);

    const extra = try gpa.alloc(u32, hdr.extra_len);
    eb.extra = extra;
    const string_bytes = try gpa.alloc(u8, hdr.string_bytes_len);
    eb.string_bytes = string_bytes;

    r.readSliceEndian(u32, extra, .little) catch |err| switch (err) {
        error.EndOfStream => |e| return e,
        error.ReadFailed => unreachable,
    };
    r.readSliceAll(string_bytes) catch |err| switch (err) {
        error.EndOfStream => |e| return e,
        error.ReadFailed => unreachable,
    };

    return eb;
}