📄 reader.cpp
字号:
// This test driver program reads an encoded record from a file
// and decodes it and displays the results..
#include <stdio.h>
#include <stdlib.h>
#include "NBAP-Constants.h"
#include "NBAP-Containers.h"
#include "NBAP-IEs.h"
#include "NBAP-PDU-ContentsTable.h"
#include "NBAP-PDU-DescriptionsTable.h"
#include "rtxsrc/rtxMemLeakCheck.h"
#include "rtxsrc/rtxDiag.h"
#define MAXMSGLEN 1024
int main (int argc, char** argv)
{
OSOCTET msgbuf[MAXMSGLEN];
OSBOOL verbose = FALSE, aligned = TRUE, trace = TRUE;
FILE* fp;
const char* filename = "message.dat";
int i, len, stat;
// Process command line arguments
if (argc > 1) {
for (i = 1; i < argc; i++) {
if (!strcmp (argv[i], "-a")) aligned = TRUE;
else if (!strcmp (argv[i], "-u")) aligned = FALSE;
else if (!strcmp (argv[i], "-v")) verbose = TRUE;
else if (!strcmp (argv[i], "-i")) filename = argv[++i];
else if (!strcmp (argv[i], "-notrace")) trace = FALSE;
else {
printf ("usage: reader -a | -u [ -v ] [ -i <filename>\n");
printf (" -a use PER aligned encoding\n");
printf (" -u use PER unaligned encoding\n");
printf (" -v verbose mode: print trace info\n");
printf (" -i <filename> read encoded msg from <filename>\n");
printf (" -notrace do not display trace info\n");
return 0;
}
}
}
// Read input file into a memory buffer
if (fp = fopen (filename, "rb")) {
len = fread (msgbuf, 1, sizeof(msgbuf), fp);
}
else {
printf ("Error opening %s for read access\n", filename);
return -1;
}
// Decode the complete message. Decoded information objects will
// be located in the 'ASN1TObject.decoded' structures within the
// main message structure..
{
ASN1PERDecodeBuffer decodeBuffer (msgbuf, len, aligned);
ASN1T_NBAP_PDU pduData;
ASN1C_NBAP_PDU pdu (decodeBuffer, pduData);
decodeBuffer.SetTrace (trace);
stat = pdu.Decode ();
if (trace) {
printf ("Dump of decoded bit fields:\n");
decodeBuffer.BinDump ("pdu");
printf ("\n");
}
if (stat == 0) {
if (trace) {
printf ("decode was successful\n");
pdu.Print ("pdu");
}
}
else {
printf ("decode failed\n");
decodeBuffer.PrintErrorInfo ();
return -1;
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -