mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 19:58:57 +08:00
Expose results of publish operations for MQTTv5.
This commit is contained in:
@@ -1,8 +1,15 @@
|
|||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using MQTTnet.Packets;
|
||||||
|
|
||||||
namespace MQTTnet.Client.Publishing
|
namespace MQTTnet.Client.Publishing
|
||||||
{
|
{
|
||||||
public class MqttClientPublishResult
|
public class MqttClientPublishResult
|
||||||
{
|
{
|
||||||
public MqttClientPublishReasonCode ReasonCode { get; set; } = MqttClientPublishReasonCode.Success;
|
public MqttClientPublishReasonCode ReasonCode { get; set; } = MqttClientPublishReasonCode.Success;
|
||||||
|
|
||||||
|
public string ReasonString { get; set; }
|
||||||
|
|
||||||
|
public List<MqttUserProperty> UserProperties { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -191,9 +191,12 @@ namespace MQTTnet.Formatter.V5
|
|||||||
{
|
{
|
||||||
var result = new MqttClientPublishResult
|
var result = new MqttClientPublishResult
|
||||||
{
|
{
|
||||||
ReasonCode = (MqttClientPublishReasonCode)pubAckPacket.ReasonCode
|
// Both enums share the same values.
|
||||||
|
ReasonCode = (MqttClientPublishReasonCode)pubAckPacket.ReasonCode.Value,
|
||||||
|
ReasonString = pubAckPacket.Properties?.ReasonString,
|
||||||
|
UserProperties = pubAckPacket.Properties?.UserProperties
|
||||||
};
|
};
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,19 +210,24 @@ namespace MQTTnet.Formatter.V5
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The PUBCOMP is the last packet in QoS 2. So we use the results from that instead of PUBREC.
|
||||||
if (pubCompPacket.ReasonCode == MqttPubCompReasonCode.PacketIdentifierNotFound)
|
if (pubCompPacket.ReasonCode == MqttPubCompReasonCode.PacketIdentifierNotFound)
|
||||||
{
|
{
|
||||||
return new MqttClientPublishResult
|
return new MqttClientPublishResult
|
||||||
{
|
{
|
||||||
ReasonCode = MqttClientPublishReasonCode.UnspecifiedError
|
ReasonCode = MqttClientPublishReasonCode.UnspecifiedError,
|
||||||
|
ReasonString = pubCompPacket.Properties?.ReasonString,
|
||||||
|
UserProperties = pubCompPacket.Properties?.UserProperties
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = new MqttClientPublishResult
|
var result = new MqttClientPublishResult
|
||||||
{
|
{
|
||||||
ReasonCode = MqttClientPublishReasonCode.Success
|
ReasonCode = MqttClientPublishReasonCode.Success,
|
||||||
|
ReasonString = pubCompPacket.Properties?.ReasonString,
|
||||||
|
UserProperties = pubCompPacket.Properties?.UserProperties
|
||||||
};
|
};
|
||||||
|
|
||||||
if (pubRecPacket.ReasonCode.HasValue)
|
if (pubRecPacket.ReasonCode.HasValue)
|
||||||
{
|
{
|
||||||
// Both enums share the same values.
|
// Both enums share the same values.
|
||||||
|
|||||||
Reference in New Issue
Block a user