Encoding a Series of Messages Using the Stream-Oriented C Encode Functions
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.
Encoding a series of messages using the stream-oriented C encode functions is very similar to encoding of one message. All that is necessary is to set up a loop in which the asn1BSE_<name> functions will be called. It is also possible to call different asn1BSE_<name> functions one after another. An example showing how to do this is as follows:
#include employee.h // include file generated by ASN1C int main () { int stat; ASN1CTXT ctxt; Employee employee; /* typedef generated by ASN1C */ const char* filename = "message.dat"; /* Step 1: Initialize the context and stream */ if (rtInitContext (&ctxt) != ASN_OK) { /* initialization failed, could be a license problem */ printf ("context initialization failed (check license)\n"); return -1; } rtStreamBufInit (&ctxt); stat = rtStreamFileOpen (&ctxt, filename, OSRTSTRMF_OUTPUT); if (stat != ASN_OK) { xu_perror (&ctxt); return stat; } for (;;) { /* Step 2: Populate the structure to be encoded */ employee.name.numocts = 5; employee.name.data = "SMITH"; ... /* Step 3: Call the generated encode function */ stat = asn1BSE_Employee (&ctxt, &employee, ASN1EXPL); /* Step 4: Check the return status and break the loop if error occurs */ if (stat != ASN_OK) { ...error processing... break; } }/* Step 5: Close the stream */ rtStreamBufClose (&ctxt); }
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 |