Skip to main content

Module readable

Module readable 

Source
Expand description

Readable, indented Links Notation representation.

This module implements the default output of crate::encode: a plain-text, indented projection where keys and values are written as they are, so the file can be read, grepped and reviewed without decoding anything.

§Shape

One construct — ( ) — is used for both objects and arrays, at every level including the root. What distinguishes them is the content of the lines: key value pairs make an object, bare values make an array.

(
  type "RouterState"
  server (
    host "127.0.0.1"
    port 18878
  )
  models (
    "claude-haiku"
    "claude-opus"
  )
)

§Value mapping

LinoValueReadable form
Object( ) with one key value pair per line
Array( ) with one value per line
Stringquoted, never encoded
Int / Float / Bool / Nullbare, so the type survives the round trip

Empty containers keep their type: an empty array is () on one line, while an empty object is written as ( and ) on two lines.

Only values that cannot be written as plain text are encoded: strings holding control characters (including newlines and tabs, which line-based tooling and CRLF normalisation would corrupt) are marked individually as (base64 "…") instead of encoding the whole document.

§Single-line form

encode_line writes the same document on one line, so one record is one line and an append-only log stays greppable, tailable and countable by wc -l. Rows can no longer be told apart by line breaks there, so an object names itself with the o link id the notation already has, and its pairs are written as their own links:

(o: (type "RouterState") (server (o: (host "127.0.0.1") (port 18878))) (models ("claude-haiku" "claude-opus")))
ValueSingle-line form
Object(o: (key value) …)
empty Object(o:)
Array(value …)
empty Array()
scalarsexactly as in the indented form

The marker is what answers the ambiguity a flat layout otherwise has: without it ((key value)) reads both as the one-pair object and as the array holding the two-element array, and an empty key makes it worse. With it, a bare ( ) is always an array and a marked one is always an object, so every value — empty key included — survives the round trip. Consequently a hand-written one-line link such as (a 1) is the two-element array, not the one-pair object: on one line, objects say so.

Constants§

BASE64_MARKER
Marker used for values that cannot be represented as plain text.
DEFAULT_INDENT
Default indentation used by encode.
OBJECT_MARKER
Link id naming an object in the single-line form, written as (o: …).

Functions§

decode
Decode the readable, indented Links Notation form back into a value.
decode_line
Decode the readable, single-line Links Notation form back into a value.
encode
Encode a value into the readable, indented Links Notation form.
encode_line
Encode a value into the readable, single-line Links Notation form.