#include <stdio.h>
#include "DecRequest.h"
#include "proxytrace2txt_v2.h"

class DecLogFile
{
private:
  FILE* FP;
  
  // 0 if this is either closed or an open file, 1 if this is an open pipe.
  int isPipe;

  inline void lsbToMsb(u_4bytes& n);
  inline void lsbToMsb(unsigned short& n);

public:
  DecLogFile();

  // If fname = "-" then stdin is used as the input file.
  // If fname ends in ".gz" then is is opened as a pipe with gunzip -c fname
  // Otherwise, it is opened as a file.
  // Returns 0 on success -1 on failure.
  int open(const char* fname);

  // Reads the next transaction from the file.  
  // Returns 0 on success, 1 on EOF, -1 on failure.
  int read(DecRequest& req);

  void close();
  
  ~DecLogFile();
};
