1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
//! Fast serialization of integers.
//!
//! This crate implements encoding and decoding of integer types to and from `FixedInt` (i.e. a
//! representation of integers similar or equal to how they are stored in memory) as well as
//! `VarInt` (encoding integers so that they only use as much memory as needed to represent their
//! magnitude).
//!
//! This is useful when (de)serializing data from and to binary representations. For example,
//! Protocol Buffers (by Google) use these kinds of encoding.
//!
//! ```
//! use integer_encoding::*;
//!
//! fn main() {
//! let a: u32 = 344;
//! let encoded_byte_slice = a.encode_fixed_light();
//! assert_eq!(Some(a), u32::decode_fixed(&encoded_byte_slice));
//! assert_eq!(4, encoded_byte_slice.len());
//!
//! let b: i32 = -111;
//! let encoded_byte_vec = b.encode_var_vec();
//! assert_eq!(Some((b, 2)), i32::decode_var(&encoded_byte_vec));
//! }
//! ```
#[forbid(unsafe_code)]
mod fixed;
mod fixed_tests;
mod varint;
mod varint_tests;
mod reader;
mod writer;
pub use fixed::FixedInt;
pub use varint::VarInt;
#[cfg(any(feature = "tokio_async", feature = "futures_async"))]
pub use reader::FixedIntAsyncReader;
pub use reader::FixedIntReader;
#[cfg(any(feature = "tokio_async", feature = "futures_async"))]
pub use reader::VarIntAsyncReader;
pub use reader::VarIntReader;
#[cfg(any(feature = "tokio_async", feature = "futures_async"))]
pub use writer::FixedIntAsyncWriter;
pub use writer::FixedIntWriter;
#[cfg(any(feature = "tokio_async", feature = "futures_async"))]
pub use writer::VarIntAsyncWriter;
pub use writer::VarIntWriter;