@Override
    protected <T> byte[] toByteArray(T message, Schema<T> schema)
    {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        LinkedBuffer buffer = buf();
        final KvpOutput output = new KvpOutput(buffer, out, schema, numeric);
        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);
        }
        byte[] data = out.toByteArray();
        // System.err.println(data.length + " | " + getClass().getSimpleName());
        return data;
    }
Test for reading/writing from stream.

@author David Yu
@created Dec 4, 2010
protostuff-kvp/src/test/java/io/protostuff/AbstractKvpStreamTest.java