Download Procedure for Calling C Decode Functions

Transcript
Generated Streaming C++ Encode
Method Format and Calling Parameters
#include employee.h
// include file generated by ASN1C
int main ()
{
int
stat;
OSCTXT
ctxt;
Employee employee;/* typedef generated by ASN1C */
const char* filename = “message.dat”;
/* Step 1: Initialize the context and stream */
if (berStrmInitContext (&ctxt) != 0) {
/* initialization failed, could be a license problem */
printf (“context initialization failed (check license)\n”);
return –1;
}
stat = rtxStreamFileCreateWriter (&ctxt, filename);
if (stat != 0) {
rtxErrPrint (&ctxt);
return stat;
}
for (;;) {
/* Step 2: Populate the structure to be encoded */
employee.name = "SMITH";
...
/* Step 3: Call the generated encode function */
stat = asn1BSE_Employee (&ctxt, &employee, ASN1EXPL);
/* Step 4: Check the return status and break the loop
if error occurs */
if (stat != 0) {
...error processing...
break;
}
}
/* Step 5: Close the stream */
rtxStreamClose (&ctxt);
}
Generated Streaming C++ Encode Method Format and Calling Parameters
C++ code generation of stream-based encoders is selected by using the –c++ and –stream compiler command line options. In this case, ASN1C generates an EncodeTo method that wraps the
C function call. This method provides a more simplified calling interface because it hides things
such as the context structure and tag type parameters.
161