Kaynağa Gözat

dont use byte reader writer in critical paths

release/3.x.x
Eggers Jan 7 yıl önce
ebeveyn
işleme
323339b0b2
2 değiştirilmiş dosya ile 15 ekleme ve 8 silme
  1. +1
    -3
      MQTTnet.Core/Serializer/MqttPacketReader.cs
  2. +14
    -5
      MQTTnet.Core/Serializer/MqttPacketSerializer.cs

+ 1
- 3
MQTTnet.Core/Serializer/MqttPacketReader.cs Dosyayı Görüntüle

@@ -52,9 +52,7 @@ namespace MQTTnet.Core.Serializer
public static MqttPacketHeader ReadHeaderFromSource(Stream stream)
{
var fixedHeader = (byte)stream.ReadByte();
var byteReader = new ByteReader(fixedHeader);
byteReader.Read(4);
var controlPacketType = (MqttControlPacketType)byteReader.Read(4);
var controlPacketType = (MqttControlPacketType)(fixedHeader >> 4);
var bodyLength = ReadBodyLengthFromSource(stream);

return new MqttPacketHeader()


+ 14
- 5
MQTTnet.Core/Serializer/MqttPacketSerializer.cs Dosyayı Görüntüle

@@ -512,12 +512,21 @@ namespace MQTTnet.Core.Serializer
writer.Write(packet.Payload);
}

var fixedHeader = new ByteWriter();
fixedHeader.Write(packet.Retain);
fixedHeader.Write((byte)packet.QualityOfServiceLevel, 2);
fixedHeader.Write(packet.Dup);
byte fixedHeader = 0;

return MqttPacketWriter.BuildFixedHeader(MqttControlPacketType.Publish, fixedHeader.Value);
if (packet.Retain)
{
fixedHeader |= 0x01;
}

fixedHeader |= (byte)((byte)packet.QualityOfServiceLevel << 1);

if ( packet.Dup )
{
fixedHeader |= 0x08;
}
return MqttPacketWriter.BuildFixedHeader(MqttControlPacketType.Publish, fixedHeader);
}

private static byte Serialize(MqttPubAckPacket packet, MqttPacketWriter writer)


Yükleniyor…
İptal
Kaydet