On this page:
11.1 High-Level Interface
encode
decode
xiden-encodings
xiden-encoding/  c
encoded-file-name
11.2 UTF-8 Conversions
coerce-string
coerce-bytes
11.3 Abbreviated Decoding Procedures
abbreviated-decode-procedure/  c
hex
base64
base32
8.0

11 Codec

 (require xiden/codec) package: xiden

The xiden/codec module encodes and decodes byte strings. Note that ports are not used, so all data sits entirely in memory.

11.1 High-Level Interface

procedure

(encode encoding variant)  (or/c bytes? string?)

  encoding : xiden-encoding/c
  variant : (or/c bytes? string?)
Encodes a byte string or UTF-8 encoded string according to encoding. The return value type matches the type of variant.

procedure

(decode encoding encoded)  (or/c bytes? string?)

  encoding : xiden-encoding/c
  encoded : (or/c bytes? string?)
Decodes a byte string or UTF-8 encoded string according to encoding. The return value type matches the type of encoded.

A list of supported encodings of byte strings.

Bound to
  '(base64 base32 hex colon-separated-hex)

A contract that accepts a value in xiden-encodings.

procedure

(encoded-file-name variant)  path-string?

  variant : (or/c bytes? string?)
Returns up to the first 32 characters of (coerce-string (encode 'base32 variant)), which is suitable for use as a file name across platforms.

11.2 UTF-8 Conversions

procedure

(coerce-string v)  string?

  v : (or/c string? bytes?)
Equivalent to

(if (string? v) v (bytes->string/utf-8 v))

procedure

(coerce-bytes v)  bytes?

  v : (or/c string? bytes?)
Equivalent to

(if (bytes? v) v (string->bytes/utf-8 v))

11.3 Abbreviated Decoding Procedures

An abbreviated decoding procedure (or ADP) helps a user represent a byte string with a more convenient notation.

e.g.

(integrity 'sha384 (base64 "z/2YR1yTDC0YBvgQFpGUzXGtqZdPx+E//C2tyYNDENnLf7NGexuuDc/3yOhoGqBn"))

Decodes a hex-encoded string to bytes. The process is case-insensitive.

encoded may separate each pair of hex digits with ":".

This implies (equal? (hex "deadbeef") (hex "de:ad:be:ef")).

Decodes a Base64-encoded string to bytes.

Decodes a Base32-encoded string to bytes.