The q* stdlib docs
qencoding: base64 & hex codecs
qencoding provides the encoding.* built-ins: base64 and hex codecs implemented from scratch with zero third-party dependencies. base64 follows RFC 4648 (standard +/ alphabet with = padding); hex encodes to lowercase. Encoding takes a string (its UTF-8 bytes) or raw bytes and returns the encoded string; decoding takes the encoded string and returns the decoded text.
What it gives you#
qencoding registers four public built-ins, all single-argument, following the shared DMS convention.
| Function | Input | Output | Notes |
|---|---|---|---|
| encoding.base64_encode | Str (UTF-8 bytes) or Bytes | Str | RFC 4648 standard alphabet, = padding. |
| encoding.base64_decode | Str | Str | Ignores whitespace and = padding. |
| encoding.hex_encode | Str (UTF-8 bytes) or Bytes | Str | Lowercase hex, two chars per byte. |
| encoding.hex_decode | Str | Str | Accepts upper or lower case; skips non-hex chars. |
base64 details#
base64_encode uses the standard alphabet A-Z a-z 0-9 + / and pads the final group with = so the output length is always a multiple of four. base64_decode is forgiving: it filters out = padding and any ASCII whitespace before decoding, and ignores characters outside the alphabet, peeling out whole bytes from the bit stream.
Known vectors from the source confirm the encoder: "Man" encodes to TWFu, "Ma" to TWE=, and "M" to TQ==.
hex details#
hex_encode emits two lowercase hex digits per byte (digits 0-9 and a-f). hex_decode accepts both upper and lower case, drops any non-hex characters, and combines digits in pairs — a trailing odd digit is dropped. For example "AB" hex-encodes to 4142 (the ASCII codes of A and B).
Reusable library helpers#
base64_encode and base64_decode are also exposed as plain public functions (not just QQL built-ins) so other crates can reuse them directly — for instance the WebSocket handshake and the crypto package's password hashing both call base64_encode. The public encoding.* built-ins are reachable from QQL but not through that internal helper path.
Resource budget#
The encoding.* built-ins declare an empty resource request (no fixed memory or storage reservation) — they do lightweight, bounded byte-level work.
Example#
Encoding the string "Man" to base64 yields the canonical three-byte-to-four-char result.
Request
encoding.base64_encode("Man")
# wire form:
{ "0": { "Str": "Man" } }Response
{ "result": { "Str": "TWFu" } }Output
TWFuRequest
encoding.hex_encode("AB")
encoding.base64_decode("TWFu")Response
{ "result": { "Str": "4142" } }
{ "result": { "Str": "Man" } }Output
4142
Man