vint64: simple and efficient variable-length integer encoding
vint64 is an implementation of a variable-length encoding for 64-bit
little endian integers which optimizes for simplicity and performance.
This crate implements a variable-length encoding for 64-bit little endian integers with a number of properties which make it superior in almost every way to other variable-length integer encodings like LEB128, SQLite "Varuints", or CBOR:
- Capable of expressing the full 64-bit integer range with a maximum of 9-bytes
- Total length of a
vint64can be determined via the first byte alone
- Provides the most compact encoding possible for every value in range
- No loops involved in decoding: just (unaligned) loads, masks, and shifts
- No complex branch-heavy logic: decoding is CTZ + shifts and sanity checks
Some precedent for this sort of encoding can be found in the Extensible Binary Meta Language (used by e.g. the Matroska media container format), however note that the specific type of "vint" used by that format still requires a loop to decode.
Copyright © 2019-2020 iqlusion
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.