Function varint_simd::decode
source · pub fn decode<T: VarIntTarget>(
bytes: &[u8]
) -> Result<(T, usize), VarIntDecodeError>
Expand description
Decodes a single varint from the input slice.
Produces a tuple containing the decoded number and the number of bytes read. For best performance, provide a slice at least 16 bytes in length, or use the unsafe version directly.
Examples
use varint_simd::{decode, VarIntDecodeError};
fn main() -> Result<(), VarIntDecodeError> {
let decoded = decode::<u32>(&[185, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])?;
assert_eq!(decoded, (1337, 2));
Ok(())
}