@SuppressWarnings("unchecked")
@Override
protected Object encode(ChannelHandlerContext ctx, Channel c, Object msg) throws Exception {
if (msg instanceof Message) {
Message message = (Message) msg;
Class<? extends Message> clazz = message.getClass();
MessageCodec<Message> codec = (MessageCodec<Message>) CodecLookupService.find(clazz);
if (codec == null) {
throw new IOException("Unknown message type: " + clazz + ".");
}