From 6eac7049baf975a571620fa29ee8b16f155485fa Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Mon, 16 Apr 2018 15:19:34 +1200 Subject: [PATCH] Update text and binary formatter helpers to be shared (#2035) --- .../MessageParserBenchmark.cs | 4 +++- .../Microsoft.AspNetCore.SignalR.Microbenchmarks.csproj | 5 +++++ .../Internal/Formatters => Common}/BinaryMessageFormatter.cs | 4 ++-- .../Internal/Formatters => Common}/BinaryMessageParser.cs | 4 ++-- .../Internal/Formatters => Common}/TextMessageFormatter.cs | 4 ++-- .../Internal/Formatters => Common}/TextMessageParser.cs | 4 ++-- .../Microsoft.AspNetCore.SignalR.Common.csproj | 2 ++ .../Protocol/HandshakeProtocol.cs | 1 - .../Microsoft.AspNetCore.SignalR.Protocols.Json.csproj | 2 ++ .../Protocol/JsonHubProtocol.cs | 1 - ...Microsoft.AspNetCore.SignalR.Protocols.MessagePack.csproj | 2 ++ .../Protocol/MessagePackHubProtocol.cs | 1 - .../Microsoft.AspNetCore.SignalR.Client.Tests.csproj | 2 ++ .../TestConnection.cs | 1 - .../Internal/Formatters/BinaryMessageFormatterTests.cs | 1 - .../Internal/Formatters/BinaryMessageParserTests.cs | 2 +- .../Internal/Formatters/TextMessageFormatterTests.cs | 2 +- .../Internal/Formatters/TextMessageParserTests.cs | 2 +- .../Internal/Protocol/JsonHubProtocolTests.cs | 1 - .../Internal/Protocol/MessagePackHubProtocolTests.cs | 1 - .../Microsoft.AspNetCore.SignalR.Common.Tests.csproj | 5 +++++ 21 files changed, 32 insertions(+), 19 deletions(-) rename src/{Microsoft.AspNetCore.SignalR.Common/Internal/Formatters => Common}/BinaryMessageFormatter.cs (93%) rename src/{Microsoft.AspNetCore.SignalR.Common/Internal/Formatters => Common}/BinaryMessageParser.cs (96%) rename src/{Microsoft.AspNetCore.SignalR.Common/Internal/Formatters => Common}/TextMessageFormatter.cs (86%) rename src/{Microsoft.AspNetCore.SignalR.Common/Internal/Formatters => Common}/TextMessageParser.cs (88%) diff --git a/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/MessageParserBenchmark.cs b/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/MessageParserBenchmark.cs index 575ad44f82..f08d29a6e6 100644 --- a/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/MessageParserBenchmark.cs +++ b/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/MessageParserBenchmark.cs @@ -1,9 +1,11 @@ +// 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.IO; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Internal; -using Microsoft.AspNetCore.SignalR.Internal.Formatters; namespace Microsoft.AspNetCore.SignalR.Microbenchmarks { diff --git a/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks.csproj b/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks.csproj index 63357c6ff1..545d54f9b3 100644 --- a/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks.csproj +++ b/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks.csproj @@ -5,6 +5,11 @@ netcoreapp2.1 + + + + + diff --git a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Formatters/BinaryMessageFormatter.cs b/src/Common/BinaryMessageFormatter.cs similarity index 93% rename from src/Microsoft.AspNetCore.SignalR.Common/Internal/Formatters/BinaryMessageFormatter.cs rename to src/Common/BinaryMessageFormatter.cs index 0ef7d0b5fe..62e31a8459 100644 --- a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Formatters/BinaryMessageFormatter.cs +++ b/src/Common/BinaryMessageFormatter.cs @@ -4,9 +4,9 @@ using System; using System.Buffers; -namespace Microsoft.AspNetCore.SignalR.Internal.Formatters +namespace Microsoft.AspNetCore.Internal { - public static class BinaryMessageFormatter + internal static class BinaryMessageFormatter { public static void WriteLengthPrefix(long length, IBufferWriter output) { diff --git a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Formatters/BinaryMessageParser.cs b/src/Common/BinaryMessageParser.cs similarity index 96% rename from src/Microsoft.AspNetCore.SignalR.Common/Internal/Formatters/BinaryMessageParser.cs rename to src/Common/BinaryMessageParser.cs index 9c5ca212eb..0f76cc8c72 100644 --- a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Formatters/BinaryMessageParser.cs +++ b/src/Common/BinaryMessageParser.cs @@ -4,9 +4,9 @@ using System; using System.Buffers; -namespace Microsoft.AspNetCore.SignalR.Internal.Formatters +namespace Microsoft.AspNetCore.Internal { - public static class BinaryMessageParser + internal static class BinaryMessageParser { private const int MaxLengthPrefixSize = 5; diff --git a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Formatters/TextMessageFormatter.cs b/src/Common/TextMessageFormatter.cs similarity index 86% rename from src/Microsoft.AspNetCore.SignalR.Common/Internal/Formatters/TextMessageFormatter.cs rename to src/Common/TextMessageFormatter.cs index 058172984e..32470f320b 100644 --- a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Formatters/TextMessageFormatter.cs +++ b/src/Common/TextMessageFormatter.cs @@ -4,9 +4,9 @@ using System.Buffers; using System.IO; -namespace Microsoft.AspNetCore.SignalR.Internal.Formatters +namespace Microsoft.AspNetCore.Internal { - public static class TextMessageFormatter + internal static class TextMessageFormatter { // This record separator is supposed to be used only for JSON payloads where 0x1e character // will not occur (is not a valid character) and therefore it is safe to not escape it diff --git a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Formatters/TextMessageParser.cs b/src/Common/TextMessageParser.cs similarity index 88% rename from src/Microsoft.AspNetCore.SignalR.Common/Internal/Formatters/TextMessageParser.cs rename to src/Common/TextMessageParser.cs index 566465e278..3d7d233e59 100644 --- a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Formatters/TextMessageParser.cs +++ b/src/Common/TextMessageParser.cs @@ -4,9 +4,9 @@ using System; using System.Buffers; -namespace Microsoft.AspNetCore.SignalR.Internal.Formatters +namespace Microsoft.AspNetCore.Internal { - public static class TextMessageParser + internal static class TextMessageParser { public static bool TryParseMessage(ref ReadOnlySequence buffer, out ReadOnlySequence payload) { diff --git a/src/Microsoft.AspNetCore.SignalR.Common/Microsoft.AspNetCore.SignalR.Common.csproj b/src/Microsoft.AspNetCore.SignalR.Common/Microsoft.AspNetCore.SignalR.Common.csproj index 7656d3074b..98d1cf30f7 100644 --- a/src/Microsoft.AspNetCore.SignalR.Common/Microsoft.AspNetCore.SignalR.Common.csproj +++ b/src/Microsoft.AspNetCore.SignalR.Common/Microsoft.AspNetCore.SignalR.Common.csproj @@ -10,6 +10,8 @@ + + diff --git a/src/Microsoft.AspNetCore.SignalR.Common/Protocol/HandshakeProtocol.cs b/src/Microsoft.AspNetCore.SignalR.Common/Protocol/HandshakeProtocol.cs index 0cd599c672..9e80ca0446 100644 --- a/src/Microsoft.AspNetCore.SignalR.Common/Protocol/HandshakeProtocol.cs +++ b/src/Microsoft.AspNetCore.SignalR.Common/Protocol/HandshakeProtocol.cs @@ -6,7 +6,6 @@ using System.Buffers; using System.IO; using Microsoft.AspNetCore.Internal; using Microsoft.AspNetCore.SignalR.Internal; -using Microsoft.AspNetCore.SignalR.Internal.Formatters; using Newtonsoft.Json; namespace Microsoft.AspNetCore.SignalR.Protocol diff --git a/src/Microsoft.AspNetCore.SignalR.Protocols.Json/Microsoft.AspNetCore.SignalR.Protocols.Json.csproj b/src/Microsoft.AspNetCore.SignalR.Protocols.Json/Microsoft.AspNetCore.SignalR.Protocols.Json.csproj index 6578fb5c3a..47f37af697 100644 --- a/src/Microsoft.AspNetCore.SignalR.Protocols.Json/Microsoft.AspNetCore.SignalR.Protocols.Json.csproj +++ b/src/Microsoft.AspNetCore.SignalR.Protocols.Json/Microsoft.AspNetCore.SignalR.Protocols.Json.csproj @@ -9,6 +9,8 @@ + + diff --git a/src/Microsoft.AspNetCore.SignalR.Protocols.Json/Protocol/JsonHubProtocol.cs b/src/Microsoft.AspNetCore.SignalR.Protocols.Json/Protocol/JsonHubProtocol.cs index 5c1c1488e9..919d89399f 100644 --- a/src/Microsoft.AspNetCore.SignalR.Protocols.Json/Protocol/JsonHubProtocol.cs +++ b/src/Microsoft.AspNetCore.SignalR.Protocols.Json/Protocol/JsonHubProtocol.cs @@ -9,7 +9,6 @@ using System.Runtime.ExceptionServices; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Internal; using Microsoft.AspNetCore.SignalR.Internal; -using Microsoft.AspNetCore.SignalR.Internal.Formatters; using Microsoft.Extensions.Options; using Newtonsoft.Json; using Newtonsoft.Json.Linq; diff --git a/src/Microsoft.AspNetCore.SignalR.Protocols.MessagePack/Microsoft.AspNetCore.SignalR.Protocols.MessagePack.csproj b/src/Microsoft.AspNetCore.SignalR.Protocols.MessagePack/Microsoft.AspNetCore.SignalR.Protocols.MessagePack.csproj index a4c7cbc0be..f92a2c9aad 100644 --- a/src/Microsoft.AspNetCore.SignalR.Protocols.MessagePack/Microsoft.AspNetCore.SignalR.Protocols.MessagePack.csproj +++ b/src/Microsoft.AspNetCore.SignalR.Protocols.MessagePack/Microsoft.AspNetCore.SignalR.Protocols.MessagePack.csproj @@ -8,6 +8,8 @@ + + diff --git a/src/Microsoft.AspNetCore.SignalR.Protocols.MessagePack/Protocol/MessagePackHubProtocol.cs b/src/Microsoft.AspNetCore.SignalR.Protocols.MessagePack/Protocol/MessagePackHubProtocol.cs index dfd1d98c8f..cc8009045a 100644 --- a/src/Microsoft.AspNetCore.SignalR.Protocols.MessagePack/Protocol/MessagePackHubProtocol.cs +++ b/src/Microsoft.AspNetCore.SignalR.Protocols.MessagePack/Protocol/MessagePackHubProtocol.cs @@ -12,7 +12,6 @@ using MessagePack; using MessagePack.Formatters; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Internal; -using Microsoft.AspNetCore.SignalR.Internal.Formatters; using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.SignalR.Protocol diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/Microsoft.AspNetCore.SignalR.Client.Tests.csproj b/test/Microsoft.AspNetCore.SignalR.Client.Tests/Microsoft.AspNetCore.SignalR.Client.Tests.csproj index efdeb1d1fc..43229b1bea 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/Microsoft.AspNetCore.SignalR.Client.Tests.csproj +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/Microsoft.AspNetCore.SignalR.Client.Tests.csproj @@ -6,6 +6,8 @@ + + diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestConnection.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestConnection.cs index b458330203..2cec05e1db 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestConnection.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestConnection.cs @@ -12,7 +12,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Internal; -using Microsoft.AspNetCore.SignalR.Internal.Formatters; using Microsoft.AspNetCore.SignalR.Protocol; using Newtonsoft.Json; diff --git a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Formatters/BinaryMessageFormatterTests.cs b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Formatters/BinaryMessageFormatterTests.cs index 910f8c0818..3f6c4e592a 100644 --- a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Formatters/BinaryMessageFormatterTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Formatters/BinaryMessageFormatterTests.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Text; using Microsoft.AspNetCore.Internal; using Microsoft.AspNetCore.SignalR.Internal; -using Microsoft.AspNetCore.SignalR.Internal.Formatters; using Xunit; namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Formatters diff --git a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Formatters/BinaryMessageParserTests.cs b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Formatters/BinaryMessageParserTests.cs index ad7139a331..c2f02811e7 100644 --- a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Formatters/BinaryMessageParserTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Formatters/BinaryMessageParserTests.cs @@ -5,7 +5,7 @@ using System; using System.Buffers; using System.Collections.Generic; using System.Text; -using Microsoft.AspNetCore.SignalR.Internal.Formatters; +using Microsoft.AspNetCore.Internal; using Xunit; namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Formatters diff --git a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Formatters/TextMessageFormatterTests.cs b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Formatters/TextMessageFormatterTests.cs index 43bbfab16d..a444f0108c 100644 --- a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Formatters/TextMessageFormatterTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Formatters/TextMessageFormatterTests.cs @@ -4,7 +4,7 @@ using System; using System.IO; using System.Text; -using Microsoft.AspNetCore.SignalR.Internal.Formatters; +using Microsoft.AspNetCore.Internal; using Xunit; namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Formatters diff --git a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Formatters/TextMessageParserTests.cs b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Formatters/TextMessageParserTests.cs index f7a337e174..df6330d833 100644 --- a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Formatters/TextMessageParserTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Formatters/TextMessageParserTests.cs @@ -4,7 +4,7 @@ using System; using System.Buffers; using System.Text; -using Microsoft.AspNetCore.SignalR.Internal.Formatters; +using Microsoft.AspNetCore.Internal; using Xunit; namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Formatters diff --git a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/JsonHubProtocolTests.cs b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/JsonHubProtocolTests.cs index d71bd7266b..18fea62dd5 100644 --- a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/JsonHubProtocolTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/JsonHubProtocolTests.cs @@ -8,7 +8,6 @@ using System.IO; using System.Linq; using System.Text; using Microsoft.AspNetCore.Internal; -using Microsoft.AspNetCore.SignalR.Internal.Formatters; using Microsoft.AspNetCore.SignalR.Protocol; using Microsoft.Extensions.Options; using Newtonsoft.Json; diff --git a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/MessagePackHubProtocolTests.cs b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/MessagePackHubProtocolTests.cs index ee33493be8..dcfe2b23a1 100644 --- a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/MessagePackHubProtocolTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/MessagePackHubProtocolTests.cs @@ -8,7 +8,6 @@ using System.Diagnostics; using System.IO; using System.Linq; using Microsoft.AspNetCore.Internal; -using Microsoft.AspNetCore.SignalR.Internal.Formatters; using Xunit; namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol diff --git a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Microsoft.AspNetCore.SignalR.Common.Tests.csproj b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Microsoft.AspNetCore.SignalR.Common.Tests.csproj index bc58f85974..585c330599 100644 --- a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Microsoft.AspNetCore.SignalR.Common.Tests.csproj +++ b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Microsoft.AspNetCore.SignalR.Common.Tests.csproj @@ -4,6 +4,11 @@ $(StandardTestTfms) + + + + + PreserveNewest