http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishRequest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishRequest.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishRequest.java
index f814c5d..adc6df9 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishRequest.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishRequest.java
@@ -382,138 +382,96 @@ public class GridDhtTxFinishRequest<K, V> extends 
GridDistributedTxFinishRequest
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        writer.setBuffer(buf);
 
         if (!super.writeTo(buf))
             return false;
 
-        if (!commState.typeWritten) {
-            if (!commState.putByte(null, directType()))
+        if (!typeWritten) {
+            if (!writer.writeByte(null, directType()))
                 return false;
 
-            commState.typeWritten = true;
+            typeWritten = true;
         }
 
-        switch (commState.idx) {
+        switch (state) {
             case 21:
-                if (!commState.putEnum("isolation", isolation))
+                if (!writer.writeEnum("isolation", isolation))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 22:
-                if (!commState.putGridUuid("miniId", miniId))
+                if (!writer.writeIgniteUuid("miniId", miniId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 23:
-                if (!commState.putUuid("nearNodeId", nearNodeId))
+                if (!writer.writeUuid("nearNodeId", nearNodeId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 24:
-                if (!commState.putLongList("nearTtls", nearTtls))
+                if (!writer.writeMessage("nearTtls", nearTtls != null ? 
nearTtls.clone() : null))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 25:
-                if (nearWritesBytes != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, nearWritesBytes.size()))
-                            return false;
-
-                        commState.it = nearWritesBytes.iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        if (!commState.putByteArray(null, 
(byte[])commState.cur))
-                            return false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
+                if (!writer.writeCollection("nearWritesBytes", 
nearWritesBytes, byte[].class))
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 26:
-                if (!commState.putBoolean("onePhaseCommit", onePhaseCommit))
+                if (!writer.writeBoolean("onePhaseCommit", onePhaseCommit))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 27:
-                if (pendingVers != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, pendingVers.size()))
-                            return false;
-
-                        commState.it = pendingVers.iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        if (!commState.putCacheVersion(null, 
(GridCacheVersion)commState.cur))
-                            return false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
+                if (!writer.writeCollection("pendingVers", pendingVers, 
GridCacheVersion.class))
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 28:
-                if (!commState.putBoolean("sysInvalidate", sysInvalidate))
+                if (!writer.writeUuid("subjId", subjId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 29:
-                if (!commState.putLong("topVer", topVer))
+                if (!writer.writeBoolean("sysInvalidate", sysInvalidate))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 30:
-                if (!commState.putLongList("ttls", ttls))
+                if (!writer.writeInt("taskNameHash", taskNameHash))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 31:
-                if (!commState.putCacheVersion("writeVer", writeVer))
+                if (!writer.writeLong("topVer", topVer))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 32:
-                if (!commState.putUuid("subjId", subjId))
+                if (!writer.writeMessage("ttls", ttls != null ? ttls.clone() : 
null))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 33:
-                if (!commState.putInt("taskNameHash", taskNameHash))
+                if (!writer.writeMessage("writeVer", writeVer != null ? 
writeVer.clone() : null))
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 
@@ -523,161 +481,115 @@ public class GridDhtTxFinishRequest<K, V> extends 
GridDistributedTxFinishRequest
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean readFrom(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        reader.setBuffer(buf);
 
         if (!super.readFrom(buf))
             return false;
 
-        switch (commState.idx) {
+        switch (state) {
             case 21:
-                byte isolation0 = commState.getByte("isolation");
+                isolation = reader.readEnum("isolation", 
IgniteTxIsolation.class);
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                isolation = IgniteTxIsolation.fromOrdinal(isolation0);
-
-                commState.idx++;
+                state++;
 
             case 22:
-                miniId = commState.getGridUuid("miniId");
+                miniId = reader.readIgniteUuid("miniId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 23:
-                nearNodeId = commState.getUuid("nearNodeId");
+                nearNodeId = reader.readUuid("nearNodeId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 24:
-                nearTtls = commState.getLongList("nearTtls");
+                nearTtls = reader.readMessage("nearTtls");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 25:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
+                nearWritesBytes = reader.readCollection("nearWritesBytes", 
byte[].class);
 
-                if (commState.readSize >= 0) {
-                    if (nearWritesBytes == null)
-                        nearWritesBytes = new ArrayList<>(commState.readSize);
-
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        byte[] _val = commState.getByteArray(null);
-
-                        if (!commState.lastRead())
-                            return false;
-
-                        nearWritesBytes.add((byte[])_val);
-
-                        commState.readItems++;
-                    }
-                }
-
-                commState.readSize = -1;
-                commState.readItems = 0;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 26:
-                onePhaseCommit = commState.getBoolean("onePhaseCommit");
+                onePhaseCommit = reader.readBoolean("onePhaseCommit");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 27:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
+                pendingVers = reader.readCollection("pendingVers", 
GridCacheVersion.class);
 
-                if (commState.readSize >= 0) {
-                    if (pendingVers == null)
-                        pendingVers = new ArrayList<>(commState.readSize);
-
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        GridCacheVersion _val = 
commState.getCacheVersion(null);
-
-                        if (!commState.lastRead())
-                            return false;
-
-                        pendingVers.add((GridCacheVersion)_val);
-
-                        commState.readItems++;
-                    }
-                }
-
-                commState.readSize = -1;
-                commState.readItems = 0;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 28:
-                sysInvalidate = commState.getBoolean("sysInvalidate");
+                subjId = reader.readUuid("subjId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 29:
-                topVer = commState.getLong("topVer");
+                sysInvalidate = reader.readBoolean("sysInvalidate");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 30:
-                ttls = commState.getLongList("ttls");
+                taskNameHash = reader.readInt("taskNameHash");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 31:
-                writeVer = commState.getCacheVersion("writeVer");
+                topVer = reader.readLong("topVer");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 32:
-                subjId = commState.getUuid("subjId");
+                ttls = reader.readMessage("ttls");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 33:
-                taskNameHash = commState.getInt("taskNameHash");
+                writeVer = reader.readMessage("writeVer");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishResponse.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishResponse.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishResponse.java
index 590f06a..c8b2046 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishResponse.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishResponse.java
@@ -90,24 +90,24 @@ public class GridDhtTxFinishResponse<K, V> extends 
GridDistributedTxFinishRespon
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        writer.setBuffer(buf);
 
         if (!super.writeTo(buf))
             return false;
 
-        if (!commState.typeWritten) {
-            if (!commState.putByte(null, directType()))
+        if (!typeWritten) {
+            if (!writer.writeByte(null, directType()))
                 return false;
 
-            commState.typeWritten = true;
+            typeWritten = true;
         }
 
-        switch (commState.idx) {
+        switch (state) {
             case 5:
-                if (!commState.putGridUuid("miniId", miniId))
+                if (!writer.writeIgniteUuid("miniId", miniId))
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 
@@ -117,19 +117,19 @@ public class GridDhtTxFinishResponse<K, V> extends 
GridDistributedTxFinishRespon
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean readFrom(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        reader.setBuffer(buf);
 
         if (!super.readFrom(buf))
             return false;
 
-        switch (commState.idx) {
+        switch (state) {
             case 5:
-                miniId = commState.getGridUuid("miniId");
+                miniId = reader.readIgniteUuid("miniId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareRequest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareRequest.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareRequest.java
index d7af780..a57827c 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareRequest.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareRequest.java
@@ -346,111 +346,90 @@ public class GridDhtTxPrepareRequest<K, V> extends 
GridDistributedTxPrepareReque
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        writer.setBuffer(buf);
 
         if (!super.writeTo(buf))
             return false;
 
-        if (!commState.typeWritten) {
-            if (!commState.putByte(null, directType()))
+        if (!typeWritten) {
+            if (!writer.writeByte(null, directType()))
                 return false;
 
-            commState.typeWritten = true;
+            typeWritten = true;
         }
 
-        switch (commState.idx) {
+        switch (state) {
             case 22:
-                if (!commState.putGridUuid("futId", futId))
+                if (!writer.writeIgniteUuid("futId", futId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 23:
-                if (!commState.putBitSet("invalidateNearEntries", 
invalidateNearEntries))
+                if (!writer.writeBitSet("invalidateNearEntries", 
invalidateNearEntries))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 24:
-                if (!commState.putBoolean("last", last))
+                if (!writer.writeBoolean("last", last))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 25:
-                if (!commState.putGridUuid("miniId", miniId))
+                if (!writer.writeIgniteUuid("miniId", miniId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 26:
-                if (!commState.putUuid("nearNodeId", nearNodeId))
+                if (!writer.writeUuid("nearNodeId", nearNodeId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 27:
-                if (nearWritesBytes != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, nearWritesBytes.size()))
-                            return false;
-
-                        commState.it = nearWritesBytes.iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        if (!commState.putByteArray(null, 
(byte[])commState.cur))
-                            return false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
+                if (!writer.writeCollection("nearWritesBytes", 
nearWritesBytes, byte[].class))
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 28:
-                if (!commState.putCacheVersion("nearXidVer", nearXidVer))
+                if (!writer.writeMessage("nearXidVer", nearXidVer != null ? 
nearXidVer.clone() : null))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 29:
-                if (!commState.putByteArray("ownedBytes", ownedBytes))
+                if (!writer.writeByteArray("ownedBytes", ownedBytes))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 30:
-                if (!commState.putLong("topVer", topVer))
+                if (!writer.writeBitSet("preloadKeys", preloadKeys))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 31:
-                if (!commState.putUuid("subjId", subjId))
+                if (!writer.writeUuid("subjId", subjId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 32:
-                if (!commState.putInt("taskNameHash", taskNameHash))
+                if (!writer.writeInt("taskNameHash", taskNameHash))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 33:
-                if (!commState.putBitSet("preloadKeys", preloadKeys))
+                if (!writer.writeLong("topVer", topVer))
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 
@@ -460,129 +439,107 @@ public class GridDhtTxPrepareRequest<K, V> extends 
GridDistributedTxPrepareReque
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean readFrom(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        reader.setBuffer(buf);
 
         if (!super.readFrom(buf))
             return false;
 
-        switch (commState.idx) {
+        switch (state) {
             case 22:
-                futId = commState.getGridUuid("futId");
+                futId = reader.readIgniteUuid("futId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 23:
-                invalidateNearEntries = 
commState.getBitSet("invalidateNearEntries");
+                invalidateNearEntries = 
reader.readBitSet("invalidateNearEntries");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 24:
-                last = commState.getBoolean("last");
+                last = reader.readBoolean("last");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 25:
-                miniId = commState.getGridUuid("miniId");
+                miniId = reader.readIgniteUuid("miniId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 26:
-                nearNodeId = commState.getUuid("nearNodeId");
+                nearNodeId = reader.readUuid("nearNodeId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 27:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
+                nearWritesBytes = reader.readCollection("nearWritesBytes", 
byte[].class);
 
-                if (commState.readSize >= 0) {
-                    if (nearWritesBytes == null)
-                        nearWritesBytes = new ArrayList<>(commState.readSize);
-
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        byte[] _val = commState.getByteArray(null);
-
-                        if (!commState.lastRead())
-                            return false;
-
-                        nearWritesBytes.add((byte[])_val);
-
-                        commState.readItems++;
-                    }
-                }
-
-                commState.readSize = -1;
-                commState.readItems = 0;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 28:
-                nearXidVer = commState.getCacheVersion("nearXidVer");
+                nearXidVer = reader.readMessage("nearXidVer");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 29:
-                ownedBytes = commState.getByteArray("ownedBytes");
+                ownedBytes = reader.readByteArray("ownedBytes");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 30:
-                topVer = commState.getLong("topVer");
+                preloadKeys = reader.readBitSet("preloadKeys");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 31:
-                subjId = commState.getUuid("subjId");
+                subjId = reader.readUuid("subjId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 32:
-                taskNameHash = commState.getInt("taskNameHash");
+                taskNameHash = reader.readInt("taskNameHash");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 33:
-                preloadKeys = commState.getBitSet("preloadKeys");
+                topVer = reader.readLong("topVer");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareResponse.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareResponse.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareResponse.java
index fd6c0b4..3196399 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareResponse.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareResponse.java
@@ -232,111 +232,48 @@ public class GridDhtTxPrepareResponse<K, V> extends 
GridDistributedTxPrepareResp
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        writer.setBuffer(buf);
 
         if (!super.writeTo(buf))
             return false;
 
-        if (!commState.typeWritten) {
-            if (!commState.putByte(null, directType()))
+        if (!typeWritten) {
+            if (!writer.writeByte(null, directType()))
                 return false;
 
-            commState.typeWritten = true;
+            typeWritten = true;
         }
 
-        switch (commState.idx) {
+        switch (state) {
             case 10:
-                if (!commState.putGridUuid("futId", futId))
+                if (!writer.writeIgniteUuid("futId", futId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 11:
-                if (invalidParts != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, invalidParts.size()))
-                            return false;
-
-                        commState.it = invalidParts.iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        if (!commState.putInt(null, (int)commState.cur))
-                            return false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
+                if (!writer.writeCollection("invalidParts", invalidParts, 
int.class))
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 12:
-                if (!commState.putGridUuid("miniId", miniId))
+                if (!writer.writeIgniteUuid("miniId", miniId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 13:
-                if (nearEvictedBytes != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, nearEvictedBytes.size()))
-                            return false;
-
-                        commState.it = nearEvictedBytes.iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        if (!commState.putByteArray(null, 
(byte[])commState.cur))
-                            return false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
+                if (!writer.writeCollection("nearEvictedBytes", 
nearEvictedBytes, byte[].class))
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 14:
-                if (preloadEntriesBytes != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, 
preloadEntriesBytes.size()))
-                            return false;
-
-                        commState.it = preloadEntriesBytes.iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        if (!commState.putByteArray(null, 
(byte[])commState.cur))
-                            return false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
+                if (!writer.writeCollection("preloadEntriesBytes", 
preloadEntriesBytes, byte[].class))
+                    return false;
 
-                commState.idx++;
+                state++;
 
         }
 
@@ -346,117 +283,51 @@ public class GridDhtTxPrepareResponse<K, V> extends 
GridDistributedTxPrepareResp
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean readFrom(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        reader.setBuffer(buf);
 
         if (!super.readFrom(buf))
             return false;
 
-        switch (commState.idx) {
+        switch (state) {
             case 10:
-                futId = commState.getGridUuid("futId");
+                futId = reader.readIgniteUuid("futId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 11:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
-
-                if (commState.readSize >= 0) {
-                    if (invalidParts == null)
-                        invalidParts = new ArrayList<>(commState.readSize);
+                invalidParts = reader.readCollection("invalidParts", 
int.class);
 
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        int _val = commState.getInt(null);
-
-                        if (!commState.lastRead())
-                            return false;
-
-                        invalidParts.add((Integer)_val);
-
-                        commState.readItems++;
-                    }
-                }
-
-                commState.readSize = -1;
-                commState.readItems = 0;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 12:
-                miniId = commState.getGridUuid("miniId");
+                miniId = reader.readIgniteUuid("miniId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 13:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
-
-                if (commState.readSize >= 0) {
-                    if (nearEvictedBytes == null)
-                        nearEvictedBytes = new ArrayList<>(commState.readSize);
-
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        byte[] _val = commState.getByteArray(null);
-
-                        if (!commState.lastRead())
-                            return false;
-
-                        nearEvictedBytes.add((byte[])_val);
+                nearEvictedBytes = reader.readCollection("nearEvictedBytes", 
byte[].class);
 
-                        commState.readItems++;
-                    }
-                }
-
-                commState.readSize = -1;
-                commState.readItems = 0;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 14:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
-
-                if (commState.readSize >= 0) {
-                    if (preloadEntriesBytes == null)
-                        preloadEntriesBytes = new 
ArrayList<>(commState.readSize);
-
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        byte[] _val = commState.getByteArray(null);
+                preloadEntriesBytes = 
reader.readCollection("preloadEntriesBytes", byte[].class);
 
-                        if (!commState.lastRead())
-                            return false;
-
-                        preloadEntriesBytes.add((byte[])_val);
-
-                        commState.readItems++;
-                    }
-                }
-
-                commState.readSize = -1;
-                commState.readItems = 0;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java
index 19a9dce..7c381d6 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java
@@ -126,45 +126,24 @@ public class GridDhtUnlockRequest<K, V> extends 
GridDistributedUnlockRequest<K,
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        writer.setBuffer(buf);
 
         if (!super.writeTo(buf))
             return false;
 
-        if (!commState.typeWritten) {
-            if (!commState.putByte(null, directType()))
+        if (!typeWritten) {
+            if (!writer.writeByte(null, directType()))
                 return false;
 
-            commState.typeWritten = true;
+            typeWritten = true;
         }
 
-        switch (commState.idx) {
+        switch (state) {
             case 9:
-                if (nearKeyBytes != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, nearKeyBytes.size()))
-                            return false;
+                if (!writer.writeCollection("nearKeyBytes", nearKeyBytes, 
byte[].class))
+                    return false;
 
-                        commState.it = nearKeyBytes.iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        if (!commState.putByteArray(null, 
(byte[])commState.cur))
-                            return false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
-
-                commState.idx++;
+                state++;
 
         }
 
@@ -174,41 +153,19 @@ public class GridDhtUnlockRequest<K, V> extends 
GridDistributedUnlockRequest<K,
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean readFrom(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        reader.setBuffer(buf);
 
         if (!super.readFrom(buf))
             return false;
 
-        switch (commState.idx) {
+        switch (state) {
             case 9:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
-
-                if (commState.readSize >= 0) {
-                    if (nearKeyBytes == null)
-                        nearKeyBytes = new ArrayList<>(commState.readSize);
-
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        byte[] _val = commState.getByteArray(null);
-
-                        if (!commState.lastRead())
-                            return false;
-
-                        nearKeyBytes.add((byte[])_val);
-
-                        commState.readItems++;
-                    }
-                }
+                nearKeyBytes = reader.readCollection("nearKeyBytes", 
byte[].class);
 
-                commState.readSize = -1;
-                commState.readItems = 0;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicDeferredUpdateResponse.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicDeferredUpdateResponse.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicDeferredUpdateResponse.java
index 07ba0bb..955bb4f 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicDeferredUpdateResponse.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicDeferredUpdateResponse.java
@@ -94,45 +94,24 @@ public class GridDhtAtomicDeferredUpdateResponse<K, V> 
extends GridCacheMessage<
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        writer.setBuffer(buf);
 
         if (!super.writeTo(buf))
             return false;
 
-        if (!commState.typeWritten) {
-            if (!commState.putByte(null, directType()))
+        if (!typeWritten) {
+            if (!writer.writeByte(null, directType()))
                 return false;
 
-            commState.typeWritten = true;
+            typeWritten = true;
         }
 
-        switch (commState.idx) {
+        switch (state) {
             case 3:
-                if (futVers != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, futVers.size()))
-                            return false;
+                if (!writer.writeCollection("futVers", futVers, 
GridCacheVersion.class))
+                    return false;
 
-                        commState.it = futVers.iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        if (!commState.putCacheVersion(null, 
(GridCacheVersion)commState.cur))
-                            return false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
-
-                commState.idx++;
+                state++;
 
         }
 
@@ -142,41 +121,19 @@ public class GridDhtAtomicDeferredUpdateResponse<K, V> 
extends GridCacheMessage<
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean readFrom(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        reader.setBuffer(buf);
 
         if (!super.readFrom(buf))
             return false;
 
-        switch (commState.idx) {
+        switch (state) {
             case 3:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
-
-                if (commState.readSize >= 0) {
-                    if (futVers == null)
-                        futVers = new ArrayList<>(commState.readSize);
-
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        GridCacheVersion _val = 
commState.getCacheVersion(null);
-
-                        if (!commState.lastRead())
-                            return false;
-
-                        futVers.add((GridCacheVersion)_val);
-
-                        commState.readItems++;
-                    }
-                }
+                futVers = reader.readCollection("futVers", 
GridCacheVersion.class);
 
-                commState.readSize = -1;
-                commState.readItems = 0;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java
index c69fc6e..6b59e82 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java
@@ -728,306 +728,138 @@ public class GridDhtAtomicUpdateRequest<K, V> extends 
GridCacheMessage<K, V> imp
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        writer.setBuffer(buf);
 
         if (!super.writeTo(buf))
             return false;
 
-        if (!commState.typeWritten) {
-            if (!commState.putByte(null, directType()))
+        if (!typeWritten) {
+            if (!writer.writeByte(null, directType()))
                 return false;
 
-            commState.typeWritten = true;
+            typeWritten = true;
         }
 
-        switch (commState.idx) {
+        switch (state) {
             case 3:
-                if (!commState.putLongList("drExpireTimes", drExpireTimes))
+                if (!writer.writeMessage("drExpireTimes", drExpireTimes != 
null ? drExpireTimes.clone() : null))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 4:
-                if (drVers != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, drVers.size()))
-                            return false;
-
-                        commState.it = drVers.iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        if (!commState.putCacheVersion(null, 
(GridCacheVersion)commState.cur))
-                            return false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
+                if (!writer.writeCollection("drVers", drVers, 
GridCacheVersion.class))
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 5:
-                if (!commState.putCacheVersion("futVer", futVer))
+                if (!writer.writeCollection("entryProcessorsBytes", 
entryProcessorsBytes, byte[].class))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 6:
-                if (invokeArgsBytes != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, invokeArgsBytes.length))
-                            return false;
-
-                        commState.it = arrayIterator(invokeArgsBytes);
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        if (!commState.putByteArray(null, 
(byte[])commState.cur))
-                            return false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
+                if (!writer.writeBoolean("forceTransformBackups", 
forceTransformBackups))
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 7:
-                if (keyBytes != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, keyBytes.size()))
-                            return false;
-
-                        commState.it = keyBytes.iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        if (!commState.putByteArray(null, 
(byte[])commState.cur))
-                            return false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
+                if (!writer.writeMessage("futVer", futVer != null ? 
futVer.clone() : null))
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 8:
-                if (!commState.putLongList("nearExpireTimes", nearExpireTimes))
+                if (!writer.writeObjectArray("invokeArgsBytes", 
invokeArgsBytes, byte[].class))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 9:
-                if (!commState.putLongList("nearTtls", nearTtls))
+                if (!writer.writeCollection("keyBytes", keyBytes, 
byte[].class))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 10:
-                if (!commState.putUuid("nodeId", nodeId))
+                if (!writer.writeCollection("nearEntryProcessorsBytes", 
nearEntryProcessorsBytes, byte[].class))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 11:
-                if (!commState.putEnum("syncMode", syncMode))
+                if (!writer.writeMessage("nearExpireTimes", nearExpireTimes != 
null ? nearExpireTimes.clone() : null))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 12:
-                if (!commState.putLong("topVer", topVer))
+                if (!writer.writeCollection("nearKeyBytes", nearKeyBytes, 
byte[].class))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 13:
-                if (!commState.putLongList("ttls", ttls))
+                if (!writer.writeMessage("nearTtls", nearTtls != null ? 
nearTtls.clone() : null))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 14:
-                if (valBytes != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, valBytes.size()))
-                            return false;
-
-                        commState.it = valBytes.iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        if (!commState.putValueBytes(null, 
(GridCacheValueBytes)commState.cur))
-                            return false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
+                if (!writer.writeCollection("nearValBytes", nearValBytes, 
GridCacheValueBytes.class))
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 15:
-                if (!commState.putCacheVersion("writeVer", writeVer))
+                if (!writer.writeUuid("nodeId", nodeId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 16:
-                if (nearKeyBytes != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, nearKeyBytes.size()))
-                            return false;
-
-                        commState.it = nearKeyBytes.iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        if (!commState.putByteArray(null, 
(byte[])commState.cur))
-                            return false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
+                if (!writer.writeUuid("subjId", subjId))
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 17:
-                if (nearValBytes != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, nearValBytes.size()))
-                            return false;
-
-                        commState.it = nearValBytes.iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        if (!commState.putValueBytes(null, 
(GridCacheValueBytes)commState.cur))
-                            return false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
+                if (!writer.writeEnum("syncMode", syncMode))
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 18:
-                if (entryProcessorsBytes != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, 
entryProcessorsBytes.size()))
-                            return false;
-
-                        commState.it = entryProcessorsBytes.iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        if (!commState.putByteArray(null, 
(byte[])commState.cur))
-                            return false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
+                if (!writer.writeInt("taskNameHash", taskNameHash))
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 19:
-                if (!commState.putBoolean("forceTransformBackups", 
forceTransformBackups))
+                if (!writer.writeLong("topVer", topVer))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 20:
-                if (nearEntryProcessorsBytes != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, 
nearEntryProcessorsBytes.size()))
-                            return false;
-
-                        commState.it = nearEntryProcessorsBytes.iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        if (!commState.putByteArray(null, 
(byte[])commState.cur))
-                            return false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
+                if (!writer.writeMessage("ttls", ttls != null ? ttls.clone() : 
null))
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 21:
-                if (!commState.putUuid("subjId", subjId))
+                if (!writer.writeCollection("valBytes", valBytes, 
GridCacheValueBytes.class))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 22:
-                if (!commState.putInt("taskNameHash", taskNameHash))
+                if (!writer.writeMessage("writeVer", writeVer != null ? 
writeVer.clone() : null))
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 
@@ -1037,349 +869,171 @@ public class GridDhtAtomicUpdateRequest<K, V> extends 
GridCacheMessage<K, V> imp
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean readFrom(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        reader.setBuffer(buf);
 
         if (!super.readFrom(buf))
             return false;
 
-        switch (commState.idx) {
+        switch (state) {
             case 3:
-                drExpireTimes = commState.getLongList("drExpireTimes");
+                drExpireTimes = reader.readMessage("drExpireTimes");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 4:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
-
-                if (commState.readSize >= 0) {
-                    if (drVers == null)
-                        drVers = new ArrayList<>(commState.readSize);
-
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        GridCacheVersion _val = 
commState.getCacheVersion(null);
-
-                        if (!commState.lastRead())
-                            return false;
-
-                        drVers.add((GridCacheVersion)_val);
+                drVers = reader.readCollection("drVers", 
GridCacheVersion.class);
 
-                        commState.readItems++;
-                    }
-                }
-
-                commState.readSize = -1;
-                commState.readItems = 0;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 5:
-                futVer = commState.getCacheVersion("futVer");
+                entryProcessorsBytes = 
reader.readCollection("entryProcessorsBytes", byte[].class);
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 6:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
-
-                if (commState.readSize >= 0) {
-                    if (invokeArgsBytes == null)
-                        invokeArgsBytes = new byte[commState.readSize][];
-
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        byte[] _val = commState.getByteArray(null);
-
-                        if (!commState.lastRead())
-                            return false;
-
-                        invokeArgsBytes[i] = (byte[])_val;
+                forceTransformBackups = 
reader.readBoolean("forceTransformBackups");
 
-                        commState.readItems++;
-                    }
-                }
-
-                commState.readSize = -1;
-                commState.readItems = 0;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 7:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
-
-                if (commState.readSize >= 0) {
-                    if (keyBytes == null)
-                        keyBytes = new ArrayList<>(commState.readSize);
-
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        byte[] _val = commState.getByteArray(null);
-
-                        if (!commState.lastRead())
-                            return false;
+                futVer = reader.readMessage("futVer");
 
-                        keyBytes.add((byte[])_val);
-
-                        commState.readItems++;
-                    }
-                }
-
-                commState.readSize = -1;
-                commState.readItems = 0;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 8:
-                nearExpireTimes = commState.getLongList("nearExpireTimes");
+                invokeArgsBytes = reader.readObjectArray("invokeArgsBytes", 
byte[].class);
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 9:
-                nearTtls = commState.getLongList("nearTtls");
+                keyBytes = reader.readCollection("keyBytes", byte[].class);
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 10:
-                nodeId = commState.getUuid("nodeId");
+                nearEntryProcessorsBytes = 
reader.readCollection("nearEntryProcessorsBytes", byte[].class);
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 11:
-                byte syncMode0 = commState.getByte("syncMode");
+                nearExpireTimes = reader.readMessage("nearExpireTimes");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                syncMode = 
CacheWriteSynchronizationMode.fromOrdinal(syncMode0);
-
-                commState.idx++;
+                state++;
 
             case 12:
-                topVer = commState.getLong("topVer");
+                nearKeyBytes = reader.readCollection("nearKeyBytes", 
byte[].class);
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 13:
-                ttls = commState.getLongList("ttls");
+                nearTtls = reader.readMessage("nearTtls");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 14:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
-
-                if (commState.readSize >= 0) {
-                    if (valBytes == null)
-                        valBytes = new ArrayList<>(commState.readSize);
-
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        GridCacheValueBytes _val = 
commState.getValueBytes(null);
+                nearValBytes = reader.readCollection("nearValBytes", 
GridCacheValueBytes.class);
 
-                        if (!commState.lastRead())
-                            return false;
-
-                        valBytes.add((GridCacheValueBytes)_val);
-
-                        commState.readItems++;
-                    }
-                }
-
-                commState.readSize = -1;
-                commState.readItems = 0;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 15:
-                writeVer = commState.getCacheVersion("writeVer");
+                nodeId = reader.readUuid("nodeId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 16:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
-
-                if (commState.readSize >= 0) {
-                    if (nearKeyBytes == null)
-                        nearKeyBytes = new ArrayList<>(commState.readSize);
+                subjId = reader.readUuid("subjId");
 
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        byte[] _val = commState.getByteArray(null);
-
-                        if (!commState.lastRead())
-                            return false;
-
-                        nearKeyBytes.add((byte[])_val);
-
-                        commState.readItems++;
-                    }
-                }
-
-                commState.readSize = -1;
-                commState.readItems = 0;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 17:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
-
-                if (commState.readSize >= 0) {
-                    if (nearValBytes == null)
-                        nearValBytes = new ArrayList<>(commState.readSize);
+                syncMode = reader.readEnum("syncMode", 
CacheWriteSynchronizationMode.class);
 
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        GridCacheValueBytes _val = 
commState.getValueBytes(null);
-
-                        if (!commState.lastRead())
-                            return false;
-
-                        nearValBytes.add((GridCacheValueBytes)_val);
-
-                        commState.readItems++;
-                    }
-                }
-
-                commState.readSize = -1;
-                commState.readItems = 0;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 18:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
+                taskNameHash = reader.readInt("taskNameHash");
 
-                if (commState.readSize >= 0) {
-                    if (entryProcessorsBytes == null)
-                        entryProcessorsBytes = new 
ArrayList<>(commState.readSize);
-
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        byte[] _val = commState.getByteArray(null);
-
-                        if (!commState.lastRead())
-                            return false;
-
-                        entryProcessorsBytes.add((byte[])_val);
-
-                        commState.readItems++;
-                    }
-                }
-
-                commState.readSize = -1;
-                commState.readItems = 0;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 19:
-                forceTransformBackups = 
commState.getBoolean("forceTransformBackups");
+                topVer = reader.readLong("topVer");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 20:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
+                ttls = reader.readMessage("ttls");
 
-                if (commState.readSize >= 0) {
-                    if (nearEntryProcessorsBytes == null)
-                        nearEntryProcessorsBytes = new 
ArrayList<>(commState.readSize);
-
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        byte[] _val = commState.getByteArray(null);
-
-                        if (!commState.lastRead())
-                            return false;
-
-                        nearEntryProcessorsBytes.add((byte[])_val);
-
-                        commState.readItems++;
-                    }
-                }
-
-                commState.readSize = -1;
-                commState.readItems = 0;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 21:
-                subjId = commState.getUuid("subjId");
+                valBytes = reader.readCollection("valBytes", 
GridCacheValueBytes.class);
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 22:
-                taskNameHash = commState.getInt("taskNameHash");
+                writeVer = reader.readMessage("writeVer");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java
index afd013c..256c4b6 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java
@@ -205,63 +205,42 @@ public class GridDhtAtomicUpdateResponse<K, V> extends 
GridCacheMessage<K, V> im
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        writer.setBuffer(buf);
 
         if (!super.writeTo(buf))
             return false;
 
-        if (!commState.typeWritten) {
-            if (!commState.putByte(null, directType()))
+        if (!typeWritten) {
+            if (!writer.writeByte(null, directType()))
                 return false;
 
-            commState.typeWritten = true;
+            typeWritten = true;
         }
 
-        switch (commState.idx) {
+        switch (state) {
             case 3:
-                if (!commState.putByteArray("errBytes", errBytes))
+                if (!writer.writeByteArray("errBytes", errBytes))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 4:
-                if (!commState.putByteArray("failedKeysBytes", 
failedKeysBytes))
+                if (!writer.writeByteArray("failedKeysBytes", failedKeysBytes))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 5:
-                if (!commState.putCacheVersion("futVer", futVer))
+                if (!writer.writeMessage("futVer", futVer != null ? 
futVer.clone() : null))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 6:
-                if (nearEvictedBytes != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, nearEvictedBytes.size()))
-                            return false;
-
-                        commState.it = nearEvictedBytes.iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        if (!commState.putByteArray(null, 
(byte[])commState.cur))
-                            return false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
+                if (!writer.writeCollection("nearEvictedBytes", 
nearEvictedBytes, byte[].class))
+                    return false;
 
-                commState.idx++;
+                state++;
 
         }
 
@@ -271,65 +250,43 @@ public class GridDhtAtomicUpdateResponse<K, V> extends 
GridCacheMessage<K, V> im
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean readFrom(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        reader.setBuffer(buf);
 
         if (!super.readFrom(buf))
             return false;
 
-        switch (commState.idx) {
+        switch (state) {
             case 3:
-                errBytes = commState.getByteArray("errBytes");
+                errBytes = reader.readByteArray("errBytes");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 4:
-                failedKeysBytes = commState.getByteArray("failedKeysBytes");
+                failedKeysBytes = reader.readByteArray("failedKeysBytes");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 5:
-                futVer = commState.getCacheVersion("futVer");
+                futVer = reader.readMessage("futVer");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 6:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
+                nearEvictedBytes = reader.readCollection("nearEvictedBytes", 
byte[].class);
 
-                if (commState.readSize >= 0) {
-                    if (nearEvictedBytes == null)
-                        nearEvictedBytes = new ArrayList<>(commState.readSize);
-
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        byte[] _val = commState.getByteArray(null);
-
-                        if (!commState.lastRead())
-                            return false;
-
-                        nearEvictedBytes.add((byte[])_val);
-
-                        commState.readItems++;
-                    }
-                }
-
-                commState.readSize = -1;
-                commState.readItems = 0;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
         }
 

Reply via email to