code: public static byte[] toBytes(TBase<?, ?> record) throws TException {
          if (record == null) {
              return null;
          }
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          TTransport transport = new TIOStreamTransport(null, baos);
          TProtocol oProtocol = protocolFactory.getProtocol(transport);
          record.write(oProtocol);
          // baos.close();
          return baos.toByteArray();
      }
docs: Serializes a thrift object to byte array.
  
  @param record
  @return
  @throws TException