Ejemplo n.º 1
0
        public void Write(MqttBufferWriter propertyWriter)
        {
            if (propertyWriter is MqttBufferWriter writer)
            {
                WriteBinary(writer._buffer, 0, writer.Length);
                return;
            }

            if (propertyWriter == null)
            {
                throw new ArgumentNullException(nameof(propertyWriter));
            }

            throw new InvalidOperationException($"{nameof(propertyWriter)} must be of type {nameof(MqttBufferWriter)}");
        }
Ejemplo n.º 2
0
        public static IMqttPacketFormatter GetMqttPacketFormatter(MqttProtocolVersion protocolVersion, MqttBufferWriter bufferWriter)
        {
            if (protocolVersion == MqttProtocolVersion.Unknown)
            {
                throw new InvalidOperationException("MQTT protocol version is invalid.");
            }

            switch (protocolVersion)
            {
            case MqttProtocolVersion.V500:
            {
                return(new MqttV5PacketFormatter(bufferWriter));
            }

            case MqttProtocolVersion.V310:
            case MqttProtocolVersion.V311:
            {
                return(new MqttV3PacketFormatter(bufferWriter, protocolVersion));
            }

            default:
            {
                throw new NotSupportedException();
            }
            }
        }
Ejemplo n.º 3
0
 public MqttPacketFormatterAdapter(MqttProtocolVersion protocolVersion, MqttBufferWriter bufferWriter) : this(bufferWriter)
 {
     UseProtocolVersion(protocolVersion);
 }
Ejemplo n.º 4
0
 public MqttPacketFormatterAdapter(MqttBufferWriter mqttBufferWriter)
 {
     _bufferWriter = mqttBufferWriter ?? throw new ArgumentNullException(nameof(mqttBufferWriter));
 }