@@ -369,9 +369,12 @@ impl WebRtcDialerState {
369369 error:: NegotiationError :: ParseError ( ParseError :: InvalidData )
370370 } ) ?;
371371
372- let payload = tail[ ..len] . to_vec ( ) ;
373-
374- let message = Message :: decode ( payload. into ( ) ) ;
372+ let len_size = remaining. len ( ) - tail. len ( ) ;
373+ let bytes = Bytes :: from ( payload) ;
374+ let payload = bytes. slice ( len_size..len_size + len) ;
375+ let remaining = bytes. slice ( len_size + len..) ;
376+
377+ let message = Message :: decode ( payload) ;
375378
376379 tracing:: trace!(
377380 target: LOG_TARGET ,
@@ -396,7 +399,7 @@ impl WebRtcDialerState {
396399 Err ( _) => return Err ( error:: NegotiationError :: ParseError ( ParseError :: InvalidData ) ) ,
397400 } ;
398401
399- match drain_trailing_protocols ( tail , len ) {
402+ match drain_trailing_protocols ( remaining ) {
400403 Ok ( protos) => protocols. extend ( protos) ,
401404 Err ( error) => return Err ( error) ,
402405 }
@@ -439,18 +442,16 @@ impl WebRtcDialerState {
439442}
440443
441444fn drain_trailing_protocols (
442- tail : & [ u8 ] ,
443- len : usize ,
445+ mut remaining : Bytes ,
444446) -> Result < Vec < Protocol > , error:: NegotiationError > {
445447 let mut protocols = vec ! [ ] ;
446- let mut remaining = & tail[ len..] ;
447448
448449 loop {
449450 if remaining. is_empty ( ) {
450451 break ;
451452 }
452453
453- let ( len, tail) = unsigned_varint:: decode:: usize ( remaining) . map_err ( |error| {
454+ let ( len, tail) = unsigned_varint:: decode:: usize ( & remaining) . map_err ( |error| {
454455 tracing:: debug!(
455456 target: LOG_TARGET ,
456457 ?error,
@@ -471,9 +472,10 @@ fn drain_trailing_protocols(
471472 return Err ( error:: NegotiationError :: ParseError ( ParseError :: InvalidData ) ) ;
472473 }
473474
474- let payload = tail[ ..len] . to_vec ( ) ;
475+ let len_size = remaining. len ( ) - tail. len ( ) ;
476+ let payload = remaining. slice ( len_size..len_size + len) ;
475477
476- match Message :: decode ( payload. into ( ) ) {
478+ match Message :: decode ( payload) {
477479 Ok ( Message :: Protocol ( protocol) ) => protocols. push ( protocol) ,
478480 Err ( error) => {
479481 tracing:: debug!(
@@ -487,7 +489,7 @@ fn drain_trailing_protocols(
487489 _ => return Err ( error:: NegotiationError :: StateMismatch ) ,
488490 }
489491
490- remaining = & tail [ len..] ;
492+ remaining = remaining . slice ( len_size + len..) ;
491493 }
492494
493495 Ok ( protocols)
0 commit comments