Decode Method

The generated decode method for BER/DER has the following general form:

   public override void Decode (Asn1BerDecodeBuffer buffer,
                                bool explicitTagging, int implicitLength);

Users of the C and C++ version of the product might recognize this form. It is very similar to the C function prototype. A reference to an Asn1BerDecodeBuffer object is passed that specifies the message being decoded. This is similar to the context variable in the C version of the product.

The explicitTagging and implicitLength arguments should be of no concern to the average user. The explicitTagging argument should be set to true and the implicitLength argument set to zero. These arguments are only used in internal calls generated by the compiler when implicit tagging is used. In this case, the decoder will at times only be concerned with decoding the contents of a field and not the tag information. At the outer levels, it will always be necessary to decode a tag and length.

The C# decode method reports errors by throwing exceptions. This is a change from the C/C++ version that returned a status value. The Asn1Exception class is the base class for all exceptions defined for ASN1C. A complete list of these exceptions can be found in the ASN1C Exceptions section.

For PER, the signature is similar:

   public override void Decode (Asn1PerDecodeBuffer buffer);

In this case, the explicitTagging and implicitLength arguments are not required since PER has no tagging. The only required argument is a reference to a decode buffer object.

For XER or XML, the default behavior is to generate code using the System.Xml.XmlReader class to parse the XML. The following methods are generated:

  public void DecodeDocument(System.Xml.XmlReader reader)
  public void Decode(System.Xml.XmlReader reader, bool asGroup)
         

If -sax is specified on the command line, then the generated code uses the SAX API for parsing. In this case, two overloaded decode methods are generated:

   public override void Decode (System.Object reader, string xmlURI);

   public override void Decode (System.Object reader, Stream byteStream);

These take as arguments an XML reader object reference and a reference to an input source object. The XML reader object is a standard class within an XML parser that reads and parses an XML document. The input source can either be a URI (this can be a local filename) or an in-memory byte stream.