Add support for TopicAlias in application message builder.

This commit is contained in:
Christian Kratky
2020-11-09 17:22:32 +01:00
parent eaf1195f95
commit 6c15693456
2 changed files with 18 additions and 8 deletions
@@ -222,9 +222,14 @@ namespace MQTTnet
public MqttApplicationMessage Build()
{
if (string.IsNullOrEmpty(_topic))
if (!_topicAlias.HasValue && string.IsNullOrEmpty(_topic))
{
throw new MqttProtocolViolationException("Topic is not set.");
throw new MqttProtocolViolationException("Topic or TopicAlias is not set.");
}
if (_topicAlias == 0)
{
throw new MqttProtocolViolationException("A Topic Alias of 0 is not permitted. A sender MUST NOT send a PUBLISH packet containing a Topic Alias which has the value 0 [MQTT-3.3.2-8].");
}
var applicationMessage = new MqttApplicationMessage