Chapter 8. Generated PER Encode Methods

Table of Contents

Generated Java Method Format and Calling Parameters
Procedure for Calling Java PER Encode Methods
Reuse of Java Encoding Objects

The generation of methods to encode data in accordance with the Packed Encoding Rules (PER) is similar to how methods were generated in the BER/DER case discussed previously. For each ASN.1 production defined in the ASN.1 source file, a Java encode method may be generated. This function will convert a populated variable of the given type into an encoded ASN.1 message.

An encode method is only generated if it is required to alter the encoding of the base class method. The Java model is built on inheritance from a set of common run-time base classes. These run-time classes contain default implementations of encode/decode methods that handle the encoding/decoding of the basic types.

For simple assignments, the generation of an encode method is not necessary. For example, the following production will not result in the generation of an encode method:

   X ::= INTEGER

In this case, the generated Java class extends the Asn1Integer base class and the default encode method within this class is sufficient to encode a value of the generated type.

In the case of BER/DER, a custom encode method was generated if a) the type was tagged, or b) it contained a testable constraint. In the case of PER, only the latter condition will cause a custom method to be generated. The reason is because PER basically ignores the tags on tagged types and they therefore have no effect on the final decoded message component.

For example, the following declaration will cause a custom encode method to be generated because the value range constraint is a PER-visible that will alter the encoding:

   X ::= INTEGER (1..255)

In this case, special logic is necessary to apply the value range constraint.

Some types will always cause encode methods to be generated. At the primitive level, this is true for the ENUMERATED type. This type will always contain a custom set of enumerated values. All constructed types (SEQUENCE, SET, SEQUENCE/SET OF, and CHOICE) will cause encode methods to be added to the generated classes.