11// Copyright (c) Microsoft. All rights reserved.
22// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+ #nullable enable
34
45using System ;
56using System . Buffers ;
@@ -14,7 +15,7 @@ namespace Microsoft.Azure.SignalR
1415 internal sealed class MemoryBufferWriter : Stream , IBufferWriter < byte >
1516 {
1617 [ ThreadStatic ]
17- private static MemoryBufferWriter _cachedInstance ;
18+ private static MemoryBufferWriter ? _cachedInstance ;
1819
1920#if DEBUG
2021 private bool _inUse ;
@@ -23,8 +24,8 @@ internal sealed class MemoryBufferWriter : Stream, IBufferWriter<byte>
2324 private readonly int _minimumSegmentSize ;
2425 private int _bytesWritten ;
2526
26- private List < CompletedBuffer > _completedSegments ;
27- private byte [ ] _currentSegment ;
27+ private List < CompletedBuffer > ? _completedSegments ;
28+ private byte [ ] ? _currentSegment ;
2829 private int _position ;
2930
3031 public MemoryBufferWriter ( int minimumSegmentSize = 4096 )
@@ -107,14 +108,14 @@ public Memory<byte> GetMemory(int sizeHint = 0)
107108 {
108109 EnsureCapacity ( sizeHint ) ;
109110
110- return _currentSegment . AsMemory ( _position , _currentSegment . Length - _position ) ;
111+ return _currentSegment . AsMemory ( _position , _currentSegment ! . Length - _position ) ;
111112 }
112113
113114 public Span < byte > GetSpan ( int sizeHint = 0 )
114115 {
115116 EnsureCapacity ( sizeHint ) ;
116117
117- return _currentSegment . AsSpan ( _position , _currentSegment . Length - _position ) ;
118+ return _currentSegment . AsSpan ( _position , _currentSegment ! . Length - _position ) ;
118119 }
119120
120121 public void CopyTo ( IBufferWriter < byte > destination )
@@ -137,7 +138,7 @@ public override Task CopyToAsync(Stream destination, int bufferSize, Cancellatio
137138 if ( _completedSegments == null )
138139 {
139140 // There is only one segment so write without awaiting.
140- return destination . WriteAsync ( _currentSegment , 0 , _position ) ;
141+ return destination . WriteAsync ( _currentSegment ! , 0 , _position ) ;
141142 }
142143
143144 return CopyToSlowAsync ( destination ) ;
@@ -194,7 +195,7 @@ private async Task CopyToSlowAsync(Stream destination)
194195 }
195196 }
196197
197- await destination . WriteAsync ( _currentSegment , 0 , _position ) ;
198+ await destination . WriteAsync ( _currentSegment ! , 0 , _position ) ;
198199 }
199200
200201 public byte [ ] ToArray ( )
@@ -270,7 +271,7 @@ public override void WriteByte(byte value)
270271 else
271272 {
272273 AddSegment ( ) ;
273- _currentSegment [ 0 ] = value ;
274+ _currentSegment ! [ 0 ] = value ;
274275 }
275276
276277 _position ++ ;
0 commit comments