class FASTCodec extends AbstractCodec {

	@Override
	public void encode(
			IoSession session,
			Object message,
			ProtocolEncoderOutput out) throws Exception {

		IMessageToFastConverter converter = getIMessageToFastConverter();
		IMessage iMsg = (IMessage) message;

        Message fastMsg = converter.convert(iMsg);
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		Context oc = getOutputContext(session);
		MessageOutputStream msgOutStream = new MessageOutputStream(os, oc);
		msgOutStream.writeMessage(fastMsg);
		byte[] outputdata = os.toByteArray();
		byte[] blockHeader = TypeCodec.UINT.encode(new IntegerValue(outputdata.length));

		byte[] result = Arrays.copyOf(blockHeader, blockHeader.length + outputdata.length);
		System.arraycopy(outputdata, 0, result, blockHeader.length, outputdata.length);

		out.write(IoBuffer.wrap(result));
		if (settings.isResetContextAfterEachUdpPacket()) {
			oc.reset();
		}
	}

}