From b06d51d53568eae56fd2fea076e0ab5da6e1fb11 Mon Sep 17 00:00:00 2001 From: "Liangying.Wei" Date: Fri, 6 Dec 2024 17:09:56 +0800 Subject: [PATCH] update ...+ console.log("Application has started successfully."); ``` file: src/config.js diff: ``` - const port = 3000; + const port = process.env.PORT || 3000; ``` Commit message: Update log message and port configuration --- .../ServiceProtocol.cs | 2501 ++++++++--------- 1 file changed, 1250 insertions(+), 1251 deletions(-) diff --git a/src/Microsoft.Azure.SignalR.Protocols/ServiceProtocol.cs b/src/Microsoft.Azure.SignalR.Protocols/ServiceProtocol.cs index 28549d788..3fa5efe33 100644 --- a/src/Microsoft.Azure.SignalR.Protocols/ServiceProtocol.cs +++ b/src/Microsoft.Azure.SignalR.Protocols/ServiceProtocol.cs @@ -11,1534 +11,1533 @@ using MessagePack; using Microsoft.Extensions.Primitives; -namespace Microsoft.Azure.SignalR.Protocol +namespace Microsoft.Azure.SignalR.Protocol; + +/// +/// Implements the Azure SignalR Service Protocol. +/// +public class ServiceProtocol : IServiceProtocol { - /// - /// Implements the Azure SignalR Service Protocol. - /// - public class ServiceProtocol : IServiceProtocol - { - private static readonly IDictionary> EmptyReadOnlyMemoryDictionary = new Dictionary>(); + private static readonly IDictionary> EmptyReadOnlyMemoryDictionary = new Dictionary>(); - private static readonly IDictionary EmptyStringValuesDictionaryIgnoreCase = new Dictionary(StringComparer.OrdinalIgnoreCase); + private static readonly IDictionary EmptyStringValuesDictionaryIgnoreCase = new Dictionary(StringComparer.OrdinalIgnoreCase); - private static readonly int ProtocolVersion = 1; + private static readonly int ProtocolVersion = 1; - /// - public int Version => ProtocolVersion; + /// + public int Version => ProtocolVersion; - /// - public bool TryParseMessage(ref ReadOnlySequence input, out ServiceMessage? message) + /// + public bool TryParseMessage(ref ReadOnlySequence input, out ServiceMessage? message) + { + if (!BinaryMessageParser.TryParseMessage(ref input, out var payload)) { - if (!BinaryMessageParser.TryParseMessage(ref input, out var payload)) - { - message = null; - return false; - } - - var reader = new MessagePackReader(payload); - - message = ParseMessage(ref reader); - return true; + message = null; + return false; } - private static ServiceMessage? ParseMessage(ref MessagePackReader reader) - { - var arrayLength = reader.ReadArrayHeader(); + var reader = new MessagePackReader(payload); - var messageType = reader.ReadInt32(); + message = ParseMessage(ref reader); + return true; + } - switch (messageType) - { - case ServiceProtocolConstants.HandshakeRequestType: - return CreateHandshakeRequestMessage(ref reader, arrayLength); - case ServiceProtocolConstants.HandshakeResponseType: - return CreateHandshakeResponseMessage(ref reader, arrayLength); - case ServiceProtocolConstants.AccessKeyRequestType: - return CreateAccessKeyRequestMessage(ref reader, arrayLength); - case ServiceProtocolConstants.AccessKeyResponseType: - return CreateAccessKeyResponseMessage(ref reader, arrayLength); - case ServiceProtocolConstants.PingMessageType: - return CreatePingMessage(ref reader, arrayLength); - case ServiceProtocolConstants.OpenConnectionMessageType: - return CreateOpenConnectionMessage(ref reader, arrayLength); - case ServiceProtocolConstants.CloseConnectionMessageType: - return CreateCloseConnectionMessage(ref reader, arrayLength); - case ServiceProtocolConstants.ConnectionDataMessageType: - return CreateConnectionDataMessage(ref reader, arrayLength); - case ServiceProtocolConstants.ConnectionReconnectMessageType: - return CreateConnectionReconnectMessage(ref reader, arrayLength); - case ServiceProtocolConstants.MultiConnectionDataMessageType: - return CreateMultiConnectionDataMessage(ref reader, arrayLength); - case ServiceProtocolConstants.UserDataMessageType: - return CreateUserDataMessage(ref reader, arrayLength); - case ServiceProtocolConstants.MultiUserDataMessageType: - return CreateMultiUserDataMessage(ref reader, arrayLength); - case ServiceProtocolConstants.BroadcastDataMessageType: - return CreateBroadcastDataMessage(ref reader, arrayLength); - case ServiceProtocolConstants.JoinGroupMessageType: - return CreateJoinGroupMessage(ref reader, arrayLength); - case ServiceProtocolConstants.LeaveGroupMessageType: - return CreateLeaveGroupMessage(ref reader, arrayLength); - case ServiceProtocolConstants.UserJoinGroupMessageType: - return CreateUserJoinGroupMessage(ref reader, arrayLength); - case ServiceProtocolConstants.UserLeaveGroupMessageType: - return CreateUserLeaveGroupMessage(ref reader, arrayLength); - case ServiceProtocolConstants.UserJoinGroupWithAckMessageType: - return CreateUserJoinGroupWithAckMessage(ref reader, arrayLength); - case ServiceProtocolConstants.UserLeaveGroupWithAckMessageType: - return CreateUserLeaveGroupWithAckMessage(ref reader, arrayLength); - case ServiceProtocolConstants.GroupBroadcastDataMessageType: - return CreateGroupBroadcastDataMessage(ref reader, arrayLength); - case ServiceProtocolConstants.MultiGroupBroadcastDataMessageType: - return CreateMultiGroupBroadcastDataMessage(ref reader, arrayLength); - case ServiceProtocolConstants.ServiceErrorMessageType: - return CreateServiceErrorMessage(ref reader); - case ServiceProtocolConstants.ServiceEventMessageType: - return CreateServiceEventMessage(ref reader); - case ServiceProtocolConstants.JoinGroupWithAckMessageType: - return CreateJoinGroupWithAckMessage(ref reader, arrayLength); - case ServiceProtocolConstants.LeaveGroupWithAckMessageType: - return CreateLeaveGroupWithAckMessage(ref reader, arrayLength); - case ServiceProtocolConstants.CheckUserInGroupWithAckMessageType: - return CreateCheckUserInGroupWithAckMessage(ref reader, arrayLength); - case ServiceProtocolConstants.CheckGroupExistenceWithAckMessageType: - return CreateGroupExistenceWithAckMessage(ref reader, arrayLength); - case ServiceProtocolConstants.CheckConnectionExistenceWithAckMessageType: - return CreateCheckConnectionExistenceWithAckMessage(ref reader, arrayLength); - case ServiceProtocolConstants.CheckUserExistenceWithAckMessageType: - return CreateCheckUserExistenceWithAckMessage(ref reader, arrayLength); - case ServiceProtocolConstants.CloseConnectionsWithAckMessageType: + private static ServiceMessage? ParseMessage(ref MessagePackReader reader) + { + var arrayLength = reader.ReadArrayHeader(); + + var messageType = reader.ReadInt32(); + + switch (messageType) + { + case ServiceProtocolConstants.HandshakeRequestType: + return CreateHandshakeRequestMessage(ref reader, arrayLength); + case ServiceProtocolConstants.HandshakeResponseType: + return CreateHandshakeResponseMessage(ref reader, arrayLength); + case ServiceProtocolConstants.AccessKeyRequestType: + return CreateAccessKeyRequestMessage(ref reader, arrayLength); + case ServiceProtocolConstants.AccessKeyResponseType: + return CreateAccessKeyResponseMessage(ref reader, arrayLength); + case ServiceProtocolConstants.PingMessageType: + return CreatePingMessage(ref reader, arrayLength); + case ServiceProtocolConstants.OpenConnectionMessageType: + return CreateOpenConnectionMessage(ref reader, arrayLength); + case ServiceProtocolConstants.CloseConnectionMessageType: + return CreateCloseConnectionMessage(ref reader, arrayLength); + case ServiceProtocolConstants.ConnectionDataMessageType: + return CreateConnectionDataMessage(ref reader, arrayLength); + case ServiceProtocolConstants.ConnectionReconnectMessageType: + return CreateConnectionReconnectMessage(ref reader, arrayLength); + case ServiceProtocolConstants.MultiConnectionDataMessageType: + return CreateMultiConnectionDataMessage(ref reader, arrayLength); + case ServiceProtocolConstants.UserDataMessageType: + return CreateUserDataMessage(ref reader, arrayLength); + case ServiceProtocolConstants.MultiUserDataMessageType: + return CreateMultiUserDataMessage(ref reader, arrayLength); + case ServiceProtocolConstants.BroadcastDataMessageType: + return CreateBroadcastDataMessage(ref reader, arrayLength); + case ServiceProtocolConstants.JoinGroupMessageType: + return CreateJoinGroupMessage(ref reader, arrayLength); + case ServiceProtocolConstants.LeaveGroupMessageType: + return CreateLeaveGroupMessage(ref reader, arrayLength); + case ServiceProtocolConstants.UserJoinGroupMessageType: + return CreateUserJoinGroupMessage(ref reader, arrayLength); + case ServiceProtocolConstants.UserLeaveGroupMessageType: + return CreateUserLeaveGroupMessage(ref reader, arrayLength); + case ServiceProtocolConstants.UserJoinGroupWithAckMessageType: + return CreateUserJoinGroupWithAckMessage(ref reader, arrayLength); + case ServiceProtocolConstants.UserLeaveGroupWithAckMessageType: + return CreateUserLeaveGroupWithAckMessage(ref reader, arrayLength); + case ServiceProtocolConstants.GroupBroadcastDataMessageType: + return CreateGroupBroadcastDataMessage(ref reader, arrayLength); + case ServiceProtocolConstants.MultiGroupBroadcastDataMessageType: + return CreateMultiGroupBroadcastDataMessage(ref reader, arrayLength); + case ServiceProtocolConstants.ServiceErrorMessageType: + return CreateServiceErrorMessage(ref reader); + case ServiceProtocolConstants.ServiceEventMessageType: + return CreateServiceEventMessage(ref reader); + case ServiceProtocolConstants.JoinGroupWithAckMessageType: + return CreateJoinGroupWithAckMessage(ref reader, arrayLength); + case ServiceProtocolConstants.LeaveGroupWithAckMessageType: + return CreateLeaveGroupWithAckMessage(ref reader, arrayLength); + case ServiceProtocolConstants.CheckUserInGroupWithAckMessageType: + return CreateCheckUserInGroupWithAckMessage(ref reader, arrayLength); + case ServiceProtocolConstants.CheckGroupExistenceWithAckMessageType: + return CreateGroupExistenceWithAckMessage(ref reader, arrayLength); + case ServiceProtocolConstants.CheckConnectionExistenceWithAckMessageType: + return CreateCheckConnectionExistenceWithAckMessage(ref reader, arrayLength); + case ServiceProtocolConstants.CheckUserExistenceWithAckMessageType: + return CreateCheckUserExistenceWithAckMessage(ref reader, arrayLength); + case ServiceProtocolConstants.CloseConnectionsWithAckMessageType: #pragma warning disable CS0612 // Type or member is obsolete - return CreateCloseConnectionsWithAckMessage(ref reader, arrayLength); - case ServiceProtocolConstants.CloseConnectionWithAckMessageType: - return CreateCloseConnectionWithAckMessage(ref reader, arrayLength); + return CreateCloseConnectionsWithAckMessage(ref reader, arrayLength); + case ServiceProtocolConstants.CloseConnectionWithAckMessageType: + return CreateCloseConnectionWithAckMessage(ref reader, arrayLength); #pragma warning restore CS0612 // Type or member is obsolete - case ServiceProtocolConstants.CloseUserConnectionsWithAckMessageType: - return CreateCloseUserConnectionsWithAckMessage(ref reader, arrayLength); - case ServiceProtocolConstants.CloseGroupConnectionsWithAckMessageType: - return CreateCloseGroupConnectionsWithAckMessage(ref reader, arrayLength); - case ServiceProtocolConstants.AckMessageType: - return CreateAckMessage(ref reader, arrayLength); - case ServiceProtocolConstants.ClientInvocationMessageType: - return CreateClientInvocationMessage(ref reader, arrayLength); - case ServiceProtocolConstants.ClientCompletionMessageType: - return CreateClientCompletionMessage(ref reader, arrayLength); - case ServiceProtocolConstants.ErrorCompletionMessageType: - return CreateErrorCompletionMessage(ref reader, arrayLength); - case ServiceProtocolConstants.ServiceMappingMessageType: - return CreateServiceMappingMessage(ref reader, arrayLength); - case ServiceProtocolConstants.ConnectionFlowControlMessageType: - return CreateConnectionFlowControlMessage(ref reader, arrayLength); - default: - // Future protocol changes can add message types, old clients can ignore them - return null; - } + case ServiceProtocolConstants.CloseUserConnectionsWithAckMessageType: + return CreateCloseUserConnectionsWithAckMessage(ref reader, arrayLength); + case ServiceProtocolConstants.CloseGroupConnectionsWithAckMessageType: + return CreateCloseGroupConnectionsWithAckMessage(ref reader, arrayLength); + case ServiceProtocolConstants.AckMessageType: + return CreateAckMessage(ref reader, arrayLength); + case ServiceProtocolConstants.ClientInvocationMessageType: + return CreateClientInvocationMessage(ref reader, arrayLength); + case ServiceProtocolConstants.ClientCompletionMessageType: + return CreateClientCompletionMessage(ref reader, arrayLength); + case ServiceProtocolConstants.ErrorCompletionMessageType: + return CreateErrorCompletionMessage(ref reader, arrayLength); + case ServiceProtocolConstants.ServiceMappingMessageType: + return CreateServiceMappingMessage(ref reader, arrayLength); + case ServiceProtocolConstants.ConnectionFlowControlMessageType: + return CreateConnectionFlowControlMessage(ref reader, arrayLength); + default: + // Future protocol changes can add message types, old clients can ignore them + return null; } + } - /// - public void WriteMessage(ServiceMessage message, IBufferWriter output) - { - var memoryBufferWriter = MemoryBufferWriter.Get(); + /// + public void WriteMessage(ServiceMessage message, IBufferWriter output) + { + var memoryBufferWriter = MemoryBufferWriter.Get(); - try - { - var writer = new MessagePackWriter(memoryBufferWriter); + try + { + var writer = new MessagePackWriter(memoryBufferWriter); - // Write message to a buffer so we can get its length - WriteMessageCore(ref writer, message); + // Write message to a buffer so we can get its length + WriteMessageCore(ref writer, message); - // Write length then message to output - BinaryMessageFormatter.WriteLengthPrefix(memoryBufferWriter.Length, output); - memoryBufferWriter.CopyTo(output); - } - finally - { - MemoryBufferWriter.Return(memoryBufferWriter); - } + // Write length then message to output + BinaryMessageFormatter.WriteLengthPrefix(memoryBufferWriter.Length, output); + memoryBufferWriter.CopyTo(output); } - - /// - public ReadOnlyMemory GetMessageBytes(ServiceMessage message) + finally { - var memoryBufferWriter = MemoryBufferWriter.Get(); + MemoryBufferWriter.Return(memoryBufferWriter); + } + } - try - { - var writer = new MessagePackWriter(memoryBufferWriter); + /// + public ReadOnlyMemory GetMessageBytes(ServiceMessage message) + { + var memoryBufferWriter = MemoryBufferWriter.Get(); - // Write message to a buffer so we can get its length - WriteMessageCore(ref writer, message); + try + { + var writer = new MessagePackWriter(memoryBufferWriter); - var dataLength = memoryBufferWriter.Length; - var prefixLength = BinaryMessageFormatter.LengthPrefixLength(memoryBufferWriter.Length); + // Write message to a buffer so we can get its length + WriteMessageCore(ref writer, message); - var array = new byte[dataLength + prefixLength]; - var span = array.AsSpan(); + var dataLength = memoryBufferWriter.Length; + var prefixLength = BinaryMessageFormatter.LengthPrefixLength(memoryBufferWriter.Length); - // Write length then message to output - var written = BinaryMessageFormatter.WriteLengthPrefix(memoryBufferWriter.Length, span); - Debug.Assert(written == prefixLength); - memoryBufferWriter.CopyTo(span.Slice(prefixLength)); + var array = new byte[dataLength + prefixLength]; + var span = array.AsSpan(); - return array; - } - finally - { - MemoryBufferWriter.Return(memoryBufferWriter); - } - } + // Write length then message to output + var written = BinaryMessageFormatter.WriteLengthPrefix(memoryBufferWriter.Length, span); + Debug.Assert(written == prefixLength); + memoryBufferWriter.CopyTo(span.Slice(prefixLength)); - private static void WriteMessageCore(ref MessagePackWriter writer, ServiceMessage message) + return array; + } + finally { + MemoryBufferWriter.Return(memoryBufferWriter); + } + } + + private static void WriteMessageCore(ref MessagePackWriter writer, ServiceMessage message) + { #pragma warning disable CS0618 // Type or member is obsolete - switch (message) - { - case HandshakeRequestMessage handshakeRequestMessage: - WriteHandshakeRequestMessage(ref writer, handshakeRequestMessage); - break; - case HandshakeResponseMessage handshakeResponseMessage: - WriteHandshakeResponseMessage(ref writer, handshakeResponseMessage); - break; - case AccessKeyRequestMessage accessKeyRequestMessage: - WriteAccessKeyRequestMessage(ref writer, accessKeyRequestMessage); - break; - case AccessKeyResponseMessage accessKeyResponseMessage: - WriteAccessKeyResponseMessage(ref writer, accessKeyResponseMessage); - break; - case PingMessage pingMessage: - WritePingMessage(ref writer, pingMessage); - break; - case OpenConnectionMessage openConnectionMessage: - WriteOpenConnectionMessage(ref writer, openConnectionMessage); - break; - case CloseConnectionMessage closeConnectionMessage: - WriteCloseConnectionMessage(ref writer, closeConnectionMessage); - break; - case ConnectionDataMessage connectionDataMessage: - WriteConnectionDataMessage(ref writer, connectionDataMessage); - break; - case ConnectionReconnectMessage connectionReconnectMessage: - WriteConnectionReconnectMessage(ref writer, connectionReconnectMessage); - break; - case MultiConnectionDataMessage multiConnectionDataMessage: - WriteMultiConnectionDataMessage(ref writer, multiConnectionDataMessage); - break; - case UserDataMessage userDataMessage: - WriteUserDataMessage(ref writer, userDataMessage); - break; - case MultiUserDataMessage multiUserDataMessage: - WriteMultiUserDataMessage(ref writer, multiUserDataMessage); - break; - case BroadcastDataMessage broadcastDataMessage: - WriteBroadcastDataMessage(ref writer, broadcastDataMessage); - break; - case JoinGroupMessage joinGroupMessage: - WriteJoinGroupMessage(ref writer, joinGroupMessage); - break; - case JoinGroupWithAckMessage joinGroupWithAckMessage: - WriteJoinGroupWithAckMessage(ref writer, joinGroupWithAckMessage); - break; - case LeaveGroupMessage leaveGroupMessage: - WriteLeaveGroupMessage(ref writer, leaveGroupMessage); - break; - case LeaveGroupWithAckMessage leaveGroupWithAckMessage: - WriteLeaveGroupWithAckMessage(ref writer, leaveGroupWithAckMessage); - break; - case CheckUserInGroupWithAckMessage checkUserInGroupWithAckMessage: - WriteCheckUserInGroupWithAckMessage(ref writer, checkUserInGroupWithAckMessage); - break; - case CheckGroupExistenceWithAckMessage checkAnyConnectionInGroupWithAckMessage: - WriteCheckGroupExistenceWithAckMessage(ref writer, checkAnyConnectionInGroupWithAckMessage); - break; - case CheckConnectionExistenceWithAckMessage checkConnectionExistenceWithAckMessage: - WriteCheckConnectionExistenceWithAckMessage(ref writer, checkConnectionExistenceWithAckMessage); - break; - case CheckUserExistenceWithAckMessage checkConnectionExistenceAsUserWithAckMessage: - WriteCheckUserExistenceWithAckMessage(ref writer, checkConnectionExistenceAsUserWithAckMessage); - break; - case UserJoinGroupMessage userJoinGroupMessage: - WriteUserJoinGroupMessage(ref writer, userJoinGroupMessage); - break; - case UserLeaveGroupMessage userLeaveGroupMessage: - WriteUserLeaveGroupMessage(ref writer, userLeaveGroupMessage); - break; - case UserJoinGroupWithAckMessage userJoinGroupWithAckMessage: - WriteUserJoinGroupWithAckMessage(ref writer, userJoinGroupWithAckMessage); - break; - case UserLeaveGroupWithAckMessage userLeaveGroupWithAckMessage: - WriteUserLeaveGroupWithAckMessage(ref writer, userLeaveGroupWithAckMessage); - break; - case GroupBroadcastDataMessage groupBroadcastDataMessage: - WriteGroupBroadcastDataMessage(ref writer, groupBroadcastDataMessage); - break; - case MultiGroupBroadcastDataMessage multiGroupBroadcastDataMessage: - WriteMultiGroupBroadcastDataMessage(ref writer, multiGroupBroadcastDataMessage); - break; - case ServiceErrorMessage serviceErrorMessage: - WriteServiceErrorMessage(ref writer, serviceErrorMessage); - break; - case ServiceEventMessage serviceWarningMessage: - WriteServiceEventMessage(ref writer, serviceWarningMessage); - break; - case CloseConnectionWithAckMessage closeConnectionWithAckMessage: + switch (message) + { + case HandshakeRequestMessage handshakeRequestMessage: + WriteHandshakeRequestMessage(ref writer, handshakeRequestMessage); + break; + case HandshakeResponseMessage handshakeResponseMessage: + WriteHandshakeResponseMessage(ref writer, handshakeResponseMessage); + break; + case AccessKeyRequestMessage accessKeyRequestMessage: + WriteAccessKeyRequestMessage(ref writer, accessKeyRequestMessage); + break; + case AccessKeyResponseMessage accessKeyResponseMessage: + WriteAccessKeyResponseMessage(ref writer, accessKeyResponseMessage); + break; + case PingMessage pingMessage: + WritePingMessage(ref writer, pingMessage); + break; + case OpenConnectionMessage openConnectionMessage: + WriteOpenConnectionMessage(ref writer, openConnectionMessage); + break; + case CloseConnectionMessage closeConnectionMessage: + WriteCloseConnectionMessage(ref writer, closeConnectionMessage); + break; + case ConnectionDataMessage connectionDataMessage: + WriteConnectionDataMessage(ref writer, connectionDataMessage); + break; + case ConnectionReconnectMessage connectionReconnectMessage: + WriteConnectionReconnectMessage(ref writer, connectionReconnectMessage); + break; + case MultiConnectionDataMessage multiConnectionDataMessage: + WriteMultiConnectionDataMessage(ref writer, multiConnectionDataMessage); + break; + case UserDataMessage userDataMessage: + WriteUserDataMessage(ref writer, userDataMessage); + break; + case MultiUserDataMessage multiUserDataMessage: + WriteMultiUserDataMessage(ref writer, multiUserDataMessage); + break; + case BroadcastDataMessage broadcastDataMessage: + WriteBroadcastDataMessage(ref writer, broadcastDataMessage); + break; + case JoinGroupMessage joinGroupMessage: + WriteJoinGroupMessage(ref writer, joinGroupMessage); + break; + case JoinGroupWithAckMessage joinGroupWithAckMessage: + WriteJoinGroupWithAckMessage(ref writer, joinGroupWithAckMessage); + break; + case LeaveGroupMessage leaveGroupMessage: + WriteLeaveGroupMessage(ref writer, leaveGroupMessage); + break; + case LeaveGroupWithAckMessage leaveGroupWithAckMessage: + WriteLeaveGroupWithAckMessage(ref writer, leaveGroupWithAckMessage); + break; + case CheckUserInGroupWithAckMessage checkUserInGroupWithAckMessage: + WriteCheckUserInGroupWithAckMessage(ref writer, checkUserInGroupWithAckMessage); + break; + case CheckGroupExistenceWithAckMessage checkAnyConnectionInGroupWithAckMessage: + WriteCheckGroupExistenceWithAckMessage(ref writer, checkAnyConnectionInGroupWithAckMessage); + break; + case CheckConnectionExistenceWithAckMessage checkConnectionExistenceWithAckMessage: + WriteCheckConnectionExistenceWithAckMessage(ref writer, checkConnectionExistenceWithAckMessage); + break; + case CheckUserExistenceWithAckMessage checkConnectionExistenceAsUserWithAckMessage: + WriteCheckUserExistenceWithAckMessage(ref writer, checkConnectionExistenceAsUserWithAckMessage); + break; + case UserJoinGroupMessage userJoinGroupMessage: + WriteUserJoinGroupMessage(ref writer, userJoinGroupMessage); + break; + case UserLeaveGroupMessage userLeaveGroupMessage: + WriteUserLeaveGroupMessage(ref writer, userLeaveGroupMessage); + break; + case UserJoinGroupWithAckMessage userJoinGroupWithAckMessage: + WriteUserJoinGroupWithAckMessage(ref writer, userJoinGroupWithAckMessage); + break; + case UserLeaveGroupWithAckMessage userLeaveGroupWithAckMessage: + WriteUserLeaveGroupWithAckMessage(ref writer, userLeaveGroupWithAckMessage); + break; + case GroupBroadcastDataMessage groupBroadcastDataMessage: + WriteGroupBroadcastDataMessage(ref writer, groupBroadcastDataMessage); + break; + case MultiGroupBroadcastDataMessage multiGroupBroadcastDataMessage: + WriteMultiGroupBroadcastDataMessage(ref writer, multiGroupBroadcastDataMessage); + break; + case ServiceErrorMessage serviceErrorMessage: + WriteServiceErrorMessage(ref writer, serviceErrorMessage); + break; + case ServiceEventMessage serviceWarningMessage: + WriteServiceEventMessage(ref writer, serviceWarningMessage); + break; + case CloseConnectionWithAckMessage closeConnectionWithAckMessage: #pragma warning disable CS0612 // Type or member is obsolete - WriteCloseConnectionWithAckMessage(ref writer, closeConnectionWithAckMessage); - break; - case CloseConnectionsWithAckMessage closeConnectionsWithAckMessage: - WriteCloseConnectionsWithAckMessage(ref writer, closeConnectionsWithAckMessage); + WriteCloseConnectionWithAckMessage(ref writer, closeConnectionWithAckMessage); + break; + case CloseConnectionsWithAckMessage closeConnectionsWithAckMessage: + WriteCloseConnectionsWithAckMessage(ref writer, closeConnectionsWithAckMessage); #pragma warning restore CS0612 // Type or member is obsolete - break; - case CloseUserConnectionsWithAckMessage closeUserConnectionsWithAckMessage: - WriteCloseUserConnectionsWithAckMessage(ref writer, closeUserConnectionsWithAckMessage); - break; - case CloseGroupConnectionsWithAckMessage closeGroupConnectionsWithAckMessage: - WriteCloseGroupConnectionsWithAckMessage(ref writer, closeGroupConnectionsWithAckMessage); - break; - case AckMessage ackMessage: - WriteAckMessage(ref writer, ackMessage); - break; - case ClientInvocationMessage clientInvocationMessage: - WriteClientInvocationMessage(ref writer, clientInvocationMessage); - break; - case ClientCompletionMessage clientCompletionMesssage: - WriteClientCompletionMessage(ref writer, clientCompletionMesssage); - break; - case ErrorCompletionMessage errorCompletionMesssage: - WriteErrorCompletionMessage(ref writer, errorCompletionMesssage); - break; - case ServiceMappingMessage serviceMappingMessage: - WriteServiceMappingMessage(ref writer, serviceMappingMessage); - break; - case ConnectionFlowControlMessage connectionFlowControlMessage: - WriteConnectionFlowControlMessage(ref writer, connectionFlowControlMessage); - break; - default: - throw new InvalidDataException($"Unexpected message type: {message.GetType().Name}"); - } + break; + case CloseUserConnectionsWithAckMessage closeUserConnectionsWithAckMessage: + WriteCloseUserConnectionsWithAckMessage(ref writer, closeUserConnectionsWithAckMessage); + break; + case CloseGroupConnectionsWithAckMessage closeGroupConnectionsWithAckMessage: + WriteCloseGroupConnectionsWithAckMessage(ref writer, closeGroupConnectionsWithAckMessage); + break; + case AckMessage ackMessage: + WriteAckMessage(ref writer, ackMessage); + break; + case ClientInvocationMessage clientInvocationMessage: + WriteClientInvocationMessage(ref writer, clientInvocationMessage); + break; + case ClientCompletionMessage clientCompletionMesssage: + WriteClientCompletionMessage(ref writer, clientCompletionMesssage); + break; + case ErrorCompletionMessage errorCompletionMesssage: + WriteErrorCompletionMessage(ref writer, errorCompletionMesssage); + break; + case ServiceMappingMessage serviceMappingMessage: + WriteServiceMappingMessage(ref writer, serviceMappingMessage); + break; + case ConnectionFlowControlMessage connectionFlowControlMessage: + WriteConnectionFlowControlMessage(ref writer, connectionFlowControlMessage); + break; + default: + throw new InvalidDataException($"Unexpected message type: {message.GetType().Name}"); + } #pragma warning restore CS0618 // Type or member is obsolete - writer.Flush(); - } + writer.Flush(); + } - private static void WriteHandshakeRequestMessage(ref MessagePackWriter writer, HandshakeRequestMessage message) - { - writer.WriteArrayHeader(7); - writer.Write(ServiceProtocolConstants.HandshakeRequestType); - writer.Write(message.Version); - writer.Write(message.ConnectionType); - writer.Write(message.ConnectionType == 0 ? "" : message.Target ?? string.Empty); - writer.Write(message.MigrationLevel); - message.WriteExtensionMembers(ref writer); - writer.Write(message.AllowStatefulReconnects); - } + private static void WriteHandshakeRequestMessage(ref MessagePackWriter writer, HandshakeRequestMessage message) + { + writer.WriteArrayHeader(7); + writer.Write(ServiceProtocolConstants.HandshakeRequestType); + writer.Write(message.Version); + writer.Write(message.ConnectionType); + writer.Write(message.ConnectionType == 0 ? "" : message.Target ?? string.Empty); + writer.Write(message.MigrationLevel); + message.WriteExtensionMembers(ref writer); + writer.Write(message.AllowStatefulReconnects); + } - private static void WriteHandshakeResponseMessage(ref MessagePackWriter writer, HandshakeResponseMessage message) - { - writer.WriteArrayHeader(4); - writer.Write(ServiceProtocolConstants.HandshakeResponseType); - writer.Write(message.ErrorMessage); - message.WriteExtensionMembers(ref writer); - writer.Write(message.ConnectionId); - } + private static void WriteHandshakeResponseMessage(ref MessagePackWriter writer, HandshakeResponseMessage message) + { + writer.WriteArrayHeader(4); + writer.Write(ServiceProtocolConstants.HandshakeResponseType); + writer.Write(message.ErrorMessage); + message.WriteExtensionMembers(ref writer); + writer.Write(message.ConnectionId); + } - private static void WriteAccessKeyRequestMessage(ref MessagePackWriter writer, AccessKeyRequestMessage message) - { - writer.WriteArrayHeader(4); - writer.Write(ServiceProtocolConstants.AccessKeyRequestType); - writer.Write(message.Token); - writer.Write(message.Kid); - message.WriteExtensionMembers(ref writer); - } + private static void WriteAccessKeyRequestMessage(ref MessagePackWriter writer, AccessKeyRequestMessage message) + { + writer.WriteArrayHeader(4); + writer.Write(ServiceProtocolConstants.AccessKeyRequestType); + writer.Write(message.Token); + writer.Write(message.Kid); + message.WriteExtensionMembers(ref writer); + } - private static void WriteAccessKeyResponseMessage(ref MessagePackWriter writer, AccessKeyResponseMessage message) - { - writer.WriteArrayHeader(6); - writer.Write(ServiceProtocolConstants.AccessKeyResponseType); - writer.Write(message.Kid); - writer.Write(message.AccessKey); - writer.Write(message.ErrorType); - writer.Write(message.ErrorMessage); - message.WriteExtensionMembers(ref writer); - } + private static void WriteAccessKeyResponseMessage(ref MessagePackWriter writer, AccessKeyResponseMessage message) + { + writer.WriteArrayHeader(6); + writer.Write(ServiceProtocolConstants.AccessKeyResponseType); + writer.Write(message.Kid); + writer.Write(message.AccessKey); + writer.Write(message.ErrorType); + writer.Write(message.ErrorMessage); + message.WriteExtensionMembers(ref writer); + } - private static void WritePingMessage(ref MessagePackWriter writer, PingMessage message) + private static void WritePingMessage(ref MessagePackWriter writer, PingMessage message) + { + writer.WriteArrayHeader(message.Messages.Length + 1); + writer.Write(ServiceProtocolConstants.PingMessageType); + foreach (var item in message.Messages) { - writer.WriteArrayHeader(message.Messages.Length + 1); - writer.Write(ServiceProtocolConstants.PingMessageType); - foreach (var item in message.Messages) - { - writer.Write(item); - } + writer.Write(item); } + } - private static void WriteOpenConnectionMessage(ref MessagePackWriter writer, OpenConnectionMessage message) - { - writer.WriteArrayHeader(6); - writer.Write(ServiceProtocolConstants.OpenConnectionMessageType); - writer.Write(message.ConnectionId); + private static void WriteOpenConnectionMessage(ref MessagePackWriter writer, OpenConnectionMessage message) + { + writer.WriteArrayHeader(6); + writer.Write(ServiceProtocolConstants.OpenConnectionMessageType); + writer.Write(message.ConnectionId); - if (message.Claims?.Length > 0) - { - writer.WriteMapHeader(message.Claims.Length); - foreach (var claim in message.Claims) - { - writer.Write(claim.Type); - writer.Write(claim.Value); - } - } - else + if (message.Claims?.Length > 0) + { + writer.WriteMapHeader(message.Claims.Length); + foreach (var claim in message.Claims) { - writer.WriteMapHeader(0); + writer.Write(claim.Type); + writer.Write(claim.Value); } - WriteHeaders(ref writer, message.Headers); - - writer.Write(message.QueryString); - message.WriteExtensionMembers(ref writer); } - - private static void WriteCloseConnectionMessage(ref MessagePackWriter writer, CloseConnectionMessage message) + else { - writer.WriteArrayHeader(5); - writer.Write(ServiceProtocolConstants.CloseConnectionMessageType); - writer.Write(message.ConnectionId); - writer.Write(message.ErrorMessage); - WriteHeaders(ref writer, message.Headers); - message.WriteExtensionMembers(ref writer); + writer.WriteMapHeader(0); } + WriteHeaders(ref writer, message.Headers); - [Obsolete] - private static void WriteCloseConnectionWithAckMessage(ref MessagePackWriter writer, CloseConnectionWithAckMessage message) - { - writer.WriteArrayHeader(5); - writer.Write(ServiceProtocolConstants.CloseConnectionWithAckMessageType); - writer.Write(message.ConnectionId); - writer.Write(message.Reason); - writer.Write(message.AckId); - message.WriteExtensionMembers(ref writer); - } + writer.Write(message.QueryString); + message.WriteExtensionMembers(ref writer); + } - [Obsolete] - private static void WriteCloseConnectionsWithAckMessage(ref MessagePackWriter writer, CloseConnectionsWithAckMessage message) - { - writer.WriteArrayHeader(5); - writer.Write(ServiceProtocolConstants.CloseConnectionsWithAckMessageType); - writer.Write(message.Reason); - writer.Write(message.AckId); - WriteStringArray(ref writer, message.ExcludedList); - message.WriteExtensionMembers(ref writer); - } + private static void WriteCloseConnectionMessage(ref MessagePackWriter writer, CloseConnectionMessage message) + { + writer.WriteArrayHeader(5); + writer.Write(ServiceProtocolConstants.CloseConnectionMessageType); + writer.Write(message.ConnectionId); + writer.Write(message.ErrorMessage); + WriteHeaders(ref writer, message.Headers); + message.WriteExtensionMembers(ref writer); + } - private static void WriteCloseUserConnectionsWithAckMessage(ref MessagePackWriter writer, CloseUserConnectionsWithAckMessage message) - { - writer.WriteArrayHeader(6); - writer.Write(ServiceProtocolConstants.CloseUserConnectionsWithAckMessageType); - writer.Write(message.UserId); - writer.Write(message.Reason); - writer.Write(message.AckId); - WriteStringArray(ref writer, message.ExcludedList); - message.WriteExtensionMembers(ref writer); - } + [Obsolete] + private static void WriteCloseConnectionWithAckMessage(ref MessagePackWriter writer, CloseConnectionWithAckMessage message) + { + writer.WriteArrayHeader(5); + writer.Write(ServiceProtocolConstants.CloseConnectionWithAckMessageType); + writer.Write(message.ConnectionId); + writer.Write(message.Reason); + writer.Write(message.AckId); + message.WriteExtensionMembers(ref writer); + } - private static void WriteCloseGroupConnectionsWithAckMessage(ref MessagePackWriter writer, CloseGroupConnectionsWithAckMessage message) - { - writer.WriteArrayHeader(6); - writer.Write(ServiceProtocolConstants.CloseGroupConnectionsWithAckMessageType); - writer.Write(message.GroupName); - writer.Write(message.Reason); - writer.Write(message.AckId); - WriteStringArray(ref writer, message.ExcludedList); - message.WriteExtensionMembers(ref writer); - } + [Obsolete] + private static void WriteCloseConnectionsWithAckMessage(ref MessagePackWriter writer, CloseConnectionsWithAckMessage message) + { + writer.WriteArrayHeader(5); + writer.Write(ServiceProtocolConstants.CloseConnectionsWithAckMessageType); + writer.Write(message.Reason); + writer.Write(message.AckId); + WriteStringArray(ref writer, message.ExcludedList); + message.WriteExtensionMembers(ref writer); + } - private static void WriteConnectionDataMessage(ref MessagePackWriter writer, ConnectionDataMessage message) - { - writer.WriteArrayHeader(4); - writer.Write(ServiceProtocolConstants.ConnectionDataMessageType); - writer.Write(message.ConnectionId); - writer.Write(message.Payload); - message.WriteExtensionMembers(ref writer); - } + private static void WriteCloseUserConnectionsWithAckMessage(ref MessagePackWriter writer, CloseUserConnectionsWithAckMessage message) + { + writer.WriteArrayHeader(6); + writer.Write(ServiceProtocolConstants.CloseUserConnectionsWithAckMessageType); + writer.Write(message.UserId); + writer.Write(message.Reason); + writer.Write(message.AckId); + WriteStringArray(ref writer, message.ExcludedList); + message.WriteExtensionMembers(ref writer); + } - private static void WriteConnectionReconnectMessage(ref MessagePackWriter writer, ConnectionReconnectMessage message) - { - writer.WriteArrayHeader(3); - writer.Write(ServiceProtocolConstants.ConnectionReconnectMessageType); - writer.Write(message.ConnectionId); - message.WriteExtensionMembers(ref writer); - } + private static void WriteCloseGroupConnectionsWithAckMessage(ref MessagePackWriter writer, CloseGroupConnectionsWithAckMessage message) + { + writer.WriteArrayHeader(6); + writer.Write(ServiceProtocolConstants.CloseGroupConnectionsWithAckMessageType); + writer.Write(message.GroupName); + writer.Write(message.Reason); + writer.Write(message.AckId); + WriteStringArray(ref writer, message.ExcludedList); + message.WriteExtensionMembers(ref writer); + } - private static void WriteMultiConnectionDataMessage(ref MessagePackWriter writer, MultiConnectionDataMessage message) - { - writer.WriteArrayHeader(4); - writer.Write(ServiceProtocolConstants.MultiConnectionDataMessageType); - WriteStringArray(ref writer, message.ConnectionList); - WritePayloads(ref writer, message.Payloads); - message.WriteExtensionMembers(ref writer); - } + private static void WriteConnectionDataMessage(ref MessagePackWriter writer, ConnectionDataMessage message) + { + writer.WriteArrayHeader(4); + writer.Write(ServiceProtocolConstants.ConnectionDataMessageType); + writer.Write(message.ConnectionId); + writer.Write(message.Payload); + message.WriteExtensionMembers(ref writer); + } - private static void WriteUserDataMessage(ref MessagePackWriter writer, UserDataMessage message) - { - writer.WriteArrayHeader(4); - writer.Write(ServiceProtocolConstants.UserDataMessageType); - writer.Write(message.UserId); - WritePayloads(ref writer, message.Payloads); - message.WriteExtensionMembers(ref writer); - } + private static void WriteConnectionReconnectMessage(ref MessagePackWriter writer, ConnectionReconnectMessage message) + { + writer.WriteArrayHeader(3); + writer.Write(ServiceProtocolConstants.ConnectionReconnectMessageType); + writer.Write(message.ConnectionId); + message.WriteExtensionMembers(ref writer); + } - private static void WriteMultiUserDataMessage(ref MessagePackWriter writer, MultiUserDataMessage message) - { - writer.WriteArrayHeader(4); - writer.Write(ServiceProtocolConstants.MultiUserDataMessageType); - WriteStringArray(ref writer, message.UserList); - WritePayloads(ref writer, message.Payloads); - message.WriteExtensionMembers(ref writer); - } + private static void WriteMultiConnectionDataMessage(ref MessagePackWriter writer, MultiConnectionDataMessage message) + { + writer.WriteArrayHeader(4); + writer.Write(ServiceProtocolConstants.MultiConnectionDataMessageType); + WriteStringArray(ref writer, message.ConnectionList); + WritePayloads(ref writer, message.Payloads); + message.WriteExtensionMembers(ref writer); + } - private static void WriteBroadcastDataMessage(ref MessagePackWriter writer, BroadcastDataMessage message) - { - writer.WriteArrayHeader(4); - writer.Write(ServiceProtocolConstants.BroadcastDataMessageType); - WriteStringArray(ref writer, message.ExcludedList); - WritePayloads(ref writer, message.Payloads); - message.WriteExtensionMembers(ref writer); - } + private static void WriteUserDataMessage(ref MessagePackWriter writer, UserDataMessage message) + { + writer.WriteArrayHeader(4); + writer.Write(ServiceProtocolConstants.UserDataMessageType); + writer.Write(message.UserId); + WritePayloads(ref writer, message.Payloads); + message.WriteExtensionMembers(ref writer); + } - private static void WriteJoinGroupMessage(ref MessagePackWriter writer, JoinGroupMessage message) - { - writer.WriteArrayHeader(4); - writer.Write(ServiceProtocolConstants.JoinGroupMessageType); - writer.Write(message.ConnectionId); - writer.Write(message.GroupName); - message.WriteExtensionMembers(ref writer); - } + private static void WriteMultiUserDataMessage(ref MessagePackWriter writer, MultiUserDataMessage message) + { + writer.WriteArrayHeader(4); + writer.Write(ServiceProtocolConstants.MultiUserDataMessageType); + WriteStringArray(ref writer, message.UserList); + WritePayloads(ref writer, message.Payloads); + message.WriteExtensionMembers(ref writer); + } - private static void WriteLeaveGroupMessage(ref MessagePackWriter writer, LeaveGroupMessage message) - { - writer.WriteArrayHeader(4); - writer.Write(ServiceProtocolConstants.LeaveGroupMessageType); - writer.Write(message.ConnectionId); - writer.Write(message.GroupName); - message.WriteExtensionMembers(ref writer); - } + private static void WriteBroadcastDataMessage(ref MessagePackWriter writer, BroadcastDataMessage message) + { + writer.WriteArrayHeader(4); + writer.Write(ServiceProtocolConstants.BroadcastDataMessageType); + WriteStringArray(ref writer, message.ExcludedList); + WritePayloads(ref writer, message.Payloads); + message.WriteExtensionMembers(ref writer); + } - private static void WriteUserJoinGroupMessage(ref MessagePackWriter writer, UserJoinGroupMessage message) - { - writer.WriteArrayHeader(4); - writer.Write(ServiceProtocolConstants.UserJoinGroupMessageType); - writer.Write(message.UserId); - writer.Write(message.GroupName); - message.WriteExtensionMembers(ref writer); - } + private static void WriteJoinGroupMessage(ref MessagePackWriter writer, JoinGroupMessage message) + { + writer.WriteArrayHeader(4); + writer.Write(ServiceProtocolConstants.JoinGroupMessageType); + writer.Write(message.ConnectionId); + writer.Write(message.GroupName); + message.WriteExtensionMembers(ref writer); + } - private static void WriteUserLeaveGroupMessage(ref MessagePackWriter writer, UserLeaveGroupMessage message) - { - writer.WriteArrayHeader(4); - writer.Write(ServiceProtocolConstants.UserLeaveGroupMessageType); - writer.Write(message.UserId); - writer.Write(message.GroupName); - message.WriteExtensionMembers(ref writer); - } + private static void WriteLeaveGroupMessage(ref MessagePackWriter writer, LeaveGroupMessage message) + { + writer.WriteArrayHeader(4); + writer.Write(ServiceProtocolConstants.LeaveGroupMessageType); + writer.Write(message.ConnectionId); + writer.Write(message.GroupName); + message.WriteExtensionMembers(ref writer); + } - private static void WriteUserJoinGroupWithAckMessage(ref MessagePackWriter writer, UserJoinGroupWithAckMessage message) - { - writer.WriteArrayHeader(5); - writer.Write(ServiceProtocolConstants.UserJoinGroupWithAckMessageType); - writer.Write(message.UserId); - writer.Write(message.GroupName); - writer.Write(message.AckId); - message.WriteExtensionMembers(ref writer); - } + private static void WriteUserJoinGroupMessage(ref MessagePackWriter writer, UserJoinGroupMessage message) + { + writer.WriteArrayHeader(4); + writer.Write(ServiceProtocolConstants.UserJoinGroupMessageType); + writer.Write(message.UserId); + writer.Write(message.GroupName); + message.WriteExtensionMembers(ref writer); + } - private static void WriteUserLeaveGroupWithAckMessage(ref MessagePackWriter writer, UserLeaveGroupWithAckMessage message) - { - writer.WriteArrayHeader(5); - writer.Write(ServiceProtocolConstants.UserLeaveGroupWithAckMessageType); - writer.Write(message.UserId); - writer.Write(message.GroupName); - writer.Write(message.AckId); - message.WriteExtensionMembers(ref writer); - } + private static void WriteUserLeaveGroupMessage(ref MessagePackWriter writer, UserLeaveGroupMessage message) + { + writer.WriteArrayHeader(4); + writer.Write(ServiceProtocolConstants.UserLeaveGroupMessageType); + writer.Write(message.UserId); + writer.Write(message.GroupName); + message.WriteExtensionMembers(ref writer); + } - private static void WriteGroupBroadcastDataMessage(ref MessagePackWriter writer, GroupBroadcastDataMessage message) - { - writer.WriteArrayHeader(7); - writer.Write(ServiceProtocolConstants.GroupBroadcastDataMessageType); - writer.Write(message.GroupName); - WriteStringArray(ref writer, message.ExcludedList); - WritePayloads(ref writer, message.Payloads); - message.WriteExtensionMembers(ref writer); - WriteStringArray(ref writer, message.ExcludedUserList); - writer.Write(message.CallerUserId); - } + private static void WriteUserJoinGroupWithAckMessage(ref MessagePackWriter writer, UserJoinGroupWithAckMessage message) + { + writer.WriteArrayHeader(5); + writer.Write(ServiceProtocolConstants.UserJoinGroupWithAckMessageType); + writer.Write(message.UserId); + writer.Write(message.GroupName); + writer.Write(message.AckId); + message.WriteExtensionMembers(ref writer); + } - private static void WriteMultiGroupBroadcastDataMessage(ref MessagePackWriter writer, MultiGroupBroadcastDataMessage message) - { - writer.WriteArrayHeader(4); - writer.Write(ServiceProtocolConstants.MultiGroupBroadcastDataMessageType); - WriteStringArray(ref writer, message.GroupList); - WritePayloads(ref writer, message.Payloads); - message.WriteExtensionMembers(ref writer); - } + private static void WriteUserLeaveGroupWithAckMessage(ref MessagePackWriter writer, UserLeaveGroupWithAckMessage message) + { + writer.WriteArrayHeader(5); + writer.Write(ServiceProtocolConstants.UserLeaveGroupWithAckMessageType); + writer.Write(message.UserId); + writer.Write(message.GroupName); + writer.Write(message.AckId); + message.WriteExtensionMembers(ref writer); + } - private static void WriteServiceErrorMessage(ref MessagePackWriter writer, ServiceErrorMessage message) - { - writer.WriteArrayHeader(2); - writer.Write(ServiceProtocolConstants.ServiceErrorMessageType); - writer.Write(message.ErrorMessage); - } + private static void WriteGroupBroadcastDataMessage(ref MessagePackWriter writer, GroupBroadcastDataMessage message) + { + writer.WriteArrayHeader(7); + writer.Write(ServiceProtocolConstants.GroupBroadcastDataMessageType); + writer.Write(message.GroupName); + WriteStringArray(ref writer, message.ExcludedList); + WritePayloads(ref writer, message.Payloads); + message.WriteExtensionMembers(ref writer); + WriteStringArray(ref writer, message.ExcludedUserList); + writer.Write(message.CallerUserId); + } - private static void WriteServiceEventMessage(ref MessagePackWriter writer, ServiceEventMessage message) - { - writer.WriteArrayHeader(6); - writer.Write(ServiceProtocolConstants.ServiceEventMessageType); - writer.Write((int)message.Type); - writer.Write(message.Id); - writer.Write((int)message.Kind); - writer.Write(message.Message); - message.WriteExtensionMembers(ref writer); - } + private static void WriteMultiGroupBroadcastDataMessage(ref MessagePackWriter writer, MultiGroupBroadcastDataMessage message) + { + writer.WriteArrayHeader(4); + writer.Write(ServiceProtocolConstants.MultiGroupBroadcastDataMessageType); + WriteStringArray(ref writer, message.GroupList); + WritePayloads(ref writer, message.Payloads); + message.WriteExtensionMembers(ref writer); + } - private static void WriteJoinGroupWithAckMessage(ref MessagePackWriter writer, JoinGroupWithAckMessage message) - { - writer.WriteArrayHeader(5); - writer.Write(ServiceProtocolConstants.JoinGroupWithAckMessageType); - writer.Write(message.ConnectionId); - writer.Write(message.GroupName); - writer.Write(message.AckId); - message.WriteExtensionMembers(ref writer); - } + private static void WriteServiceErrorMessage(ref MessagePackWriter writer, ServiceErrorMessage message) + { + writer.WriteArrayHeader(2); + writer.Write(ServiceProtocolConstants.ServiceErrorMessageType); + writer.Write(message.ErrorMessage); + } - private static void WriteLeaveGroupWithAckMessage(ref MessagePackWriter writer, LeaveGroupWithAckMessage message) - { - writer.WriteArrayHeader(5); - writer.Write(ServiceProtocolConstants.LeaveGroupWithAckMessageType); - writer.Write(message.ConnectionId); - writer.Write(message.GroupName); - writer.Write(message.AckId); - message.WriteExtensionMembers(ref writer); - } + private static void WriteServiceEventMessage(ref MessagePackWriter writer, ServiceEventMessage message) + { + writer.WriteArrayHeader(6); + writer.Write(ServiceProtocolConstants.ServiceEventMessageType); + writer.Write((int)message.Type); + writer.Write(message.Id); + writer.Write((int)message.Kind); + writer.Write(message.Message); + message.WriteExtensionMembers(ref writer); + } - private static void WriteCheckUserInGroupWithAckMessage(ref MessagePackWriter writer, CheckUserInGroupWithAckMessage message) - { - writer.WriteArrayHeader(5); - writer.Write(ServiceProtocolConstants.CheckUserInGroupWithAckMessageType); - writer.Write(message.UserId); - writer.Write(message.GroupName); - writer.Write(message.AckId); - message.WriteExtensionMembers(ref writer); - } + private static void WriteJoinGroupWithAckMessage(ref MessagePackWriter writer, JoinGroupWithAckMessage message) + { + writer.WriteArrayHeader(5); + writer.Write(ServiceProtocolConstants.JoinGroupWithAckMessageType); + writer.Write(message.ConnectionId); + writer.Write(message.GroupName); + writer.Write(message.AckId); + message.WriteExtensionMembers(ref writer); + } - private static void WriteCheckGroupExistenceWithAckMessage(ref MessagePackWriter writer, CheckGroupExistenceWithAckMessage message) - { - writer.WriteArrayHeader(4); - writer.Write(ServiceProtocolConstants.CheckGroupExistenceWithAckMessageType); - writer.Write(message.GroupName); - writer.Write(message.AckId); - message.WriteExtensionMembers(ref writer); - } + private static void WriteLeaveGroupWithAckMessage(ref MessagePackWriter writer, LeaveGroupWithAckMessage message) + { + writer.WriteArrayHeader(5); + writer.Write(ServiceProtocolConstants.LeaveGroupWithAckMessageType); + writer.Write(message.ConnectionId); + writer.Write(message.GroupName); + writer.Write(message.AckId); + message.WriteExtensionMembers(ref writer); + } - private static void WriteCheckConnectionExistenceWithAckMessage(ref MessagePackWriter writer, CheckConnectionExistenceWithAckMessage message) - { - writer.WriteArrayHeader(4); - writer.Write(ServiceProtocolConstants.CheckConnectionExistenceWithAckMessageType); - writer.Write(message.ConnectionId); - writer.Write(message.AckId); - message.WriteExtensionMembers(ref writer); - } + private static void WriteCheckUserInGroupWithAckMessage(ref MessagePackWriter writer, CheckUserInGroupWithAckMessage message) + { + writer.WriteArrayHeader(5); + writer.Write(ServiceProtocolConstants.CheckUserInGroupWithAckMessageType); + writer.Write(message.UserId); + writer.Write(message.GroupName); + writer.Write(message.AckId); + message.WriteExtensionMembers(ref writer); + } - private static void WriteCheckUserExistenceWithAckMessage(ref MessagePackWriter writer, CheckUserExistenceWithAckMessage message) - { - writer.WriteArrayHeader(4); - writer.Write(ServiceProtocolConstants.CheckUserExistenceWithAckMessageType); - writer.Write(message.UserId); - writer.Write(message.AckId); - message.WriteExtensionMembers(ref writer); - } + private static void WriteCheckGroupExistenceWithAckMessage(ref MessagePackWriter writer, CheckGroupExistenceWithAckMessage message) + { + writer.WriteArrayHeader(4); + writer.Write(ServiceProtocolConstants.CheckGroupExistenceWithAckMessageType); + writer.Write(message.GroupName); + writer.Write(message.AckId); + message.WriteExtensionMembers(ref writer); + } - private static void WriteAckMessage(ref MessagePackWriter writer, AckMessage message) - { - writer.WriteArrayHeader(5); - writer.Write(ServiceProtocolConstants.AckMessageType); - writer.Write(message.AckId); - writer.Write(message.Status); - writer.Write(message.Message); - message.WriteExtensionMembers(ref writer); - } + private static void WriteCheckConnectionExistenceWithAckMessage(ref MessagePackWriter writer, CheckConnectionExistenceWithAckMessage message) + { + writer.WriteArrayHeader(4); + writer.Write(ServiceProtocolConstants.CheckConnectionExistenceWithAckMessageType); + writer.Write(message.ConnectionId); + writer.Write(message.AckId); + message.WriteExtensionMembers(ref writer); + } - private static void WriteClientInvocationMessage(ref MessagePackWriter writer, ClientInvocationMessage message) - { - writer.WriteArrayHeader(6); - writer.Write(ServiceProtocolConstants.ClientInvocationMessageType); - writer.Write(message.InvocationId); - writer.Write(message.ConnectionId); - writer.Write(message.CallerServerId); - WritePayloads(ref writer, message.Payloads); - message.WriteExtensionMembers(ref writer); - } + private static void WriteCheckUserExistenceWithAckMessage(ref MessagePackWriter writer, CheckUserExistenceWithAckMessage message) + { + writer.WriteArrayHeader(4); + writer.Write(ServiceProtocolConstants.CheckUserExistenceWithAckMessageType); + writer.Write(message.UserId); + writer.Write(message.AckId); + message.WriteExtensionMembers(ref writer); + } - private static void WriteClientCompletionMessage(ref MessagePackWriter writer, ClientCompletionMessage message) - { - writer.WriteArrayHeader(7); - writer.Write(ServiceProtocolConstants.ClientCompletionMessageType); - writer.Write(message.InvocationId); - writer.Write(message.ConnectionId); - writer.Write(message.CallerServerId); - writer.Write(message.Protocol); - writer.Write(message.Payload); - message.WriteExtensionMembers(ref writer); - } + private static void WriteAckMessage(ref MessagePackWriter writer, AckMessage message) + { + writer.WriteArrayHeader(5); + writer.Write(ServiceProtocolConstants.AckMessageType); + writer.Write(message.AckId); + writer.Write(message.Status); + writer.Write(message.Message); + message.WriteExtensionMembers(ref writer); + } - private static void WriteErrorCompletionMessage(ref MessagePackWriter writer, ErrorCompletionMessage message) - { - writer.WriteArrayHeader(6); - writer.Write(ServiceProtocolConstants.ErrorCompletionMessageType); - writer.Write(message.InvocationId); - writer.Write(message.ConnectionId); - writer.Write(message.CallerServerId); - writer.Write(message.Error); - message.WriteExtensionMembers(ref writer); - } + private static void WriteClientInvocationMessage(ref MessagePackWriter writer, ClientInvocationMessage message) + { + writer.WriteArrayHeader(6); + writer.Write(ServiceProtocolConstants.ClientInvocationMessageType); + writer.Write(message.InvocationId); + writer.Write(message.ConnectionId); + writer.Write(message.CallerServerId); + WritePayloads(ref writer, message.Payloads); + message.WriteExtensionMembers(ref writer); + } - private static void WriteServiceMappingMessage(ref MessagePackWriter writer, ServiceMappingMessage message) - { - writer.WriteArrayHeader(5); - writer.Write(ServiceProtocolConstants.ServiceMappingMessageType); - writer.Write(message.InvocationId); - writer.Write(message.ConnectionId); - writer.Write(message.InstanceId); - message.WriteExtensionMembers(ref writer); - } + private static void WriteClientCompletionMessage(ref MessagePackWriter writer, ClientCompletionMessage message) + { + writer.WriteArrayHeader(7); + writer.Write(ServiceProtocolConstants.ClientCompletionMessageType); + writer.Write(message.InvocationId); + writer.Write(message.ConnectionId); + writer.Write(message.CallerServerId); + writer.Write(message.Protocol); + writer.Write(message.Payload); + message.WriteExtensionMembers(ref writer); + } - private static void WriteConnectionFlowControlMessage(ref MessagePackWriter writer, ConnectionFlowControlMessage message) - { - writer.WriteArrayHeader(5); - writer.Write(ServiceProtocolConstants.ConnectionFlowControlMessageType); - writer.Write(message.ConnectionId); - writer.WriteInt32((int)message.ConnectionType); - writer.WriteInt32((int)message.Operation); - message.WriteExtensionMembers(ref writer); - } + private static void WriteErrorCompletionMessage(ref MessagePackWriter writer, ErrorCompletionMessage message) + { + writer.WriteArrayHeader(6); + writer.Write(ServiceProtocolConstants.ErrorCompletionMessageType); + writer.Write(message.InvocationId); + writer.Write(message.ConnectionId); + writer.Write(message.CallerServerId); + writer.Write(message.Error); + message.WriteExtensionMembers(ref writer); + } + + private static void WriteServiceMappingMessage(ref MessagePackWriter writer, ServiceMappingMessage message) + { + writer.WriteArrayHeader(5); + writer.Write(ServiceProtocolConstants.ServiceMappingMessageType); + writer.Write(message.InvocationId); + writer.Write(message.ConnectionId); + writer.Write(message.InstanceId); + message.WriteExtensionMembers(ref writer); + } + + private static void WriteConnectionFlowControlMessage(ref MessagePackWriter writer, ConnectionFlowControlMessage message) + { + writer.WriteArrayHeader(5); + writer.Write(ServiceProtocolConstants.ConnectionFlowControlMessageType); + writer.Write(message.ConnectionId); + writer.WriteInt32((int)message.ConnectionType); + writer.WriteInt32((int)message.Operation); + message.WriteExtensionMembers(ref writer); + } - private static void WriteStringArray(ref MessagePackWriter writer, IReadOnlyList? array) + private static void WriteStringArray(ref MessagePackWriter writer, IReadOnlyList? array) + { + if (array?.Count > 0) { - if (array?.Count > 0) - { - writer.WriteArrayHeader(array.Count); - foreach (var value in array) - { - writer.Write(value); - } - } - else + writer.WriteArrayHeader(array.Count); + foreach (var value in array) { - writer.WriteArrayHeader(0); + writer.Write(value); } } + else + { + writer.WriteArrayHeader(0); + } + } - private static void WritePayloads(ref MessagePackWriter writer, IDictionary> payloads) + private static void WritePayloads(ref MessagePackWriter writer, IDictionary> payloads) + { + if (payloads?.Count > 0) { - if (payloads?.Count > 0) + writer.WriteMapHeader(payloads.Count); + foreach (var payload in payloads) { - writer.WriteMapHeader(payloads.Count); - foreach (var payload in payloads) - { - writer.Write(payload.Key); + writer.Write(payload.Key); - /*********************************************************************************/ - writer.Write(payload.Value.Span); - /*********************************************************************************/ - // REVIEW : PREVIOUS CODE WAS : - //bool isArray = MemoryMarshal.TryGetArray(payload.Value, out var segment); - //Debug.Assert(isArray, "We're not using managed memory"); + /*********************************************************************************/ + writer.Write(payload.Value.Span); + /*********************************************************************************/ + // REVIEW : PREVIOUS CODE WAS : + //bool isArray = MemoryMarshal.TryGetArray(payload.Value, out var segment); + //Debug.Assert(isArray, "We're not using managed memory"); - // writer.WriteBytes(segment.Array, segment.Offset, segment.Count); - /*********************************************************************************/ - } - } - else - { - writer.WriteMapHeader(0); + // writer.WriteBytes(segment.Array, segment.Offset, segment.Count); + /*********************************************************************************/ } } + else + { + writer.WriteMapHeader(0); + } + } - private static void WriteHeaders(ref MessagePackWriter writer, IDictionary headers) + private static void WriteHeaders(ref MessagePackWriter writer, IDictionary headers) + { + if (headers?.Count > 0) { - if (headers?.Count > 0) + writer.WriteMapHeader(headers.Count); + foreach (var header in headers) { - writer.WriteMapHeader(headers.Count); - foreach (var header in headers) + writer.Write(header.Key); + writer.WriteArrayHeader(header.Value.Count); + foreach (var stringValue in header.Value) { - writer.Write(header.Key); - writer.WriteArrayHeader(header.Value.Count); - foreach (var stringValue in header.Value) - { - writer.Write(stringValue); - } + writer.Write(stringValue); } } - else - { - writer.WriteMapHeader(0); - } } - - private static AccessKeyRequestMessage CreateAccessKeyRequestMessage(ref MessagePackReader reader, int arrayLength) + else { - var message = new AccessKeyRequestMessage() - { - Token = ReadString(ref reader, "token"), - Kid = ReadString(ref reader, "kid"), - }; - message.ReadExtensionMembers(ref reader); - return message; + writer.WriteMapHeader(0); } + } - private static AccessKeyResponseMessage CreateAccessKeyResponseMessage(ref MessagePackReader reader, int arrayLength) + private static AccessKeyRequestMessage CreateAccessKeyRequestMessage(ref MessagePackReader reader, int arrayLength) + { + var message = new AccessKeyRequestMessage() { - var message = new AccessKeyResponseMessage() - { - Kid = ReadString(ref reader, "kid"), - AccessKey = ReadString(ref reader, "accessKey"), - ErrorType = ReadString(ref reader, "errorType"), - ErrorMessage = ReadString(ref reader, "errorMessage"), - }; - message.ReadExtensionMembers(ref reader); - return message; - } + Token = ReadString(ref reader, "token"), + Kid = ReadString(ref reader, "kid"), + }; + message.ReadExtensionMembers(ref reader); + return message; + } - private static HandshakeRequestMessage CreateHandshakeRequestMessage(ref MessagePackReader reader, int arrayLength) - { - var version = ReadInt32(ref reader, "version"); - var result = new HandshakeRequestMessage(version); - if (arrayLength >= 4) - { - result.ConnectionType = ReadInt32(ref reader, "connectionType"); - result.Target = ReadString(ref reader, "target"); - } - result.MigrationLevel = arrayLength >= 5 ? ReadInt32(ref reader, "migratableStatus") : 0; - if (arrayLength >= 6) - { - result.ReadExtensionMembers(ref reader); - } - if (arrayLength >= 7) - { - result.AllowStatefulReconnects = ReadBoolean(ref reader, "enableStatefulReconnects"); - } - return result; - } + private static AccessKeyResponseMessage CreateAccessKeyResponseMessage(ref MessagePackReader reader, int arrayLength) + { + var message = new AccessKeyResponseMessage() + { + Kid = ReadString(ref reader, "kid"), + AccessKey = ReadString(ref reader, "accessKey"), + ErrorType = ReadString(ref reader, "errorType"), + ErrorMessage = ReadString(ref reader, "errorMessage"), + }; + message.ReadExtensionMembers(ref reader); + return message; + } - private static HandshakeResponseMessage CreateHandshakeResponseMessage(ref MessagePackReader reader, int arrayLength) + private static HandshakeRequestMessage CreateHandshakeRequestMessage(ref MessagePackReader reader, int arrayLength) + { + var version = ReadInt32(ref reader, "version"); + var result = new HandshakeRequestMessage(version); + if (arrayLength >= 4) { - var errorMessage = ReadString(ref reader, "errorMessage"); - var result = new HandshakeResponseMessage(errorMessage); - if (arrayLength >= 3) - { - result.ReadExtensionMembers(ref reader); - } - if (arrayLength >= 4) - { - result.ConnectionId = ReadString(ref reader, "connectionId"); - } - return result; + result.ConnectionType = ReadInt32(ref reader, "connectionType"); + result.Target = ReadString(ref reader, "target"); } - - private static PingMessage CreatePingMessage(ref MessagePackReader reader, int arrayLength) + result.MigrationLevel = arrayLength >= 5 ? ReadInt32(ref reader, "migratableStatus") : 0; + if (arrayLength >= 6) { - if (arrayLength > 1) - { - var length = arrayLength - 1; - var values = new string?[length]; - for (int i = 0; i < length; i++) - { - values[i] = ReadString(ref reader, "messages[{0}]", i); - } - - return new PingMessage { Messages = values }; - } - return PingMessage.Instance; + result.ReadExtensionMembers(ref reader); } - - private static OpenConnectionMessage CreateOpenConnectionMessage(ref MessagePackReader reader, int arrayLength) + if (arrayLength >= 7) { - var connectionId = ReadStringNotNull(ref reader, "connectionId"); - var claims = ReadClaims(ref reader); - - // Backward compatible with old versions - if (arrayLength >= 5) - { - var headers = ReadHeaders(ref reader); - var queryString = ReadString(ref reader, "queryString"); - var result = new OpenConnectionMessage(connectionId, claims, headers, queryString); - if (arrayLength >= 6) - { - result.ReadExtensionMembers(ref reader); - } - return result; - } - else - { - return new OpenConnectionMessage(connectionId, claims); - } + result.AllowStatefulReconnects = ReadBoolean(ref reader, "enableStatefulReconnects"); } + return result; + } - private static CloseConnectionMessage CreateCloseConnectionMessage(ref MessagePackReader reader, int arrayLength) + private static HandshakeResponseMessage CreateHandshakeResponseMessage(ref MessagePackReader reader, int arrayLength) + { + var errorMessage = ReadString(ref reader, "errorMessage"); + var result = new HandshakeResponseMessage(errorMessage); + if (arrayLength >= 3) { - var connectionId = ReadStringNotNull(ref reader, "connectionId"); - var errorMessage = ReadString(ref reader, "errorMessage"); - var headers = arrayLength >= 4 ? ReadHeaders(ref reader) : new Dictionary(); - var result = new CloseConnectionMessage(connectionId, errorMessage, headers); - if (arrayLength >= 5) - { - result.ReadExtensionMembers(ref reader); - } - return result; + result.ReadExtensionMembers(ref reader); } - - [Obsolete] - private static CloseConnectionWithAckMessage CreateCloseConnectionWithAckMessage(ref MessagePackReader reader, int arrayLength) + if (arrayLength >= 4) { - var connectionId = ReadStringNotNull(ref reader, "connectionId"); - var reason = ReadString(ref reader, "reason"); - var ackId = ReadInt32(ref reader, "ackId"); - var result = new CloseConnectionWithAckMessage(connectionId, ackId) - { - Reason = reason - }; - if (arrayLength >= 5) - { - result.ReadExtensionMembers(ref reader); - } - return result; + result.ConnectionId = ReadString(ref reader, "connectionId"); } + return result; + } - [Obsolete] - private static CloseConnectionsWithAckMessage CreateCloseConnectionsWithAckMessage(ref MessagePackReader reader, int arrayLength) + private static PingMessage CreatePingMessage(ref MessagePackReader reader, int arrayLength) + { + if (arrayLength > 1) { - var reason = ReadString(ref reader, "reason"); - var ackId = ReadInt32(ref reader, "ackId"); - var excluded = ReadStringArray(ref reader, "excluded"); - - var result = new CloseConnectionsWithAckMessage(ackId) + var length = arrayLength - 1; + var values = new string?[length]; + for (int i = 0; i < length; i++) { - Reason = reason, - ExcludedList = excluded - }; - if (arrayLength >= 5) - { - result.ReadExtensionMembers(ref reader); + values[i] = ReadString(ref reader, "messages[{0}]", i); } - return result; + + return new PingMessage { Messages = values }; } + return PingMessage.Instance; + } - private static CloseUserConnectionsWithAckMessage CreateCloseUserConnectionsWithAckMessage(ref MessagePackReader reader, int arrayLength) - { - var userId = ReadStringNotNull(ref reader, "userId"); - var reason = ReadString(ref reader, "reason"); - var ackId = ReadInt32(ref reader, "ackId"); - var excluded = ReadStringArray(ref reader, "excluded"); + private static OpenConnectionMessage CreateOpenConnectionMessage(ref MessagePackReader reader, int arrayLength) + { + var connectionId = ReadStringNotNull(ref reader, "connectionId"); + var claims = ReadClaims(ref reader); - var result = new CloseUserConnectionsWithAckMessage(userId, ackId) - { - Reason = reason, - ExcludedList = excluded - }; + // Backward compatible with old versions + if (arrayLength >= 5) + { + var headers = ReadHeaders(ref reader); + var queryString = ReadString(ref reader, "queryString"); + var result = new OpenConnectionMessage(connectionId, claims, headers, queryString); if (arrayLength >= 6) { result.ReadExtensionMembers(ref reader); } return result; } - - private static CloseGroupConnectionsWithAckMessage CreateCloseGroupConnectionsWithAckMessage(ref MessagePackReader reader, int arrayLength) + else { - var group = ReadStringNotNull(ref reader, "group"); - var reason = ReadString(ref reader, "reason"); - var ackId = ReadInt32(ref reader, "ackId"); - var excluded = ReadStringArray(ref reader, "excluded"); - - var result = new CloseGroupConnectionsWithAckMessage(group, ackId) - { - Reason = reason, - ExcludedList = excluded - }; - if (arrayLength >= 6) - { - result.ReadExtensionMembers(ref reader); - } - return result; + return new OpenConnectionMessage(connectionId, claims); } + } - private static ConnectionDataMessage CreateConnectionDataMessage(ref MessagePackReader reader, int arrayLength) + private static CloseConnectionMessage CreateCloseConnectionMessage(ref MessagePackReader reader, int arrayLength) + { + var connectionId = ReadStringNotNull(ref reader, "connectionId"); + var errorMessage = ReadString(ref reader, "errorMessage"); + var headers = arrayLength >= 4 ? ReadHeaders(ref reader) : new Dictionary(); + var result = new CloseConnectionMessage(connectionId, errorMessage, headers); + if (arrayLength >= 5) { - var connectionId = ReadStringNotNull(ref reader, "connectionId"); - var payload = ReadBytes(ref reader, "payload"); - - var result = new ConnectionDataMessage(connectionId, payload); - if (arrayLength >= 4) - { - result.ReadExtensionMembers(ref reader); - } - return result; + result.ReadExtensionMembers(ref reader); } + return result; + } - private static ConnectionReconnectMessage CreateConnectionReconnectMessage(ref MessagePackReader reader, int arrayLength) + [Obsolete] + private static CloseConnectionWithAckMessage CreateCloseConnectionWithAckMessage(ref MessagePackReader reader, int arrayLength) + { + var connectionId = ReadStringNotNull(ref reader, "connectionId"); + var reason = ReadString(ref reader, "reason"); + var ackId = ReadInt32(ref reader, "ackId"); + var result = new CloseConnectionWithAckMessage(connectionId, ackId) + { + Reason = reason + }; + if (arrayLength >= 5) { - var connectionId = ReadStringNotNull(ref reader, "connectionId"); - - var result = new ConnectionReconnectMessage(connectionId); result.ReadExtensionMembers(ref reader); - return result; } + return result; + } - private static MultiConnectionDataMessage CreateMultiConnectionDataMessage(ref MessagePackReader reader, int arrayLength) - { - var connectionList = ReadStringArray(ref reader, "connectionList"); - var payloads = ReadPayloads(ref reader); + [Obsolete] + private static CloseConnectionsWithAckMessage CreateCloseConnectionsWithAckMessage(ref MessagePackReader reader, int arrayLength) + { + var reason = ReadString(ref reader, "reason"); + var ackId = ReadInt32(ref reader, "ackId"); + var excluded = ReadStringArray(ref reader, "excluded"); - var result = new MultiConnectionDataMessage(connectionList, payloads); - if (arrayLength >= 4) - { - result.ReadExtensionMembers(ref reader); - } - return result; + var result = new CloseConnectionsWithAckMessage(ackId) + { + Reason = reason, + ExcludedList = excluded + }; + if (arrayLength >= 5) + { + result.ReadExtensionMembers(ref reader); } + return result; + } - private static ServiceMessage CreateUserDataMessage(ref MessagePackReader reader, int arrayLength) - { - var userId = ReadStringNotNull(ref reader, "userId"); - var payloads = ReadPayloads(ref reader); + private static CloseUserConnectionsWithAckMessage CreateCloseUserConnectionsWithAckMessage(ref MessagePackReader reader, int arrayLength) + { + var userId = ReadStringNotNull(ref reader, "userId"); + var reason = ReadString(ref reader, "reason"); + var ackId = ReadInt32(ref reader, "ackId"); + var excluded = ReadStringArray(ref reader, "excluded"); - var result = new UserDataMessage(userId, payloads); - if (arrayLength >= 4) - { - result.ReadExtensionMembers(ref reader); - } - return result; + var result = new CloseUserConnectionsWithAckMessage(userId, ackId) + { + Reason = reason, + ExcludedList = excluded + }; + if (arrayLength >= 6) + { + result.ReadExtensionMembers(ref reader); } + return result; + } - private static MultiUserDataMessage CreateMultiUserDataMessage(ref MessagePackReader reader, int arrayLength) - { - var userList = ReadStringArray(ref reader, "userList"); - var payloads = ReadPayloads(ref reader); + private static CloseGroupConnectionsWithAckMessage CreateCloseGroupConnectionsWithAckMessage(ref MessagePackReader reader, int arrayLength) + { + var group = ReadStringNotNull(ref reader, "group"); + var reason = ReadString(ref reader, "reason"); + var ackId = ReadInt32(ref reader, "ackId"); + var excluded = ReadStringArray(ref reader, "excluded"); - var result = new MultiUserDataMessage(userList, payloads); - if (arrayLength >= 4) - { - result.ReadExtensionMembers(ref reader); - } - return result; + var result = new CloseGroupConnectionsWithAckMessage(group, ackId) + { + Reason = reason, + ExcludedList = excluded + }; + if (arrayLength >= 6) + { + result.ReadExtensionMembers(ref reader); } + return result; + } - private static BroadcastDataMessage CreateBroadcastDataMessage(ref MessagePackReader reader, int arrayLength) - { - var excludedList = ReadStringArray(ref reader, "excludedList"); - var payloads = ReadPayloads(ref reader); + private static ConnectionDataMessage CreateConnectionDataMessage(ref MessagePackReader reader, int arrayLength) + { + var connectionId = ReadStringNotNull(ref reader, "connectionId"); + var payload = ReadBytes(ref reader, "payload"); - var result = new BroadcastDataMessage(excludedList, payloads); - if (arrayLength >= 4) - { - result.ReadExtensionMembers(ref reader); - } - return result; + var result = new ConnectionDataMessage(connectionId, payload); + if (arrayLength >= 4) + { + result.ReadExtensionMembers(ref reader); } + return result; + } - private static JoinGroupMessage CreateJoinGroupMessage(ref MessagePackReader reader, int arrayLength) - { - var connectionId = ReadStringNotNull(ref reader, "connectionId"); - var groupName = ReadStringNotNull(ref reader, "groupName"); + private static ConnectionReconnectMessage CreateConnectionReconnectMessage(ref MessagePackReader reader, int arrayLength) + { + var connectionId = ReadStringNotNull(ref reader, "connectionId"); - var result = new JoinGroupMessage(connectionId, groupName); - if (arrayLength >= 4) - { - result.ReadExtensionMembers(ref reader); - } - return result; - } + var result = new ConnectionReconnectMessage(connectionId); + result.ReadExtensionMembers(ref reader); + return result; + } - private static LeaveGroupMessage CreateLeaveGroupMessage(ref MessagePackReader reader, int arrayLength) + private static MultiConnectionDataMessage CreateMultiConnectionDataMessage(ref MessagePackReader reader, int arrayLength) + { + var connectionList = ReadStringArray(ref reader, "connectionList"); + var payloads = ReadPayloads(ref reader); + + var result = new MultiConnectionDataMessage(connectionList, payloads); + if (arrayLength >= 4) { - var connectionId = ReadStringNotNull(ref reader, "connectionId"); - var groupName = ReadString(ref reader, "groupName"); + result.ReadExtensionMembers(ref reader); + } + return result; + } - var result = new LeaveGroupMessage(connectionId, groupName); - if (arrayLength >= 4) - { - result.ReadExtensionMembers(ref reader); - } - return result; + private static ServiceMessage CreateUserDataMessage(ref MessagePackReader reader, int arrayLength) + { + var userId = ReadStringNotNull(ref reader, "userId"); + var payloads = ReadPayloads(ref reader); + + var result = new UserDataMessage(userId, payloads); + if (arrayLength >= 4) + { + result.ReadExtensionMembers(ref reader); } + return result; + } - private static UserJoinGroupMessage CreateUserJoinGroupMessage(ref MessagePackReader reader, int arrayLength) - { - var userId = ReadStringNotNull(ref reader, "userId"); - var groupName = ReadStringNotNull(ref reader, "groupName"); + private static MultiUserDataMessage CreateMultiUserDataMessage(ref MessagePackReader reader, int arrayLength) + { + var userList = ReadStringArray(ref reader, "userList"); + var payloads = ReadPayloads(ref reader); - var result = new UserJoinGroupMessage(userId, groupName); - if (arrayLength >= 4) - { - result.ReadExtensionMembers(ref reader); - } - return result; + var result = new MultiUserDataMessage(userList, payloads); + if (arrayLength >= 4) + { + result.ReadExtensionMembers(ref reader); } + return result; + } - private static UserLeaveGroupMessage CreateUserLeaveGroupMessage(ref MessagePackReader reader, int arrayLength) - { - var userId = ReadStringNotNull(ref reader, "userId"); - var groupName = ReadString(ref reader, "groupName"); + private static BroadcastDataMessage CreateBroadcastDataMessage(ref MessagePackReader reader, int arrayLength) + { + var excludedList = ReadStringArray(ref reader, "excludedList"); + var payloads = ReadPayloads(ref reader); - var result = new UserLeaveGroupMessage(userId, groupName); - if (arrayLength >= 4) - { - result.ReadExtensionMembers(ref reader); - } - return result; + var result = new BroadcastDataMessage(excludedList, payloads); + if (arrayLength >= 4) + { + result.ReadExtensionMembers(ref reader); } + return result; + } - private static UserJoinGroupWithAckMessage CreateUserJoinGroupWithAckMessage(ref MessagePackReader reader, int arrayLength) - { - var userId = ReadStringNotNull(ref reader, "userId"); - var groupName = ReadStringNotNull(ref reader, "groupName"); - var ackId = ReadInt32(ref reader, "ackId"); + private static JoinGroupMessage CreateJoinGroupMessage(ref MessagePackReader reader, int arrayLength) + { + var connectionId = ReadStringNotNull(ref reader, "connectionId"); + var groupName = ReadStringNotNull(ref reader, "groupName"); - var result = new UserJoinGroupWithAckMessage(userId, groupName, ackId); + var result = new JoinGroupMessage(connectionId, groupName); + if (arrayLength >= 4) + { result.ReadExtensionMembers(ref reader); - return result; } + return result; + } - private static UserLeaveGroupWithAckMessage CreateUserLeaveGroupWithAckMessage(ref MessagePackReader reader, int arrayLength) - { - var userId = ReadStringNotNull(ref reader, "userId"); - var groupName = ReadString(ref reader, "groupName"); - var ackId = ReadInt32(ref reader, "ackId"); + private static LeaveGroupMessage CreateLeaveGroupMessage(ref MessagePackReader reader, int arrayLength) + { + var connectionId = ReadStringNotNull(ref reader, "connectionId"); + var groupName = ReadString(ref reader, "groupName"); - var result = new UserLeaveGroupWithAckMessage(userId, groupName, ackId); + var result = new LeaveGroupMessage(connectionId, groupName); + if (arrayLength >= 4) + { result.ReadExtensionMembers(ref reader); - return result; } + return result; + } - private static GroupBroadcastDataMessage CreateGroupBroadcastDataMessage(ref MessagePackReader reader, int arrayLength) - { - var groupName = ReadStringNotNull(ref reader, "groupName"); - var excludedList = ReadStringArray(ref reader, "excludedList"); - var payloads = ReadPayloads(ref reader); + private static UserJoinGroupMessage CreateUserJoinGroupMessage(ref MessagePackReader reader, int arrayLength) + { + var userId = ReadStringNotNull(ref reader, "userId"); + var groupName = ReadStringNotNull(ref reader, "groupName"); - var result = new GroupBroadcastDataMessage(groupName, excludedList, payloads); - if (arrayLength >= 5) - { - result.ReadExtensionMembers(ref reader); - } + var result = new UserJoinGroupMessage(userId, groupName); + if (arrayLength >= 4) + { + result.ReadExtensionMembers(ref reader); + } + return result; + } - if (arrayLength >= 7) - { - result.ExcludedUserList = ReadStringArray(ref reader, "excludedUserList"); - result.CallerUserId = ReadString(ref reader, "callerUserId"); - } + private static UserLeaveGroupMessage CreateUserLeaveGroupMessage(ref MessagePackReader reader, int arrayLength) + { + var userId = ReadStringNotNull(ref reader, "userId"); + var groupName = ReadString(ref reader, "groupName"); - return result; + var result = new UserLeaveGroupMessage(userId, groupName); + if (arrayLength >= 4) + { + result.ReadExtensionMembers(ref reader); } + return result; + } - private static MultiGroupBroadcastDataMessage CreateMultiGroupBroadcastDataMessage(ref MessagePackReader reader, int arrayLength) - { - var groupList = ReadStringArray(ref reader, "groupList"); - var payloads = ReadPayloads(ref reader); + private static UserJoinGroupWithAckMessage CreateUserJoinGroupWithAckMessage(ref MessagePackReader reader, int arrayLength) + { + var userId = ReadStringNotNull(ref reader, "userId"); + var groupName = ReadStringNotNull(ref reader, "groupName"); + var ackId = ReadInt32(ref reader, "ackId"); - var result = new MultiGroupBroadcastDataMessage(groupList, payloads); - if (arrayLength >= 4) - { - result.ReadExtensionMembers(ref reader); - } - return result; - } + var result = new UserJoinGroupWithAckMessage(userId, groupName, ackId); + result.ReadExtensionMembers(ref reader); + return result; + } - private static ServiceErrorMessage CreateServiceErrorMessage(ref MessagePackReader reader) - { - var errorMessage = ReadString(ref reader, "errorMessage"); + private static UserLeaveGroupWithAckMessage CreateUserLeaveGroupWithAckMessage(ref MessagePackReader reader, int arrayLength) + { + var userId = ReadStringNotNull(ref reader, "userId"); + var groupName = ReadString(ref reader, "groupName"); + var ackId = ReadInt32(ref reader, "ackId"); - return new ServiceErrorMessage(errorMessage); - } + var result = new UserLeaveGroupWithAckMessage(userId, groupName, ackId); + result.ReadExtensionMembers(ref reader); + return result; + } - private static ServiceEventMessage CreateServiceEventMessage(ref MessagePackReader reader) + private static GroupBroadcastDataMessage CreateGroupBroadcastDataMessage(ref MessagePackReader reader, int arrayLength) + { + var groupName = ReadStringNotNull(ref reader, "groupName"); + var excludedList = ReadStringArray(ref reader, "excludedList"); + var payloads = ReadPayloads(ref reader); + + var result = new GroupBroadcastDataMessage(groupName, excludedList, payloads); + if (arrayLength >= 5) { - var type = ReadInt32(ref reader, "type"); - var id = ReadString(ref reader, "id"); - var kind = ReadInt32(ref reader, "kind"); - var message = ReadString(ref reader, "message"); - var result = new ServiceEventMessage((ServiceEventObjectType)type, id, (ServiceEventKind)kind, message); result.ReadExtensionMembers(ref reader); - return result; } - private static JoinGroupWithAckMessage CreateJoinGroupWithAckMessage(ref MessagePackReader reader, int arrayLength) + if (arrayLength >= 7) { - var connectionId = ReadStringNotNull(ref reader, "connectionId"); - var groupName = ReadStringNotNull(ref reader, "groupName"); - var ackId = ReadInt32(ref reader, "ackId"); - - var result = new JoinGroupWithAckMessage(connectionId, groupName, ackId); - if (arrayLength >= 5) - { - result.ReadExtensionMembers(ref reader); - } - return result; + result.ExcludedUserList = ReadStringArray(ref reader, "excludedUserList"); + result.CallerUserId = ReadString(ref reader, "callerUserId"); } - private static LeaveGroupWithAckMessage CreateLeaveGroupWithAckMessage(ref MessagePackReader reader, int arrayLength) - { - var connectionId = ReadStringNotNull(ref reader, "connectionId"); - var groupName = ReadString(ref reader, "groupName"); - var ackId = ReadInt32(ref reader, "ackId"); + return result; + } - var result = new LeaveGroupWithAckMessage(connectionId, groupName, ackId); - if (arrayLength >= 5) - { - result.ReadExtensionMembers(ref reader); - } - return result; - } + private static MultiGroupBroadcastDataMessage CreateMultiGroupBroadcastDataMessage(ref MessagePackReader reader, int arrayLength) + { + var groupList = ReadStringArray(ref reader, "groupList"); + var payloads = ReadPayloads(ref reader); - private static CheckUserInGroupWithAckMessage CreateCheckUserInGroupWithAckMessage(ref MessagePackReader reader, int arrayLength) + var result = new MultiGroupBroadcastDataMessage(groupList, payloads); + if (arrayLength >= 4) { - var userId = ReadStringNotNull(ref reader, "userId"); - var groupName = ReadStringNotNull(ref reader, "groupName"); - var ackId = ReadInt32(ref reader, "ackId"); - - var result = new CheckUserInGroupWithAckMessage(userId, groupName, ackId); - if (arrayLength >= 5) - { - result.ReadExtensionMembers(ref reader); - } - return result; + result.ReadExtensionMembers(ref reader); } + return result; + } - private static CheckGroupExistenceWithAckMessage CreateGroupExistenceWithAckMessage(ref MessagePackReader reader, int arrayLength) - { - var groupName = ReadStringNotNull(ref reader, "groupName"); - var ackId = ReadInt32(ref reader, "ackId"); + private static ServiceErrorMessage CreateServiceErrorMessage(ref MessagePackReader reader) + { + var errorMessage = ReadString(ref reader, "errorMessage"); + + return new ServiceErrorMessage(errorMessage); + } + + private static ServiceEventMessage CreateServiceEventMessage(ref MessagePackReader reader) + { + var type = ReadInt32(ref reader, "type"); + var id = ReadString(ref reader, "id"); + var kind = ReadInt32(ref reader, "kind"); + var message = ReadString(ref reader, "message"); + var result = new ServiceEventMessage((ServiceEventObjectType)type, id, (ServiceEventKind)kind, message); + result.ReadExtensionMembers(ref reader); + return result; + } + + private static JoinGroupWithAckMessage CreateJoinGroupWithAckMessage(ref MessagePackReader reader, int arrayLength) + { + var connectionId = ReadStringNotNull(ref reader, "connectionId"); + var groupName = ReadStringNotNull(ref reader, "groupName"); + var ackId = ReadInt32(ref reader, "ackId"); - var result = new CheckGroupExistenceWithAckMessage(groupName, ackId); + var result = new JoinGroupWithAckMessage(connectionId, groupName, ackId); + if (arrayLength >= 5) + { result.ReadExtensionMembers(ref reader); - return result; } + return result; + } - private static CheckConnectionExistenceWithAckMessage CreateCheckConnectionExistenceWithAckMessage(ref MessagePackReader reader, int arrayLength) - { - var connectionId = ReadStringNotNull(ref reader, "connectionId"); - var ackId = ReadInt32(ref reader, "ackId"); + private static LeaveGroupWithAckMessage CreateLeaveGroupWithAckMessage(ref MessagePackReader reader, int arrayLength) + { + var connectionId = ReadStringNotNull(ref reader, "connectionId"); + var groupName = ReadString(ref reader, "groupName"); + var ackId = ReadInt32(ref reader, "ackId"); - var result = new CheckConnectionExistenceWithAckMessage(connectionId, ackId); + var result = new LeaveGroupWithAckMessage(connectionId, groupName, ackId); + if (arrayLength >= 5) + { result.ReadExtensionMembers(ref reader); - return result; } + return result; + } - private static CheckUserExistenceWithAckMessage CreateCheckUserExistenceWithAckMessage(ref MessagePackReader reader, int arrayLength) - { - var userId = ReadStringNotNull(ref reader, "userId"); - var ackId = ReadInt32(ref reader, "ackId"); + private static CheckUserInGroupWithAckMessage CreateCheckUserInGroupWithAckMessage(ref MessagePackReader reader, int arrayLength) + { + var userId = ReadStringNotNull(ref reader, "userId"); + var groupName = ReadStringNotNull(ref reader, "groupName"); + var ackId = ReadInt32(ref reader, "ackId"); - var result = new CheckUserExistenceWithAckMessage(userId, ackId); + var result = new CheckUserInGroupWithAckMessage(userId, groupName, ackId); + if (arrayLength >= 5) + { result.ReadExtensionMembers(ref reader); - return result; } + return result; + } - private static AckMessage CreateAckMessage(ref MessagePackReader reader, int arrayLength) - { - var ackId = ReadInt32(ref reader, "ackId"); - var status = ReadInt32(ref reader, "status"); - var message = ReadString(ref reader, "message"); + private static CheckGroupExistenceWithAckMessage CreateGroupExistenceWithAckMessage(ref MessagePackReader reader, int arrayLength) + { + var groupName = ReadStringNotNull(ref reader, "groupName"); + var ackId = ReadInt32(ref reader, "ackId"); - var result = new AckMessage(ackId, status, message); - if (arrayLength >= 5) - { - result.ReadExtensionMembers(ref reader); - } - return result; - } + var result = new CheckGroupExistenceWithAckMessage(groupName, ackId); + result.ReadExtensionMembers(ref reader); + return result; + } - private static ClientInvocationMessage CreateClientInvocationMessage(ref MessagePackReader reader, int arrayLength) - { - var invocationId = ReadStringNotNull(ref reader, "invocationId"); - var connectionId = ReadStringNotNull(ref reader, "connectionId"); - var callerServerId = ReadStringNotNull(ref reader, "callerServerId"); - var payloads = ReadPayloads(ref reader); + private static CheckConnectionExistenceWithAckMessage CreateCheckConnectionExistenceWithAckMessage(ref MessagePackReader reader, int arrayLength) + { + var connectionId = ReadStringNotNull(ref reader, "connectionId"); + var ackId = ReadInt32(ref reader, "ackId"); - var result = new ClientInvocationMessage(invocationId, connectionId, callerServerId, payloads); - result.ReadExtensionMembers(ref reader); - return result; - } + var result = new CheckConnectionExistenceWithAckMessage(connectionId, ackId); + result.ReadExtensionMembers(ref reader); + return result; + } - private static ClientCompletionMessage CreateClientCompletionMessage(ref MessagePackReader reader, int arrayLength) - { - var invocationId = ReadStringNotNull(ref reader, "invocationId"); - var connectionId = ReadStringNotNull(ref reader, "connectionId"); - var callerServerId = ReadStringNotNull(ref reader, "callerServerId"); - var protocol = ReadString(ref reader, "protocol"); - var payload = ReadBytes(ref reader, "payload"); + private static CheckUserExistenceWithAckMessage CreateCheckUserExistenceWithAckMessage(ref MessagePackReader reader, int arrayLength) + { + var userId = ReadStringNotNull(ref reader, "userId"); + var ackId = ReadInt32(ref reader, "ackId"); + + var result = new CheckUserExistenceWithAckMessage(userId, ackId); + result.ReadExtensionMembers(ref reader); + return result; + } - var result = new ClientCompletionMessage(invocationId, connectionId, callerServerId, protocol, payload); + private static AckMessage CreateAckMessage(ref MessagePackReader reader, int arrayLength) + { + var ackId = ReadInt32(ref reader, "ackId"); + var status = ReadInt32(ref reader, "status"); + var message = ReadString(ref reader, "message"); + var result = new AckMessage(ackId, status, message); + if (arrayLength >= 5) + { result.ReadExtensionMembers(ref reader); - return result; } + return result; + } - private static ErrorCompletionMessage CreateErrorCompletionMessage(ref MessagePackReader reader, int arrayLength) - { - var invocationId = ReadStringNotNull(ref reader, "invocationId"); - var connectionId = ReadStringNotNull(ref reader, "connectionId"); - var callerServerId = ReadStringNotNull(ref reader, "callerServerId"); - var error = ReadString(ref reader, "error"); + private static ClientInvocationMessage CreateClientInvocationMessage(ref MessagePackReader reader, int arrayLength) + { + var invocationId = ReadStringNotNull(ref reader, "invocationId"); + var connectionId = ReadStringNotNull(ref reader, "connectionId"); + var callerServerId = ReadStringNotNull(ref reader, "callerServerId"); + var payloads = ReadPayloads(ref reader); + + var result = new ClientInvocationMessage(invocationId, connectionId, callerServerId, payloads); + result.ReadExtensionMembers(ref reader); + return result; + } - var result = new ErrorCompletionMessage(invocationId, connectionId, callerServerId, error); + private static ClientCompletionMessage CreateClientCompletionMessage(ref MessagePackReader reader, int arrayLength) + { + var invocationId = ReadStringNotNull(ref reader, "invocationId"); + var connectionId = ReadStringNotNull(ref reader, "connectionId"); + var callerServerId = ReadStringNotNull(ref reader, "callerServerId"); + var protocol = ReadString(ref reader, "protocol"); + var payload = ReadBytes(ref reader, "payload"); - result.ReadExtensionMembers(ref reader); - return result; - } + var result = new ClientCompletionMessage(invocationId, connectionId, callerServerId, protocol, payload); - private static ServiceMappingMessage CreateServiceMappingMessage(ref MessagePackReader reader, int arrayLength) - { - var invocationId = ReadStringNotNull(ref reader, "invocationId"); - var connectionId = ReadStringNotNull(ref reader, "connectionId"); - var instanceId = ReadStringNotNull(ref reader, "instanceId"); + result.ReadExtensionMembers(ref reader); + return result; + } - var result = new ServiceMappingMessage(invocationId, connectionId, instanceId); + private static ErrorCompletionMessage CreateErrorCompletionMessage(ref MessagePackReader reader, int arrayLength) + { + var invocationId = ReadStringNotNull(ref reader, "invocationId"); + var connectionId = ReadStringNotNull(ref reader, "connectionId"); + var callerServerId = ReadStringNotNull(ref reader, "callerServerId"); + var error = ReadString(ref reader, "error"); - result.ReadExtensionMembers(ref reader); - return result; - } + var result = new ErrorCompletionMessage(invocationId, connectionId, callerServerId, error); - private static ConnectionFlowControlMessage CreateConnectionFlowControlMessage(ref MessagePackReader reader, int arrayLength) - { - var connectionId = ReadStringNotNull(ref reader, "connectionId"); - var connectionType = ReadInt32(ref reader, "connectionType"); - var operation = ReadInt32(ref reader, "operation"); + result.ReadExtensionMembers(ref reader); + return result; + } - switch (connectionType) - { - case (int)ConnectionType.Client: - case (int)ConnectionType.Server: - break; - default: - throw new InvalidDataException($"Unsupported connection type: {connectionType}"); - } + private static ServiceMappingMessage CreateServiceMappingMessage(ref MessagePackReader reader, int arrayLength) + { + var invocationId = ReadStringNotNull(ref reader, "invocationId"); + var connectionId = ReadStringNotNull(ref reader, "connectionId"); + var instanceId = ReadStringNotNull(ref reader, "instanceId"); - switch (operation) - { - case (int)ConnectionFlowControlOperation.Pause: - case (int)ConnectionFlowControlOperation.PauseAck: - case (int)ConnectionFlowControlOperation.Resume: - case (int)ConnectionFlowControlOperation.Offline: - break; - default: - throw new InvalidDataException($"Unsupported operation: {operation}"); - } + var result = new ServiceMappingMessage(invocationId, connectionId, instanceId); - var result = new ConnectionFlowControlMessage( - connectionId, - (ConnectionFlowControlOperation)operation, - (ConnectionType)connectionType); - return result; + result.ReadExtensionMembers(ref reader); + return result; + } + + private static ConnectionFlowControlMessage CreateConnectionFlowControlMessage(ref MessagePackReader reader, int arrayLength) + { + var connectionId = ReadStringNotNull(ref reader, "connectionId"); + var connectionType = ReadInt32(ref reader, "connectionType"); + var operation = ReadInt32(ref reader, "operation"); + + switch (connectionType) + { + case (int)ConnectionType.Client: + case (int)ConnectionType.Server: + break; + default: + throw new InvalidDataException($"Unsupported connection type: {connectionType}"); } - private static Claim[] ReadClaims(ref MessagePackReader reader) + switch (operation) { - var claimCount = ReadMapLength(ref reader, "claims"); - if (claimCount > 0) - { - var claims = new Claim[claimCount]; + case (int)ConnectionFlowControlOperation.Pause: + case (int)ConnectionFlowControlOperation.PauseAck: + case (int)ConnectionFlowControlOperation.Resume: + case (int)ConnectionFlowControlOperation.Offline: + break; + default: + throw new InvalidDataException($"Unsupported operation: {operation}"); + } - for (var i = 0; i < claimCount; i++) - { - var type = ReadString(ref reader, "claims[{0}].Type", i); - var value = ReadString(ref reader, "claims[{0}].Value", i); - claims[i] = new Claim(type, value); - } + var result = new ConnectionFlowControlMessage( + connectionId, + (ConnectionFlowControlOperation)operation, + (ConnectionType)connectionType); + return result; + } + + private static Claim[] ReadClaims(ref MessagePackReader reader) + { + var claimCount = ReadMapLength(ref reader, "claims"); + if (claimCount > 0) + { + var claims = new Claim[claimCount]; - return claims; + for (var i = 0; i < claimCount; i++) + { + var type = ReadString(ref reader, "claims[{0}].Type", i); + var value = ReadString(ref reader, "claims[{0}].Value", i); + claims[i] = new Claim(type, value); } - return []; + return claims; } - private static IDictionary> ReadPayloads(ref MessagePackReader reader) + return []; + } + + private static IDictionary> ReadPayloads(ref MessagePackReader reader) + { + var payloadCount = ReadMapLength(ref reader, "payloads"); + if (payloadCount > 0) { - var payloadCount = ReadMapLength(ref reader, "payloads"); - if (payloadCount > 0) + var payloads = new ArrayDictionary>((int)payloadCount, StringComparer.OrdinalIgnoreCase); + for (var i = 0; i < payloadCount; i++) { - var payloads = new ArrayDictionary>((int)payloadCount, StringComparer.OrdinalIgnoreCase); - for (var i = 0; i < payloadCount; i++) - { - var keyName = $"payloads[{i}].key"; - - var key = ReadStringNotNull(ref reader, keyName); - var value = ReadBytes(ref reader, "payloads[{0}].value", i); - payloads.Add(key, value); - } + var keyName = $"payloads[{i}].key"; - return payloads; + var key = ReadStringNotNull(ref reader, keyName); + var value = ReadBytes(ref reader, "payloads[{0}].value", i); + payloads.Add(key, value); } - return EmptyReadOnlyMemoryDictionary; + return payloads; } - private static IDictionary ReadHeaders(ref MessagePackReader reader) + return EmptyReadOnlyMemoryDictionary; + } + + private static IDictionary ReadHeaders(ref MessagePackReader reader) + { + var headerCount = ReadMapLength(ref reader, "headers"); + if (headerCount > 0) { - var headerCount = ReadMapLength(ref reader, "headers"); - if (headerCount > 0) + var headers = new Dictionary((int)headerCount, StringComparer.OrdinalIgnoreCase); + for (var i = 0; i < headerCount; i++) { - var headers = new Dictionary((int)headerCount, StringComparer.OrdinalIgnoreCase); - for (var i = 0; i < headerCount; i++) + var keyName = $"headers[{i}].key"; + var key = ReadStringNotNull(ref reader, keyName); + var count = ReadArrayLength(ref reader, $"headers[{i}].value.length"); + var stringValues = new string?[count]; + for (var j = 0; j < count; j++) { - var keyName = $"headers[{i}].key"; - var key = ReadStringNotNull(ref reader, keyName); - var count = ReadArrayLength(ref reader, $"headers[{i}].value.length"); - var stringValues = new string?[count]; - for (var j = 0; j < count; j++) - { - stringValues[j] = ReadString(ref reader, $"headers[{i}].value[{j}]"); - } - headers.Add(key, stringValues); + stringValues[j] = ReadString(ref reader, $"headers[{i}].value[{j}]"); } - - return headers; + headers.Add(key, stringValues); } - return EmptyStringValuesDictionaryIgnoreCase; + return headers; } - private static bool ReadBoolean(ref MessagePackReader reader, string field) + return EmptyStringValuesDictionaryIgnoreCase; + } + + private static bool ReadBoolean(ref MessagePackReader reader, string field) + { + try { - try - { - return reader.ReadBoolean(); - } - catch (Exception ex) - { - throw new InvalidDataException($"Reading '{field}' as Boolean failed.", ex); - } + return reader.ReadBoolean(); } - - private static int ReadInt32(ref MessagePackReader reader, string field) + catch (Exception ex) { - try - { - return reader.ReadInt32(); - } - catch (Exception ex) - { - throw new InvalidDataException($"Reading '{field}' as Int32 failed.", ex); - } - + throw new InvalidDataException($"Reading '{field}' as Boolean failed.", ex); } + } - private static string? ReadString(ref MessagePackReader reader, string field) + private static int ReadInt32(ref MessagePackReader reader, string field) + { + try { - try - { - return reader.ReadString(); - } - catch (Exception ex) - { - throw new InvalidDataException($"Reading '{field}' as String failed.", ex); - } + return reader.ReadInt32(); } - - private static string ReadStringNotNull(ref MessagePackReader reader, string field) + catch (Exception ex) { - string? result = null; - try - { - result = reader.ReadString(); - } - catch (Exception ex) - { - throw new InvalidDataException($"Reading '{field}' as String failed.", ex); - } + throw new InvalidDataException($"Reading '{field}' as Int32 failed.", ex); + } - if (result == null) - { - throw new InvalidDataException($"Reading '{field}' as Not-Null String failed."); - } + } - return result; + private static string? ReadString(ref MessagePackReader reader, string field) + { + try + { + return reader.ReadString(); + } + catch (Exception ex) + { + throw new InvalidDataException($"Reading '{field}' as String failed.", ex); } + } - private static string? ReadString(ref MessagePackReader reader, string formatField, int param) + private static string ReadStringNotNull(ref MessagePackReader reader, string field) + { + string? result = null; + try { - try - { - return reader.ReadString(); - } - catch (Exception ex) - { - throw new InvalidDataException($"Reading '{string.Format(formatField, param)}' as String failed.", ex); - } + result = reader.ReadString(); + } + catch (Exception ex) + { + throw new InvalidDataException($"Reading '{field}' as String failed.", ex); } - private static string[] ReadStringArray(ref MessagePackReader reader, string field) + if (result == null) { - var arrayLength = ReadArrayLength(ref reader, field); - if (arrayLength > 0) - { - var array = new string[arrayLength]; - for (int i = 0; i < arrayLength; i++) - { - var fieldName = $"{field}[{i}]"; - array[i] = ReadStringNotNull(ref reader, fieldName); - } + throw new InvalidDataException($"Reading '{field}' as Not-Null String failed."); + } - return array; - } + return result; + } - return []; + private static string? ReadString(ref MessagePackReader reader, string formatField, int param) + { + try + { + return reader.ReadString(); + } + catch (Exception ex) + { + throw new InvalidDataException($"Reading '{string.Format(formatField, param)}' as String failed.", ex); } + } - private static byte[] ReadBytes(ref MessagePackReader reader, string field) + private static string[] ReadStringArray(ref MessagePackReader reader, string field) + { + var arrayLength = ReadArrayLength(ref reader, field); + if (arrayLength > 0) { - try - { - return reader.ReadBytes()?.ToArray() ?? Array.Empty(); - } - catch (Exception ex) + var array = new string[arrayLength]; + for (int i = 0; i < arrayLength; i++) { - throw new InvalidDataException($"Reading '{field}' as Byte[] failed.", ex); + var fieldName = $"{field}[{i}]"; + array[i] = ReadStringNotNull(ref reader, fieldName); } + + return array; } - private static byte[] ReadBytes(ref MessagePackReader reader, string formatField, int param) + return []; + } + + private static byte[] ReadBytes(ref MessagePackReader reader, string field) + { + try { - try - { - return reader.ReadBytes()?.ToArray() ?? Array.Empty(); - } - catch (Exception ex) - { - throw new InvalidDataException($"Reading '{string.Format(formatField, param)}' as Byte[] failed.", ex); - } + return reader.ReadBytes()?.ToArray() ?? Array.Empty(); + } + catch (Exception ex) + { + throw new InvalidDataException($"Reading '{field}' as Byte[] failed.", ex); } + } - private static long ReadMapLength(ref MessagePackReader reader, string field) + private static byte[] ReadBytes(ref MessagePackReader reader, string formatField, int param) + { + try { - try - { - return reader.ReadMapHeader(); - } - catch (Exception ex) - { - throw new InvalidDataException($"Reading map length for '{field}' failed.", ex); - } + return reader.ReadBytes()?.ToArray() ?? Array.Empty(); + } + catch (Exception ex) + { + throw new InvalidDataException($"Reading '{string.Format(formatField, param)}' as Byte[] failed.", ex); } + } - private static long ReadArrayLength(ref MessagePackReader reader, string field) + private static long ReadMapLength(ref MessagePackReader reader, string field) + { + try { - try - { - return reader.ReadArrayHeader(); - } - catch (Exception ex) - { - throw new InvalidDataException($"Reading array length for '{field}' failed.", ex); - } + return reader.ReadMapHeader(); + } + catch (Exception ex) + { + throw new InvalidDataException($"Reading map length for '{field}' failed.", ex); + } + } + private static long ReadArrayLength(ref MessagePackReader reader, string field) + { + try + { + return reader.ReadArrayHeader(); + } + catch (Exception ex) + { + throw new InvalidDataException($"Reading array length for '{field}' failed.", ex); } + } } \ No newline at end of file