mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-27 08:42:37 +08:00
Avoid to check the type of propertyWriter parameter (#1600)
Refactor code of MqttBufferWriter
This commit is contained in:
@@ -66,7 +66,7 @@ namespace MQTTnet.Formatter
|
|||||||
public static int GetVariableByteIntegerSize(uint value)
|
public static int GetVariableByteIntegerSize(uint value)
|
||||||
{
|
{
|
||||||
// From RFC: Table 2.4 Size of Remaining Length field
|
// From RFC: Table 2.4 Size of Remaining Length field
|
||||||
|
|
||||||
// 0 (0x00) to 127 (0x7F)
|
// 0 (0x00) to 127 (0x7F)
|
||||||
if (value <= 127)
|
if (value <= 127)
|
||||||
{
|
{
|
||||||
@@ -103,18 +103,12 @@ namespace MQTTnet.Formatter
|
|||||||
|
|
||||||
public void Write(MqttBufferWriter propertyWriter)
|
public void Write(MqttBufferWriter propertyWriter)
|
||||||
{
|
{
|
||||||
if (propertyWriter is MqttBufferWriter writer)
|
|
||||||
{
|
|
||||||
WriteBinary(writer._buffer, 0, writer.Length);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (propertyWriter == null)
|
if (propertyWriter == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(propertyWriter));
|
throw new ArgumentNullException(nameof(propertyWriter));
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new InvalidOperationException($"{nameof(propertyWriter)} must be of type {nameof(MqttBufferWriter)}");
|
WriteBinary(propertyWriter._buffer, 0, propertyWriter.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteBinary(byte[] buffer, int offset, int count)
|
public void WriteBinary(byte[] buffer, int offset, int count)
|
||||||
|
|||||||
Reference in New Issue
Block a user