|
@@ -89,6 +89,8 @@ namespace MQTTnet.Serializer |
|
|
|
|
|
|
|
|
public void Write(byte[] array, int offset, int count) |
|
|
public void Write(byte[] array, int offset, int count) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (array == null) throw new ArgumentNullException(nameof(array)); |
|
|
|
|
|
|
|
|
EnsureAdditionalCapacity(count); |
|
|
EnsureAdditionalCapacity(count); |
|
|
|
|
|
|
|
|
Array.Copy(array, offset, _buffer, _position, count); |
|
|
Array.Copy(array, offset, _buffer, _position, count); |
|
@@ -135,17 +137,18 @@ namespace MQTTnet.Serializer |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
EnsureCapacity(additionalCapacity - freeSpace); |
|
|
|
|
|
|
|
|
EnsureCapacity(_buffer.Length + additionalCapacity - freeSpace); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void EnsureCapacity(int capacity) |
|
|
private void EnsureCapacity(int capacity) |
|
|
{ |
|
|
{ |
|
|
if (_buffer.Length >= capacity) |
|
|
|
|
|
|
|
|
var newBufferLength = _buffer.Length; |
|
|
|
|
|
|
|
|
|
|
|
if (newBufferLength >= capacity) |
|
|
{ |
|
|
{ |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var newBufferLength = _buffer.Length; |
|
|
|
|
|
|
|
|
|
|
|
while (newBufferLength < capacity) |
|
|
while (newBufferLength < capacity) |
|
|
{ |
|
|
{ |
|
|
newBufferLength *= 2; |
|
|
newBufferLength *= 2; |
|
@@ -157,6 +160,7 @@ namespace MQTTnet.Serializer |
|
|
private void IncreasePostition(int length) |
|
|
private void IncreasePostition(int length) |
|
|
{ |
|
|
{ |
|
|
_position += length; |
|
|
_position += length; |
|
|
|
|
|
|
|
|
if (_position > Length) |
|
|
if (_position > Length) |
|
|
{ |
|
|
{ |
|
|
Length = _position; |
|
|
Length = _position; |
|
|