1- #region Copyright notice and license
1+ #region Copyright notice and license
22
33// Copyright 2019 The gRPC Authors
44//
@@ -62,18 +62,23 @@ public override Task FlushAsync(CancellationToken cancellationToken)
6262 }
6363
6464 public override int Read ( byte [ ] buffer , int offset , int count )
65+ {
66+ return Read ( buffer . AsSpan ( offset , count ) ) ;
67+ }
68+
69+ public override int Read ( Span < byte > buffer )
6570 {
6671 var remaining = _readOnlySequence . Slice ( _position ) ;
67- var toCopy = remaining . Slice ( 0 , Math . Min ( count , remaining . Length ) ) ;
72+ var toCopy = remaining . Slice ( 0 , Math . Min ( buffer . Length , remaining . Length ) ) ;
6873 _position = toCopy . End ;
69- toCopy . CopyTo ( buffer . AsSpan ( offset , count ) ) ;
74+ toCopy . CopyTo ( buffer ) ;
7075 return ( int ) toCopy . Length ;
7176 }
7277
7378 public override Task < int > ReadAsync ( byte [ ] buffer , int offset , int count , CancellationToken cancellationToken )
7479 {
7580 cancellationToken . ThrowIfCancellationRequested ( ) ;
76- var bytesRead = Read ( buffer , offset , count ) ;
81+ var bytesRead = Read ( buffer . AsSpan ( offset , count ) ) ;
7782 if ( bytesRead == 0 )
7883 {
7984 return TaskOfZero ;
@@ -89,6 +94,12 @@ public override Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancel
8994 }
9095 }
9196
97+ public override ValueTask < int > ReadAsync ( Memory < byte > buffer , CancellationToken cancellationToken = default )
98+ {
99+ cancellationToken . ThrowIfCancellationRequested ( ) ;
100+ return new ValueTask < int > ( Read ( buffer . Span ) ) ;
101+ }
102+
92103 public override int ReadByte ( )
93104 {
94105 var remaining = _readOnlySequence . Slice ( _position ) ;
@@ -152,6 +163,8 @@ public override long Seek(long offset, SeekOrigin origin)
152163
153164 public override Task WriteAsync ( byte [ ] buffer , int offset , int count , CancellationToken cancellationToken ) => throw new NotSupportedException ( ) ;
154165
166+ public override ValueTask WriteAsync ( ReadOnlyMemory < byte > buffer , CancellationToken cancellationToken = default ) => throw new NotSupportedException ( ) ;
167+
155168 public override async Task CopyToAsync ( Stream destination , int bufferSize , CancellationToken cancellationToken )
156169 {
157170 foreach ( var segment in _readOnlySequence )
0 commit comments