public int serialize(String filename, Routable routable, DataTamper tamper) {
        Version version = version();
        String path = getPath(version + "-java-" + filename + ".dat");
        byte[] data = protocol.encode(version, routable);
        data = tamper.tamperWith(data);
        assertNotNull(data);
        assertTrue(data.length > 0);
        try {
            if (fileContentIsUnchanged(path, data)) {
                System.out.println(String.format("Serialization for '%s' is unchanged; not overwriting it", path));
            } else {
                System.out.println(String.format("Serializing to '%s'..", path));
                // This only happens when protocol encoding has changed and takes place
                // during local development, not regular test runs.
                TestFileUtil.writeToFile(path, data);
            }
        } catch (IOException e) {
            throw new AssertionError(e);
        }
        assertEquals(routable.getType(), protocol.decode(version, data).getType());
        return data.length;
    }
Writes the content of the given routable to the given file.

@param filename The name of the file to write to.
@param routable The routable to serialize.
@param tamper allows tampering with serialized data
@return The size of the written file.
documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/MessagesTestBase.java