Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/SignalR/SignalR.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"src\\Servers\\IIS\\IISIntegration\\src\\Microsoft.AspNetCore.Server.IISIntegration.csproj",
"src\\Servers\\Kestrel\\Core\\src\\Microsoft.AspNetCore.Server.Kestrel.Core.csproj",
"src\\Servers\\Kestrel\\Kestrel\\src\\Microsoft.AspNetCore.Server.Kestrel.csproj",
"src\\Servers\\Kestrel\\Transport.Quic\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.csproj",
"src\\Servers\\Kestrel\\Transport.Sockets\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj",
"src\\SignalR\\clients\\csharp\\Client.Core\\src\\Microsoft.AspNetCore.SignalR.Client.Core.csproj",
"src\\SignalR\\clients\\csharp\\Client.SourceGenerator\\src\\Microsoft.AspNetCore.SignalR.Client.SourceGenerator.csproj",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.ExceptionServices;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
Expand Down Expand Up @@ -187,7 +188,25 @@ public ReadOnlyMemory<byte> GetMessageBytes(HubMessage message)
}
else if (reader.ValueTextEquals(TargetPropertyNameBytes.EncodedUtf8Bytes))
{
#if NETCOREAPP
reader.Read();

if (reader.TokenType != JsonTokenType.String)
{
throw new InvalidDataException($"Expected '{TargetPropertyName}' to be of type {JsonTokenType.String}.");
}

if (!reader.HasValueSequence)
{
target = binder.GetTarget(reader.ValueSpan) ?? reader.GetString();
}
else
{
target = reader.GetString();
}
#else
target = reader.ReadAsString(TargetPropertyName);
#endif
}
else if (reader.ValueTextEquals(ErrorPropertyNameBytes.EncodedUtf8Bytes))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.ExceptionServices;
using System.Text;
using MessagePack;
using Microsoft.AspNetCore.Internal;

Expand Down Expand Up @@ -77,7 +78,7 @@ private HubMessage CreateInvocationMessage(ref MessagePackReader reader, IInvoca
invocationId = null;
}

var target = ReadString(ref reader, "target");
var target = ReadString(ref reader, binder, "target");

object[]? arguments;
try
Expand Down Expand Up @@ -569,6 +570,26 @@ private static int ReadInt32(ref MessagePackReader reader, string field)
}
}

protected static string ReadString(ref MessagePackReader reader, IInvocationBinder binder, string field)
{
try
{
#if NETCOREAPP
if (reader.TryReadStringSpan(out var span))
{
return binder.GetTarget(span) ?? Encoding.UTF8.GetString(span);
}
return reader.ReadString();
#else
return reader.ReadString();
#endif
}
catch (Exception ex)
{
throw new InvalidDataException($"Reading '{field}' as String failed.", ex);
}
}

