Patch reverse order byte

pull/1/head
unknown 6 years ago
parent 8e59fa2755
commit a81b8311b6

@ -2,14 +2,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using DOM.Services;
using Xunit;
using ZeroLevel.DocumentObjectModel;
using ZeroLevel.Network;
using ZeroLevel.Services.Serialization;
using ZeroLevel.UnitTests.Models;
namespace ZeroLevel.UnitTests
namespace ZeroLevel.Serialization
{
public class SerializationTests
{
@ -346,5 +345,20 @@ namespace ZeroLevel.UnitTests
MakePrimitiveTest<Document>(CompositeInstanceFactory.MakeDocument(), comparator);
}
[Fact]
public void ReverseByteOrderTest()
{
var data = new byte[4] { 0, 0, 8, 1 };
using (var reader = new MemoryStreamReader(data))
{
Assert.Equal(17301504, reader.ReadInt32());
}
using (var reader = new MemoryStreamReader(data))
{
reader.ReverseByteOrder(true);
Assert.Equal(2049, reader.ReadInt32());
}
}
}
}

@ -142,14 +142,14 @@ 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)
if (_reverseByteOrder && count > 1)
{
byte b;
for (int i = 0; i < (count >> 1); i++)
{
b = buffer[i];
buffer[i] = buffer[count - i];
buffer[count - i] = b;
buffer[i] = buffer[count - i - 1];
buffer[count - i - 1] = b;
}
}
return buffer;

@ -5,15 +5,15 @@
<Description>Infrastructure layer library</Description>
<Authors>ogoun</Authors>
<Company>ogoun</Company>
<AssemblyVersion>2.0.3.0</AssemblyVersion>
<PackageReleaseNotes>Update serialization</PackageReleaseNotes>
<AssemblyVersion>2.0.4.0</AssemblyVersion>
<PackageReleaseNotes>Patch</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/ogoun/Zero/wiki</PackageProjectUrl>
<Copyright>Copyright Ogoun 2019</Copyright>
<PackageLicenseUrl>https://opensource.org/licenses/MIT</PackageLicenseUrl>
<PackageIconUrl>https://raw.githubusercontent.com/ogoun/Zero/master/zero.png</PackageIconUrl>
<RepositoryUrl>https://github.com/ogoun/Zero</RepositoryUrl>
<RepositoryType>GitHub</RepositoryType>
<Version>2.0.3</Version>
<Version>2.0.4</Version>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

Loading…
Cancel
Save

Powered by TurnKey Linux.