private static byte[] serialize(final SampleClass t) throws Exception
    {
        ObjectOutputStream oos = null;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try
        {
            oos = new ObjectOutputStream(baos);
            t.writeExternal(oos);
        }
        catch (IOException e)
        {
            throw new Exception(e);
        }
        finally
        {
            tryClose(oos);
        }
        return baos.toByteArray();
    }
From https://groups.google.com/forum/#!topic/protostuff/D7Bb1REf8pQ (Anil Pandge)
protostuff-core/src/test/java/io/protostuff/CodedDataInputTest.java