mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 19:58:57 +08:00
Add support for TopicAlias in application message builder.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user