TOC PREV NEXT INDEX


Procedure for Using the Stream-Oriented C++ Control Class Encode Method



The procedure to stream-oriented encode a message using the C++ class interface is as follows:


A program fragment that could be used to encode an employee record is as follows. This example uses a file output stream:

   #include employee.h         // include file generated by ASN1C
 

 
   main ()
 
   {
 
      int msglen;
 
      const char* filename = "message.dat"
 

 
      try {
 
         // step 1: construct output stream object. 
 

 
         ASN1BERFileOutputStream out (filename);
 

 
         try {
 
            // step 2: construct ASN1C C++ generated class.
 

 
            ASN1T_PersonnelRecord msgData;
 
            ASN1C_PersonnelRecord employee (msgData);
 

 
            // step 3: populate msgData structure with data to be
 
            // encoded. (note: this uses the generated assignment
 
            // operator to assign a string).
 

 
            employee.msgData.name = "SMITH";
 
            ...
 
            // step 4: invoke << operator or EncodeTo method
 

 
            out << employee; 
 
            // or employee.EncodeTo (out); can be used here.
 

 
            if (trace) {
 
               printf ("Encoding was successful\n");
 
            }
 
         }
 
         catch (ASN1RTLException& ex) {
 
            printf ("Encoding failed. Status = %i\n", 
 
            ex.getStatus());
 
            out.printErrorInfo ();
 

 
            ...error processing...
 

 
            exit (-1);
 
         }
 
         catch (ASN1RTLException& ex) {
 
         printf ("Exception thrown: Status = %i\n", ex.getStatus());
 
         return -1;
 
      }
 
   }
 


Objective Systems, Inc.

102 Pickering Way, Suite #506
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