
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:
- Create an ASN1BEROutputStream inherited object.
- Create a variable of the ASN1T_<name> type and populate it with the data to be encoded.
- Create a variable of the generated ASN1C_<name> class specifying the item created in 2 as an argument to the constructor.
- Invoke the EncodeTo method or << operator.
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 #506Exton, 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 |