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.
Zig › build-web/ › main.zig › helloMessage
helloMessage
main.helloMessage
fn helloMessage (msg_bytes : []align (4 ) u8 ) Allocator .Error !void
File
Code
fn helloMessage (msg_bytes : []align (4 ) u8 ) Allocator .Error !void {
if (msg_bytes .len < @sizeOf (abi .Hello )) @panic ("malformed Hello message" );
const hdr : *const abi .Hello = @ptrCast (msg_bytes [0 ..@sizeOf (abi .Hello )]);
const trailing = msg_bytes [@sizeOf (abi .Hello )..];
client_base_timestamp = js .timestamp ();
server_base_timestamp = hdr .timestamp ;
const steps = try gpa .alloc (Step , hdr .steps_len );
errdefer gpa .free (steps );
const step_name_lens : []align (1 ) const u32 = @ptrCast (trailing [0 .. steps .len * 4 ]);
const step_name_data_len : usize = len : {
var sum : usize = 0 ;
for (step_name_lens ) |n | sum += n ;
break :len sum ;
};
const step_name_data : []const u8 = trailing [steps .len * 4 ..][0 ..step_name_data_len ];
const step_status_bits : []const u8 = trailing [steps .len * 4 + step_name_data_len ..];
const duped_step_name_data = try gpa .dupe (u8 , step_name_data );
errdefer gpa .free (duped_step_name_data );
var name_off : usize = 0 ;
for (steps , step_name_lens , 0 ..) |*step_out , name_len , step_idx | {
step_out .* = .{
.name = duped_step_name_data [name_off ..][0 ..name_len ],
.status = @fromBackingInt (@intCast (@as (u2 , @truncate (step_status_bits [step_idx / 4 ] >> @intCast ((step_idx % 4 ) * 2 ))))),
};
name_off += name_len ;
}
gpa .free (step_list );
gpa .free (step_list_data );
step_list = steps ;
step_list_data = duped_step_name_data ;
js .hello (step_list .len , hdr .status , hdr .flags .time_report );
}