Generated Class Definition
A class definition is generated for each defined production in the ASN.1 source file. This class is derived from the ASN1CType base class. This class provides a set of common attributes and methods for encoding/decoding ASN.1 messages. It hides most of the complexity of calling the encode/decode functions directly.
class ASN1C_<name> : public ASN1CType { protected: ASN1T_<name>& msgData; public: ASN1C_<name> (ASN1MessageBuffer& msgBuf, ASN1T_<name>& data); int Encode (); int Decode (); } ;The name of the generated class is `ASN1C_<name>' where `<name>' is the name of the production. The only defined attribute is a public variable reference named `msgData' of the generated type.
The constructor arguments are a reference to an `ASN1MessageBuffer' type and a reference to an `ASN1T_<name>' type. The message buffer argument is a class defined in either the Asn1BerCppTypes.h or Asn1PerCppTypes.h. There are special subclasses for encoding (ASN1BEREncodeBuffer or ASN1PEREncodeBuffer) and decoding (ASN1BERDecodeBuffer and ASN1PERDecodeBuffer). Variables of either of these subclasses can be passed to the constructor depending on whether encoding or decoding is to be performed. The purpose of the buffer objects is to wrap all of the internal values required to manage encode or decode buffers. Examples of using this object can be found in the section on Encoding and Decoding messages.
The `ASN1T_<name>' argument is used to specify the data variable containing data to be encoded or to receive data on a decode call. The procedure for encoding is to declare a variable of this type, populate it with data, and then instantiate the ASN1C_<name> object to associate a message buffer object with the data to be encoded. The Encode method can then be called to encode the data. On the decode side, a variable must be declared and passed to the constructor to receive the decoded data.
Note that the ASN1C_ class declarations are only required in the application code as an entry point for encoding or decoding a top-level message (or Protocol Data Unit - PDU). Identifying these PDUs and declaring them in a configuration file using the <isPDU/> empty element can attain large savings in the amount of code generated for a particular application. For example, in some H.323 applications, the main PDU structure used is H323-UserInformation. The following configuration file entry could be used to only generate the ASN1C_ control class for this PDU:
<asn1config> <module> <name>H323-MESSAGES</name> <production> <name>H323-UserInformation</name> <isPDU/> </production> </module> </asn1config>This will cause only a single ASN1C_ class definition to be added to the generated code - that for the H323-UserInformation production. If this information was not included an ASN1C_ class would be generated for all productions and the vast majority of them would never be used.
If the module contains no PDUs (i.e,. contains support types only), the <noPDU/> empty element can be specified at the module level to indicate that no control classes should be generated for the module.
class ASN1C_<name> : public ASN1CType, ASN1XERSAXHandler { protected: ASN1T_<name>& msgData; ... additional control variables public: ASN1C_<name> (ASN1MessageBuffer& msgBuf, ASN1T_<name>& data); int Encode (); int Decode (); // SAX Content Handler Interface virtual void startElement (const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attrs); virtual void characters (const XMLCh* const chars, const unsigned int length); virtual void endElement (const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname); } ;
This allows an object of this class to be registered as a SAX content handler with any SAX-compliant XML parser. The parser would be used to read and parse XML documents. The methods generated by ASN1C would then receive the parsed data via the SAX interface and use the results to populate the data variables with the decoded data.
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 |