diff --git a/Source/MQTTnet/Formatter/V5/MqttV5PacketEncoder.cs b/Source/MQTTnet/Formatter/V5/MqttV5PacketEncoder.cs index 06863fa0..95699925 100644 --- a/Source/MQTTnet/Formatter/V5/MqttV5PacketEncoder.cs +++ b/Source/MQTTnet/Formatter/V5/MqttV5PacketEncoder.cs @@ -67,6 +67,11 @@ public MqttPacketBuffer Encode(MqttPacket packet) byte EncodeAuthPacket(MqttAuthPacket packet) { + _propertiesWriter.WriteAuthenticationMethod(packet.AuthenticationMethod); + _propertiesWriter.WriteAuthenticationData(packet.AuthenticationData); + _propertiesWriter.WriteReasonString(packet.ReasonString); + _propertiesWriter.WriteUserProperties(packet.UserProperties); + // MQTT spec: The Reason Code and Property Length can be omitted if the Reason Code is 0x00 (Success) and there are no Properties. // In this case the AUTH has a Remaining Length of 0. if (packet.ReasonCode == MqttAuthenticateReasonCode.Success && _propertiesWriter.Length == 0) @@ -76,11 +81,6 @@ byte EncodeAuthPacket(MqttAuthPacket packet) _bufferWriter.WriteByte((byte)packet.ReasonCode); - _propertiesWriter.WriteAuthenticationMethod(packet.AuthenticationMethod); - _propertiesWriter.WriteAuthenticationData(packet.AuthenticationData); - _propertiesWriter.WriteReasonString(packet.ReasonString); - _propertiesWriter.WriteUserProperties(packet.UserProperties); - _propertiesWriter.WriteTo(_bufferWriter); _propertiesWriter.Reset();