TOC PREV NEXT INDEX


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



The procedure to encode a message directly to an output stream 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"
 

 
      // step 1: construct output stream object. 
 

 
      ASN1BERFileOutputStream out (filename);
 
      if (out.getStatus () != ASN_OK) {
 
         out.printErrorInfo ();
 
         return -1;
 
      }
 

 
      // 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).
 

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

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

 
      // step 5: check status of the operation
 

 
      if (out.getStatus () != ASN_OK) {
 
         printf ("Encoding failed. Status = %i\n", out.getStatus());
 
         out.printErrorInfo ();
 
         return -1;
 
      }
 

 
      if (trace) {
 
         printf ("Encoding was successful\n");
 
      }
 
   }
 



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