Encoding a Series of Messages Using the Stream-Oriented C++ Control Class Interface
Encoding a series of messages using the stream-oriented C++ control class is similar to the C method of encoding. All that is necessary is to create a loop in which EncodeTo or Encode methods will be called (or the overloaded << streaming operator). It is also possible to call different EncodeTo methods (or Encode or operator <<) one after another. An example showing how to do this is as follows:
#include employee.h // include file generated by ASN1C int main () { const ASN1OCTET* msgptr; ASN1OCTET msgbuf[1024]; int msglen; const char* filename = "message.dat" try { // step 1: construct stream object. ASN1BERFileOutputStream out (filename); try { // step 2: construct ASN1C C++ generated class. ASN1T_PersonnelRecord msgData; ASN1C_PersonnelRecord employee (msgData); for (;;) { // 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 #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 |