BER/DER Deferred Decoding

Another way to improve decoding performance of large messages is through the use of deferred decoding. This allows for the selective decoding of only parts of a message in a single decode function call. When combined with the fast copy procedure defined above, this can significantly reduce decoding time because large parts of messages can be skipped.

Deferred decoding can be done on elements defined within a SEQUENCE, SET or CHOICE construct. It is done by designating an element to be an open type by using the <isOpenType/> configuration setting. This setting causes the ASN1C compiler to insert an Asn1OpenType placeholder in place of the type that would have normally been used for the element. The data in its original encoded form will be stored in the open type container when the message is decoded. If fast copy is used, only a pointer to the data in the message buffer is stored so large copies of data are avoided.

The data within the deferred decoding open type container can be fully decoded later by using a special decode function generated by the ASN1C compiler for this purpose. The format of this function is as follows:

   asn1D_<ProdName>_<ElementName>_OpenType (OSCTXT* pctxt, <ElementType>* pvalue)

Here <ProdName> is replaced with name of the type assignment and <ElementName > is replaced with name of the element. In this function, the argument pctxt is used to pass the a pointer to a context variable initialized with the open type data and the pvalue argument will hold the final decoded data value.

In following example, decoding of the element id is deferred:

   Identifier ::= SEQUENCE {
      id INTEGER,
      oid OBJECT IDENTIFIER
   }

The following configuration file is required to indicate the element id is to be processed as an open type (i.e. that it will be decoded later):

   <asn1config>
      <module>
         <name>modulename</name>
         <production>
            <name>Identifier</name>
            <element>
               <name>id</name>
               <isOpenType/>
            <element/>
         <production/>
      <module/>
   <asn1config/>

In the generated code, the element id type will be replaced with an open type (Asn1OpenType for C or Asn1TOpenType for C++) and the following additional function is generated:

   EXTERN int asn1D_Identifier_id_OpenType (OSCTXT* pctxt, OSINT32* pvalue);

In the Identifier decode function, element id is decoded as an open type.