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 ProtostuffOutput output = new ProtostuffOutput(buffer);
        final GraphProtostuffOutput graphOutput = new GraphProtostuffOutput(output);
        try
        {
            schema.writeTo(graphOutput, 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 using the given schema.

@return the byte array containing the data.
protostuff-core/src/main/java/io/protostuff/GraphIOUtil.java