11use crate :: leb128:: { self , max_leb128_len} ;
2- use crate :: serialize:: { self , Encoder as _} ;
2+ use crate :: serialize:: { self , Decoder as _ , Encoder as _} ;
33use std:: convert:: TryInto ;
44use std:: fs:: File ;
55use std:: io:: { self , Write } ;
@@ -548,13 +548,6 @@ impl<'a> Decoder<'a> {
548548 pub fn advance ( & mut self , bytes : usize ) {
549549 self . position += bytes;
550550 }
551-
552- #[ inline]
553- pub fn read_raw_bytes ( & mut self , bytes : usize ) -> & ' a [ u8 ] {
554- let start = self . position ;
555- self . position += bytes;
556- & self . data [ start..self . position ]
557- }
558551}
559552
560553macro_rules! read_leb128 {
@@ -662,7 +655,7 @@ impl<'a> serialize::Decoder for Decoder<'a> {
662655 }
663656
664657 #[ inline]
665- fn read_str ( & mut self ) -> & str {
658+ fn read_str ( & mut self ) -> & ' a str {
666659 let len = self . read_usize ( ) ;
667660 let sentinel = self . data [ self . position + len] ;
668661 assert ! ( sentinel == STR_SENTINEL ) ;
@@ -674,10 +667,10 @@ impl<'a> serialize::Decoder for Decoder<'a> {
674667 }
675668
676669 #[ inline]
677- fn read_raw_bytes_into ( & mut self , s : & mut [ u8 ] ) {
670+ fn read_raw_bytes ( & mut self , bytes : usize ) -> & ' a [ u8 ] {
678671 let start = self . position ;
679- self . position += s . len ( ) ;
680- s . copy_from_slice ( & self . data [ start..self . position ] ) ;
672+ self . position += bytes ;
673+ & self . data [ start..self . position ]
681674 }
682675}
683676
@@ -745,10 +738,10 @@ impl<'a> serialize::Decodable<Decoder<'a>> for IntEncodedWithFixedSize {
745738 fn decode ( decoder : & mut Decoder < ' a > ) -> IntEncodedWithFixedSize {
746739 let _start_pos = decoder. position ( ) ;
747740 let bytes = decoder. read_raw_bytes ( IntEncodedWithFixedSize :: ENCODED_SIZE ) ;
741+ let value = u64:: from_le_bytes ( bytes. try_into ( ) . unwrap ( ) ) ;
748742 let _end_pos = decoder. position ( ) ;
749743 debug_assert_eq ! ( ( _end_pos - _start_pos) , IntEncodedWithFixedSize :: ENCODED_SIZE ) ;
750744
751- let value = u64:: from_le_bytes ( bytes. try_into ( ) . unwrap ( ) ) ;
752745 IntEncodedWithFixedSize ( value)
753746 }
754747}
0 commit comments