
Encoding a Series of Messages Using the C++ Control Class Interface
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.
If a user was to repeatedly instantiate and destroy the C++ objects involved in the encoding of a message, performance would suffer. This is not necessary however, because the C++ objects can be reused to allow multiple messages to be encoded. As example showing how to do this is as follows:
#include employee.h // include file generated by ASN1C main () { const OSOCTET* msgptr; OSOCTET msgbuf[1024]; int msglen; ASN1BEREncodeBuffer encodeBuffer (msgbuf, sizeof(msgbuf)); ASN1T_PersonnelRecord msgData; ASN1C_PersonnelRecord employee (encodeBuffer, msgData); // Encode loop starts here, this will repeatedly use the // objects declared above to encode the messages for (;;) { // logic here to read record from some source (database, // flat file, socket, etc.)..// populate structure with data to be encoded msgData.name = "SMITH"; ... // invoke Encode method if ((msglen = employee.Encode ()) > 0) { // encoding successful, get pointer to start of message msgptr = encodeBuffer.getMsgPtr(); // do something with the encoded message... } else error processing... // Call the init method on the encodeBuffer object to // prepare the buffer for encoding another message.. encodeBuffer.init(); } }
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 |