MqttTopicValidator.cs 695 B

12345678910111213141516171819202122232425
  1. using MQTTnet.Exceptions;
  2. namespace MQTTnet.Protocol
  3. {
  4. public static class MqttTopicValidator
  5. {
  6. public static void ThrowIfInvalid(string topic)
  7. {
  8. if (string.IsNullOrEmpty(topic))
  9. {
  10. throw new MqttProtocolViolationException("Topic should not be empty.");
  11. }
  12. if (topic.Contains("+"))
  13. {
  14. throw new MqttProtocolViolationException("The character '+' is not allowed in topics.");
  15. }
  16. if (topic.Contains("#"))
  17. {
  18. throw new MqttProtocolViolationException("The character '#' is not allowed in topics.");
  19. }
  20. }
  21. }
  22. }