protected Object decode()

in netty-custom-correlation/src/main/java/org/apache/camel/example/netty/MyCodecDecoder.java [46:64]


    protected Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
        ByteBuf buf = (ByteBuf) super.decode(ctx, buffer);
        if (buf != null) {
            try {
                int pos = buf.bytesBefore((byte) startByte);
                if (pos >= 0) {
                    ByteBuf msg = buf.readerIndex(pos + 1).slice();
                    return asString(msg);
                } else {
                    throw new DecoderException("Did not find start byte " + (int) startByte);
                }
            } finally {
                // We need to release the buf here to avoid the memory leak
                buf.release();
            }
        }
        // Message not complete yet - return null to be called again
        return null;
    }