TOC PREV NEXT INDEX


Procedure for Using the C++ Control Class Encode Method



The procedure to encode a message using the C++ class interface is as follows:








A program fragment that could be used to encode an employee record is as follows:

    #include employee.h         // include file generated by ASN1C
 

 
    main ()
 
    {
 
        const OSOCTET* msgptr;
 
        OSOCTET msgbuf[1024];
 
        int     msglen, stat;
 
        OSBOOL  canonical = FALSE;
 

 
        // step 1: instantiate an instance of the XER encode 
 
        // buffer class.  This example specifies a static 
 
        // message buffer..
 

 
        ASN1XEREncodeBuffer encodeBuffer (msgbuf, 
 
                                          sizeof(msgbuf), 
 
                                          canonical);
 

 
        // 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 Road
Exton, 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
TOC PREV NEXT INDEX