1 /// Helper function for reading big endian u16 values from a ptr unchecked.
2 ///
3 /// # Safety
4 ///
5 /// It is in the responsibility of the caller to ensure there are at least 2
6 /// bytes accessable via the ptr. If this is not the case undefined behavior
7 /// will be triggered.
8 #[inline]
get_unchecked_be_u16(ptr: *const u8) -> u169 pub(crate) unsafe fn get_unchecked_be_u16(ptr: *const u8) -> u16 {
10 u16::from_be_bytes([*ptr, *ptr.add(1)])
11 }
12
13 /// Helper function for reading big endian u32 values from a ptr unchecked.
14 ///
15 /// # Safety
16 ///
17 /// It is in the responsibility of the caller to ensure there are at least 4
18 /// bytes accessable via the ptr. If this is not the case undefined behavior
19 /// will be triggered.
20 #[inline]
get_unchecked_be_u32(ptr: *const u8) -> u3221 pub(crate) unsafe fn get_unchecked_be_u32(ptr: *const u8) -> u32 {
22 u32::from_be_bytes([*ptr, *ptr.add(1), *ptr.add(2), *ptr.add(3)])
23 }
24
25 /// Helper function for reading a 4 byte fixed-size array.
26 ///
27 /// # Safety
28 ///
29 /// It is in the responsibility of the caller to ensure there are at least 4
30 /// bytes accessable via the ptr. If this is not the case undefined behavior
31 /// will be triggered.
32 #[inline]
get_unchecked_4_byte_array(ptr: *const u8) -> [u8; 4]33 pub(crate) unsafe fn get_unchecked_4_byte_array(ptr: *const u8) -> [u8; 4] {
34 [*ptr, *ptr.add(1), *ptr.add(2), *ptr.add(3)]
35 }
36
37 /// Helper function for reading a 6 byte fixed-size array.
38 ///
39 /// # Safety
40 ///
41 /// It is in the responsibility of the caller to ensure there are at least 6
42 /// bytes accessable via the ptr. If this is not the case undefined behavior
43 /// will be triggered.
44 #[inline]
get_unchecked_6_byte_array(ptr: *const u8) -> [u8; 6]45 pub(crate) unsafe fn get_unchecked_6_byte_array(ptr: *const u8) -> [u8; 6] {
46 [
47 *ptr,
48 *ptr.add(1),
49 *ptr.add(2),
50 *ptr.add(3),
51 *ptr.add(4),
52 *ptr.add(5),
53 ]
54 }
55
56 /// Helper function for reading a 8 byte fixed-size array.
57 ///
58 /// # Safety
59 ///
60 /// It is in the responsibility of the caller to ensure there are at least 6
61 /// bytes accessable via the ptr. If this is not the case undefined behavior
62 /// will be triggered.
63 #[inline]
get_unchecked_8_byte_array(ptr: *const u8) -> [u8; 8]64 pub(crate) unsafe fn get_unchecked_8_byte_array(ptr: *const u8) -> [u8; 8] {
65 [
66 *ptr,
67 *ptr.add(1),
68 *ptr.add(2),
69 *ptr.add(3),
70 *ptr.add(4),
71 *ptr.add(5),
72 *ptr.add(6),
73 *ptr.add(7),
74 ]
75 }
76
77 /// Helper function for reading a 16 byte fixed-size array.
78 ///
79 /// # Safety
80 ///
81 /// It is in the responsibility of the caller to ensure there are at least 16
82 /// bytes accessable via the ptr. If this is not the case undefined behavior
83 /// will be triggered.
84 #[inline]
get_unchecked_16_byte_array(ptr: *const u8) -> [u8; 16]85 pub(crate) unsafe fn get_unchecked_16_byte_array(ptr: *const u8) -> [u8; 16] {
86 [
87 *ptr,
88 *ptr.add(1),
89 *ptr.add(2),
90 *ptr.add(3),
91 *ptr.add(4),
92 *ptr.add(5),
93 *ptr.add(6),
94 *ptr.add(7),
95 *ptr.add(8),
96 *ptr.add(9),
97 *ptr.add(10),
98 *ptr.add(11),
99 *ptr.add(12),
100 *ptr.add(13),
101 *ptr.add(14),
102 *ptr.add(15),
103 ]
104 }
105