preserves/_includes/cheatsheet-binary.md

2.8 KiB
Raw Blame History

For a value V, we write «V» for the binary encoding of V.

{:.postcard-grammar.binarysyntax} «#f» | = | 80 «#t» | = | 81

{:.postcard-grammar.binarysyntax} «@W V» | = | 85 «W» «V» «#!V» | = | 86 «V»

{:.postcard-grammar.binarysyntax} «V» | = | 87``08 binary64(V) | if V ∈ Double

{:.postcard-grammar.binarysyntax} «V» | = | B0 varint(|intbytes(V)|) intbytes(V) | if V ∈ SignedInteger «V» | = | B1 varint(|utf8(V)|) utf8(V) | if V ∈ String «V» | = | B2 varint(|V|) V | if V ∈ ByteString «V» | = | B3 varint(|utf8(V)|) utf8(V) | if V ∈ Symbol

{:.postcard-grammar.binarysyntax} «<L F1 ... Fm>» | = | B4 «L» «F1» ... «Fm» 84 «[X1 ... Xm]» | = | B5 «X1» ... «Xm» 84 «#{E1 ... Em}» | = | B6 «E1» ... «Em» 84 «{K1:V1 ... Km:Vm}» | = | B7 «K1» «V1» ... «Km» «Vm» 84

{:.postcard-grammar.binarysyntax} varint(n) | = | n | if n < 128 | | (n & 127) | 128 varint(n >> 7) | if n ≥ 128

{:.postcard-grammar.binarysyntax} intbytes(n) | = | the empty sequence if n = 0, otherwise signedBigEndian(n)

{:.postcard-grammar.binarysyntax} signedBigEndian(n) | = | n & 255 | if 128 ≤ n ≤ 127 | | signedBigEndian(n >> 8) n & 255 | otherwise

The function binary64(D) yields the big-endian 8-byte IEEE 754 binary representation of D.