Encode Method

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

   public override int Encode (Asn1BerEncodeBuffer buffer, bool explicitTagging);

The Asn1BerEncodeBuffer argument specifies the buffer into which the message will be encoded. The explicitTagging 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 not 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 override void Encode (Asn1PerEncodeBuffer buffer);

In this case, the explicitTagging 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 is no need for a return value.

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

   public override void Encode (Asn1XerEncodeBuffer buffer, string elemName);

In this case, the buffer reference is to an XER encode buffer and an element name argument is added. The element name is the name of the element that is to bracket the XML encoded value (i.e. <elemName>value</elemName>). The return type is also void as in the PER case because errors are reported through the exception mechanism.

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

   public override void Encode (Asn1OerEncodeBuffer buffer);