|
3 | 3 | [](https://github.com/bbqsrc/fastvlq/actions) |
4 | 4 | [](https://docs.rs/fastvlq) |
5 | 5 |
|
6 | | -Encode and decode with a variant of [variable-length quantity](https://en.wikipedia.org/wiki/Variable-length_quantity) data. |
| 6 | +A fast variant of [variable-length quantity](https://en.wikipedia.org/wiki/Variable-length_quantity) encoding with a focus on speed and `no_std` support. |
7 | 7 |
|
8 | | -The algorithm uses leading zeros to count how many bytes are required for decoding. |
| 8 | +The algorithm uses leading zeros in the first byte to determine how many bytes are required for decoding, allowing the length to be known immediately without parsing the entire value. |
| 9 | + |
| 10 | +## Supported Types |
| 11 | + |
| 12 | +| Type | Max Bytes | |
| 13 | +|------|-----------| |
| 14 | +| `Vu32` | 5 | |
| 15 | +| `Vi32` | 5 | |
| 16 | +| `Vu64` | 9 | |
| 17 | +| `Vi64` | 9 | |
| 18 | +| `Vu128` | 18 | |
| 19 | +| `Vi128` | 18 | |
| 20 | + |
| 21 | +Signed types (`Vi*`) use zigzag encoding for efficient storage of small absolute values. |
| 22 | + |
| 23 | +## Vu64 Compression |
| 24 | + |
| 25 | +| Bytes | Min | Max | |
| 26 | +|-------|-----|-----| |
| 27 | +| 1 | 0 | 127 (0x7F) | |
| 28 | +| 2 | 128 (0x80) | 16,511 (0x407F) | |
| 29 | +| 3 | 16,512 (0x4080) | 2,113,663 (0x20407F) | |
| 30 | +| 4 | 2,113,664 (0x204080) | 270,549,119 (0x1020407F) | |
| 31 | +| 5 | 270,549,120 (0x10204080) | 34,630,287,487 (0x81020407F) | |
| 32 | +| 6 | 34,630,287,488 (0x810204080) | 4,432,676,798,591 (0x4081020407F) | |
| 33 | +| 7 | 4,432,676,798,592 (0x40810204080) | 567,382,630,219,903 (0x204081020407F) | |
| 34 | +| 8 | 567,382,630,219,904 (0x2040810204080) | 72,624,976,668,147,839 (0x10204081020407F) | |
| 35 | +| 9 | 72,624,976,668,147,840 (0x102040810204080) | 18,446,744,073,709,551,615 (0xFFFFFFFFFFFFFFFF) | |
9 | 36 |
|
10 | 37 | ## Usage |
11 | 38 |
|
12 | 39 | Add this to your `Cargo.toml`: |
13 | 40 |
|
14 | 41 | ```toml |
15 | 42 | [dependencies] |
16 | | -fastvlq = "1" |
| 43 | +fastvlq = "2" |
17 | 44 | ``` |
18 | 45 |
|
| 46 | +## Features |
| 47 | + |
| 48 | +- `std` (default) - Enables `Read`/`Write` extension traits |
| 49 | +- `async` - Enables async `Read`/`Write` extension traits via `futures-io` |
| 50 | + |
19 | 51 | ## Where is this used? |
20 | 52 |
|
21 | 53 | * [box](https://github.com/bbqsrc/box) - a modern replacement for the zip file format |
|
0 commit comments