本文整理汇总了C++中AsnBuf::InstallData方法的典型用法代码示例。如果您正苦于以下问题:C++ AsnBuf::InstallData方法的具体用法?C++ AsnBuf::InstallData怎么用?C++ AsnBuf::InstallData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsnBuf
的用法示例。
在下文中一共展示了AsnBuf::InstallData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exit
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);
}
*/
}
示例2: exit
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;
}