Values

Bytes

Bytes encode themselves.

byte::=0x000x00||0xFF0xFF

Integers

All integers are encoded using the LEB128 variable-length integer encoding, in either unsigned or signed variant.

Unsigned integers are encoded in unsigned LEB128 format. As an additional constraint, the total number of bytes encoding a value of type uN must not exceed ceil(N/7) bytes.

uN::=n:byten(ifn<27n<2N)|n:byte  m:u(N7)27m+(n27)(ifn27N>7)

Signed integers are encoded in signed LEB128 format, which uses a two’s complement representation. As an additional constraint, the total number of bytes encoding a value of type sN must not exceed ceil(N/7) bytes.

sN::=n:byten(ifn<26n<2N1)|n:byten27(if26n<27n272N1)|n:byte  m:s(N7)27m+(n27)(ifn27N>7)

Uninterpreted integers are encoded as signed integers.

iN::=n:sNi(ifn=signedN(i))

Note

The side conditions N>7 in the productions for non-terminal bytes of the u and s encodings restrict the encoding’s length. However, “trailing zeros” are still allowed within these bounds. For example, 0x03 and 0x83 0x00 are both well-formed encodings for the value 3 as a u8. Similarly, either of 0x7e and 0xFE 0x7F and 0xFE 0xFF 0x7F are well-formed encodings of the value 2 as a s16.

The side conditions on the value n of terminal bytes further enforce that any unused bits in these bytes must be 0 for positive values and 1 for negative ones. For example, 0x83 0x10 is malformed as a u8 encoding. Similarly, both 0x83 0x3E and 0xFF 0x7B are malformed as s8 encodings.

Floating-Point

Floating-point values are encoded directly by their IEEE 754 (Section 3.4) bit pattern in little endian byte order:

fN::=b:byteN/8bytesfN1(b)

Names

Names are encoded as a vector of bytes containing the Unicode (Section 3.9) UTF-8 encoding of the name’s character sequence.

name::=b:vec(byte)name(ifutf8(name)=b)

The auxiliary utf8 function expressing this encoding is defined as follows:

utf8(c)=(utf8(c))utf8(c)=b(ifc<U+80c=b)utf8(c)=b1 b2(ifU+80c<U+800c=26(b10xC0)+(b20x80))utf8(c)=b1 b2 b3(ifU+800c<U+D800U+E000c<U+10000c=212(b10xE0)+26(b20x80)+(b30x80))utf8(c)=b1 b2 b3 b4(ifU+10000c<U+110000c=218(b10xF0)+212(b20x80)+26(b30x80)+(b40x80))whereb2,b3,b4<0xC0

Note

Unlike in some other formats, name strings are not 0-terminated.