static <T> byte[] toByteArrayStreamedProtostuff(T message, Schema<T> schema)
    {
        /*
         * final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ProtostuffIOUtil.writeTo(out, message,
         * schema, new LinkedBuffer(BUF_SIZE)); } catch (IOException e) { throw new
         * RuntimeException("Serializing to a byte array threw an IOException " + "(should never happen).", e); } return
         * out.toByteArray();
         */

        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        final LinkedBuffer buffer = new LinkedBuffer(BUF_SIZE);
        final ProtostuffOutput output = new ProtostuffOutput(buffer, out);

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

        return out.toByteArray();
    }
Benchmark to compare the serialization speed of 3 types. CodedOutput, BufferedOutput and DeferredOutput.

@author David Yu
@created Nov 13, 2009
protostuff-core/src/test/java/io/protostuff/CompareOutputsTest.java