Skip to main content

Module compact

Module compact 

Expand description

The compact form a history entry takes in a change message.

An entry is a tree of JSON values; written as JSON text it repeats every key name, quotes every string and spells ids and times out in decimal and hex. Here every value is a one-byte tag and its body:

tagvalue
n f tnull, false, true
u n / i nthe integer n / −1 − n
d len textany other number, as its JSON text
s len bytesa string, UTF-8
k nthe nth of [WORDS] (keys and values every entry uses)
r nthe nth string written with s, U or H before it
U 22 digitsa lowercase hyphenated UUID
H 22 digits32 lowercase hex digits (a gesture)
[ nan array of n values
{ nan object of n keys (string values) each followed by its value

Numbers n and lengths are written six bits a byte, low bits first: a byte below 0x40 ends the number, 0x40 + bits continues it. A digit is '0' + bits (six bits). Every byte but those inside strings is below 0x80, so the whole is UTF-8 and travels as a change message does. Keys keep their order; a value decodes to exactly the tree it was written from.

[WORDS] only grows: a word’s index is part of every stored entry.

Functions§

decode
The JSON text of the value text was written from; None when it is not one whole value.
encode
The message form of value.