From 6b1a6c054ef9772487cbe2862fb8f64823e47881 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Sun, 10 Sep 2017 00:07:41 +0200 Subject: [PATCH] Even more performance optimizations --- MQTTnet.Core/Packets/MqttConnAckPacket.cs | 2 +- MQTTnet.Core/Packets/MqttConnectPacket.cs | 4 ++-- MQTTnet.Core/Packets/MqttPublishPacket.cs | 11 ++++++++--- MQTTnet.Core/Packets/MqttSubAckPacket.cs | 3 +-- MQTTnet.Core/Packets/MqttSubscribePacket.cs | 3 +-- MQTTnet.Core/Server/MqttClientSession.cs | 2 +- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/MQTTnet.Core/Packets/MqttConnAckPacket.cs b/MQTTnet.Core/Packets/MqttConnAckPacket.cs index d8a5fd9..e80a0af 100644 --- a/MQTTnet.Core/Packets/MqttConnAckPacket.cs +++ b/MQTTnet.Core/Packets/MqttConnAckPacket.cs @@ -10,7 +10,7 @@ namespace MQTTnet.Core.Packets public override string ToString() { - return $"{nameof(MqttConnAckPacket)}: [ConnectReturnCode={ConnectReturnCode}] [IsSessionPresent={IsSessionPresent}]"; + return nameof(MqttConnAckPacket) + ": [ConnectReturnCode=" + ConnectReturnCode + "] [IsSessionPresent=" + IsSessionPresent + "]"; } } } diff --git a/MQTTnet.Core/Packets/MqttConnectPacket.cs b/MQTTnet.Core/Packets/MqttConnectPacket.cs index 6db92a2..b1d6e3b 100644 --- a/MQTTnet.Core/Packets/MqttConnectPacket.cs +++ b/MQTTnet.Core/Packets/MqttConnectPacket.cs @@ -2,7 +2,7 @@ namespace MQTTnet.Core.Packets { - public sealed class MqttConnectPacket: MqttBasePacket + public sealed class MqttConnectPacket : MqttBasePacket { public MqttProtocolVersion ProtocolVersion { get; set; } @@ -20,7 +20,7 @@ namespace MQTTnet.Core.Packets public override string ToString() { - return $"{nameof(MqttConnectPacket)} [ClientId={ClientId}] [Username={Username}] [Password={Password}] [KeepAlivePeriod={KeepAlivePeriod}] [CleanSession={CleanSession}]"; + return nameof(MqttConnectPacket) + ": [ClientId=" + ClientId + "] [Username=" + Username + "] [Password=" + Password + "] [KeepAlivePeriod=" + KeepAlivePeriod + "] [CleanSession=" + CleanSession + "]"; } } } diff --git a/MQTTnet.Core/Packets/MqttPublishPacket.cs b/MQTTnet.Core/Packets/MqttPublishPacket.cs index 750a152..8476ccb 100644 --- a/MQTTnet.Core/Packets/MqttPublishPacket.cs +++ b/MQTTnet.Core/Packets/MqttPublishPacket.cs @@ -1,4 +1,4 @@ -using System.Text; +using System; using MQTTnet.Core.Protocol; namespace MQTTnet.Core.Packets @@ -17,8 +17,13 @@ namespace MQTTnet.Core.Packets public override string ToString() { - return - $"{nameof(MqttPublishPacket)} [Topic={Topic}] [Payload={Encoding.UTF8.GetString(Payload, 0, Payload.Length)}] [QoSLevel={QualityOfServiceLevel}] [Dup={Dup}] [Retain={Retain}] [PacketIdentifier={PacketIdentifier}]"; + return nameof(MqttPublishPacket) + + ": [Topic=" + Topic + "]" + + " [Payload=" + Convert.ToBase64String(Payload) + "]" + + " [QoSLevel=" + QualityOfServiceLevel + "]" + + " [Dup=" + Dup + "]" + + " [Retain=" + Retain + "]" + + " [PacketIdentifier=" + PacketIdentifier + "]"; } } } diff --git a/MQTTnet.Core/Packets/MqttSubAckPacket.cs b/MQTTnet.Core/Packets/MqttSubAckPacket.cs index f63d0ca..ee577ae 100644 --- a/MQTTnet.Core/Packets/MqttSubAckPacket.cs +++ b/MQTTnet.Core/Packets/MqttSubAckPacket.cs @@ -13,8 +13,7 @@ namespace MQTTnet.Core.Packets public override string ToString() { var subscribeReturnCodesText = string.Join(",", SubscribeReturnCodes.Select(f => f.ToString())); - return - $"{nameof(MqttSubAckPacket)} [PacketIdentifier={PacketIdentifier}] [SubscribeReturnCodes={subscribeReturnCodesText}]"; + return nameof(MqttSubAckPacket) + ": [PacketIdentifier=" + PacketIdentifier + "] [SubscribeReturnCodes=" + subscribeReturnCodesText + "]"; } } } diff --git a/MQTTnet.Core/Packets/MqttSubscribePacket.cs b/MQTTnet.Core/Packets/MqttSubscribePacket.cs index 007bde7..6f4877b 100644 --- a/MQTTnet.Core/Packets/MqttSubscribePacket.cs +++ b/MQTTnet.Core/Packets/MqttSubscribePacket.cs @@ -12,8 +12,7 @@ namespace MQTTnet.Core.Packets public override string ToString() { var topicFiltersText = string.Join(",", TopicFilters.Select(f => $"{f.Topic}@{f.QualityOfServiceLevel}")); - return - $"{nameof(MqttSubscribePacket)} [PacketIdentifier={PacketIdentifier}] [TopicFilters={topicFiltersText}]"; + return nameof(MqttSubscribePacket) + ": [PacketIdentifier=" + PacketIdentifier + "] [TopicFilters=" + topicFiltersText + "]"; } } } diff --git a/MQTTnet.Core/Server/MqttClientSession.cs b/MQTTnet.Core/Server/MqttClientSession.cs index 0dd8c85..9b811ec 100644 --- a/MQTTnet.Core/Server/MqttClientSession.cs +++ b/MQTTnet.Core/Server/MqttClientSession.cs @@ -76,7 +76,7 @@ namespace MQTTnet.Core.Server _cancellationTokenSource.Cancel(); Adapter = null; - MqttTrace.Information(nameof(MqttClientSession), $"Client '{_identifier}': Disconnected."); + MqttTrace.Information(nameof(MqttClientSession), "Client '{0}': Disconnected.", _identifier); } }