public void OnDataReceived(Guid clientId, Memory <byte> data) { try { var type = _deserializer.ParsePayloadType(data); _logger.LogInformation($"Received data with type: {type} from client: {clientId}"); switch (type) { case PayloadType.Msg: var message = _deserializer.ToMessage(data); OnMessage(clientId, message); break; case PayloadType.Ack: var ack = _deserializer.ToAck(data); OnMessageAck(clientId, ack); break; case PayloadType.Nack: var nack = _deserializer.ToNack(data); OnMessageNack(clientId, nack); break; case PayloadType.SubscribeTopic: var subscribeQueue = _deserializer.ToSubscribeTopic(data); OnSubscribeTopic(clientId, subscribeQueue); break; case PayloadType.UnsubscribeTopic: var unsubscribeQueue = _deserializer.ToUnsubscribeTopic(data); OnUnsubscribeTopic(clientId, unsubscribeQueue); break; case PayloadType.TopicDeclare: var queueDeclare = _deserializer.ToTopicDeclare(data); OnDeclareQueue(clientId, queueDeclare); break; case PayloadType.TopicDelete: var queueDelete = _deserializer.ToTopicDelete(data); OnDeleteQueue(clientId, queueDelete); break; case PayloadType.Configure: var configure = _deserializer.ToConfigureClient(data); OnConfigureClient(clientId, configure); break; } } catch (Exception e) { _logger.LogError($"Failed to deserialize data from client: {clientId} with error: {e}"); } }
/// <inheritdoc /> public void DataReceived(object clientSessionObject, ClientSessionDataReceivedEventArgs dataReceivedEventArgs) { var data = dataReceivedEventArgs.Data; var payloadType = _deserializer.ParsePayloadType(data); switch (payloadType) { case PayloadType.Ok: OnOk(data); break; case PayloadType.Error: OnError(data); break; case PayloadType.TopicMessage: OnMessage(data); break; default: throw new InvalidOperationException( "Failed to map type to appropriate action while parsing payload"); } }