TOC PREV NEXT INDEX


Encoding a Series of Messages Using the Stream-Oriented C Encode Functions



A common application of BER encoding is the repetitive encoding of a series of the same type of message over and over again. For example, a TAP3 batch application might read billing data out of a database table and encode each of the records for a batch transmission.

Encoding a series of messages using the stream-oriented C encode functions is very similar to encoding of one message. All that is necessary is to set up a loop in which the asn1BSE_<name> functions will be called. It is also possible to call different asn1BSE_<name> functions one after another. An example showing how to do this is as follows:

    #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);
 
   }
 


Objective Systems, Inc.

55 Dowlin Forge Road
Exton, Pennsylvania 19341
http://www.obj-sys.com
Phone: (484) 875-9841
Toll-free: (877) 307-6855 (US only)
Fax: (484) 875-9830
info@obj-sys.com
TOC PREV NEXT INDEX