
Procedure for Using the C++ Control Class Decode Method
Normally when a message is received and read into a buffer, it can be one of several different message types. So the first job a programmer has before calling a decode function is determining which function to call. The ASN1BERDecodeBuffer class has a standard method for parsing the initial tag/length from a message to determine the type of message received. This call is used in conjunction with a switch statement on generated tag constants for the known message set in order to pick a decoder to call.
Once it is known which type of message has been received, an instance of a generated message class can be instantiated and the decode function called. The start of message pointer and message length (if known) must be specified either in the constructor call or in the call to the decode function itself.
#include employee.h // include file generated by ASN1C main () { OSOCTET msgbuf[1024]; ASN1TAG msgtag; int msglen, status; .. logic to read message into msgbuf .. // Use the ASN1BERDecodeBuffer class to parse the initial // tag/length from the message.. ASN1BERDecodeBuffer decodeBuffer (msgbuf, len); status = decodeBuffer.ParseTagLen (msgtag, msglen);if (status != 0) { // handle error ... } // Now switch on initial tag value to determine what type of // message was received.. switch (msgtag) { case TV_PersonnelRecord: // compiler generated constant { ASN1T_PersonnelRecord msgData; ASN1C_PersonnelRecord employee (decodeBuffer, msgData); if ((status = employee.Decode ()) == 0) { // decoding successful, data in msgData process received data.. } else error processing... } case TV_ ... // handle other known messagesNote that the call to free memory is not required to release dynamic memory when using the C++ interface. This is because the control class hides all of the details of managing the context and releasing dynamic memory. The memory is automatically released when both the message buffer object (ASN1BERMessageBuffer) and the control class object (ASN1C_<ProdName>) are deleted or go out of scope. Reference counting of a context variable shared by both interfaces is used to accomplish this.
Objective Systems, Inc.55 Dowlin Forge RoadExton, 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 |