You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/10/21 16:50:11 UTC
[19/20] ignite git commit: IGNITE-1651: Fixed C#.
IGNITE-1651: Fixed C#.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/5069a216
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/5069a216
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/5069a216
Branch: refs/heads/ignite-1651
Commit: 5069a216fedfef98f5b894be5298dc54e29a8485
Parents: 605a2b2
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Oct 21 17:08:36 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Oct 21 17:08:36 2015 +0300
----------------------------------------------------------------------
.../Impl/Portable/PortableBuilderImpl.cs | 3 ++
.../Impl/Portable/PortableReaderImpl.cs | 9 ++++--
.../Impl/Portable/PortableUserObject.cs | 6 ++--
.../Impl/Portable/PortableUtils.cs | 34 ++++++++++++++++++--
.../Impl/Portable/PortableWriterImpl.cs | 4 +--
.../Impl/Portable/PortablesImpl.cs | 1 +
6 files changed, 46 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/5069a216/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableBuilderImpl.cs
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableBuilderImpl.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableBuilderImpl.cs
index 037ac85..fd14d17 100644
--- a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableBuilderImpl.cs
+++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableBuilderImpl.cs
@@ -395,6 +395,8 @@ namespace Apache.Ignite.Core.Impl.Portable
}
else if (inHdr == PortableUtils.HdrFull)
{
+ PortableUtils.ValidateProtocolVersion(inStream);
+
byte inUsrFlag = inStream.ReadByte();
int inTypeId = inStream.ReadInt();
int inHash = inStream.ReadInt();
@@ -415,6 +417,7 @@ namespace Apache.Ignite.Core.Impl.Portable
{
// New object, write in full form.
outStream.WriteByte(PortableUtils.HdrFull);
+ outStream.WriteByte(PortableUtils.ProtoVer);
outStream.WriteByte(inUsrFlag);
outStream.WriteInt(inTypeId);
outStream.WriteInt(changeHash ? hash : inHash);
http://git-wip-us.apache.org/repos/asf/ignite/blob/5069a216/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableReaderImpl.cs
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableReaderImpl.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableReaderImpl.cs
index 176ca27..26847b8 100644
--- a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableReaderImpl.cs
+++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableReaderImpl.cs
@@ -668,7 +668,7 @@ namespace Apache.Ignite.Core.Impl.Portable
if (!doDetach)
return GetPortableUserObject(pos, pos, Stream.Array());
- Stream.Seek(pos + 10, SeekOrigin.Begin);
+ Stream.Seek(pos + PortableUtils.OffsetLen, SeekOrigin.Begin);
var len = Stream.ReadInt();
@@ -688,6 +688,9 @@ namespace Apache.Ignite.Core.Impl.Portable
[SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "hashCode")]
private T ReadFullObject<T>(int pos)
{
+ // Validate protocol version.
+ PortableUtils.ValidateProtocolVersion(Stream);
+
// Read header.
bool userType = Stream.ReadBool();
int typeId = Stream.ReadInt();
@@ -879,7 +882,7 @@ namespace Apache.Ignite.Core.Impl.Portable
{
// This method is expected to be called when stream pointer is set either before
// the field or on raw data offset.
- int start = _curPos + 18;
+ int start = _curPos + PortableUtils.FullHdrLen;
int end = _curPos + _curRawOffset;
int initial = Stream.Position;
@@ -1001,7 +1004,7 @@ namespace Apache.Ignite.Core.Impl.Portable
/// <param name="bytes">Bytes.</param>
private PortableUserObject GetPortableUserObject(int pos, int offs, byte[] bytes)
{
- Stream.Seek(pos + 2, SeekOrigin.Begin);
+ Stream.Seek(pos + PortableUtils.OffsetTypeId, SeekOrigin.Begin);
var id = Stream.ReadInt();
http://git-wip-us.apache.org/repos/asf/ignite/blob/5069a216/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUserObject.cs
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUserObject.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUserObject.cs
index 3ca8a5f..0d67533 100644
--- a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUserObject.cs
+++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUserObject.cs
@@ -186,7 +186,7 @@ namespace Apache.Ignite.Core.Impl.Portable
{
IPortableStream stream = new PortableHeapStream(_data);
- stream.Seek(_offset + 14, SeekOrigin.Begin);
+ stream.Seek(_offset + PortableUtils.OffsetRawOff, SeekOrigin.Begin);
int rawDataOffset = stream.ReadInt();
@@ -256,12 +256,12 @@ namespace Apache.Ignite.Core.Impl.Portable
// 4. Check if objects have the same raw data.
IPortableStream stream = new PortableHeapStream(_data);
- stream.Seek(_offset + 10, SeekOrigin.Begin);
+ stream.Seek(_offset + PortableUtils.OffsetLen, SeekOrigin.Begin);
int len = stream.ReadInt();
int rawOffset = stream.ReadInt();
IPortableStream thatStream = new PortableHeapStream(that._data);
- thatStream.Seek(_offset + 10, SeekOrigin.Begin);
+ thatStream.Seek(_offset + PortableUtils.OffsetLen, SeekOrigin.Begin);
int thatLen = thatStream.ReadInt();
int thatRawOffset = thatStream.ReadInt();
http://git-wip-us.apache.org/repos/asf/ignite/blob/5069a216/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUtils.cs
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUtils.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUtils.cs
index 3143e45..93c0c56 100644
--- a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUtils.cs
+++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUtils.cs
@@ -25,6 +25,7 @@ namespace Apache.Ignite.Core.Impl.Portable
using System.IO;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary;
+ using System.Security.Policy;
using System.Text;
using Apache.Ignite.Core.Impl.Common;
using Apache.Ignite.Core.Impl.Portable.IO;
@@ -46,9 +47,24 @@ namespace Apache.Ignite.Core.Impl.Portable
/** Header of object in fully serialized form. */
public const byte HdrFull = 103;
-
+
+ /** Protocol versnion. */
+ public const byte ProtoVer = 1;
+
/** Full header length. */
- public const int FullHdrLen = 18;
+ public const int FullHdrLen = 19;
+
+ /** Offset: hash code. */
+ public const int OffsetTypeId = 3;
+
+ /** Offset: hash code. */
+ public const int OffsetHashCode = 7;
+
+ /** Offset: length. */
+ public const int OffsetLen = 11;
+
+ /** Offset: raw data offset. */
+ public const int OffsetRawOff = 15;
/** Type: object. */
public const byte TypeObject = HdrFull;
@@ -1760,7 +1776,7 @@ namespace Apache.Ignite.Core.Impl.Portable
*/
public static IDictionary<int, int> ObjectFields(IPortableStream stream, int typeId, int rawDataOffset)
{
- int endPos = stream.Position + rawDataOffset - 18;
+ int endPos = stream.Position + rawDataOffset - FullHdrLen;
// First loop detects amount of fields in the object.
int retPos = stream.Position;
@@ -2006,6 +2022,18 @@ namespace Apache.Ignite.Core.Impl.Portable
return null;
}
+ /// <summary>
+ /// Validate protocol version.
+ /// </summary>
+ /// <param name="stream">Stream.</param>
+ public static void ValidateProtocolVersion(IPortableStream stream)
+ {
+ byte ver = stream.ReadByte();
+
+ if (ver != ProtoVer)
+ throw new PortableException("Unsupported protocol version: " + ver);
+ }
+
/**
* <summary>Convert date to Java ticks.</summary>
* <param name="date">Date</param>
http://git-wip-us.apache.org/repos/asf/ignite/blob/5069a216/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableWriterImpl.cs
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableWriterImpl.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableWriterImpl.cs
index c44a0a4..3cfc357 100644
--- a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableWriterImpl.cs
+++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortableWriterImpl.cs
@@ -865,7 +865,7 @@ namespace Apache.Ignite.Core.Impl.Portable
// Write header.
_stream.WriteByte(PortableUtils.HdrFull);
-
+ _stream.WriteByte(PortableUtils.ProtoVer);
_stream.WriteBool(desc.UserType);
_stream.WriteInt(desc.TypeId);
_stream.WriteInt(obj.GetHashCode());
@@ -895,7 +895,7 @@ namespace Apache.Ignite.Core.Impl.Portable
// Calculate and write length.
int retPos = _stream.Position;
- _stream.Seek(pos + 10, SeekOrigin.Begin);
+ _stream.Seek(pos + PortableUtils.OffsetLen, SeekOrigin.Begin);
int len = retPos - pos;
http://git-wip-us.apache.org/repos/asf/ignite/blob/5069a216/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortablesImpl.cs
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortablesImpl.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortablesImpl.cs
index 066f46b..d277c05 100644
--- a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortablesImpl.cs
+++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Impl/Portable/PortablesImpl.cs
@@ -180,6 +180,7 @@ namespace Apache.Ignite.Core.Impl.Portable
PortableHeapStream stream = new PortableHeapStream(18);
stream.WriteByte(PortableUtils.HdrFull);
+ stream.WriteByte(PortableUtils.ProtoVer);
stream.WriteBool(true);
stream.WriteInt(desc.TypeId);
stream.WriteInt(0); // Hash.