@Override
        public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
            if (message == null) {
                LOGGER.error("Message is null");
                return;
            }
            if (!(message instanceof RemotingCommand)) {
                LOGGER.error("{} is not instanceof RemotingCommand", message);
                return;
            }
            RemotingCommand remotingCommand = (RemotingCommand) message;

            try {
                ByteBuffer byteBuffer = codec.encode(remotingCommand);
                IoBuffer ioBuffer = bufferAllocator.wrap(byteBuffer);
                out.write(ioBuffer);
                out.flush();
            } catch (Exception e) {
                Channel channel = new MinaChannel(session);
                LOGGER.error("encode exception, addr={}, remotingCommand={}", RemotingHelper.parseChannelRemoteAddr(channel), remotingCommand.toString(), e);
                RemotingHelper.closeChannel(channel);
            }
        }
@author Robert HG (254963746@qq.com) on 11/4/15.
lts-core/src/main/java/com/github/ltsopensource/remoting/mina/MinaCodecFactory.java