API review changes (#1992)
- Changed GetMessageBytes to return ReadOnlyMemory - Make HandshakeProtocol.SuccessHandshakeData a readonly field
This commit is contained in:
parent
70c63fe9e8
commit
4a568e90d2
|
|
@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
|
|||
{
|
||||
}
|
||||
|
||||
public byte[] GetMessageBytes(HubMessage message)
|
||||
public ReadOnlyMemory<byte> GetMessageBytes(HubMessage message)
|
||||
{
|
||||
return HubProtocolExtensions.GetMessageBytes(this, message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
|
|||
public class HubProtocolBenchmark
|
||||
{
|
||||
private IHubProtocol _hubProtocol;
|
||||
private byte[] _binaryInput;
|
||||
private ReadOnlyMemory<byte> _binaryInput;
|
||||
private TestBinder _binder;
|
||||
private HubMessage _hubMessage;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
|
@ -195,7 +196,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
|
|||
_innerProtocol.WriteMessage(message, output);
|
||||
}
|
||||
|
||||
public byte[] GetMessageBytes(HubMessage message)
|
||||
public ReadOnlyMemory<byte> GetMessageBytes(HubMessage message)
|
||||
{
|
||||
return HubProtocolExtensions.GetMessageBytes(this, message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
|
|||
output.Write(_fixedOutput);
|
||||
}
|
||||
|
||||
public byte[] GetMessageBytes(HubMessage message)
|
||||
public ReadOnlyMemory<byte> GetMessageBytes(HubMessage message)
|
||||
{
|
||||
return HubProtocolExtensions.GetMessageBytes(this, message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
|
|||
private const string ErrorPropertyName = "error";
|
||||
private const string TypePropertyName = "type";
|
||||
|
||||
public static ReadOnlyMemory<byte> SuccessHandshakeData { get; }
|
||||
public static ReadOnlyMemory<byte> SuccessHandshakeData;
|
||||
|
||||
static HandshakeProtocol()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
|
|||
|
||||
void WriteMessage(HubMessage message, IBufferWriter<byte> output);
|
||||
|
||||
byte[] GetMessageBytes(HubMessage message);
|
||||
ReadOnlyMemory<byte> GetMessageBytes(HubMessage message);
|
||||
|
||||
bool IsVersionSupported(int version);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.SignalR
|
|||
private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1);
|
||||
|
||||
private long _lastSendTimestamp = Stopwatch.GetTimestamp();
|
||||
private byte[] _cachedPingMessage;
|
||||
private ReadOnlyMemory<byte> _cachedPingMessage;
|
||||
|
||||
public HubConnectionContext(ConnectionContext connectionContext, TimeSpan keepAliveInterval, ILoggerFactory loggerFactory)
|
||||
{
|
||||
|
|
@ -223,11 +223,7 @@ namespace Microsoft.AspNetCore.SignalR
|
|||
{
|
||||
try
|
||||
{
|
||||
Debug.Assert(_cachedPingMessage != null);
|
||||
|
||||
_connectionContext.Transport.Output.Write(_cachedPingMessage);
|
||||
|
||||
await _connectionContext.Transport.Output.FlushAsync();
|
||||
await _connectionContext.Transport.Output.WriteAsync(_cachedPingMessage);
|
||||
|
||||
Log.SentPing(_logger);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal
|
|||
return serialized;
|
||||
}
|
||||
|
||||
private void SetCache(string protocolName, byte[] serialized)
|
||||
private void SetCache(string protocolName, ReadOnlyMemory<byte> serialized)
|
||||
{
|
||||
if (_cachedItem1.ProtocolName == null)
|
||||
{
|
||||
|
|
@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal
|
|||
}
|
||||
}
|
||||
|
||||
private bool TryGetCached(string protocolName, out byte[] result)
|
||||
private bool TryGetCached(string protocolName, out ReadOnlyMemory<byte> result)
|
||||
{
|
||||
if (string.Equals(_cachedItem1.ProtocolName, protocolName, StringComparison.Ordinal))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR.Internal
|
||||
{
|
||||
public readonly struct SerializedMessage
|
||||
{
|
||||
public string ProtocolName { get; }
|
||||
public byte[] Serialized { get; }
|
||||
public ReadOnlyMemory<byte> Serialized { get; }
|
||||
|
||||
public SerializedMessage(string protocolName, byte[] serialized)
|
||||
public SerializedMessage(string protocolName, ReadOnlyMemory<byte> serialized)
|
||||
{
|
||||
ProtocolName = protocolName;
|
||||
Serialized = serialized;
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
|
|||
TextMessageFormatter.WriteRecordSeparator(output);
|
||||
}
|
||||
|
||||
public byte[] GetMessageBytes(HubMessage message)
|
||||
public ReadOnlyMemory<byte> GetMessageBytes(HubMessage message)
|
||||
{
|
||||
return HubProtocolExtensions.GetMessageBytes(this, message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
|
|||
}
|
||||
}
|
||||
|
||||
public byte[] GetMessageBytes(HubMessage message)
|
||||
public ReadOnlyMemory<byte> GetMessageBytes(HubMessage message)
|
||||
{
|
||||
var writer = MemoryBufferWriter.Get();
|
||||
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
|||
}
|
||||
}
|
||||
|
||||
public byte[] GetMessageBytes(HubMessage message)
|
||||
public ReadOnlyMemory<byte> GetMessageBytes(HubMessage message)
|
||||
{
|
||||
return HubProtocolExtensions.GetMessageBytes(this, message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -202,10 +202,10 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
|
|||
|
||||
public void WriteMessage(HubMessage message, IBufferWriter<byte> output)
|
||||
{
|
||||
output.Write(GetMessageBytes(message));
|
||||
output.Write(GetMessageBytes(message).Span);
|
||||
}
|
||||
|
||||
public byte[] GetMessageBytes(HubMessage message)
|
||||
public ReadOnlyMemory<byte> GetMessageBytes(HubMessage message)
|
||||
{
|
||||
SerializationCount += 1;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue