public static <T> int writeTo(LinkedBuffer buffer, T message, Schema<T> schema)
    {
        if (buffer.start != buffer.offset)
            throw new IllegalArgumentException("Buffer previously used and had not been reset.");

        final XmlXOutput output = new XmlXOutput(buffer, schema);

        final String name = schema.messageName();
        try
        {
            // header and start root element
            output.tail = output.sink.writeByte(XmlXOutput.END_TAG, output,
                    output.sink.writeStrAscii(name, output,
                            output.sink.writeByte(XmlXOutput.START_TAG, output,
                                    output.sink.writeByteArray(HEADER, output, output.tail))));

            schema.writeTo(output, message);

            // end root element
            output.tail = output.sink.writeByte(XmlXOutput.END_TAG, output,
                    output.sink.writeStrAscii(name, output,
                            output.sink.writeByteArray(XmlXOutput.START_SLASH_TAG, output, output.tail)));
        }
        catch (IOException e)
        {
            throw new RuntimeException("Serializing to a LinkedBuffer threw an IOException " +
                    "(should never happen).", e);
        }

        return output.getSize();
    }
Writes the {@code message} into the {@link LinkedBuffer} using the given schema.

@return the size of the message
protostuff-xml/src/main/java/io/protostuff/XmlXIOUtil.java