Skip to content

Commit

Permalink
Fix issue
Browse files Browse the repository at this point in the history
  • Loading branch information
chkr1011 committed Aug 25, 2024
1 parent 351384c commit 49bd2e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Source/MQTTnet/Formatter/V5/MqttV5PacketDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ public MqttPacket Decode(ReceivedMqttPacket receivedMqttPacket)

MqttPacket DecodeAuthPacket(ArraySegment<byte> body)
{
ThrowIfBodyIsEmpty(body);

_bufferReader.SetBuffer(body.Array, body.Offset, body.Count);

var packet = new MqttAuthPacket();

// 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 (_bufferReader.EndOfStream)
{
packet.ReasonCode = MqttAuthenticateReasonCode.Success;
Expand Down
7 changes: 7 additions & 0 deletions Source/MQTTnet/Formatter/V5/MqttV5PacketEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ public MqttPacketBuffer Encode(MqttPacket packet)

byte EncodeAuthPacket(MqttAuthPacket packet)
{
// 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)
{
return MqttBufferWriter.BuildFixedHeader(MqttControlPacketType.Auth);
}

_bufferWriter.WriteByte((byte)packet.ReasonCode);

_propertiesWriter.WriteAuthenticationMethod(packet.AuthenticationMethod);
Expand Down

0 comments on commit 49bd2e9

Please sign in to comment.