mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 17:23:04 +08:00
29 lines
781 B
C#
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.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|