@Override
    protected void encode(ChannelHandlerContext ctx, CharSequence msg, List<Object> out) throws Exception {
        if (msg.length() == 0) {
            return;
        }

        out.add(ByteBufUtil.encodeString(ctx.alloc(), CharBuffer.wrap(msg), charset));
    }
@Test
    public void testEncode() {
        String msg = "Test";
        EmbeddedChannel channel = new EmbeddedChannel(new StringEncoder());
        Assertions.assertTrue(channel.writeOutbound(msg));
        Assertions.assertTrue(channel.finish());
        ByteBuf buf = channel.readOutbound();
        byte[] data = new byte[buf.readableBytes()];
        buf.readBytes(data);
        Assertions.assertArrayEquals(msg.getBytes(CharsetUtil.UTF_8), data);
        Assertions.assertNull(channel.readOutbound());
        buf.release();
        assertFalse(channel.finish());
    }