Skip to content

Commit

Permalink
Merge branch 'dev' into ff31
Browse files Browse the repository at this point in the history
  • Loading branch information
vicancy authored Nov 20, 2024
2 parents 165e09c + f317977 commit d55230b
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 617 deletions.
17 changes: 9 additions & 8 deletions src/Common/MemoryBufferWriter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#nullable enable

using System;
using System.Buffers;
Expand All @@ -14,7 +15,7 @@ namespace Microsoft.Azure.SignalR
internal sealed class MemoryBufferWriter : Stream, IBufferWriter<byte>
{
[ThreadStatic]
private static MemoryBufferWriter _cachedInstance;
private static MemoryBufferWriter? _cachedInstance;

#if DEBUG
private bool _inUse;
Expand All @@ -23,8 +24,8 @@ internal sealed class MemoryBufferWriter : Stream, IBufferWriter<byte>
private readonly int _minimumSegmentSize;
private int _bytesWritten;

private List<CompletedBuffer> _completedSegments;
private byte[] _currentSegment;
private List<CompletedBuffer>? _completedSegments;
private byte[]? _currentSegment;
private int _position;

public MemoryBufferWriter(int minimumSegmentSize = 4096)
Expand Down Expand Up @@ -107,14 +108,14 @@ public Memory<byte> GetMemory(int sizeHint = 0)
{
EnsureCapacity(sizeHint);

return _currentSegment.AsMemory(_position, _currentSegment.Length - _position);
return _currentSegment.AsMemory(_position, _currentSegment!.Length - _position);
}

public Span<byte> GetSpan(int sizeHint = 0)
{
EnsureCapacity(sizeHint);

return _currentSegment.AsSpan(_position, _currentSegment.Length - _position);
return _currentSegment.AsSpan(_position, _currentSegment!.Length - _position);
}

public void CopyTo(IBufferWriter<byte> destination)
Expand All @@ -137,7 +138,7 @@ public override Task CopyToAsync(Stream destination, int bufferSize, Cancellatio
if (_completedSegments == null)
{
// There is only one segment so write without awaiting.
return destination.WriteAsync(_currentSegment, 0, _position);
return destination.WriteAsync(_currentSegment!, 0, _position);
}

return CopyToSlowAsync(destination);
Expand Down Expand Up @@ -194,7 +195,7 @@ private async Task CopyToSlowAsync(Stream destination)
}
}

await destination.WriteAsync(_currentSegment, 0, _position);
await destination.WriteAsync(_currentSegment!, 0, _position);
}

public byte[] ToArray()
Expand Down Expand Up @@ -270,7 +271,7 @@ public override void WriteByte(byte value)
else
{
AddSegment();
_currentSegment[0] = value;
_currentSegment![0] = value;
}

_position++;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#nullable enable
using System.Buffers;

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

public interface IServerlessProtocol
{
public interface IServerlessProtocol
{
// TODO: Have a discussion about how to handle version change.
/// <summary>
/// Gets the version of the protocol.
/// </summary>
int Version { get; }
// TODO: Have a discussion about how to handle version change.
/// <summary>
/// Gets the version of the protocol.
/// </summary>
int Version { get; }

/// <summary>
/// Creates a new <see cref="ServerlessMessage"/> from the specified serialized representation.
/// </summary>
/// <param name="input">The serialized representation of the message.</param>
/// <param name="message">When this method returns <c>true</c>, contains the parsed message.</param>
/// <returns>A value that is <c>true</c> if the <see cref="ServerlessMessage"/> was successfully parsed; otherwise, <c>false</c>.</returns>
bool TryParseMessage(ref ReadOnlySequence<byte> input, out ServerlessMessage message);
}
/// <summary>
/// Creates a new <see cref="ServerlessMessage"/> from the specified serialized representation.
/// </summary>
/// <param name="input">The serialized representation of the message.</param>
/// <param name="message">When this method returns <c>true</c>, contains the parsed message.</param>
/// <returns>A value that is <c>true</c> if the <see cref="ServerlessMessage"/> was successfully parsed; otherwise, <c>false</c>.</returns>
bool TryParseMessage(ref ReadOnlySequence<byte> input, out ServerlessMessage? message);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#nullable enable

namespace Microsoft.Azure.SignalR.Serverless.Protocols;

Expand Down
Loading

0 comments on commit d55230b

Please sign in to comment.