@@ -440,6 +440,13 @@ impl<'a> TBinaryUnsafeInputProtocol<'a> {
440440 pub fn index ( & self ) -> usize {
441441 self . index
442442 }
443+
444+ #[ doc( hidden) ]
445+ fn advance ( & mut self , len : usize ) {
446+ self . trans . advance ( len) ;
447+ self . buf . advance ( len) ;
448+ self . index -= len;
449+ }
443450}
444451
445452impl < ' a > TLengthProtocol for TBinaryUnsafeInputProtocol < ' a > {
@@ -615,6 +622,7 @@ impl<'a> TInputProtocol for TBinaryUnsafeInputProtocol<'a> {
615622 let name = self . read_faststr ( ) ?;
616623
617624 let sequence_number = self . read_i32 ( ) ?;
625+ self . advance ( self . index ) ;
618626 Ok ( TMessageIdentifier :: new ( name, message_type, sequence_number) )
619627 }
620628
@@ -668,8 +676,9 @@ impl<'a> TInputProtocol for TBinaryUnsafeInputProtocol<'a> {
668676 #[ inline]
669677 fn read_bytes ( & mut self ) -> Result < Bytes , ThriftException > {
670678 let len = self . read_i32 ( ) ?;
671- let val = Bytes :: copy_from_slice ( & self . buf [ self . index ..self . index + len as usize ] ) ;
672- self . index += len as usize ;
679+ self . advance ( self . index ) ;
680+ let val = Bytes :: copy_from_slice ( & self . trans . split_to ( len as usize ) ) ;
681+ self . buf = unsafe { slice:: from_raw_parts ( self . trans . as_ptr ( ) , self . trans . len ( ) ) } ;
673682 Ok ( val)
674683 }
675684
@@ -681,11 +690,10 @@ impl<'a> TInputProtocol for TBinaryUnsafeInputProtocol<'a> {
681690 ) -> Result < Bytes , ThriftException > {
682691 if ptr. is_none ( ) {
683692 len -= self . index ;
684- self . trans . advance ( self . index ) ;
693+ self . advance ( self . index ) ;
685694 }
686695 self . index = 0 ;
687- let val = Bytes :: copy_from_slice ( & self . buf [ self . index ..self . index + len] ) ;
688- self . trans . advance ( len) ;
696+ let val = Bytes :: copy_from_slice ( & self . trans . split_to ( len) ) ;
689697 self . buf = unsafe { slice:: from_raw_parts ( self . trans . as_ptr ( ) , self . trans . len ( ) ) } ;
690698
691699 Ok ( val)
@@ -770,11 +778,10 @@ impl<'a> TInputProtocol for TBinaryUnsafeInputProtocol<'a> {
770778 fn read_faststr ( & mut self ) -> Result < FastStr , ThriftException > {
771779 unsafe {
772780 let len = self . read_i32 ( ) . unwrap_unchecked ( ) as usize ;
773- let val = FastStr :: new ( str:: from_utf8_unchecked (
774- self . buf . get_unchecked ( self . index ..self . index + len) ,
775- ) ) ;
776- self . index += len;
777- Ok ( val)
781+ self . advance ( self . index ) ;
782+ let bytes = Bytes :: copy_from_slice ( & self . trans . split_to ( len) ) ;
783+ self . buf = slice:: from_raw_parts ( self . trans . as_ptr ( ) , self . trans . len ( ) ) ;
784+ Ok ( FastStr :: from_bytes_unchecked ( bytes) )
778785 }
779786 }
780787
@@ -827,8 +834,9 @@ impl<'a> TInputProtocol for TBinaryUnsafeInputProtocol<'a> {
827834 #[ inline]
828835 fn read_bytes_vec ( & mut self ) -> Result < Vec < u8 > , ThriftException > {
829836 let len = self . read_i32 ( ) ? as usize ;
830- let val = self . buf [ self . index ..self . index + len] . to_vec ( ) ;
831- self . index += len;
837+ self . advance ( self . index ) ;
838+ let val = self . trans . split_to ( len) . into ( ) ;
839+ self . buf = unsafe { slice:: from_raw_parts ( self . trans . as_ptr ( ) , self . trans . len ( ) ) } ;
832840 Ok ( val)
833841 }
834842
@@ -841,8 +849,7 @@ impl<'a> TInputProtocol for TBinaryUnsafeInputProtocol<'a> {
841849 fn skip ( & mut self , field_type : TType ) -> Result < usize , ThriftException > {
842850 debug_assert ! ( self . index >= FIELD_BEGIN_LEN ) ;
843851
844- self . trans . advance ( self . index - FIELD_BEGIN_LEN ) ;
845- self . index = FIELD_BEGIN_LEN ;
852+ self . advance ( self . index - FIELD_BEGIN_LEN ) ;
846853 self . buf = unsafe { slice:: from_raw_parts ( self . trans . as_ptr ( ) , self . trans . len ( ) ) } ;
847854
848855 self . skip_till_depth ( field_type, crate :: thrift:: MAXIMUM_SKIP_DEPTH )
0 commit comments