Search in sources :

Example 1 with StringInOutPayload

use of com.ctrip.xpipe.payload.StringInOutPayload in project x-pipe by ctripcorp.

the class BulkStringParser method getWriteByteBuf.

@Override
protected ByteBuf getWriteByteBuf() {
    if (payload == null) {
        if (logger.isInfoEnabled()) {
            logger.info("[getWriteBytes][payload null]");
        }
        return Unpooled.wrappedBuffer(new byte[0]);
    }
    if ((payload instanceof StringInOutPayload) || (payload instanceof ByteArrayOutputStreamPayload)) {
        try {
            ByteArrayWritableByteChannel channel = new ByteArrayWritableByteChannel();
            payload.out(channel);
            byte[] content = channel.getResult();
            String length = String.valueOf((char) DOLLAR_BYTE) + content.length + RedisClientProtocol.CRLF;
            return Unpooled.wrappedBuffer(length.getBytes(), content, RedisClientProtocol.CRLF.getBytes());
        } catch (IOException e) {
            logger.error("[getWriteBytes]", e);
            return Unpooled.wrappedBuffer(new byte[0]);
        }
    }
    throw new UnsupportedOperationException();
}
Also used : StringInOutPayload(com.ctrip.xpipe.payload.StringInOutPayload) ByteArrayWritableByteChannel(com.ctrip.xpipe.payload.ByteArrayWritableByteChannel) ByteArrayOutputStreamPayload(com.ctrip.xpipe.payload.ByteArrayOutputStreamPayload) IOException(java.io.IOException)

Aggregations

ByteArrayOutputStreamPayload (com.ctrip.xpipe.payload.ByteArrayOutputStreamPayload)1 ByteArrayWritableByteChannel (com.ctrip.xpipe.payload.ByteArrayWritableByteChannel)1 StringInOutPayload (com.ctrip.xpipe.payload.StringInOutPayload)1 IOException (java.io.IOException)1