Browse Source

Fix serialization issue of MQTTv5 PubRec packet.

release/3.x.x
Christian Kratky 5 years ago
parent
commit
2767d897a4
2 changed files with 21 additions and 12 deletions
  1. +18
    -8
      Source/MQTTnet/Formatter/IMqttPacketWriter.cs
  2. +3
    -4
      Source/MQTTnet/Formatter/V5/MqttV500PacketEncoder.cs

+ 18
- 8
Source/MQTTnet/Formatter/IMqttPacketWriter.cs View File

@@ -5,15 +5,25 @@
int Length { get; } int Length { get; }


void WriteWithLengthPrefix(string value); void WriteWithLengthPrefix(string value);
void Write(byte returnCode);
void WriteWithLengthPrefix(byte[] payload);
void Write(ushort keepAlivePeriod);
void Write(IMqttPacketWriter propertyWriter);
void WriteVariableLengthInteger(uint length);
void Write(byte[] payload, int v, int length);
void Reset(int v);
void Seek(int v);

void Write(byte value);

void WriteWithLengthPrefix(byte[] value);

void Write(ushort value);

void Write(IMqttPacketWriter value);

void WriteVariableLengthInteger(uint value);

void Write(byte[] value, int offset, int length);

void Reset(int length);

void Seek(int offset);

void FreeBuffer(); void FreeBuffer();

byte[] GetBuffer(); byte[] GetBuffer();
} }
} }

+ 3
- 4
Source/MQTTnet/Formatter/V5/MqttV500PacketEncoder.cs View File

@@ -328,10 +328,7 @@ namespace MQTTnet.Formatter.V5
{ {
ThrowReasonCodeNotSetException(); ThrowReasonCodeNotSetException();
} }

packetWriter.Write(packet.PacketIdentifier.Value);
packetWriter.Write((byte)packet.ReasonCode.Value);

var propertiesWriter = new MqttV500PropertiesWriter(); var propertiesWriter = new MqttV500PropertiesWriter();
if (packet.Properties != null) if (packet.Properties != null)
{ {
@@ -339,6 +336,8 @@ namespace MQTTnet.Formatter.V5
propertiesWriter.WriteUserProperties(packet.Properties.UserProperties); propertiesWriter.WriteUserProperties(packet.Properties.UserProperties);
} }


packetWriter.Write(packet.PacketIdentifier.Value);

if (packetWriter.Length > 0 || packet.ReasonCode.Value != MqttPubRecReasonCode.Success) if (packetWriter.Length > 0 || packet.ReasonCode.Value != MqttPubRecReasonCode.Success)
{ {
packetWriter.Write((byte)packet.ReasonCode.Value); packetWriter.Write((byte)packet.ReasonCode.Value);


Loading…
Cancel
Save