|
|
|
@ -14,6 +14,12 @@ namespace ZeroLevel.Services.Serialization
|
|
|
|
|
: IBinaryReader
|
|
|
|
|
{
|
|
|
|
|
private readonly Stream _stream;
|
|
|
|
|
private bool _reverseByteOrder = false;
|
|
|
|
|
|
|
|
|
|
public void ReverseByteOrder(bool use_reverse_byte_order)
|
|
|
|
|
{
|
|
|
|
|
_reverseByteOrder = use_reverse_byte_order;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MemoryStreamReader(byte[] data)
|
|
|
|
|
{
|
|
|
|
@ -136,6 +142,16 @@ namespace ZeroLevel.Services.Serialization
|
|
|
|
|
var readedCount = _stream.Read(buffer, 0, count);
|
|
|
|
|
if (count != readedCount)
|
|
|
|
|
throw new InvalidOperationException($"The stream returned less data ({count} bytes) than expected ({readedCount} bytes)");
|
|
|
|
|
if (_reverseByteOrder)
|
|
|
|
|
{
|
|
|
|
|
byte b;
|
|
|
|
|
for (int i = 0; i < (count >> 1); i++)
|
|
|
|
|
{
|
|
|
|
|
b = buffer[i];
|
|
|
|
|
buffer[i] = buffer[count - i];
|
|
|
|
|
buffer[count - i] = b;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|