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

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

        try
        {
            output.tail = YamlOutput.writeTag(
                    schema.messageName(),
                    false,
                    output.sink,
                    output,
                    output.sink.writeByteArray(
                            START_DIRECTIVE,
                            output,
                            buffer));

            schema.writeTo(output, message);
        }
        catch (IOException e)
        {
            throw new RuntimeException("Serializing to a byte array threw an IOException " +
                    "(should never happen).", e);
        }

        return output.toByteArray();
    }
Serializes the {@code message} into a byte array with the supplied buffer.
protostuff-yaml/src/main/java/io/protostuff/YamlIOUtil.java