UNPKG

1.05 kBTypeScriptView Raw
1/**
2 * @description
3 * Encoding and decoding of parity-codec compact numbers. The codec is created
4 * to take up the least amount of space for a specific number. It performs the
5 * same function as Length, however differs in that it uses a variable number of
6 * bytes to do the actual encoding. From the Rust implementation for compact
7 * encoding:
8 *
9 * 0b00 00 00 00 / 00 00 00 00 / 00 00 00 00 / 00 00 00 00
10 * (0 ... 2**6 - 1) (u8)
11 * xx xx xx 00
12 * (2**6 ... 2**14 - 1) (u8, u16) low LH high
13 * yL yL yL 01 / yH yH yH yL
14 * (2**14 ... 2**30 - 1) (u16, u32) low LMMH high
15 * zL zL zL 10 / zM zM zM zL / zM zM zM zM / zH zH zH zM
16 * (2**30 ... 2**536 - 1) (u32, u64, u128, U256, U512, U520) straight LE-encoded
17 * nn nn nn 11 [ / zz zz zz zz ]{4 + n}
18 *
19 * Note: we use *LOW BITS* of the LSB in LE encoding to encode the 2 bit key.
20 */
21export { compactAddLength } from './addLength';
22export { compactStripLength } from './stripLength';
23export { compactFromU8a } from './fromU8a';
24export { compactToU8a } from './toU8a';