diff --git a/_includes/cheatsheet-binary.md b/_includes/cheatsheet-binary.md index f6ca30e..0acd577 100644 --- a/_includes/cheatsheet-binary.md +++ b/_includes/cheatsheet-binary.md @@ -5,8 +5,8 @@ For a value `V`, we write `«V»` for the binary encoding of `V`. «#!V» = [0x86] ++ «V» - «V» if V ∈ Float = [0x87] ++ varint(|binary32(V)|) ++ binary32(V) - «V» if V ∈ Double = [0x87] ++ varint(|binary64(V)|) ++ binary64(V) + «V» if V ∈ Float = [0x87, 0x04] ++ binary32(V) + «V» if V ∈ Double = [0x87, 0x08] ++ binary64(V) «V» if V ∈ SignedInteger = [0xB0] ++ varint(|intbytes(V)|) ++ intbytes(V) «V» if V ∈ String = [0xB1] ++ varint(|utf8(V)|) ++ utf8(V) @@ -28,10 +28,10 @@ The functions `binary32(F)` and `binary64(D)` yield big-endian 4- and The function `intbytes(x)` is a big-endian two's-complement signed binary representation of `x`, taking exactly as many whole bytes as needed to unambiguously identify the value and its -sign; in particular, `intbytes(0)` is the empty byte sequence. +sign. In particular, `intbytes(0)` is the empty byte sequence. -**Annotations.** To annotate an encoded value `«V»` (that *MUST NOT* itself already be -annotated) with some sequence of `Value`s `V_1...V_m` (that *MUST* be non-empty), +**Annotations.** To annotate an encoded value `«V»` (which *MUST NOT* itself already be +annotated) with some sequence of `Value`s `V_1...V_m` (which *MUST* be non-empty), surround `«V»` as follows: «@V_1...@V_m V» = [0xBF] ++ «V» ++ «V_1» ++...++ «V_m» ++ [0x84] diff --git a/preserves-binary.md b/preserves-binary.md index f711078..f837b48 100644 --- a/preserves-binary.md +++ b/preserves-binary.md @@ -103,19 +103,7 @@ binary representation of `x`, taking exactly as many whole bytes as needed to unambiguously identify the value and its sign. The value 0 needs zero bytes to identify the value; non-zero values need at least one byte, and the most-significant bit in the first byte is the sign -bit. For example, - - «-257» = B0 02 FE FF «-2» = B0 01 FE «255» = B0 02 00 FF - «-256» = B0 02 FF 00 «-1» = B0 01 FF «256» = B0 02 01 00 - «-255» = B0 02 FF 01 «0» = B0 00 «32767» = B0 02 7F FF - «-129» = B0 02 FF 7F «1» = B0 01 01 «32768» = B0 03 00 80 00 - «-128» = B0 01 80 «127» = B0 01 7F «65535» = B0 03 00 FF FF - «-127» = B0 01 81 «128» = B0 02 00 80 «65536» = B0 03 01 00 00 - - «87112285931760246646623899502532662132736» - = B0 12 01 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00 - 00 00 +bit. See the [examples in the appendix below](#signedinteger-examples). ### Strings, ByteStrings and Symbols. @@ -195,16 +183,9 @@ a binary-syntax document; otherwise, it should be interpreted as text. 80 - False 81 - True - (82) RESERVED - (83) RESERVED 84 - End marker - (85) RESERVED 86 - Embedded 87 - Float and Double - (8x) RESERVED 88-8F - - (9x) RESERVED - (Ax) RESERVED B0 - Integer B1 - String @@ -215,9 +196,12 @@ a binary-syntax document; otherwise, it should be interpreted as text. B6 - Set B7 - Dictionary - (Bx) RESERVED B8-BE BF - Annotated Repr (not itself starting with BF) followed by annotations +All tags fall in the range [`0x80`, `0xBF`]. + +Tag values `82`, `83`, `85`, `88`...`AF`, and `B8`...`BE` are **reserved**. + ## Appendix. Binary SignedInteger representation Languages that provide fixed-width machine word types may find the @@ -236,5 +220,19 @@ values. | -255 ≤ n < 255 (i56) | 9 | `B0` `07` `XX` `XX` `XX` `XX` `XX` `XX` `XX` | | -263 ≤ n < 263 (i64) | 10 | `B0` `08` `XX` `XX` `XX` `XX` `XX` `XX` `XX` `XX` | +## Appendix. Binary SignedInteger examples + + «-257» = B0 02 FE FF «-2» = B0 01 FE «255» = B0 02 00 FF + «-256» = B0 02 FF 00 «-1» = B0 01 FF «256» = B0 02 01 00 + «-255» = B0 02 FF 01 «0» = B0 00 «32767» = B0 02 7F FF + «-129» = B0 02 FF 7F «1» = B0 01 01 «32768» = B0 03 00 80 00 + «-128» = B0 01 80 «127» = B0 01 7F «65535» = B0 03 00 FF FF + «-127» = B0 01 81 «128» = B0 02 00 80 «65536» = B0 03 01 00 00 + + «87112285931760246646623899502532662132736» + = B0 12 01 00 00 00 00 00 00 00 + 00 00 00 00 00 00 00 00 + 00 00 + ## Notes