ENCODE(3)
ENCODE(3) π
β encoding byte arrays as strings
okay so bestie, this is the Library Functions Manual page for ENCODE(3), and itβs literally all about turning byte arrays into cute little strings and decoding them right back. no cap, itβs giving encoding core. β¨
πΈ NAME πΈ
dec64, enc64, dec32, enc32, dec16, enc16, encodefmt β encoding byte arrays as strings. the whole squad is here. π
β¨ SYNOPSIS β¨
#include <u.h>
#include <libc.h>
int dec64(uchar *out, int lim, char *in, int n)
int enc64(char *out, int lim, uchar *in, int n)
int dec32(uchar *out, int lim, char *in, int n)
int enc32(char *out, int lim, uchar *in, int n)
int dec16(uchar *out, int lim, char *in, int n)
int enc16(char *out, int lim, uchar *in, int n)
int encodefmt(Fmt*)
π DESCRIPTION π
so like, enc16, enc32, and enc64 create null terminated strings. they return the size of the encoded string (without the null) or -1 if the encoding fails. and the encoding fails if lim, the length of the output buffer, is too small. thatβs the whole boundary-check vibe, bestie. π«Ά
dec16, dec32, and dec64 return the number of bytes decoded or -1 if the decoding fails. the decoding fails if the output buffer is not large enough or, for base 32, if the input buffer length is not a multiple of 8. yes, base 32 is out here with its own multiple-of-8 vibe check. π
encodefmt can be used with fmtinstall(3) and print(3) to print encoded representations of byte arrays. the verbs are:
Hβ base 16 (i.e. hexadecimal). the default encoding is in upper case. thelflag forces lower case. π<β base 32.[β base 64 (same as MIME).
the length of the array is specified as f2. for example, to display a 15 byte array as hex:
char x[15];
fmtinstall('H', encodefmt);
print("%.*H\n", sizeof x, x);
π SOURCE π
/src/lib9/u32.c/src/lib9/u64.c
cute little sign-off: this page is from the Library Functions Manual, titled ENCODE(3), with source files /src/lib9/u32.c and /src/lib9/u64.c. the original footer had no extra version or date beyond that manual name, so this is the whole sparkly receipt. πβ¨
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms