It is not uncommon for a particular field to change its meaning and as the result to change its name over time when the protocol evolves. Simple change of the name in the schema may result in various compilation errors of old client code when new version of the protocol definition library is released. To help with such case the CommsDSL introduces an ability to create alias names for the existing fields.
For example let's assume there is some message definition like the one below:
In case there is a need to rename the SomeField name to be SomeOtherField, then the message definition can add an <alias> with the old name to the renamed field in order to keep the old client code compiling.
In such case the code generator must allow access of the renamed field by both old and new names.
Note that the message fields must be bundled in <fields> XML element in order to allow usage of non-field definition <alias> XML child of the <message> node.
Also note that value of the field property of the <alias> element must start with $ character to indicate that the referenced field is a sibling one, similar to field conditions.
Quite often, in order to keep protocol backward compatible, developers convert existing numeric field into a when need arises to add some extra field to the message. For example, let's assume there was an enum field with limited number of valid values:
In order to keep old client code compiling it is possible to introduce alias to the SomeEnum member of the like this:
There can be any number of different <alias> nodes. The elements that are allowed to have <alias>-es are , , and .
The <alias> node may also have description which is expected to find its way into the generated code as a comment for the relevant access functions.
When a new is defined it can copy all the fields from other already defined (using copyFieldsFrom ). By default all the definitions are also copied. It is possible to modify this default behavior by using copyFieldsAliases with value.
Similar to -es can also use copyFieldsFrom to copy its field from some other definition and have all the aliases copied by default. The control of such default copying behavior is also done by using copyFieldsAliases with value.
When a new field is defined it can reuse definition of already defined other (using reuse ). By default all the definitions are also copied. It is possible to modify this default behavior by using reuseAliases with value.