pub unsafe fn read_u128_le(bytes: &[u8]) -> u128Expand description
Unsafe, near zero cost transmutation of a byte array slice into an unsigned 128-bit integer using little-endianness.
§Safety
To make it “safe” and does not cause memory errors, you must ensure the input has at least 16 bytes prior to calling this.
§Arguments
bytes: the byte array reference
returns: u128
§Examples
use hyper_byte::read_u128_le;
let slice = [0u8; 16];
// PERFECTLY SAFE
let first_value = unsafe { read_u128_le(&slice[0..16]) };
// NOT SAFE
let second_value = unsafe { read_u128_le(&slice[9..9]) };
pub fn read_u128_safe_le(array: &[u8], index: &mut usize) -> u128 {
// "SAFE" because even if the array is not of this length,
// it will still at least panic and not cause undefined behaviour
let third_value = unsafe { read_u128_le(&array[*index..(*index+16)]) };
*index += 16;
third_value
}