Encoding
Source: std/encoding.mw.
Hex, Base64 (standard and URL-safe) and UTF-8 validation and conversion.
Hex, Base64 (RFC 4648, standard and URL-safe) and UTF-8 helpers. Encoders write into a caller buffer and return the length; decoders return the decoded length or -1 on malformed input. *_len helpers give the worst-case output size.
Functions
Section titled “Functions”hex_encode_len
Section titled “hex_encode_len”fn hex_encode_len(n: i64) -> i64hex_decode_len
Section titled “hex_decode_len”fn hex_decode_len(n: i64) -> i64hex_encode
Section titled “hex_encode”fn hex_encode(src: *u8, n: i64, out: *u8) -> i64hex_decode
Section titled “hex_decode”fn hex_decode(src: *u8, n: i64, out: *u8) -> i64base64_encode_len
Section titled “base64_encode_len”fn base64_encode_len(n: i64) -> i64base64_decode_len
Section titled “base64_decode_len”fn base64_decode_len(n: i64) -> i64base64_encode
Section titled “base64_encode”fn base64_encode(src: *u8, n: i64, out: *u8) -> i64base64url_encode
Section titled “base64url_encode”fn base64url_encode(src: *u8, n: i64, out: *u8) -> i64URL-safe alphabet, no padding (as used by JWT).
base64_decode
Section titled “base64_decode”fn base64_decode(src: *u8, n: i64, out: *u8) -> i64Accepts both alphabets, optional padding, and skips ASCII whitespace (so PEM bodies can be decoded directly).
utf8_valid
Section titled “utf8_valid”fn utf8_valid(s: *u8, n: i64) -> boolutf8_count
Section titled “utf8_count”fn utf8_count(s: *u8, n: i64) -> i64utf8_decode
Section titled “utf8_decode”fn utf8_decode(s: *u8, n: i64, len: *i64) -> i64Decodes one code point; stores its byte length in *len. Returns -1 if malformed.
utf8_encode
Section titled “utf8_encode”fn utf8_encode(cp: i64, out: *u8) -> i64Encodes a code point into out (up to 4 bytes); returns the length, 0 if invalid.