-
Notifications
You must be signed in to change notification settings - Fork 9.9k
/
HubProtocolExtensions.cs
32 lines (29 loc) · 1.03 KB
/
HubProtocolExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.AspNetCore.Internal;
namespace Microsoft.AspNetCore.SignalR.Protocol;
/// <summary>
/// Extension methods for <see cref="IHubProtocol"/>.
/// </summary>
public static class HubProtocolExtensions
{
/// <summary>
/// Converts the specified <see cref="HubMessage"/> to its serialized representation.
/// </summary>
/// <param name="hubProtocol">The hub protocol.</param>
/// <param name="message">The message to convert to bytes.</param>
/// <returns>The serialized representation of the specified message.</returns>
public static byte[] GetMessageBytes(this IHubProtocol hubProtocol, HubMessage message)
{
var writer = MemoryBufferWriter.Get();
try
{
hubProtocol.WriteMessage(message, writer);
return writer.ToArray();
}
finally
{
MemoryBufferWriter.Return(writer);
}
}
}