Procedure for Using the C++ Interface

SAX handler methods are added to the C++ control class generated for each ASN.1 production.

The procedure to invoke the generated decode method is similar to that for the other encoding rules. It is as follows:

  1. Instantiate an ASN.1 XER decode buffer object (ASN1XERDecodeBuffer) to describe the message to be decoded. Constructors exist that allow an XML file or memory buffer to be specified as an input source.

  2. Instantiate an ASN1T_TypeName object to hold the decoded message data.

  3. Instantiate an ASN1C_TypeName object to decode the message. This class associates the message buffer object with the object that is to receive the decoded data. The results of the decode operation will be placed in the variable declared in step 2.

  4. Invoke the ASN1C_TypeName object Decode method. This method initiates and invokes the XML parser’s parse method to parse the document. This, in turn, invokes the generated SAX handler methods.

  5. Release dynamic memory that was allocated by the decoder. All memory associated with the decode context is released when both the ASN1XERDecodeBuffer and ASN1C_TypeName objects go out of scope.

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

   int main (int argc, char* argv[])
   {
      const char* filename = "employee.xml";
      int stat;

      // steps 1, 2, and 3: instantiate an instance of the XER
      // decoding classes. This example specifies an XML file
      // as the message input source..

      ASN1T_PersonnelRecord employee;
      ASN1XERDecodeBuffer decodeBuffer (filename);
      ASN1C_PersonnelRecord employeeC (decodeBuffer, employee);

      // step 4: invoke the decode method

      stat = employeeC.Decode ();

      if (0 == stat) {
         employeeC.Print ("employee");
      }
      else
         decodeBuffer.printErrorInfo ();

      // step 5: dynamic memory is released when employeeC and
      // decode buffer objects go out of scope.

      return (stat);

   }