Generated Compare Functions

The -genCompare option causes comparison functions to be generated. These functions can be used to compare the contents of two generated type variables.

If an output file is not specified with the –genCompare qualifier, the functions are written to separate .c files for each module in the source file. The format of the name of each file is <module>Compare.c. If an output filename is specified after the –genCompare qualifier, all functions are written to that file.

The format of the name of each generated compare function is as follows:

   asn1Compare_[<prefix>]<prodName>

where <prodName> is the name of the ASN.1 production for which the function is being generated and <prefix> is an optional prefix that can be set via a configuration file setting. The configuration setting used to set the prefix is the <typePrefix> element. This element specifies a prefix that will be applied to all generated typedef names and function names for the production.

The calling sequence for each generated compare function is as follows:

   OSBOOL asn1Compare_<name> (const char* name,
                              <name>* pvalue, <name>* pCmpValue,
                              char* errBuff, int errBufSize);

In this definition, <name> denotes the prefixed production name defined above.

The name argument is used to hold the top-level name of the variable being compared. It is typically set to the same name as the pvalue argument in quotes (for example, to compare employee records, a call to ‘asn1Compare_Employee (“employee”, &employee, etc.)’ might be used).

The pvalue argument is used to pass a pointer to a variable of the item to the first item to be compared. The pCmpValue argument is used to pass the second value. The two items are then compared field-by-field for equality.

The errBuff and errBuffSize arguments are used to describe a text buffer into which information on what fields the comparison failed on is written. These arguments specify a fixed-size buffer – if the generated text is larger than the given buffer size, the text is terminated. These arguments may be omitted by passing null (0) values if you only care to know if the structures are different and not concerned with the details.

The return value of the function is a Boolean value that is true if the variables are equal and false if they are not.