@@ -162,7 +162,6 @@ pub(crate) enum Frame {
162162 Datagram ( Datagram ) ,
163163 AckFrequency ( AckFrequency ) ,
164164 ImmediateAck ,
165- Invalid { ty : Type , reason : & ' static str } ,
166165 HandshakeDone ,
167166}
168167
@@ -204,7 +203,6 @@ impl Frame {
204203 Datagram ( _) => Type ( * DATAGRAM_TYS . start ( ) ) ,
205204 AckFrequency ( _) => Type :: ACK_FREQUENCY ,
206205 ImmediateAck => Type :: IMMEDIATE_ACK ,
207- Invalid { ty, .. } => ty,
208206 HandshakeDone => Type :: HANDSHAKE_DONE ,
209207 }
210208 }
@@ -734,25 +732,39 @@ impl Iter {
734732}
735733
736734impl Iterator for Iter {
737- type Item = Frame ;
735+ type Item = Result < Frame , InvalidFrame > ;
738736 fn next ( & mut self ) -> Option < Self :: Item > {
739737 if !self . bytes . has_remaining ( ) {
740738 return None ;
741739 }
742740 match self . try_next ( ) {
743- Ok ( x) => Some ( x ) ,
741+ Ok ( x) => Some ( Ok ( x ) ) ,
744742 Err ( e) => {
745743 // Corrupt frame, skip it and everything that follows
746744 self . bytes = io:: Cursor :: new ( Bytes :: new ( ) ) ;
747- Some ( Frame :: Invalid {
748- ty : self . last_ty . unwrap ( ) ,
745+ Some ( Err ( InvalidFrame {
746+ ty : self . last_ty ,
749747 reason : e. reason ( ) ,
750- } )
748+ } ) )
751749 }
752750 }
753751 }
754752}
755753
754+ #[ derive( Debug ) ]
755+ pub ( crate ) struct InvalidFrame {
756+ pub ( crate ) ty : Option < Type > ,
757+ pub ( crate ) reason : & ' static str ,
758+ }
759+
760+ impl From < InvalidFrame > for TransportError {
761+ fn from ( err : InvalidFrame ) -> Self {
762+ let mut te = Self :: FRAME_ENCODING_ERROR ( err. reason ) ;
763+ te. frame = err. ty ;
764+ te
765+ }
766+ }
767+
756768fn scan_ack_blocks ( buf : & mut io:: Cursor < Bytes > , largest : u64 , n : usize ) -> Result < ( ) , IterErr > {
757769 let first_block = buf. get_var ( ) ?;
758770 let mut smallest = largest. checked_sub ( first_block) . ok_or ( IterErr :: Malformed ) ?;
@@ -910,7 +922,9 @@ mod test {
910922 use assert_matches:: assert_matches;
911923
912924 fn frames ( buf : Vec < u8 > ) -> Vec < Frame > {
913- Iter :: new ( Bytes :: from ( buf) ) . collect :: < Vec < _ > > ( )
925+ Iter :: new ( Bytes :: from ( buf) )
926+ . collect :: < Result < Vec < _ > , _ > > ( )
927+ . unwrap ( )
914928 }
915929
916930 #[ test]
0 commit comments