Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages | Examples

Decode.cpp

This is an example of how to use the DataCodec class. The program reads a binary encoded rdaData object from the file specified by the first command line argument, decodes it and prints out.
See also:
Encode.cpp
#include <iostream>
#include <rda/DataCodec.h>
#include <rda/RDAService.h>

#ifdef CMW_WIN
   // Windows
   #include <windows.h>
#else
   // Unix
   #include <unistd.h>
   #include <sys/stat.h>
   #include <fcntl.h>
#endif

using namespace std;

int main(int argc, char** argv)
{
   //
   // Get the file name from the command line
   //
   const char* file = 0;
   if (argc > 1) file = argv[1];
   else
   {
      cout << "File name not specified\n";
      return 0;
   }
   //
   // Read binary data from the file
   //
        rdaRDAService::init();
   cout << "==> reading data from file: " << file << endl;
   int fd = open(file, O_RDONLY);
   if (fd == -1)
   {
      perror("open() failed");
      return 0;
   }
   char buf[10000];
   int size = read(fd, &buf, 10000);
   if (size == -1)
   {
      perror("read() failed");
      return 0;
   }
   if (size == 0)
   {
      printf("empty data file\n");
      return 0;
   }
   //
   // Decode the binary representation and print results.
   //
   rdaData* data = rdaDataCodec::decode(buf, (unsigned long)size);
   if (data) data->print();
   else cout << "conversion failed\n";
   
   delete data;
   close(fd);

   return 0;
}

RDA-2.3 documentation - 27 Jun 2007 - N.Trofimov