class SerializeUtils {

    public static byte[] serializeRequest(Request request) {
        if (request == null || request.getHdr() == null) return null;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
        try {
            request.getHdr().serialize(boa, "hdr");
            if (request.getTxn() != null) {
                request.getTxn().serialize(boa, "txn");
            }
        } catch (IOException e) {
            LOG.error("This really should be impossible", e);
        } finally {
            IOUtils.cleanup(LOG, baos);
        }
        return baos.toByteArray();
    }

}