@@ -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,9 +41,14 @@ impl<'a> Reader<'a> {
36
41
val
37
42
}
38
43
39
- fn read_u16 ( & mut self ) -> u16 {
40
- let u16_lo = self . read_u8 ( ) as u16 ;
41
- let u16_hi = self . read_u8 ( ) as u16 ;
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 ;
42
52
( u16_hi << 8 ) | u16_lo
43
53
}
44
54
@@ -168,7 +178,7 @@ impl FramebufferTag {
168
178
// TODO we can create a struct for this and implement
169
179
// DynSizedStruct for it to leverage the already existing
170
180
// functionality
171
- let num_colors = reader. read_u16 ( ) ;
181
+ let num_colors = reader. read_next_u16 ( ) ;
172
182
173
183
let palette = {
174
184
// Ensure the slice can be created without causing UB
@@ -184,12 +194,12 @@ impl FramebufferTag {
184
194
Ok ( FramebufferType :: Indexed { palette } )
185
195
}
186
196
FramebufferTypeId :: RGB => {
187
- let red_pos = reader. read_u8 ( ) ; // These refer to the bit positions of the LSB of each field
188
- let red_mask = reader. read_u8 ( ) ; // And then the length of the field from LSB to MSB
189
- let green_pos = reader. read_u8 ( ) ;
190
- let green_mask = reader. read_u8 ( ) ;
191
- let blue_pos = reader. read_u8 ( ) ;
192
- 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 ( ) ;
193
203
Ok ( FramebufferType :: RGB {
194
204
red : FramebufferField {
195
205
position : red_pos,
0 commit comments