@Override
    protected void encode(ChannelHandlerContext ctx, Object msg, List out) throws Exception {
        if (!(msg instanceof List)) {
            ByteBuf byteBuf = Unpooled.buffer();
            ((LispMessage) msg).writeTo(byteBuf);
            out.add(new DatagramPacket(byteBuf, ((LispMessage) msg).getSender()));
            return;
        }

        List<LispMessage> msgList = (List<LispMessage>) msg;

        for (LispMessage message : msgList) {
            if (message != null) {
                ByteBuf byteBuf = Unpooled.buffer();
                message.writeTo(byteBuf);
                out.add(new DatagramPacket(byteBuf, message.getSender()));
            }
        }
    }
@Test
    public void testEncodeOneEntry() throws Exception {
        LispMessageEncoder encoder = new LispMessageEncoder();
        MockLispMessage message = new MockLispMessage(LispType.LISP_MAP_REQUEST);

        List<DatagramPacket> list = Lists.newArrayList();
        encoder.encode(null, message, list);

        assertThat(list, notNullValue());

        String expected = "LISP message [LISP_MAP_REQUEST] ";
        String returned = new String(list.get(0).content().array(),
                        StandardCharsets.UTF_8).substring(0, expected.length());
        assertThat(returned, is(expected));
    }