protected static string ReadString(ref MessagePackReader reader, string field)
{
try
Expand Down
9 changes: 9 additions & 0 deletions src/SignalR/common/SignalR.Common/src/IInvocationBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@ public interface IInvocationBinder
/// <param name="streamId">The ID of the stream the stream item is a part of.</param>
/// <returns>The <see cref="Type"/> of the item the stream contains.</returns>
Type GetStreamItemType(string streamId);

#if NETCOREAPP
/// <summary>
/// Gets the <see cref="string"/> representation for the target from bytes.
/// </summary>
/// <param name="utf8Bytes">The target name as a utf8 sequence.</param>
/// <returns>A string that represents the target or null if the target string couldn't be determined.</returns>
string? GetTarget(ReadOnlySpan<byte> utf8Bytes) => null;
#endif
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Common serialization primitives for SignalR Clients Servers</Description>
Expand Down Expand Up @@ -43,4 +43,9 @@
<SupportedPlatform Include="browser" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="PublicAPI/$(TargetFramework)/PublicAPI.Shipped.txt" />
<AdditionalFiles Include="PublicAPI/$(TargetFramework)/PublicAPI.Unshipped.txt" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#nullable enable
const Microsoft.AspNetCore.SignalR.Protocol.HubProtocolConstants.CancelInvocationMessageType = 5 -> int
const Microsoft.AspNetCore.SignalR.Protocol.HubProtocolConstants.CloseMessageType = 7 -> int
const Microsoft.AspNetCore.SignalR.Protocol.HubProtocolConstants.CompletionMessageType = 3 -> int
const Microsoft.AspNetCore.SignalR.Protocol.HubProtocolConstants.InvocationMessageType = 1 -> int
const Microsoft.AspNetCore.SignalR.Protocol.HubProtocolConstants.PingMessageType = 6 -> int
const Microsoft.AspNetCore.SignalR.Protocol.HubProtocolConstants.StreamInvocationMessageType = 4 -> int
const Microsoft.AspNetCore.SignalR.Protocol.HubProtocolConstants.StreamItemMessageType = 2 -> int
Microsoft.AspNetCore.SignalR.HubException
Microsoft.AspNetCore.SignalR.HubException.HubException() -> void
Microsoft.AspNetCore.SignalR.HubException.HubException(string? message) -> void
Microsoft.AspNetCore.SignalR.HubException.HubException(string? message, System.Exception? innerException) -> void
Microsoft.AspNetCore.SignalR.HubException.HubException(System.Runtime.Serialization.SerializationInfo! info, System.Runtime.Serialization.StreamingContext context) -> void
Microsoft.AspNetCore.SignalR.IInvocationBinder
Microsoft.AspNetCore.SignalR.IInvocationBinder.GetParameterTypes(string! methodName) -> System.Collections.Generic.IReadOnlyList<System.Type!>!
Microsoft.AspNetCore.SignalR.IInvocationBinder.GetReturnType(string! invocationId) -> System.Type!
Microsoft.AspNetCore.SignalR.IInvocationBinder.GetStreamItemType(string! streamId) -> System.Type!
Microsoft.AspNetCore.SignalR.ISignalRBuilder
Microsoft.AspNetCore.SignalR.ISignalRBuilder.Services.get -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
Microsoft.AspNetCore.SignalR.Protocol.CancelInvocationMessage
Microsoft.AspNetCore.SignalR.Protocol.CancelInvocationMessage.CancelInvocationMessage(string! invocationId) -> void
Microsoft.AspNetCore.SignalR.Protocol.CloseMessage
Microsoft.AspNetCore.SignalR.Protocol.CloseMessage.AllowReconnect.get -> bool
Microsoft.AspNetCore.SignalR.Protocol.CloseMessage.CloseMessage(string? error) -> void
Microsoft.AspNetCore.SignalR.Protocol.CloseMessage.CloseMessage(string? error, bool allowReconnect) -> void
Microsoft.AspNetCore.SignalR.Protocol.CloseMessage.Error.get -> string?
Microsoft.AspNetCore.SignalR.Protocol.CompletionMessage
Microsoft.AspNetCore.SignalR.Protocol.CompletionMessage.CompletionMessage(string! invocationId, string? error, object? result, bool hasResult) -> void
Microsoft.AspNetCore.SignalR.Protocol.CompletionMessage.Error.get -> string?
Microsoft.AspNetCore.SignalR.Protocol.CompletionMessage.HasResult.get -> bool
Microsoft.AspNetCore.SignalR.Protocol.CompletionMessage.Result.get -> object?
Microsoft.AspNetCore.SignalR.Protocol.HandshakeProtocol
Microsoft.AspNetCore.SignalR.Protocol.HandshakeRequestMessage
Microsoft.AspNetCore.SignalR.Protocol.HandshakeRequestMessage.HandshakeRequestMessage(string! protocol, int version) -> void
Microsoft.AspNetCore.SignalR.Protocol.HandshakeRequestMessage.Protocol.get -> string!
Microsoft.AspNetCore.SignalR.Protocol.HandshakeRequestMessage.Version.get -> int
Microsoft.AspNetCore.SignalR.Protocol.HandshakeResponseMessage
Microsoft.AspNetCore.SignalR.Protocol.HandshakeResponseMessage.Error.get -> string?
Microsoft.AspNetCore.SignalR.Protocol.HandshakeResponseMessage.HandshakeResponseMessage(string? error) -> void
Microsoft.AspNetCore.SignalR.Protocol.HubInvocationMessage
Microsoft.AspNetCore.SignalR.Protocol.HubInvocationMessage.Headers.get -> System.Collections.Generic.IDictionary<string!, string!>?
Microsoft.AspNetCore.SignalR.Protocol.HubInvocationMessage.Headers.set -> void
Microsoft.AspNetCore.SignalR.Protocol.HubInvocationMessage.HubInvocationMessage(string? invocationId) -> void
Microsoft.AspNetCore.SignalR.Protocol.HubInvocationMessage.InvocationId.get -> string?
Microsoft.AspNetCore.SignalR.Protocol.HubMessage
Microsoft.AspNetCore.SignalR.Protocol.HubMessage.HubMessage() -> void
Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage
Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage.Arguments.get -> object?[]!
Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage.HubMethodInvocationMessage(string? invocationId, string! target, object?[]! arguments) -> void
Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage.HubMethodInvocationMessage(string? invocationId, string! target, object?[]! arguments, string![]? streamIds) -> void
Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage.StreamIds.get -> string![]?
Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage.Target.get -> string!
Microsoft.AspNetCore.SignalR.Protocol.HubProtocolConstants
Microsoft.AspNetCore.SignalR.Protocol.HubProtocolExtensions
Microsoft.AspNetCore.SignalR.Protocol.IHubProtocol
Microsoft.AspNetCore.SignalR.Protocol.IHubProtocol.GetMessageBytes(Microsoft.AspNetCore.SignalR.Protocol.HubMessage! message) -> System.ReadOnlyMemory<byte>
Microsoft.AspNetCore.SignalR.Protocol.IHubProtocol.IsVersionSupported(int version) -> bool
Microsoft.AspNetCore.SignalR.Protocol.IHubProtocol.Name.get -> string!
Microsoft.AspNetCore.SignalR.Protocol.IHubProtocol.TransferFormat.get -> Microsoft.AspNetCore.Connections.TransferFormat
Microsoft.AspNetCore.SignalR.Protocol.IHubProtocol.TryParseMessage(ref System.Buffers.ReadOnlySequence<byte> input, Microsoft.AspNetCore.SignalR.IInvocationBinder! binder, out Microsoft.AspNetCore.SignalR.Protocol.HubMessage? message) -> bool
Microsoft.AspNetCore.SignalR.Protocol.IHubProtocol.Version.get -> int
Microsoft.AspNetCore.SignalR.Protocol.IHubProtocol.WriteMessage(Microsoft.AspNetCore.SignalR.Protocol.HubMessage! message, System.Buffers.IBufferWriter<byte>! output) -> void
Microsoft.AspNetCore.SignalR.Protocol.InvocationBindingFailureMessage
Microsoft.AspNetCore.SignalR.Protocol.InvocationBindingFailureMessage.BindingFailure.get -> System.Runtime.ExceptionServices.ExceptionDispatchInfo!
Microsoft.AspNetCore.SignalR.Protocol.InvocationBindingFailureMessage.InvocationBindingFailureMessage(string? invocationId, string! target, System.Runtime.ExceptionServices.ExceptionDispatchInfo! bindingFailure) -> void
Microsoft.AspNetCore.SignalR.Protocol.InvocationBindingFailureMessage.Target.get -> string!
Microsoft.AspNetCore.SignalR.Protocol.InvocationMessage
Microsoft.AspNetCore.SignalR.Protocol.InvocationMessage.InvocationMessage(string! target, object?[]! arguments) -> void
Microsoft.AspNetCore.SignalR.Protocol.InvocationMessage.InvocationMessage(string? invocationId, string! target, object?[]! arguments) -> void
Microsoft.AspNetCore.SignalR.Protocol.InvocationMessage.InvocationMessage(string? invocationId, string! target, object?[]! arguments, string![]? streamIds) -> void
Microsoft.AspNetCore.SignalR.Protocol.PingMessage
Microsoft.AspNetCore.SignalR.Protocol.StreamBindingFailureMessage
Microsoft.AspNetCore.SignalR.Protocol.StreamBindingFailureMessage.BindingFailure.get -> System.Runtime.ExceptionServices.ExceptionDispatchInfo!
Microsoft.AspNetCore.SignalR.Protocol.StreamBindingFailureMessage.Id.get -> string!
Microsoft.AspNetCore.SignalR.Protocol.StreamBindingFailureMessage.StreamBindingFailureMessage(string! id, System.Runtime.ExceptionServices.ExceptionDispatchInfo! bindingFailure) -> void
Microsoft.AspNetCore.SignalR.Protocol.StreamInvocationMessage
Microsoft.AspNetCore.SignalR.Protocol.StreamInvocationMessage.StreamInvocationMessage(string! invocationId, string! target, object?[]! arguments) -> void
Microsoft.AspNetCore.SignalR.Protocol.StreamInvocationMessage.StreamInvocationMessage(string! invocationId, string! target, object?[]! arguments, string![]? streamIds) -> void
Microsoft.AspNetCore.SignalR.Protocol.StreamItemMessage
Microsoft.AspNetCore.SignalR.Protocol.StreamItemMessage.Item.get -> object?
Microsoft.AspNetCore.SignalR.Protocol.StreamItemMessage.Item.set -> void
Microsoft.AspNetCore.SignalR.Protocol.StreamItemMessage.StreamItemMessage(string! invocationId, object? item) -> void
override Microsoft.AspNetCore.SignalR.Protocol.CompletionMessage.ToString() -> string!
override Microsoft.AspNetCore.SignalR.Protocol.InvocationMessage.ToString() -> string!
override Microsoft.AspNetCore.SignalR.Protocol.StreamInvocationMessage.ToString() -> string!
override Microsoft.AspNetCore.SignalR.Protocol.StreamItemMessage.ToString() -> string!
static Microsoft.AspNetCore.SignalR.Protocol.CompletionMessage.Empty(string! invocationId) -> Microsoft.AspNetCore.SignalR.Protocol.CompletionMessage!
static Microsoft.AspNetCore.SignalR.Protocol.CompletionMessage.WithError(string! invocationId, string? error) -> Microsoft.AspNetCore.SignalR.Protocol.CompletionMessage!
static Microsoft.AspNetCore.SignalR.Protocol.CompletionMessage.WithResult(string! invocationId, object? payload) -> Microsoft.AspNetCore.SignalR.Protocol.CompletionMessage!
static Microsoft.AspNetCore.SignalR.Protocol.HandshakeProtocol.GetSuccessfulHandshake(Microsoft.AspNetCore.SignalR.Protocol.IHubProtocol! protocol) -> System.ReadOnlySpan<byte>
static Microsoft.AspNetCore.SignalR.Protocol.HandshakeProtocol.TryParseRequestMessage(ref System.Buffers.ReadOnlySequence<byte> buffer, out Microsoft.AspNetCore.SignalR.Protocol.HandshakeRequestMessage? requestMessage) -> bool
static Microsoft.AspNetCore.SignalR.Protocol.HandshakeProtocol.TryParseResponseMessage(ref System.Buffers.ReadOnlySequence<byte> buffer, out Microsoft.AspNetCore.SignalR.Protocol.HandshakeResponseMessage? responseMessage) -> bool
static Microsoft.AspNetCore.SignalR.Protocol.HandshakeProtocol.WriteRequestMessage(Microsoft.AspNetCore.SignalR.Protocol.HandshakeRequestMessage! requestMessage, System.Buffers.IBufferWriter<byte>! output) -> void
static Microsoft.AspNetCore.SignalR.Protocol.HandshakeProtocol.WriteResponseMessage(Microsoft.AspNetCore.SignalR.Protocol.HandshakeResponseMessage! responseMessage, System.Buffers.IBufferWriter<byte>! output) -> void
static Microsoft.AspNetCore.SignalR.Protocol.HubProtocolExtensions.GetMessageBytes(this Microsoft.AspNetCore.SignalR.Protocol.IHubProtocol! hubProtocol, Microsoft.AspNetCore.SignalR.Protocol.HubMessage! message) -> byte[]!
static readonly Microsoft.AspNetCore.SignalR.Protocol.CloseMessage.Empty -> Microsoft.AspNetCore.SignalR.Protocol.CloseMessage!
static readonly Microsoft.AspNetCore.SignalR.Protocol.HandshakeResponseMessage.Empty -> Microsoft.AspNetCore.SignalR.Protocol.HandshakeResponseMessage!
static readonly Microsoft.AspNetCore.SignalR.Protocol.PingMessage.Instance -> Microsoft.AspNetCore.SignalR.Protocol.PingMessage!
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#nullable enable
Microsoft.AspNetCore.SignalR.IInvocationBinder.GetTarget(System.ReadOnlySpan<byte> utf8Bytes) -> string?
Microsoft.AspNetCore.SignalR.Protocol.RawResult
Microsoft.AspNetCore.SignalR.Protocol.RawResult.RawResult(System.Buffers.ReadOnlySequence<byte> rawBytes) -> void
Microsoft.AspNetCore.SignalR.Protocol.RawResult.RawSerializedData.get -> System.Buffers.ReadOnlySequence<byte>
Loading