Skip to content

Commit f317977

Browse files
authored
Make serverlessProtocol project nullable (#2090)
1 parent 572436e commit f317977

File tree

10 files changed

+265
-617
lines changed

10 files changed

+265
-617
lines changed

src/Common/MemoryBufferWriter.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
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

45
using System;
56
using 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++;
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
#nullable enable
45
using System.Buffers;
56

6-
namespace Microsoft.Azure.SignalR.Serverless.Protocols
7+
namespace Microsoft.Azure.SignalR.Serverless.Protocols;
8+
9+
public interface IServerlessProtocol
710
{
8-
public interface IServerlessProtocol
9-
{
10-
// TODO: Have a discussion about how to handle version change.
11-
/// <summary>
12-
/// Gets the version of the protocol.
13-
/// </summary>
14-
int Version { get; }
11+
// TODO: Have a discussion about how to handle version change.
12+
/// <summary>
13+
/// Gets the version of the protocol.
14+
/// </summary>
15+
int Version { get; }
1516

16-
/// <summary>
17-
/// Creates a new <see cref="ServerlessMessage"/> from the specified serialized representation.
18-
/// </summary>
19-
/// <param name="input">The serialized representation of the message.</param>
20-
/// <param name="message">When this method returns <c>true</c>, contains the parsed message.</param>
21-
/// <returns>A value that is <c>true</c> if the <see cref="ServerlessMessage"/> was successfully parsed; otherwise, <c>false</c>.</returns>
22-
bool TryParseMessage(ref ReadOnlySequence<byte> input, out ServerlessMessage message);
23-
}
17+
/// <summary>
18+
/// Creates a new <see cref="ServerlessMessage"/> from the specified serialized representation.
19+
/// </summary>
20+
/// <param name="input">The serialized representation of the message.</param>
21+
/// <param name="message">When this method returns <c>true</c>, contains the parsed message.</param>
22+
/// <returns>A value that is <c>true</c> if the <see cref="ServerlessMessage"/> was successfully parsed; otherwise, <c>false</c>.</returns>
23+
bool TryParseMessage(ref ReadOnlySequence<byte> input, out ServerlessMessage? message);
2424
}

src/Microsoft.Azure.SignalR.Serverless.Protocols/Internal/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
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

45
namespace Microsoft.Azure.SignalR.Serverless.Protocols;
56

0 commit comments

Comments
 (0)