});
}
public static <T extends TBase> void testSerialization(Class<T> klass, T obj) throws Exception {
TMemoryBuffer buf = new TMemoryBuffer(0);
TBinaryProtocol binproto = new TBinaryProtocol(buf);
try {
obj.write(binproto);
// System.out.println("Size in binary protocol: " + buf.length());
buf = new TMemoryBuffer(0);
TProtocol proto = factory.getProtocol(buf);
obj.write(proto);
System.out.println("Size in compact protocol: " + buf.length());
// System.out.println(buf.inspect());
T objRead = klass.newInstance();
objRead.read(proto);
if (!obj.equals(objRead)) {
System.out.println("Expected: " + obj.toString());
System.out.println("Actual: " + objRead.toString());
// System.out.println(buf.inspect());
throw new RuntimeException("Objects didn't match!");
}
} catch (Exception e) {
System.out.println(buf.inspect());
throw e;
}
}