Download ASN.1 Compiler Version 5.8 C/C++ Compiler User`s Manual

Transcript
A code fragment showing a way to do this is as follows:
#include employee.h
/* include file generated by ASN1C */
main ()
{
ASN1TAG
msgtag;
int
msglen, stat;
ASN1CTXT ctxt;
PersonnelRecord employee;
const char* filename = “message.dat”
/* Step 1: Initialize a context variable for decoding */
if (rtInitContext (&ctxt) != ASN_OK) {
/* initialization failed, could be a license problem */
printf (“context initialization failed (check license)\n”);
return –1;
}
rtStreamBufInit (&ctxt);
/* Step 2: Open the input stream to read data */
stat = rtStreamFileOpen (&ctxt, filename, OSRTSTRMF_INPUT);
if (stat != ASN_OK) {
rtErrPrint (&ctxt);
return stat;
}
for (;;) {
/* Step 3: Test message tag for type of message received */
/* (note: this is optional, the decode function can be */
/* called directly if the type of message is known).. */
stat = rtStreamBufMark (&ctxt, 32);
if (stat != ASN_OK) {
rtErrPrint (&ctxt);
return stat;
}
stat = berDecStrmTagAndLen (&ctxt, &msgtag, &msglen);
if (stat != ASN_OK) {
rtErrPrint (&ctxt);
return stat;
}
if (msgtag == TV_PersonnelRecord)
{
stat = rtStreamBufReset (&ctxt);
ASN1C V5.8
144