/** {@inheritDoc} */ @Override public ByteBuffer encode(GridNioSession ses, GridClientMessage msg) throws IOException, GridException { assert msg != null; if (msg instanceof GridTcpRestPacket) return encodeMemcache((GridTcpRestPacket) msg); else if (msg == PING_MESSAGE) return ByteBuffer.wrap(PING_PACKET); else { byte[] data = marshaller.marshal(msg); assert data.length > 0; ByteBuffer res = ByteBuffer.allocate(data.length + 5); res.put(GRIDGAIN_REQ_FLAG); res.put(U.intToBytes(data.length)); res.put(data); res.flip(); return res; } }