@@ -22,7 +22,12 @@ impl<'a> Reader<'a> {
2222 Self { buffer, off : 0 }
2323 }
2424
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 {
2631 let val = self
2732 . buffer
2833 . get ( self . off )
@@ -36,8 +41,15 @@ impl<'a> Reader<'a> {
3641 val
3742 }
3843
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
4153 }
4254
4355 const fn current_ptr ( & self ) -> * const u8 {
@@ -166,7 +178,7 @@ impl FramebufferTag {
166178 // TODO we can create a struct for this and implement
167179 // DynSizedStruct for it to leverage the already existing
168180 // functionality
169- let num_colors = reader. read_u16 ( ) ;
181+ let num_colors = reader. read_next_u16 ( ) ;
170182
171183 let palette = {
172184 // Ensure the slice can be created without causing UB
@@ -182,12 +194,12 @@ impl FramebufferTag {
182194 Ok ( FramebufferType :: Indexed { palette } )
183195 }
184196 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 ( ) ;
191203 Ok ( FramebufferType :: RGB {
192204 red : FramebufferField {
193205 position : red_pos,
0 commit comments