mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 19:58:57 +08:00
Added package properties.
This commit is contained in:
@@ -1,6 +1,34 @@
|
||||
namespace MQTTnet.Packets
|
||||
using System.Collections.Generic;
|
||||
using MQTTnet.Packets.Properties;
|
||||
|
||||
namespace MQTTnet.Packets
|
||||
{
|
||||
public abstract class MqttConnectPacket : MqttBasePacket
|
||||
public class MqttConnectPacket : MqttBasePacket
|
||||
{
|
||||
public string ProtocolName { get; set; }
|
||||
|
||||
public byte ProtocolLevel { get; set; }
|
||||
|
||||
public string ClientId { get; set; }
|
||||
|
||||
public string Username { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
|
||||
public ushort KeepAlivePeriod { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// MQTTv5: Also called "Clean Start".
|
||||
/// </summary>
|
||||
public bool CleanSession { get; set; }
|
||||
|
||||
public MqttApplicationMessage WillMessage { get; set; }
|
||||
|
||||
public List<Property> Properties { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Connect: [ProtocolLevel=" + ProtocolLevel + "] [ClientId=" + ClientId + "] [Username=" + Username + "] [Password=" + Password + "] [KeepAlivePeriod=" + KeepAlivePeriod + "] [CleanSession=" + CleanSession + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using MQTTnet.Serializer;
|
||||
|
||||
namespace MQTTnet.Packets.Properties
|
||||
{
|
||||
public class ByteValue : IPropertyValue
|
||||
{
|
||||
public ByteValue(byte value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public byte Value { get; }
|
||||
|
||||
public void WriteTo(MqttPacketWriter writer)
|
||||
{
|
||||
if (writer == null) throw new ArgumentNullException(nameof(writer));
|
||||
|
||||
writer.Write(Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using MQTTnet.Serializer;
|
||||
|
||||
namespace MQTTnet.Packets.Properties
|
||||
{
|
||||
public interface IPropertyValue
|
||||
{
|
||||
void WriteTo(MqttPacketWriter writer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MQTTnet.Packets.Properties
|
||||
{
|
||||
public class Property
|
||||
{
|
||||
public PropertyType Type { get; set; }
|
||||
|
||||
public IPropertyValue Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
namespace MQTTnet.Packets.Properties
|
||||
{
|
||||
public enum PropertyType
|
||||
{
|
||||
PayloadFormatIndicator = 1,
|
||||
MessageExpiryInterval = 2,
|
||||
ContentType = 3,
|
||||
ResponseTopic = 8,
|
||||
CorrelationData = 9,
|
||||
SubscriptionIdentifier = 11,
|
||||
SessionExpiryInterval = 17,
|
||||
AssignedClientIdentifer = 18,
|
||||
ServerKeepAlive = 19,
|
||||
AuthenticationMethod = 21,
|
||||
AuthenticationData = 22,
|
||||
RequestProblemInformation = 23,
|
||||
WillDelayInterval = 24,
|
||||
RequestResponseInformation = 25,
|
||||
ResponseInformation = 26,
|
||||
ServerReference = 28,
|
||||
ReasonString = 31,
|
||||
ReceiveMaximum = 33,
|
||||
TopicAliasMaximum = 34,
|
||||
TopicAlias = 35,
|
||||
MaximumQoS = 36,
|
||||
RetainAvailable = 37,
|
||||
UserProperty = 38,
|
||||
MaximumPacketSize = 39,
|
||||
WildcardSubscriptionAvailable = 40,
|
||||
SubscriptionIdentifierAvailable = 41,
|
||||
SharedSubscriptionAvailable = 42
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using MQTTnet.Serializer;
|
||||
|
||||
namespace MQTTnet.Packets.Properties
|
||||
{
|
||||
public class StringValue : IPropertyValue
|
||||
{
|
||||
public StringValue(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public string Value { get; }
|
||||
|
||||
public void WriteTo(MqttPacketWriter writer)
|
||||
{
|
||||
if (writer == null) throw new ArgumentNullException(nameof(writer));
|
||||
|
||||
writer.WriteWithLengthPrefix(Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using MQTTnet.Serializer;
|
||||
|
||||
namespace MQTTnet.Packets.Properties
|
||||
{
|
||||
public class TwoByteIntegerValue : IPropertyValue
|
||||
{
|
||||
public TwoByteIntegerValue(ushort value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public ushort Value { get; }
|
||||
|
||||
public void WriteTo(MqttPacketWriter writer)
|
||||
{
|
||||
if (writer == null) throw new ArgumentNullException(nameof(writer));
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
namespace MQTTnet.Packets.V3
|
||||
{
|
||||
public class MqttV3ConnectPacket : MqttConnectPacket
|
||||
{
|
||||
public string ProtocolName { get; set; }
|
||||
|
||||
public byte ProtocolLevel { get; set; }
|
||||
|
||||
public string ClientId { get; set; }
|
||||
|
||||
public string Username { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
|
||||
public ushort KeepAlivePeriod { get; set; }
|
||||
|
||||
public bool CleanSession { get; set; }
|
||||
|
||||
public MqttApplicationMessage WillMessage { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Connect: [ProtocolLevel=" + ProtocolLevel + "] [ClientId=" + ClientId + "] [Username=" + Username + "] [Password=" + Password + "] [KeepAlivePeriod=" + KeepAlivePeriod + "] [CleanSession=" + CleanSession + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user