From caf0691902469eb94efe76a7cfd236cc9fc98cee Mon Sep 17 00:00:00 2001 From: christian <6939810+chkr1011@users.noreply.github.com> Date: Sun, 25 Aug 2024 14:39:00 +0200 Subject: [PATCH] Fix AUTH packet serialization --- Source/MQTTnet/Formatter/V5/MqttV5PacketEncoder.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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();