@Override
        public ByteBuffer encode(NioChannel channel, Object msg) {

            if (msg instanceof RemotingMsg) {
                String json = JSON.toJSONString(msg);
                if (json == null) {
                    return null;
                }
                int length = json.length();
                ByteBuffer out = ByteBuffer.allocate(4 + length);
                out.putInt(length);
                try {
                    out.put(json.getBytes("UTF-8"));
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                out.flip();
                return out;
            }
            return null;
        }
@author Robert HG (254963746@qq.com) on 2/3/16.
lts-core/src/test/java/com/github/ltsopensource/nio/CodecFactory.java