
Procedure for Using the C++ Control Class Encode Method
- Check the return status. The return value is a status value indicating whether encoding was successful or not. Zero indicates success. If encoding failed, the status value will be a negative number. The encode buffer method printErrorInfo can be invoked to get a textual explanation and stack trace of where the error occurred.
- If encoding was successful, get the start-of-message pointer and message length. The start-of-message pointer is obtained by calling the getMsgPtr method of the encode buffer object. If static encoding was specified (i.e., a message buffer address and size were specified to the XML Encode Buffer class constructor), the start-of-message pointer is the buffer start address. The message length is obtained by calling the getMsgLen method of the encode buffer object.
#include employee.h // include file generated by ASN1C main () { OSOCTET msgbuf[4096]; int msglen, stat; // step 1: instantiate an instance of the XML encode // buffer class. This example specifies a static // message buffer.. OSXMLEncodeBuffer encodeBuffer (msgbuf, sizeof(msgbuf)); // step 2: populate msgData with data to be encoded ASN1T_PersonnelRecord msgData; msgData.name.givenName = "SMITH"; ... // step 3: instantiate an instance of the ASN1C_<ProdName> // class to associate the encode buffer and message data.. ASN1C_PersonnelRecord employee (encodeBuffer, msgData); // steps 4 and 5: encode and check return status if ((stat = employee.Encode ()) == 0) { printf ("encoded XML message:\n"); printf ((const char*)msgbuf); printf ("\n"); // step 6: get start-of-message pointer and message length. // start-of-message pointer is start of msgbuf // call getMsgLen to get message length.. msgptr = encodeBuffer.getMsgPtr (); // will return &msgbuf len = encodeBuffer.getMsgLen (); } else { printf ("Encoding failed\n"); encodeBuffer.printErrorInfo (); exit (0); } // msgptr and len now describe fully encoded message ...
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 |