public IProtocolFlow GetFlow(MqttPacketType packetType)
        {
            if (!IsValidPacketType(packetType))
            {
                throw new MqttException(ClientProperties.ProtocolFlowProvider_InvalidPacketType(packetType));
            }

            ProtocolFlowType flowType = packetType.ToFlowType();


            if (!GetFlows().TryGetValue(flowType, out IProtocolFlow flow))
            {
                throw new MqttException(ClientProperties.ProtocolFlowProvider_UnknownPacketType(packetType));
            }

            return(flow);
        }
Exemple #2
0
        internal static ProtocolFlowType ToFlowType(this MqttPacketType packetType)
        {
            ProtocolFlowType flowType = default;

            switch (packetType)
            {
            case MqttPacketType.Connect:
            case MqttPacketType.ConnectAck:
                flowType = ProtocolFlowType.Connect;
                break;

            case MqttPacketType.Publish:
            case MqttPacketType.PublishRelease:
                flowType = ProtocolFlowType.PublishReceiver;
                break;

            case MqttPacketType.PublishAck:
            case MqttPacketType.PublishReceived:
            case MqttPacketType.PublishComplete:
                flowType = ProtocolFlowType.PublishSender;
                break;

            case MqttPacketType.Subscribe:
            case MqttPacketType.SubscribeAck:
                flowType = ProtocolFlowType.Subscribe;
                break;

            case MqttPacketType.Unsubscribe:
            case MqttPacketType.UnsubscribeAck:
                flowType = ProtocolFlowType.Unsubscribe;
                break;

            case MqttPacketType.PingRequest:
            case MqttPacketType.PingResponse:
                flowType = ProtocolFlowType.Ping;
                break;

            case MqttPacketType.Disconnect:
                flowType = ProtocolFlowType.Disconnect;
                break;
            }

            return(flowType);
        }