Header (.h) File
The generated C or C++ include file contains a section for each ASN.1 production defined in the ASN.1 source file. Different items will be generated depending on whether the selected output code is C or C++. In general, C++ will add some additional items (such as a control class definition) onto what is generated for C.
- Tag value constant
- Choice tag constants (CHOICE type only)
- Named bit number constants (BIT STRING type only)
- Enumerated type option values (ENUMERATED or INTEGER type only)
- C type definition
- Encode function prototype
- Decode function prototype
- Other function prototypes depending on selected options (for example, print)
- C++ control class definition (C++ only)
/**************************************************************/ /* */ /* EmployeeNumber */ /* */ /**************************************************************/ #define TV_EmployeeNumber (TM_APPL|TM_PRIM|2) typedef ASN1INT EmployeeNumber; EXTERN int asn1E_EmployeeNumber (ASN1CTXT* pctxt, EmployeeNumber *pvalue, ASN1TagType tagging); EXTERN int asn1D_EmployeeNumber (ASN1CTXT* pctxt, EmployeeNumber *pvalue, ASN1TagType tagging, int length);EmployeeNumber ::= [APPLICATION 2] IMPLICIT INTEGERIn this definition, TV_EmployeeNumber is the tag constant. Doing a logical OR on the class, form, and identifier fields forms this constant. This constant can be used in a comparison operation with a tag parsed from a message.
typedef ASN1INT EmployeeNumber;declares EmployeeNumber to be of an integer type (note: ASN1INT and other primitive type definitions can be found in the asn1type.h header file).
asn1E_EmployeeNumber and asn1D_EmployeeNumber are function prototypes for the encode and decode functions respectively. These are BER function prototypes. If the -per switch is used, PER function prototypes are generated. The PER prototypes begin with the prefix asn1PE_ and asn1PD_ for encoder and decoder respectively. XER function prototypes begin with asn1XE_ and asn1XD.
/**************************************************************/ /* */ /* EmployeeNumber */ /* */ /**************************************************************/ #define TV_EmployeeNumber (TM_APPL|TM_PRIM|2) typedef ASN1INT ASN1T_EmployeeNumber; class EXTERN ASN1C_EmployeeNumber : public ASN1CType { protected: ASN1T_EmployeeNumber& msgData; public: ASN1C_EmployeeNumber (ASN1T_EmployeeNumber& data); ASN1C_EmployeeNumber ( ASN1MessageBufferIF& msgBuf, ASN1T_EmployeeNumber& data); // standard encode/decode methods (defined in ASN1CType base class): // int Encode (); // int Decode (); // stream encode/decode methods: int EncodeTo (ASN1MessageBufferIF& msgBuf); int DecodeFrom (ASN1MessageBufferIF& msgBuf); } ; EXTERN int asn1E_EmployeeNumber (ASN1CTXT* pctxt, ASN1T_EmployeeNumber *pvalue, ASN1TagType tagging); EXTERN int asn1D_EmployeeNumber (ASN1CTXT* pctxt, ASN1T_EmployeeNumber *pvalue, ASN1TagType tagging, int length);
ASN1C_EmployeeNumber is the control class declaration. The purpose of the control class is to provide a linkage between the message buffer object and the ASN.1 typed object containing the message data. The class provides methods such as EncodeTo and DecodeFrom for encoding and decoding the contents to the linked objects. It also provides other utility methods to make populating the typed variable object easier.
ASN1C always adds an ASN1C_ prefix to the production name to form the class name. Most generated classes are derived from the standard ASN1CType base class defined in asn1Message.h. The following ASN.1 types cause code to be generated from different base classes:
- BIT STRING - The generated control class is derived from the ASN1CBitStr class
- SEQUENCE OF or SET OF with linked list storage - The generated control class is derived from the ASN1CSeqOfList base class.
- Defined Type - The generated control class for defined types is derived from the generated base class for the reference type. For example, if we have A ::= INTEGER and B ::= A, then B is a defined type and would inherit from the base class generated for A (class ASN1C_B : public ASN1C_A { ... ).
These intermediate classes are also derived from the ASN1CType base class. Their purpose is the addition of functionality specific to the given ASN.1 type. For example, the ASN1CBitStr control class provides methods for setting, clearing and testing bits in the referenced bit string variable.
In the generated control class, the msgData member variable is a reference to a variable of the generated type. The constructor takes two arguments - an Asn1MessageBufferIF (message buffer interface) object reference and a reference to a variable of the data type to be encoded or decoded. The message buffer object is a work buffer object for encoding or decoding. The interface reference can also be used to specify a stream. Stream classes are derived from this same base class. The data type reference is a reference to the `ASN1T_' variable that was generated for the data type.
Encode and Decode methods are declared that wrap the respective compiler generated C encode and decode functions. Command-line options may cause additional methods to be generated. For example, if the -print command line argument was specified; a Print method is generated to wrap the corresponding C print function.
Specification of the XML encoding rules option (-xer) causes a number of additional methods to be generated for constructed types. These additional methods are implementations of the standard Simple API for XML (SAX) content handling interface used to parse content from XML messages. The startElement, characters, and endElement methods are implemented as well as additional support methods. The control class is also defined to inherit from the ASN1XERSAXHandler base class as well as ASN1CType (or one of its descendents).
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 |