@@ -22,7 +22,12 @@ impl<'a> Reader<'a> {
22
22
Self { buffer, off : 0 }
23
23
}
24
24
25
- fn read_u8 ( & mut self ) -> u8 {
25
+ /// Reads the next [`u8`] from the buffer and updates the internal pointer.
26
+ ///
27
+ /// # Panic
28
+ ///
29
+ /// Panics if the index is out of bounds.
30
+ fn read_next_u8 ( & mut self ) -> u8 {
26
31
let val = self
27
32
. buffer
28
33
. get ( self . off )
@@ -36,8 +41,15 @@ impl<'a> Reader<'a> {
36
41
val
37
42
}
38
43
39
- fn read_u16 ( & mut self ) -> u16 {
40
- self . read_u8 ( ) as u16 | ( self . read_u8 ( ) as u16 ) << 8
44
+ /// Reads the next [`u16`] from the buffer and updates the internal pointer.
45
+ ///
46
+ /// # Panic
47
+ ///
48
+ /// Panics if the index is out of bounds.
49
+ fn read_next_u16 ( & mut self ) -> u16 {
50
+ let u16_lo = self . read_next_u8 ( ) as u16 ;
51
+ let u16_hi = self . read_next_u8 ( ) as u16 ;
52
+ ( u16_hi << 8 ) | u16_lo
41
53
}
42
54
43
55
const fn current_ptr ( & self ) -> * const u8 {
@@ -166,7 +178,7 @@ impl FramebufferTag {
166
178
// TODO we can create a struct for this and implement
167
179
// DynSizedStruct for it to leverage the already existing
168
180
// functionality
169
- let num_colors = reader. read_u16 ( ) ;
181
+ let num_colors = reader. read_next_u16 ( ) ;
170
182
171
183
let palette = {
172
184
// Ensure the slice can be created without causing UB
@@ -182,12 +194,12 @@ impl FramebufferTag {
182
194
Ok ( FramebufferType :: Indexed { palette } )
183
195
}
184
196
FramebufferTypeId :: RGB => {
185
- let red_pos = reader. read_u8 ( ) ; // These refer to the bit positions of the LSB of each field
186
- let red_mask = reader. read_u8 ( ) ; // And then the length of the field from LSB to MSB
187
- let green_pos = reader. read_u8 ( ) ;
188
- let green_mask = reader. read_u8 ( ) ;
189
- let blue_pos = reader. read_u8 ( ) ;
190
- let blue_mask = reader. read_u8 ( ) ;
197
+ let red_pos = reader. read_next_u8 ( ) ; // These refer to the bit positions of the LSB of each field
198
+ let red_mask = reader. read_next_u8 ( ) ; // And then the length of the field from LSB to MSB
199
+ let green_pos = reader. read_next_u8 ( ) ;
200
+ let green_mask = reader. read_next_u8 ( ) ;
201
+ let blue_pos = reader. read_next_u8 ( ) ;
202
+ let blue_mask = reader. read_next_u8 ( ) ;
191
203
Ok ( FramebufferType :: RGB {
192
204
red : FramebufferField {
193
205
position : red_pos,
0 commit comments