mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 01:03:01 +08:00
26 lines
696 B
C#
26 lines
696 B
C#
using System;
|
|
using System.Text;
|
|
|
|
namespace MQTTnet
|
|
{
|
|
public static class MqttApplicationMessageExtensions
|
|
{
|
|
public static string ConvertPayloadToString(this MqttApplicationMessage applicationMessage)
|
|
{
|
|
if (applicationMessage == null) throw new ArgumentNullException(nameof(applicationMessage));
|
|
|
|
if (applicationMessage.Payload == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
if (applicationMessage.Payload.Length == 0)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
return Encoding.UTF8.GetString(applicationMessage.Payload, 0, applicationMessage.Payload.Length);
|
|
}
|
|
}
|
|
}
|