pub unsafe fn read_i8_be(bytes: &[u8]) -> i8Expand description
Unsafe, near zero cost transmutation of a byte array slice into a signed 8-bit integer using big-endianness.
§Safety
To make it “safe” and does not cause memory errors, you must ensure the input has at least 1 byte prior to calling this.
§Arguments
bytes: the byte array reference
returns: i8
§Examples
use hyper_byte::read_i8_be;
let slice = [0u8; 16];
// PERFECTLY SAFE
let first_value = unsafe { read_i8_be(&slice[0..2]) };
// NOT SAFE
let second_value = unsafe { read_i8_be(&slice[9..9]) };
pub fn read_i8_safe_be(array: &[u8], index: &mut usize) -> i8 {
// "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_i8_be(&array[*index..(*index+1)]) };
*index += 1;
third_value
}