Repository: incubator-ignite Updated Branches: refs/heads/ignite-61 5089ee213 -> f125cfb40
# IGNITE-61 - Direct marshalling Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/f125cfb4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/f125cfb4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/f125cfb4 Branch: refs/heads/ignite-61 Commit: f125cfb404be35175acd06ba91a87d8a386051d1 Parents: 5089ee2 Author: Valentin Kulichenko <vkuliche...@gridgain.com> Authored: Thu Feb 5 22:18:57 2015 -0800 Committer: Valentin Kulichenko <vkuliche...@gridgain.com> Committed: Thu Feb 5 22:18:57 2015 -0800 ---------------------------------------------------------------------- .../tcp/GridMemcachedMessageWrapper.java | 21 +++++++------- .../GridTcpCommunicationByteBufferStream.java | 29 ++++++++++++++++++-- 2 files changed, 36 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f125cfb4/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridMemcachedMessageWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridMemcachedMessageWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridMemcachedMessageWrapper.java index e258375..906efa2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridMemcachedMessageWrapper.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridMemcachedMessageWrapper.java @@ -22,6 +22,7 @@ import org.apache.ignite.internal.util.*; import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.marshaller.*; +import org.gridgain.grid.util.direct.*; import java.io.*; import java.nio.*; @@ -40,6 +41,9 @@ public class GridMemcachedMessageWrapper extends GridTcpCommunicationMessageAdap /** UTF-8 charset. */ private static final Charset UTF_8 = Charset.forName("UTF-8"); + /** Stream. */ + private final GridTcpCommunicationByteBufferStream stream = new GridTcpCommunicationByteBufferStream(null); + /** * Memcached message bytes. */ @@ -63,25 +67,20 @@ public class GridMemcachedMessageWrapper extends GridTcpCommunicationMessageAdap /** {@inheritDoc} */ @Override public boolean writeTo(ByteBuffer buf) { - commState.setBuffer(buf); + stream.setBuffer(buf); if (!commState.typeWritten) { - if (!commState.putByte(null, directType())) + if (!buf.hasRemaining()) return false; + stream.writeByte(directType()); + commState.typeWritten = true; } - switch (commState.idx) { - case 0: - if (!commState.putByteArray("bytes", bytes)) - return false; - - commState.idx++; - - } + stream.writeByteArrayNoLength(bytes); - return true; + return stream.lastFinished(); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f125cfb4/modules/core/src/main/java/org/gridgain/grid/util/direct/GridTcpCommunicationByteBufferStream.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/gridgain/grid/util/direct/GridTcpCommunicationByteBufferStream.java b/modules/core/src/main/java/org/gridgain/grid/util/direct/GridTcpCommunicationByteBufferStream.java index 0ffefb4..ea4a36f 100644 --- a/modules/core/src/main/java/org/gridgain/grid/util/direct/GridTcpCommunicationByteBufferStream.java +++ b/modules/core/src/main/java/org/gridgain/grid/util/direct/GridTcpCommunicationByteBufferStream.java @@ -273,6 +273,15 @@ public class GridTcpCommunicationByteBufferStream { lastFinished = writeArray(val, BYTE_ARR_OFF, val.length, val.length); } + /** + * @param val Array. + */ + public void writeByteArrayNoLength(byte[] val) { + assert val != null; + + lastFinished = writeArray(val, BYTE_ARR_OFF, val.length, val.length, true); + } + /** {@inheritDoc} */ public void writeBoolean(boolean val) { int pos = buf.position(); @@ -565,6 +574,18 @@ public class GridTcpCommunicationByteBufferStream { * @return Whether array was fully written */ private boolean writeArray(Object arr, long off, int len, int bytes) { + return writeArray(arr, off, len, bytes, false); + } + + /** + * @param arr Array. + * @param off Offset. + * @param len Length. + * @param bytes Length in bytes. + * @param skipLen {@code true} if length should not be written. + * @return Whether array was fully written + */ + private boolean writeArray(Object arr, long off, int len, int bytes, boolean skipLen) { assert arr != null; assert arr.getClass().isArray() && arr.getClass().getComponentType().isPrimitive(); assert off > 0; @@ -573,10 +594,12 @@ public class GridTcpCommunicationByteBufferStream { assert bytes >= arrOff; if (arrOff == -1) { - if (remaining() < 4) - return false; + if (!skipLen) { + if (remaining() < 4) + return false; - writeInt(len); + writeInt(len); + } arrOff = 0; }