@@ -615,18 +615,20 @@ internal class Http2StreamPipeReader(PipeReader reader, Action<int> onReadCallba
615615{
616616 private readonly PipeReader _reader = reader ;
617617 private readonly Action < int > _onReadCallback = onReadCallback ;
618- private SequencePosition _lastReadStart ;
618+ private ReadOnlySequence < byte > _lastReadStart ;
619619
620620 public override void AdvanceTo ( SequencePosition consumed )
621621 {
622+ var consumedLength = _lastReadStart . Slice ( _lastReadStart . Start , consumed ) . Length ;
622623 _reader . AdvanceTo ( consumed ) ;
623- _onReadCallback ( consumed . GetInteger ( ) - _lastReadStart . GetInteger ( ) ) ;
624+ _onReadCallback ( checked ( ( int ) consumedLength ) ) ;
624625 }
625626
626627 public override void AdvanceTo ( SequencePosition consumed , SequencePosition examined )
627628 {
629+ var consumedLength = _lastReadStart . Slice ( _lastReadStart . Start , consumed ) . Length ;
628630 _reader . AdvanceTo ( consumed , examined ) ;
629- _onReadCallback ( consumed . GetInteger ( ) ) ;
631+ _onReadCallback ( checked ( ( int ) consumedLength ) ) ;
630632 }
631633
632634 public override void CancelPendingRead ( )
@@ -643,15 +645,15 @@ public override async ValueTask<ReadResult> ReadAsync(CancellationToken cancella
643645 {
644646 var result = await _reader . ReadAsync ( cancellationToken ) ;
645647 if ( ! result . IsCanceled )
646- _lastReadStart = result . Buffer . Start ;
648+ _lastReadStart = result . Buffer ;
647649 return result ;
648650 }
649651
650652 public override bool TryRead ( out ReadResult result )
651653 {
652654 var hasRead = _reader . TryRead ( out result ) ;
653655 if ( ! result . IsCanceled )
654- _lastReadStart = result . Buffer . Start ;
656+ _lastReadStart = result . Buffer ;
655657 return hasRead ;
656658 }
657659
0 commit comments