Decode Method

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

   public void decode (Asn1BerDecodeBuffer buffer,
                       boolean explicit, 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 explicit and implicitLength arguments should be of no concern to the average user. The explicit 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 Java decode method reports errors by throwing exceptions. This is a change from the C/C++ version that returned a status value. The method signature includes the following throws clause:

   throws Asn1Exception, java.io.IOException

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 void decode (Asn1PerDecodeBuffer buffer);

In this case, the explicit 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 org.xmlpull.v1.XmlPullParser class to parse the XML. Other parsers can be specified using -stax or -sax. When the XmlPull API is used, the following methods are generated:

   public void decodeDocument(org.xmlpull.v1.XmlPullParser reader)
            
   public void decode(org.xmlpull.v1.XmlPullParser reader, boolean asGroup)

If -stax is specified on the command line, the signatures change slightly:

   public void decodeDocument(javax.xml.stream.XMLStreamReader reader)
                        throws Asn1Exception, javax.xml.stream.XMLStreamException

   public void decode(javax.xml.stream.XMLStreamReader reader, boolean asGroup)
                        throws Asn1Exception, javax.xml.stream.XMLStreamException   

If -sax is specified on the command line, the SAX API is used and two overloaded decode methods are generated:

   public void decode (XMLReader reader, String xmlURI);

   public void decode (XMLReader reader, InputStream 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.

For OER, the decode signature is:

   public void decode(Asn1OerDecodeBuffer buffer)
                           throws java.io.IOException