Skip to content

Commit

Permalink
Fix AUTH packet serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
chkr1011 committed Aug 25, 2024
1 parent 49bd2e9 commit caf0691
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Source/MQTTnet/Formatter/V5/MqttV5PacketEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();

Expand Down

0 comments on commit caf0691

Please sign in to comment.