Beispiel #1
0
void 
Person::deserialize(ENetPacket* buf)
{
#ifndef ASN_USE_FILE
  // open the data file  
  ifstream dataFile;  
  dataFile.open ("pr.ber");

  // get size of the data file file  
  dataFile.seekg (0, ios::end);  
  int dataSize = dataFile.tellg();  
  dataFile.seekg (0);

  // read data from file into contiguous block for a buffer
  char data[dataSize];  
  dataFile.read (data, dataSize);  
  dataFile.close();  

  //  
  // put the BER data read from the file  
  // into buffer format, ready for reading from the  
  // beginning  
  //  
  AsnBuf inputBuf;  
  inputBuf.InstallData ((char*)data, dataSize);  

  size_t decodedLen;  
  ASNPerson p;

  if (!p.BDecPdu (inputBuf, decodedLen))  
    {  
      std::cerr << "ERROR - Decode routines failed, exiting..." << endl;  
        exit (1);  
    }  

#else
# error "Char Asn Decoding not implemented"
#endif

  /*
  ASNPerson p;
  const size_t dataSize = 10;
  char data[dataSize];
  size_t decodedLen;
  //buf.Init (data, dataSize);
  buf.ResetInReadMode();
  if (!p.BDecPdu ( buf, decodedLen ))
    {
      std::cerr << "Failed to decode Asn.1"<< std::endl;
      exit (1);
    }
  */
}
Beispiel #2
0
main (int argc, char *argv[])
{
    AsnBuf  inputBuf;
    AsnBuf  outputBuf;
    size_t encodedLen;
    size_t decodedLen;
    size_t      dataSize;
    ifstream dataFile;
    PersonnelRecord pr;

    if (argc != 2)
    {
        cerr << "Usage: " << argv[0] << " <BER data file name>" << endl;
        cerr << "   Decodes the given PersonnelRecord BER data file" << endl;
        cerr << "   and re-encodes it to stdout" << endl;
        exit (1);
    }


    // open the data file
    dataFile.open (argv[1]);

    if (!dataFile)
    {
        perror ("ifstream::open");
        exit (1);
    }

    // get size of the data file file
    dataFile.seekg (0, ios::end);
    dataSize = dataFile.tellg();
    dataFile.seekg (0);

    // read data from file into contiguous block for a buffer
#if HAVE_VARIABLE_SIZED_AUTOMATIC_ARRAYS
    char data[dataSize];
#else
    char *data = new char[dataSize];
    if (!data)
	return 1;
#endif /* HAVE_VARIABLE_SIZED_AUTOMATIC_ARRAYS */
    dataFile.read (data, dataSize);
    dataFile.close();

    //
    // put the BER data read from the file
    // into buffer format, ready for reading from the
    // beginning
    //
    inputBuf.InstallData (data, dataSize);

    if (!pr.BDecPdu (inputBuf, decodedLen))
    {
        cerr << "--- ERROR - Decode routines failed, exiting..." << endl;
        exit (1);
    }

    cerr  << "decodedValue PersonnelRecord ::= " << pr << endl << endl;

    //
    // allocate a new buffer set up for writing to
    //
#if HAVE_VARIABLE_SIZED_AUTOMATIC_ARRAYS
    char outputData[dataSize + 512];
#else
    char *outputData = new char[dataSize + 512];
    if (!outputData)
	return 1;
#endif /* HAVE_VARIABLE_SIZED_AUTOMATIC_ARRAYS */
    outputBuf.Init (outputData, dataSize+512);
    outputBuf.ResetInWriteRvsMode();

    if (!pr.BEncPdu (outputBuf, encodedLen))
    {
        cerr << "--- ERROR - Encode routines failed" << endl;
    }

    // write the BER value to cout
    outputBuf.ResetInReadMode();
    for (; encodedLen > 0; encodedLen--)
        cout.put (outputBuf.GetByte());

    return 0;
}