2p: Serialization

+cue

Unpack $atom to $noun.

Produces a $noun unpacked from $atom .a. The inverse of +jam.

Accepts

.a is an $atom.

Produces

A $noun.

Source

++  cue
  ~/  %cue
  |=  a=@
  ^-  *
  =+  b=0
  =+  m=`(map @ *)`~
  =<  q
  |-  ^-  [p=@ q=* r=(map @ *)]
  ?:  =(0 (cut 0 [b 1] a))
    =+  c=(rub +(b) a)
    [+(p.c) q.c (~(put by m) b q.c)]
  =+  c=(add 2 b)
  ?:  =(0 (cut 0 [+(b) 1] a))
    =+  u=$(b c)
    =+  v=$(b (add p.u c), m r.u)
    =+  w=[q.u q.v]
    [(add 2 (add p.u p.v)) w (~(put by r.v) b w)]
  =+  d=(rub c a)
  [(add 2 p.d) (need (~(get by m) q.d)) m]

Examples


+jam

Pack $noun to $atom.

Produces an $atom packed from $noun .a. The inverse of +cue.

Accepts

.a is a $noun.

Produces

An $atom.

Source

Examples


+mat

Length-encode.

Produces a cell whose tail .q is $atom .a with a bit representation of its length prepended to it (as the least significant bits). The head .p is the length of .q in bits.

Accepts

.a is an $atom.

Produces

A cell of two $atoms, .p and .q.

Source

Examples

Discussion

+mat is only used internally as a helper to +jam.


+rub

Length-decode.

The inverse of +mat. Accepts a cell of index .a and a bitstring .b and produces the cell whose tail .q is the decoded $atom at index .a and whose head is the length of the encoded $atom .q, by which the offset .a is advanced.

Accepts

.a is an $atom.

.b is a bitstring as an $atom.

Produces

A cell of two $atoms, .p and .q.

Source

Examples

Discussion

+rub is only used internally as a helper to +cue.


Last updated