Run-time and Generated Python Encode Methods

Three types of Python encode functions/methods are available for encoding different types of data. These are:

The signature for a Standard base run-time method in the Asn1BerEncodeBuffer is as follows:

def encode_* (self, value, explicit=True)

where * would be a primitive type name (boolean, integer, etc.).

The self argument is a reference to the Asn1BerEncodeBuffer object from which it was invoked (note that in Python, this argument is not explicitly passed, it refers to the object invoking the method). The value argument is the value to be encoded. The explicit argumnet is a boolean argument indicating if the universal tag and length associated with the primitive type should be applied on top of the encoded content.

The return value is the length in octets of the encoded message component. Unlike the C/C++ version, a negative value is never returned to indicate an encoding failure. That is handled by the Python exception mechanism.

The signature for a static BER encode method in a class generated for a primitive type is as follows:

    @staticmethod
    def ber_encode(value, encbuf, explicit=True):

In this case, there is no 'self' argument. A reference to the encode buffer object is passed as a formal argument in the 2nd position. The value and explicit arguments are as they were in standard base run-time method case and the return value is also the same (the encoded length).

The signature for an instance BER encode method in a class generated for a constructed type is as follows:

    def ber_encode(self, encbuf, explicit=True)

The self argument is a reference to an object of the generated class (note that in Python, this argument is not explicitly passed, it refers to the object invoking the method). >The encbuf argument is a reference to BER encode buffer object to be used to encode the data. The explicit argument is that same as in the other two cases.