compact_u64

Crates.iocompact_u64
lib.rscompact_u64
version0.2.1
created_at2025-04-09 10:01:58.47678+00
updated_at2025-09-22 19:16:17.066086+00
descriptionA machine-friendly varint.
homepage
repository
max_upload_size
id1626498
size44,975
Aljoscha Meyer (AljoschaMeyer)

documentation

README

Compact U64

A machine-friendly varint, implemented in Rust.

The general idea is the following:

  • Each encoding is preceeded by a tag of two to eight (inclusive) bits.
  • Each u64 can be encoded by setting the tag to the greatest possible number and then encoding the u64 as an eight-byte big-endian integer.
  • Each u64 that fits into four bytes can be encoded by setting the tag to the second-greatest possible number and then encoding the u64 as an four-byte big-endian integer.
  • Each u64 that fits into two bytes can be encoded by setting the tag to the third-greatest possible number and then encoding the u64 as an two-byte big-endian integer.
  • Each u64 that fits into one byte can be encoded by setting the tag to the fourth-greatest possible number and then encoding the u64 as an one-byte big-endian integer.
  • If the tag has more than two bits, then each u64 that is less than the fourth-greatest tag can be encoded in the tag directly, followed by no further bytes.
Commit count: 0

cargo fmt