mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 17:23:04 +08:00
52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
using MQTTnet.Exceptions;
|
|
using MQTTnet.Protocol;
|
|
|
|
namespace MQTTnet
|
|
{
|
|
public class TopicFilterBuilder
|
|
{
|
|
private MqttQualityOfServiceLevel _qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce;
|
|
private string _topic;
|
|
|
|
public TopicFilterBuilder WithTopic(string topic)
|
|
{
|
|
_topic = topic;
|
|
return this;
|
|
}
|
|
|
|
public TopicFilterBuilder WithQualityOfServiceLevel(MqttQualityOfServiceLevel qualityOfServiceLevel)
|
|
{
|
|
_qualityOfServiceLevel = qualityOfServiceLevel;
|
|
return this;
|
|
}
|
|
|
|
public TopicFilterBuilder WithAtLeastOnceQoS()
|
|
{
|
|
_qualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce;
|
|
return this;
|
|
}
|
|
|
|
public TopicFilterBuilder WithAtMostOnceQoS()
|
|
{
|
|
_qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce;
|
|
return this;
|
|
}
|
|
|
|
public TopicFilterBuilder WithExactlyOnceQoS()
|
|
{
|
|
_qualityOfServiceLevel = MqttQualityOfServiceLevel.ExactlyOnce;
|
|
return this;
|
|
}
|
|
|
|
public TopicFilter Build()
|
|
{
|
|
if (string.IsNullOrEmpty(_topic))
|
|
{
|
|
throw new MqttProtocolViolationException("Topic is not set.");
|
|
}
|
|
|
|
return new TopicFilter { Topic = _topic, QualityOfServiceLevel = _qualityOfServiceLevel };
|
|
}
|
|
}
|
|
}
|