Encode Method

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

   public int encode (Asn1BerEncodeBuffer buffer, boolean explicit);

The Asn1BerEncodeBuffer argument specifies the buffer into which the message will be encoded. The explicit argument is primarily for use by the compiler for generating internal calls to handle implicitly tagged elements in constructed types. Users should always set this argument to true.

The encode method returns the length of the encoded component. Unlike the C /C++ version, this return value does no double as a status value as well. Any errors that occur in the encode process are reported by throwing an ASN1C exception. A complete list of these exceptions can be found in the ASN1C Exceptions section.

The general form of a PER encode method is as follows:

   public void encode (Asn1PerEncodeBuffer buffer);

In this case, the explicit argument is not required since PER has no tagging. The only required argument is a reference to an encode buffer object. Also note that the return value is void instead of int. No intermediate lengths are returned during the encoding of a PER message. Any errors that occur are reported as an exception; hence there I no need for a return value.

The general form of an XER or XML encode method is as follows:

   public void encode (Asn1XerEncoder buffer, String elemName);

In this case, the buffer reference is to an XER encoder object and an element name argument is added. The Asn1XerEncoder reference is to an interface that allows either a message buffer or output stream object to be passed into the method. In the case of XML, this object reference would be to an Asn1XmlEncoder interface.

The element name is the name of the element that is to bracket the XML encoded value (i.e. <elemName>value</ elemName>).

The method return type is void because errors are reported through the exception mechanism.

The general form of an OER encode method is as follows:

   public void encode (Asn1OerEncodeBuffer buffer)
            throws java.io.IOException