mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 17:00:03 +08:00
33 lines
698 B
C#
33 lines
698 B
C#
namespace MQTTnet.Client
|
|
{
|
|
public class MqttPacketIdentifierProvider
|
|
{
|
|
private readonly object _syncRoot = new object();
|
|
private ushort _value;
|
|
|
|
public void Reset()
|
|
{
|
|
lock (_syncRoot)
|
|
{
|
|
_value = 0;
|
|
}
|
|
}
|
|
|
|
public ushort GetNewPacketIdentifier()
|
|
{
|
|
lock (_syncRoot)
|
|
{
|
|
_value++;
|
|
|
|
if (_value == 0)
|
|
{
|
|
// As per official MQTT documentation the package identifier should never be 0.
|
|
_value = 1;
|
|
}
|
|
|
|
return _value;
|
|
}
|
|
}
|
|
}
|
|
}
|