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 › std/ › http/ › Client.zig › basic_authorization
basic_authorization
Client.basic_authorization
pub const basic_authorization = struct
File
Code
pub const basic_authorization = struct {
pub const max_user_len = 255 ;
pub const max_password_len = 255 ;
pub const max_value_len = valueLength (max_user_len , max_password_len );
pub fn valueLength (user_len : usize , password_len : usize ) usize {
return "Basic " .len + std .base64 .standard .Encoder .calcSize (user_len + 1 + password_len );
}
pub fn valueLengthFromUri (uri : Uri ) usize {
const user : Uri .Component = uri .user orelse .empty ;
const password : Uri .Component = uri .password orelse .empty ;
var dw : Writer .Discarding = .init (&.{});
user .formatUser (&dw .writer ) catch unreachable ;
const user_len = dw .count + dw .writer .end ;
dw .count = 0 ;
dw .writer .end = 0 ;
password .formatPassword (&dw .writer ) catch unreachable ;
const password_len = dw .count + dw .writer .end ;
return valueLength (@intCast (user_len ), @intCast (password_len ));
}
pub fn value (uri : Uri , out : []u8 ) []u8 {
var bw : Writer = .fixed (out );
write (uri , &bw ) catch unreachable ;
return bw .buffered ();
}
pub fn write (uri : Uri , out : *Writer ) Writer .Error !void {
var buf : [max_user_len + 1 + max_password_len ]u8 = undefined ;
var w : Writer = .fixed (&buf );
const user : Uri .Component = uri .user orelse .empty ;
const password : Uri .Component = uri .password orelse .empty ;
user .formatUser (&w ) catch unreachable ;
w .writeByte (':' ) catch unreachable ;
password .formatPassword (&w ) catch unreachable ;
try out .print ("Basic {b64}" , .{w .buffered ()});
}
}