From 2fbb44ec6643e1b6545b9139b1ec3aed81079ee8 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Sun, 18 Nov 2018 21:54:40 +0100 Subject: [PATCH] Add more property implementations. --- Source/MQTTnet/Packets/MqttConnectPacket.cs | 2 +- .../AssignedClientIdentifierProperty.cs | 10 ++++++ .../Properties/AuthenticationDataProperty.cs | 12 +++++++ .../AuthenticationMethodProperty.cs | 10 ++++++ .../BaseTypes/BinaryDataProperty.cs | 31 +++++++++++++++++++ .../ByteProperty.cs} | 7 +++-- .../BaseTypes/FourByteIntegerProperty.cs | 27 ++++++++++++++++ .../StringProperty.cs} | 7 +++-- .../TwoByteIntegerProperty.cs} | 11 ++++--- .../BaseTypes/VariableByteIntegerProperty.cs | 26 ++++++++++++++++ .../Packets/Properties/ContentTypeProperty.cs | 10 ++++++ .../Properties/CorrelationDataProperty.cs | 12 +++++++ .../{IPropertyValue.cs => IProperty.cs} | 4 ++- .../MessageExpiryIntervalProperty.cs | 12 +++++++ .../PayloadFormatIndicatorProperty.cs | 10 ++++++ Source/MQTTnet/Packets/Properties/Property.cs | 9 ------ .../{PropertyType.cs => PropertyID.cs} | 2 +- .../RequestProblemInformationProperty.cs | 10 ++++++ .../RequestResponseInformationProperty.cs | 10 ++++++ .../Properties/ResponseTopicProperty.cs | 10 ++++++ .../Properties/ServerKeepAliveProperty.cs | 12 +++++++ .../SessionExpiryIntervalProperty.cs | 12 +++++++ .../SubscriptionIdentifierProperty.cs | 12 +++++++ .../Properties/WillDelayIntervalProperty.cs | 12 +++++++ Source/MQTTnet/Serializer/MqttPacketWriter.cs | 8 +++-- .../Serializer/MqttV310PacketSerializer.cs | 2 +- .../Serializer/MqttV500PacketSerializer.cs | 6 ++-- 27 files changed, 270 insertions(+), 26 deletions(-) create mode 100644 Source/MQTTnet/Packets/Properties/AssignedClientIdentifierProperty.cs create mode 100644 Source/MQTTnet/Packets/Properties/AuthenticationDataProperty.cs create mode 100644 Source/MQTTnet/Packets/Properties/AuthenticationMethodProperty.cs create mode 100644 Source/MQTTnet/Packets/Properties/BaseTypes/BinaryDataProperty.cs rename Source/MQTTnet/Packets/Properties/{ByteValue.cs => BaseTypes/ByteProperty.cs} (72%) create mode 100644 Source/MQTTnet/Packets/Properties/BaseTypes/FourByteIntegerProperty.cs rename Source/MQTTnet/Packets/Properties/{StringValue.cs => BaseTypes/StringProperty.cs} (71%) rename Source/MQTTnet/Packets/Properties/{TwoByteIntegerValue.cs => BaseTypes/TwoByteIntegerProperty.cs} (54%) create mode 100644 Source/MQTTnet/Packets/Properties/BaseTypes/VariableByteIntegerProperty.cs create mode 100644 Source/MQTTnet/Packets/Properties/ContentTypeProperty.cs create mode 100644 Source/MQTTnet/Packets/Properties/CorrelationDataProperty.cs rename Source/MQTTnet/Packets/Properties/{IPropertyValue.cs => IProperty.cs} (69%) create mode 100644 Source/MQTTnet/Packets/Properties/MessageExpiryIntervalProperty.cs create mode 100644 Source/MQTTnet/Packets/Properties/PayloadFormatIndicatorProperty.cs delete mode 100644 Source/MQTTnet/Packets/Properties/Property.cs rename Source/MQTTnet/Packets/Properties/{PropertyType.cs => PropertyID.cs} (97%) create mode 100644 Source/MQTTnet/Packets/Properties/RequestProblemInformationProperty.cs create mode 100644 Source/MQTTnet/Packets/Properties/RequestResponseInformationProperty.cs create mode 100644 Source/MQTTnet/Packets/Properties/ResponseTopicProperty.cs create mode 100644 Source/MQTTnet/Packets/Properties/ServerKeepAliveProperty.cs create mode 100644 Source/MQTTnet/Packets/Properties/SessionExpiryIntervalProperty.cs create mode 100644 Source/MQTTnet/Packets/Properties/SubscriptionIdentifierProperty.cs create mode 100644 Source/MQTTnet/Packets/Properties/WillDelayIntervalProperty.cs diff --git a/Source/MQTTnet/Packets/MqttConnectPacket.cs b/Source/MQTTnet/Packets/MqttConnectPacket.cs index 7c0b7a0..ec1b953 100644 --- a/Source/MQTTnet/Packets/MqttConnectPacket.cs +++ b/Source/MQTTnet/Packets/MqttConnectPacket.cs @@ -24,7 +24,7 @@ namespace MQTTnet.Packets public MqttApplicationMessage WillMessage { get; set; } - public List Properties { get; set; } + public List Properties { get; set; } public override string ToString() { diff --git a/Source/MQTTnet/Packets/Properties/AssignedClientIdentifierProperty.cs b/Source/MQTTnet/Packets/Properties/AssignedClientIdentifierProperty.cs new file mode 100644 index 0000000..b7fd3cd --- /dev/null +++ b/Source/MQTTnet/Packets/Properties/AssignedClientIdentifierProperty.cs @@ -0,0 +1,10 @@ +namespace MQTTnet.Packets.Properties +{ + public class AssignedClientIdentifierProperty : StringProperty + { + public AssignedClientIdentifierProperty(string value) + : base((byte)PropertyID.AssignedClientIdentifer, value) + { + } + } +} diff --git a/Source/MQTTnet/Packets/Properties/AuthenticationDataProperty.cs b/Source/MQTTnet/Packets/Properties/AuthenticationDataProperty.cs new file mode 100644 index 0000000..021d9e9 --- /dev/null +++ b/Source/MQTTnet/Packets/Properties/AuthenticationDataProperty.cs @@ -0,0 +1,12 @@ +using System; + +namespace MQTTnet.Packets.Properties +{ + public class AuthenticationDataProperty : BinaryDataProperty + { + public AuthenticationDataProperty(ArraySegment data) + : base((byte)PropertyID.AuthenticationData, data) + { + } + } +} diff --git a/Source/MQTTnet/Packets/Properties/AuthenticationMethodProperty.cs b/Source/MQTTnet/Packets/Properties/AuthenticationMethodProperty.cs new file mode 100644 index 0000000..7de63c3 --- /dev/null +++ b/Source/MQTTnet/Packets/Properties/AuthenticationMethodProperty.cs @@ -0,0 +1,10 @@ +namespace MQTTnet.Packets.Properties +{ + public class AuthenticationMethodProperty : StringProperty + { + public AuthenticationMethodProperty(string value) + : base((byte)PropertyID.AuthenticationMethod, value) + { + } + } +} diff --git a/Source/MQTTnet/Packets/Properties/BaseTypes/BinaryDataProperty.cs b/Source/MQTTnet/Packets/Properties/BaseTypes/BinaryDataProperty.cs new file mode 100644 index 0000000..2037b8e --- /dev/null +++ b/Source/MQTTnet/Packets/Properties/BaseTypes/BinaryDataProperty.cs @@ -0,0 +1,31 @@ +using System; +using MQTTnet.Serializer; + +namespace MQTTnet.Packets.Properties +{ + public class BinaryDataProperty : IProperty + { + public BinaryDataProperty(byte id, ArraySegment data) + { + if (data.Array == null) + { + throw new ArgumentNullException(nameof(data)); + } + + Id = id; + Data = data; + } + + public byte Id { get; } + + public ArraySegment Data { get; } + + public void WriteTo(MqttPacketWriter writer) + { + if (writer == null) throw new ArgumentNullException(nameof(writer)); + + writer.Write((ushort)Data.Count); + writer.Write(Data); + } + } +} diff --git a/Source/MQTTnet/Packets/Properties/ByteValue.cs b/Source/MQTTnet/Packets/Properties/BaseTypes/ByteProperty.cs similarity index 72% rename from Source/MQTTnet/Packets/Properties/ByteValue.cs rename to Source/MQTTnet/Packets/Properties/BaseTypes/ByteProperty.cs index 5c34cb9..e3e4121 100644 --- a/Source/MQTTnet/Packets/Properties/ByteValue.cs +++ b/Source/MQTTnet/Packets/Properties/BaseTypes/ByteProperty.cs @@ -3,13 +3,16 @@ using MQTTnet.Serializer; namespace MQTTnet.Packets.Properties { - public class ByteValue : IPropertyValue + public class ByteProperty : IProperty { - public ByteValue(byte value) + public ByteProperty(byte id, byte value) { + Id = id; Value = value; } + public byte Id { get; } + public byte Value { get; } public void WriteTo(MqttPacketWriter writer) diff --git a/Source/MQTTnet/Packets/Properties/BaseTypes/FourByteIntegerProperty.cs b/Source/MQTTnet/Packets/Properties/BaseTypes/FourByteIntegerProperty.cs new file mode 100644 index 0000000..56aafe3 --- /dev/null +++ b/Source/MQTTnet/Packets/Properties/BaseTypes/FourByteIntegerProperty.cs @@ -0,0 +1,27 @@ +using System; +using MQTTnet.Serializer; + +namespace MQTTnet.Packets.Properties.BaseTypes +{ + public class FourByteIntegerValue : IProperty + { + public FourByteIntegerValue(byte id, uint value) + { + Id = id; + Value = value; + } + + public byte Id { get; } + + public uint Value { get; } + + public void WriteTo(MqttPacketWriter writer) + { + if (writer == null) throw new ArgumentNullException(nameof(writer)); + + // TODO: Check if order must be reversed like for ushort. + var bytes = BitConverter.GetBytes(Value); + writer.Write(bytes, 0, bytes.Length); + } + } +} diff --git a/Source/MQTTnet/Packets/Properties/StringValue.cs b/Source/MQTTnet/Packets/Properties/BaseTypes/StringProperty.cs similarity index 71% rename from Source/MQTTnet/Packets/Properties/StringValue.cs rename to Source/MQTTnet/Packets/Properties/BaseTypes/StringProperty.cs index fc614ad..b791069 100644 --- a/Source/MQTTnet/Packets/Properties/StringValue.cs +++ b/Source/MQTTnet/Packets/Properties/BaseTypes/StringProperty.cs @@ -3,13 +3,16 @@ using MQTTnet.Serializer; namespace MQTTnet.Packets.Properties { - public class StringValue : IPropertyValue + public class StringProperty : IProperty { - public StringValue(string value) + public StringProperty(byte id, string value) { + Id = id; Value = value; } + public byte Id { get; } + public string Value { get; } public void WriteTo(MqttPacketWriter writer) diff --git a/Source/MQTTnet/Packets/Properties/TwoByteIntegerValue.cs b/Source/MQTTnet/Packets/Properties/BaseTypes/TwoByteIntegerProperty.cs similarity index 54% rename from Source/MQTTnet/Packets/Properties/TwoByteIntegerValue.cs rename to Source/MQTTnet/Packets/Properties/BaseTypes/TwoByteIntegerProperty.cs index 79fc919..4ed6776 100644 --- a/Source/MQTTnet/Packets/Properties/TwoByteIntegerValue.cs +++ b/Source/MQTTnet/Packets/Properties/BaseTypes/TwoByteIntegerProperty.cs @@ -1,22 +1,25 @@ using System; using MQTTnet.Serializer; -namespace MQTTnet.Packets.Properties +namespace MQTTnet.Packets.Properties.BaseTypes { - public class TwoByteIntegerValue : IPropertyValue + public class TwoByteIntegerProperty : IProperty { - public TwoByteIntegerValue(ushort value) + public TwoByteIntegerProperty(byte id, ushort value) { + Id = id; Value = value; } + public byte Id { get; } + public ushort Value { get; } public void WriteTo(MqttPacketWriter writer) { if (writer == null) throw new ArgumentNullException(nameof(writer)); - throw new NotImplementedException(); + writer.Write(Value); } } } diff --git a/Source/MQTTnet/Packets/Properties/BaseTypes/VariableByteIntegerProperty.cs b/Source/MQTTnet/Packets/Properties/BaseTypes/VariableByteIntegerProperty.cs new file mode 100644 index 0000000..26eef48 --- /dev/null +++ b/Source/MQTTnet/Packets/Properties/BaseTypes/VariableByteIntegerProperty.cs @@ -0,0 +1,26 @@ +using System; +using MQTTnet.Serializer; + +namespace MQTTnet.Packets.Properties.BaseTypes +{ + public class VariableByteIntegerProperty : IProperty + { + public VariableByteIntegerProperty(byte id, uint value) + { + Id = id; + Value = value; + } + + public byte Id { get; } + + public uint Value { get; } + + public void WriteTo(MqttPacketWriter writer) + { + if (writer == null) throw new ArgumentNullException(nameof(writer)); + + var buffer = MqttPacketWriter.EncodeVariableByteInteger(Value); + writer.Write(buffer); + } + } +} diff --git a/Source/MQTTnet/Packets/Properties/ContentTypeProperty.cs b/Source/MQTTnet/Packets/Properties/ContentTypeProperty.cs new file mode 100644 index 0000000..1e7ec42 --- /dev/null +++ b/Source/MQTTnet/Packets/Properties/ContentTypeProperty.cs @@ -0,0 +1,10 @@ +namespace MQTTnet.Packets.Properties +{ + public class ContentTypeProperty : StringProperty + { + public ContentTypeProperty(string value) + : base((byte)PropertyID.ContentType, value) + { + } + } +} diff --git a/Source/MQTTnet/Packets/Properties/CorrelationDataProperty.cs b/Source/MQTTnet/Packets/Properties/CorrelationDataProperty.cs new file mode 100644 index 0000000..f9104e8 --- /dev/null +++ b/Source/MQTTnet/Packets/Properties/CorrelationDataProperty.cs @@ -0,0 +1,12 @@ +using System; + +namespace MQTTnet.Packets.Properties +{ + public class CorrelationDataProperty : BinaryDataProperty + { + public CorrelationDataProperty(ArraySegment data) + : base((byte)PropertyID.CorrelationData, data) + { + } + } +} diff --git a/Source/MQTTnet/Packets/Properties/IPropertyValue.cs b/Source/MQTTnet/Packets/Properties/IProperty.cs similarity index 69% rename from Source/MQTTnet/Packets/Properties/IPropertyValue.cs rename to Source/MQTTnet/Packets/Properties/IProperty.cs index 005134f..739e0cd 100644 --- a/Source/MQTTnet/Packets/Properties/IPropertyValue.cs +++ b/Source/MQTTnet/Packets/Properties/IProperty.cs @@ -2,8 +2,10 @@ namespace MQTTnet.Packets.Properties { - public interface IPropertyValue + public interface IProperty { + byte Id { get; } + void WriteTo(MqttPacketWriter writer); } } diff --git a/Source/MQTTnet/Packets/Properties/MessageExpiryIntervalProperty.cs b/Source/MQTTnet/Packets/Properties/MessageExpiryIntervalProperty.cs new file mode 100644 index 0000000..7062e8b --- /dev/null +++ b/Source/MQTTnet/Packets/Properties/MessageExpiryIntervalProperty.cs @@ -0,0 +1,12 @@ +using MQTTnet.Packets.Properties.BaseTypes; + +namespace MQTTnet.Packets.Properties +{ + public class MessageExpiryIntervalProperty : FourByteIntegerValue + { + public MessageExpiryInterval(uint value) + : base((byte)PropertyID.MessageExpiryInterval, value) + { + } + } +} diff --git a/Source/MQTTnet/Packets/Properties/PayloadFormatIndicatorProperty.cs b/Source/MQTTnet/Packets/Properties/PayloadFormatIndicatorProperty.cs new file mode 100644 index 0000000..f30f5b1 --- /dev/null +++ b/Source/MQTTnet/Packets/Properties/PayloadFormatIndicatorProperty.cs @@ -0,0 +1,10 @@ +namespace MQTTnet.Packets.Properties +{ + public class PayloadFormatIndicatorProperty : ByteProperty + { + public PayloadFormatIndicatorProperty(byte value) + : base((byte)PropertyID.PayloadFormatIndicator, value) + { + } + } +} diff --git a/Source/MQTTnet/Packets/Properties/Property.cs b/Source/MQTTnet/Packets/Properties/Property.cs deleted file mode 100644 index 1fc71d6..0000000 --- a/Source/MQTTnet/Packets/Properties/Property.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace MQTTnet.Packets.Properties -{ - public class Property - { - public PropertyType Type { get; set; } - - public IPropertyValue Value { get; set; } - } -} diff --git a/Source/MQTTnet/Packets/Properties/PropertyType.cs b/Source/MQTTnet/Packets/Properties/PropertyID.cs similarity index 97% rename from Source/MQTTnet/Packets/Properties/PropertyType.cs rename to Source/MQTTnet/Packets/Properties/PropertyID.cs index 8d60aad..69a809e 100644 --- a/Source/MQTTnet/Packets/Properties/PropertyType.cs +++ b/Source/MQTTnet/Packets/Properties/PropertyID.cs @@ -1,6 +1,6 @@ namespace MQTTnet.Packets.Properties { - public enum PropertyType + public enum PropertyID { PayloadFormatIndicator = 1, MessageExpiryInterval = 2, diff --git a/Source/MQTTnet/Packets/Properties/RequestProblemInformationProperty.cs b/Source/MQTTnet/Packets/Properties/RequestProblemInformationProperty.cs new file mode 100644 index 0000000..456c973 --- /dev/null +++ b/Source/MQTTnet/Packets/Properties/RequestProblemInformationProperty.cs @@ -0,0 +1,10 @@ +namespace MQTTnet.Packets.Properties +{ + public class RequestProblemInformationProperty : ByteProperty + { + public RequestProblemInformationProperty(byte value) + : base((byte)PropertyID.RequestProblemInformation, value) + { + } + } +} diff --git a/Source/MQTTnet/Packets/Properties/RequestResponseInformationProperty.cs b/Source/MQTTnet/Packets/Properties/RequestResponseInformationProperty.cs new file mode 100644 index 0000000..9119675 --- /dev/null +++ b/Source/MQTTnet/Packets/Properties/RequestResponseInformationProperty.cs @@ -0,0 +1,10 @@ +namespace MQTTnet.Packets.Properties +{ + public class RequestResponseInformationProperty : ByteProperty + { + public RequestResponseInformationProperty(byte value) + : base((byte)PropertyID.RequestResponseInformation, value) + { + } + } +} diff --git a/Source/MQTTnet/Packets/Properties/ResponseTopicProperty.cs b/Source/MQTTnet/Packets/Properties/ResponseTopicProperty.cs new file mode 100644 index 0000000..ad41bf8 --- /dev/null +++ b/Source/MQTTnet/Packets/Properties/ResponseTopicProperty.cs @@ -0,0 +1,10 @@ +namespace MQTTnet.Packets.Properties +{ + public class ResponseTopicProperty : StringProperty + { + public ResponseTopicProperty(string value) + : base((byte)PropertyID.ResponseTopic, value) + { + } + } +} diff --git a/Source/MQTTnet/Packets/Properties/ServerKeepAliveProperty.cs b/Source/MQTTnet/Packets/Properties/ServerKeepAliveProperty.cs new file mode 100644 index 0000000..a247fb4 --- /dev/null +++ b/Source/MQTTnet/Packets/Properties/ServerKeepAliveProperty.cs @@ -0,0 +1,12 @@ +using MQTTnet.Packets.Properties.BaseTypes; + +namespace MQTTnet.Packets.Properties +{ + public class ServerKeepAliveProperty : TwoByteIntegerProperty + { + public ServerKeepAliveProperty(ushort value) + : base((byte)PropertyID.ServerKeepAlive, value) + { + } + } +} diff --git a/Source/MQTTnet/Packets/Properties/SessionExpiryIntervalProperty.cs b/Source/MQTTnet/Packets/Properties/SessionExpiryIntervalProperty.cs new file mode 100644 index 0000000..f28422e --- /dev/null +++ b/Source/MQTTnet/Packets/Properties/SessionExpiryIntervalProperty.cs @@ -0,0 +1,12 @@ +using MQTTnet.Packets.Properties.BaseTypes; + +namespace MQTTnet.Packets.Properties +{ + public class SessionExpiryIntervalProperty : FourByteIntegerValue + { + public SessionExpiryIntervalProperty(uint value) + : base((byte)PropertyID.SessionExpiryInterval, value) + { + } + } +} diff --git a/Source/MQTTnet/Packets/Properties/SubscriptionIdentifierProperty.cs b/Source/MQTTnet/Packets/Properties/SubscriptionIdentifierProperty.cs new file mode 100644 index 0000000..dca6ad5 --- /dev/null +++ b/Source/MQTTnet/Packets/Properties/SubscriptionIdentifierProperty.cs @@ -0,0 +1,12 @@ +using MQTTnet.Packets.Properties.BaseTypes; + +namespace MQTTnet.Packets.Properties +{ + public class SubscriptionIdentifierProperty : VariableByteIntegerProperty + { + public SubscriptionIdentifierProperty(uint value) + : base((byte)PropertyID.SubscriptionIdentifier, value) + { + } + } +} diff --git a/Source/MQTTnet/Packets/Properties/WillDelayIntervalProperty.cs b/Source/MQTTnet/Packets/Properties/WillDelayIntervalProperty.cs new file mode 100644 index 0000000..e285f86 --- /dev/null +++ b/Source/MQTTnet/Packets/Properties/WillDelayIntervalProperty.cs @@ -0,0 +1,12 @@ +using MQTTnet.Packets.Properties.BaseTypes; + +namespace MQTTnet.Packets.Properties +{ + public class WillDelayIntervalProperty : FourByteIntegerValue + { + public WillDelayIntervalProperty(uint value) + : base((byte)PropertyID.WillDelayInterval, value) + { + } + } +} diff --git a/Source/MQTTnet/Serializer/MqttPacketWriter.cs b/Source/MQTTnet/Serializer/MqttPacketWriter.cs index beb146f..3df5d96 100644 --- a/Source/MQTTnet/Serializer/MqttPacketWriter.cs +++ b/Source/MQTTnet/Serializer/MqttPacketWriter.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; using System.Text; using MQTTnet.Protocol; @@ -27,7 +28,7 @@ namespace MQTTnet.Serializer return (byte)fixedHeader; } - public static ArraySegment EncodeVariableByteInteger(int value) + public static ArraySegment EncodeVariableByteInteger(uint value) { if (value <= 0) { @@ -54,7 +55,7 @@ namespace MQTTnet.Serializer return new ArraySegment(buffer, 0, bufferOffset); } - public void WriteVariableLengthInteger(int value) + public void WriteVariableLengthInteger(uint value) { Write(EncodeVariableByteInteger(value)); } @@ -146,6 +147,7 @@ namespace MQTTnet.Serializer Array.Resize(ref _buffer, MaxBufferSize); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private void EnsureAdditionalCapacity(int additionalCapacity) { var freeSpace = _buffer.Length - _position; @@ -157,6 +159,7 @@ namespace MQTTnet.Serializer EnsureCapacity(_buffer.Length + additionalCapacity - freeSpace); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private void EnsureCapacity(int capacity) { var newBufferLength = _buffer.Length; @@ -174,6 +177,7 @@ namespace MQTTnet.Serializer Array.Resize(ref _buffer, newBufferLength); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private void IncreasePostition(int length) { _position += length; diff --git a/Source/MQTTnet/Serializer/MqttV310PacketSerializer.cs b/Source/MQTTnet/Serializer/MqttV310PacketSerializer.cs index bb72db1..9d36c9e 100644 --- a/Source/MQTTnet/Serializer/MqttV310PacketSerializer.cs +++ b/Source/MQTTnet/Serializer/MqttV310PacketSerializer.cs @@ -23,7 +23,7 @@ namespace MQTTnet.Serializer _packetWriter.Seek(5); var fixedHeader = SerializePacket(packet, _packetWriter); - var remainingLength = _packetWriter.Length - 5; + var remainingLength = (uint)(_packetWriter.Length - 5); var remainingLengthBuffer = MqttPacketWriter.EncodeVariableByteInteger(remainingLength); diff --git a/Source/MQTTnet/Serializer/MqttV500PacketSerializer.cs b/Source/MQTTnet/Serializer/MqttV500PacketSerializer.cs index 44ec36b..e024155 100644 --- a/Source/MQTTnet/Serializer/MqttV500PacketSerializer.cs +++ b/Source/MQTTnet/Serializer/MqttV500PacketSerializer.cs @@ -82,11 +82,11 @@ namespace MQTTnet.Serializer var propertyWriter = new MqttPacketWriter(); foreach (var property in packet.Properties) { - propertyWriter.Write((byte)property.Key); - property.Value.WriteTo(propertyWriter); + propertyWriter.Write(property.Id); + property.WriteTo(propertyWriter); } - packetWriter.WriteVariableLengthInteger(propertyWriter.Length); + packetWriter.WriteVariableLengthInteger((uint)propertyWriter.Length); packetWriter.Write(propertyWriter); }