Search in sources :

Example 1 with ByteBufferInputStream

use of com.esotericsoftware.kryo.io.ByteBufferInputStream in project hive by apache.

the class KryoMessageCodec method decode.

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    if (in.readableBytes() < 4) {
        return;
    }
    in.markReaderIndex();
    int msgSize = in.readInt();
    checkSize(msgSize);
    if (in.readableBytes() < msgSize) {
        // Incomplete message in buffer.
        in.resetReaderIndex();
        return;
    }
    try {
        ByteBuffer nioBuffer = maybeDecrypt(in.nioBuffer(in.readerIndex(), msgSize));
        Input kryoIn = new Input(new ByteBufferInputStream(nioBuffer));
        Object msg = kryos.get().readClassAndObject(kryoIn);
        LOG.debug("Decoded message of type {} ({} bytes)", msg != null ? msg.getClass().getName() : msg, msgSize);
        out.add(msg);
    } finally {
        in.skipBytes(msgSize);
    }
}
Also used : Input(com.esotericsoftware.kryo.io.Input) ByteBufferInputStream(com.esotericsoftware.kryo.io.ByteBufferInputStream) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ByteBufferInputStream (com.esotericsoftware.kryo.io.ByteBufferInputStream)1 Input (com.esotericsoftware.kryo.io.Input)1 ByteBuffer (java.nio.ByteBuffer)1