ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [08/22] ignite git commit: IGNITE-1770: Reader refactoring (4): "readHeaderIfNeeded"
Date Mon, 26 Oct 2015 12:57:51 GMT
IGNITE-1770: Reader refactoring (4): "readHeaderIfNeeded"


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/dd8dbf89
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/dd8dbf89
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/dd8dbf89

Branch: refs/heads/ignite-1770
Commit: dd8dbf891616567805937a8d549293e2fb62c8da
Parents: 0489b14
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Mon Oct 26 12:40:34 2015 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Mon Oct 26 12:40:34 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/PortableReaderExImpl.java | 35 ++++++++++++--------
 1 file changed, 21 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/dd8dbf89/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
index 08d0594..efa1716 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
@@ -192,27 +192,32 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
     /**
      * Preloads typeId from the input array.
      */
-    private void readHeaderIfNeeded(boolean skipObjByte) {
+    private void parseHeaderIfNeeded(boolean skipObjByte) {
         if (hdrParsed)
             return;
 
-        int pos = rawOff;
+        int retPos = in.position();
+        int retRawOff = rawOff;
 
-        if (!skipObjByte)
-            // skip obj type byte
-            rawOff++;
+        in.position(start);
 
-        // Validate protocol version.
-        PortableUtils.checkProtocolVersion(doReadByte(true));
+        byte hdr = in.readByte();
 
-        // Skip flags
-        rawOff += 2;
+        if (hdr != GridPortableMarshaller.OBJ)
+            throw new PortableException("Invalid header [pos=" + retPos + "expected=" + GridPortableMarshaller.OBJ
+
+                ", actual=" + hdr + ']');
 
-        typeId = doReadInt(true);
+        PortableUtils.checkProtocolVersion(in.readByte());
+
+        in.position(in.position() + 2); // Skip flags.
+
+        typeId = in.readInt();
 
         if (typeId == UNREGISTERED_TYPE_ID) {
             // Skip to the class name position.
-            rawOff += (GridPortableMarshaller.DFLT_HDR_LEN - 8);
+            in.position(in.position() + GridPortableMarshaller.DFLT_HDR_LEN - 8);
+
+            rawOff = in.position();
 
             int off = rawOff;
 
@@ -230,7 +235,9 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
         else
             hdrLen = DFLT_HDR_LEN;
 
-        in.position(rawOff = pos);
+        // Restore state.
+        in.position(retPos);
+        rawOff = retRawOff;
 
         hdrParsed = true;
     }
@@ -1820,7 +1827,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
                 break;
 
             case OBJ:
-                readHeaderIfNeeded(true);
+                parseHeaderIfNeeded(true);
 
                 assert typeId != UNREGISTERED_TYPE_ID;
 
@@ -2675,7 +2682,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
     private int fieldId(String name) {
         assert name != null;
 
-        readHeaderIfNeeded(false);
+        parseHeaderIfNeeded(false);
 
         assert typeId != UNREGISTERED_TYPE_ID;
 


Mime
View raw message