@Override
    protected void decode(ChannelHandlerContext ctx,
                          ByteBuf byteBuf,
                          List<Object> out) throws Exception {

        if (!ctx.channel().isActive()) {
            // In testing, I see decode being called AFTER decode last.
            // This check avoids that from reading corrupted frames
            return;
        }

        // Note that a single call to readFrom results in reading a single
        // OFMessage from the channel buffer, which is passed on to, and processed
        // by, the controller (in OFChannelHandler).
        // This is different from earlier behavior (with the original openflowj),
        // where we parsed all the messages in the buffer, before passing on
        // a list of the parsed messages to the controller.
        // The performance *may or may not* not be as good as before.
        OFMessageReader<OFMessage> reader = OFFactories.getGenericReader();

        OFMessage message = reader.readFrom(byteBuf);
        while (message != null) {
            out.add(message);
            message = reader.readFrom(byteBuf);
        }
    }
@Test
    public void testDecode() throws Exception {
        OFMessageDecoder decoder = OFMessageDecoder.getInstance();
        ByteBuf channelBuffer = getHelloMessageBuffer();
        List<Object> out = new ArrayList<>();
        decoder.decode(new ActiveChannelHandlerContextAdapter(),
                       channelBuffer,
                       out);
        assertThat(out.size(), is(1));
        assertThat(out.get(0), instanceOf(OFHello.class));
    }