mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 11:45:43 +08:00
Improve payload handling and allocation.
This commit is contained in:
@@ -79,24 +79,21 @@ namespace MQTTnet.Formatter
|
||||
else
|
||||
{
|
||||
WriteWithLengthPrefix(Encoding.UTF8.GetBytes(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteWithLengthPrefix(byte[] value)
|
||||
{
|
||||
if (value == null) throw new ArgumentNullException(nameof(value));
|
||||
|
||||
EnsureAdditionalCapacity(value.Length + 2);
|
||||
|
||||
if (value.Length == 0)
|
||||
if (value == null || value.Length == 0)
|
||||
{
|
||||
Write(ZeroTwoByteIntegerArray);
|
||||
Write(ZeroTwoByteIntegerArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnsureAdditionalCapacity(value.Length + 2);
|
||||
Write((ushort)value.Length);
|
||||
Write(value, 0, value.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(byte @byte)
|
||||
@@ -131,7 +128,7 @@ namespace MQTTnet.Formatter
|
||||
Array.Copy(buffer, offset, _buffer, _offset, count);
|
||||
IncreasePosition(count);
|
||||
}
|
||||
|
||||
|
||||
public void Write(MqttPacketWriter propertyWriter)
|
||||
{
|
||||
if (propertyWriter == null) throw new ArgumentNullException(nameof(propertyWriter));
|
||||
|
||||
Reference in New Issue
Block a user