public void serializeMessage(AMF0Message message) throws IOException {
        //if (log.isInfoEnabled())
        //    log.info("Serializing Message, for more info turn on debug level");

        clearStoredObjects();
        outputStream.writeShort(message.getVersion());
        // write header
        outputStream.writeShort(message.getHeaderCount());
        Iterator<AMF0Header> headers = message.getHeaders().iterator();
        while (headers.hasNext()) {
            AMF0Header header = headers.next();
            writeHeader(header);
        }
        // write body
        outputStream.writeShort(message.getBodyCount());
        Iterator<AMF0Body> bodies = message.getBodies();
        while (bodies.hasNext()) {
            AMF0Body body = bodies.next();
            writeBody(body);
        }
    }