MessageFrameDecoder extends ByteToMessageDecoder { @Override protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) { logger.trace("decoding {} bytes from {}", in.readableBytes(), in); if (in.readableBytes() <= 2) { return; } final int readerIdx = in.readerIndex(); final int writerIdx = in.writerIndex(); int len = 0; try { final DERBuffer buffer = new NettyDERBuffer(in.readSlice(in.readableBytes())); len = readMessageLength(buffer); } finally { logger.trace("decoded message length of {} for {}", len, in); in.setIndex(readerIdx, writerIdx); } if (len > 0) { logger.trace("read enough bytes from {} to decode message", in); out.add(in.readRetainedSlice(len)); if (ctx != null) { ctx.fireUserEventTriggered(NettyConnection.MessageStatus.READ); } } else { logger.trace("could not read enough bytes from {} to decode message", in); } }    }
@Test(groups = "transport", dataProvider = "response") public void decode(final byte[] berValue, final boolean frame) throws Exception { final List<Object> out = new ArrayList<>(); decoder.decode(null, Unpooled.wrappedBuffer(berValue), out); Assert.assertEquals(!out.isEmpty(), frame); if (frame) { Assert.assertEquals(((ByteBuf) out.get(0)).array(), berValue); } }