1
1
use crate :: leb128:: { self , max_leb128_len} ;
2
- use crate :: serialize:: { self , Encoder as _} ;
2
+ use crate :: serialize:: { self , Decoder as _ , Encoder as _} ;
3
3
use std:: convert:: TryInto ;
4
4
use std:: fs:: File ;
5
5
use std:: io:: { self , Write } ;
@@ -548,13 +548,6 @@ impl<'a> Decoder<'a> {
548
548
pub fn advance ( & mut self , bytes : usize ) {
549
549
self . position += bytes;
550
550
}
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
- }
558
551
}
559
552
560
553
macro_rules! read_leb128 {
@@ -662,7 +655,7 @@ impl<'a> serialize::Decoder for Decoder<'a> {
662
655
}
663
656
664
657
#[ inline]
665
- fn read_str ( & mut self ) -> & str {
658
+ fn read_str ( & mut self ) -> & ' a str {
666
659
let len = self . read_usize ( ) ;
667
660
let sentinel = self . data [ self . position + len] ;
668
661
assert ! ( sentinel == STR_SENTINEL ) ;
@@ -674,10 +667,10 @@ impl<'a> serialize::Decoder for Decoder<'a> {
674
667
}
675
668
676
669
#[ inline]
677
- fn read_raw_bytes_into ( & mut self , s : & mut [ u8 ] ) {
670
+ fn read_raw_bytes ( & mut self , bytes : usize ) -> & ' a [ u8 ] {
678
671
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 ]
681
674
}
682
675
}
683
676
@@ -745,10 +738,10 @@ impl<'a> serialize::Decodable<Decoder<'a>> for IntEncodedWithFixedSize {
745
738
fn decode ( decoder : & mut Decoder < ' a > ) -> IntEncodedWithFixedSize {
746
739
let _start_pos = decoder. position ( ) ;
747
740
let bytes = decoder. read_raw_bytes ( IntEncodedWithFixedSize :: ENCODED_SIZE ) ;
741
+ let value = u64:: from_le_bytes ( bytes. try_into ( ) . unwrap ( ) ) ;
748
742
let _end_pos = decoder. position ( ) ;
749
743
debug_assert_eq ! ( ( _end_pos - _start_pos) , IntEncodedWithFixedSize :: ENCODED_SIZE ) ;
750
744
751
- let value = u64:: from_le_bytes ( bytes. try_into ( ) . unwrap ( ) ) ;
752
745
IntEncodedWithFixedSize ( value)
753
746
}
754
747
}
0 commit comments