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
use std::mem::size_of;

pub mod error;
pub mod prelude;
mod primitive;

pub use bytes;
pub use faster_hex;

// Little Endian
pub type Number = u32;
// Size of Number
pub const NUMBER_SIZE: usize = size_of::<Number>();

#[inline]
pub fn unpack_number(slice: &[u8]) -> Number {
    #[allow(clippy::cast_ptr_alignment)]
    let le = slice.as_ptr() as *const Number;
    Number::from_le(unsafe { *le })
}

#[inline]
pub fn pack_number(num: Number) -> [u8; 4] {
    num.to_le_bytes()
}

#[inline]
pub fn unpack_number_vec(slice: &[u8]) -> &[[u8; 4]] {
    #[allow(clippy::cast_ptr_alignment)]
    unsafe {
        &*(slice as *const [u8] as *const [[u8; 4]])
    }
}