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.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using DOM.Services;
using Xunit; using Xunit;
using ZeroLevel.DocumentObjectModel; using ZeroLevel.DocumentObjectModel;
using ZeroLevel.Network; using ZeroLevel.Network;
using ZeroLevel.Services.Serialization; using ZeroLevel.Services.Serialization;
using ZeroLevel.UnitTests.Models; using ZeroLevel.UnitTests.Models;
namespace ZeroLevel.UnitTests namespace ZeroLevel.Serialization
{ {
public class SerializationTests public class SerializationTests
{ {
@ -346,5 +345,20 @@ namespace ZeroLevel.UnitTests
MakePrimitiveTest<Document>(CompositeInstanceFactory.MakeDocument(), comparator); 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); var readedCount = _stream.Read(buffer, 0, count);
if (count != readedCount) if (count != readedCount)
throw new InvalidOperationException($"The stream returned less data ({count} bytes) than expected ({readedCount} bytes)"); throw new InvalidOperationException($"The stream returned less data ({count} bytes) than expected ({readedCount} bytes)");
if (_reverseByteOrder) if (_reverseByteOrder && count > 1)
{ {
byte b; byte b;
for (int i = 0; i < (count >> 1); i++) for (int i = 0; i < (count >> 1); i++)
{ {
b = buffer[i]; b = buffer[i];
buffer[i] = buffer[count - i]; buffer[i] = buffer[count - i - 1];
buffer[count - i] = b; buffer[count - i - 1] = b;
} }
} }
return buffer; return buffer;

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

Loading…
Cancel
Save

Powered by TurnKey Linux.