Files
MQTTnet/Source/MQTTnet/Protocol/MqttTopicValidator.cs
T

29 lines
781 B
C#

using MQTTnet.Exceptions;
namespace MQTTnet.Protocol
{
public static class MqttTopicValidator
{
public static void ThrowIfInvalid(string topic)
{
if (string.IsNullOrEmpty(topic))
{
throw new MqttProtocolViolationException("Topic should not be empty.");
}
foreach(var @char in topic)
{
if (@char == '+')
{
throw new MqttProtocolViolationException("The character '+' is not allowed in topics.");
}
if (@char == '#')
{
throw new MqttProtocolViolationException("The character '#' is not allowed in topics.");
}
}
}
}
}