IGNITE-2625 .NET: Fixed field offset calculation in BinaryReader.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/3dce33f5 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/3dce33f5 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/3dce33f5 Branch: refs/heads/ignite-2407 Commit: 3dce33f5a007aa15adfc1e79b1ac96e86683e9fb Parents: 6c4bad1 Author: Pavel Tupitsyn <[email protected]> Authored: Fri Feb 12 16:09:00 2016 +0300 Committer: vozerov-gridgain <[email protected]> Committed: Fri Feb 12 16:09:00 2016 +0300 ---------------------------------------------------------------------- .../Binary/BinaryStructureTest.cs | 38 ++++++++++++++------ .../Impl/Binary/BinaryReader.cs | 2 +- 2 files changed, 28 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/3dce33f5/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryStructureTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryStructureTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryStructureTest.cs index 78ee8c0..1ab81c5 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryStructureTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryStructureTest.cs @@ -20,9 +20,11 @@ namespace Apache.Ignite.Core.Tests.Binary using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; + using System.IO; using Apache.Ignite.Core.Binary; using Apache.Ignite.Core.Impl; using Apache.Ignite.Core.Impl.Binary; + using Apache.Ignite.Core.Impl.Binary.IO; using NUnit.Framework; /// <summary> @@ -66,15 +68,29 @@ namespace Apache.Ignite.Core.Tests.Binary Marshaller marsh = new Marshaller(cfg); // 3. Marshal all data and ensure deserialized object is fine. - foreach (BranchedType obj in objs) + // Use single stream to test object offsets + using (var stream = new BinaryHeapStream(128)) { - Console.WriteLine(">>> Write object [mode=" + obj.mode + ']'); + var writer = marsh.StartMarshal(stream); - byte[] data = marsh.Marshal(obj); + foreach (var obj in objs) + { + Console.WriteLine(">>> Write object [mode=" + obj.mode + ']'); - BranchedType other = marsh.Unmarshal<BranchedType>(data); + writer.WriteObject(obj); - Assert.IsTrue(obj.Equals(other)); + } + + stream.Seek(0, SeekOrigin.Begin); + + var reader = marsh.StartUnmarshal(stream); + + foreach (var obj in objs) + { + var other = reader.ReadObject<BranchedType>(); + + Assert.IsTrue(obj.Equals(other)); + } } Console.WriteLine(); @@ -206,30 +222,30 @@ namespace Apache.Ignite.Core.Tests.Binary break; case 2: - f2 = reader.ReadInt("f2"); - f3 = reader.ReadInt("f3"); f4 = reader.ReadInt("f4"); + f3 = reader.ReadInt("f3"); + f2 = reader.ReadInt("f2"); break; case 3: + f5 = reader.ReadInt("f5"); f2 = reader.ReadInt("f2"); f3 = reader.ReadInt("f3"); - f5 = reader.ReadInt("f5"); break; case 4: - f2 = reader.ReadInt("f2"); - f3 = reader.ReadInt("f3"); f5 = reader.ReadInt("f5"); f6 = reader.ReadInt("f6"); + f2 = reader.ReadInt("f2"); + f3 = reader.ReadInt("f3"); break; case 5: - f2 = reader.ReadInt("f2"); f3 = reader.ReadInt("f3"); + f2 = reader.ReadInt("f2"); f7 = reader.ReadInt("f7"); break; http://git-wip-us.apache.org/repos/asf/ignite/blob/3dce33f5/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs index 1c5c719..16aae93 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReader.cs @@ -938,7 +938,7 @@ namespace Apache.Ignite.Core.Impl.Binary if (!_curSchemaMap.TryGetValue(fieldId, out pos)) return false; - Stream.Seek(pos, SeekOrigin.Begin); + Stream.Seek(pos + _curPos, SeekOrigin.Begin); } return true;
