pub fn encode_varint(value: u64, buf: &mut [u8]) -> usizeExpand description
Encode a u64 value as an unsigned LEB128 varint into the provided buffer.
§Returns
The number of bytes written (1–10).
§Panics
Panics if buf is shorter than the required encoding length.
A 10-byte buffer is always sufficient for any u64.
§Wire format examples
| Value | Encoded bytes | Length |
|---|---|---|
| 0 | [0x00] | 1 |
| 1 | [0x01] | 1 |
| 127 | [0x7F] | 1 |
| 128 | [0x80, 0x01] | 2 |
| 300 | [0xAC, 0x02] | 2 |
| 16383 | [0xFF, 0x7F] | 2 |
| 16384 | [0x80, 0x80, 0x01] | 3 |