public static <T> int getSize(T message, Schema<T> schema, boolean encodeNestedMessageAsGroup)
    {
        ComputedSizeOutput sizeCount = new ComputedSizeOutput(encodeNestedMessageAsGroup);
        try
        {
            schema.writeTo(sizeCount, message);
        }
        catch (IOException e)
        {
            throw new RuntimeException("Serializing to a byte array threw an IOException " +
                    "(should never happen).", e);
        }
        return sizeCount.size;
    }
Computes the serialized size of a message tied to a schema.
protostuff-core/src/test/java/io/protostuff/ComputedSizeOutput.java