-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
275 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
# Aliases | ||
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: | ||
``` | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<schema ...> | ||
<message name="Msg1" id="0x1"> | ||
<int name="SomeField" type="uint32" /> | ||
... | ||
</message> | ||
</schema> | ||
``` | ||
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. | ||
``` | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<schema ...> | ||
<message name="Msg1" id="0x1"> | ||
<fields> | ||
<int name="SomeOtherField" type="uint32" /> | ||
... | ||
</fields> | ||
<alias name="SomeField" field="$SomeOtherField" /> | ||
</message> | ||
</schema> | ||
``` | ||
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 [<optional>](../fields/optional.md) field conditions. | ||
|
||
Quite often, in order to keep protocol backward compatible, developers convert | ||
existing numeric field into a [<bitfield>](../fields/bitfield.md) 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: | ||
``` | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<schema ...> | ||
<message name="Msg1" id="0x1"> | ||
<enum name="SomeEnum" type="uint8"> | ||
<validValue name="V1" val="0" /> | ||
<validValue name="V2" val="1" /> | ||
<validValue name="V3" val="2" /> | ||
</enum> | ||
... | ||
</message> | ||
</schema> | ||
``` | ||
When need arises to introduce new value the developer may decide to save I/O | ||
traffic reuse the same byte occupied by the `SomeEnum` field, like below. | ||
``` | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<schema ...> | ||
<message name="Msg1" id="0x1"> | ||
<bitfield name="F1" | ||
<enum name="SomeEnum" type="uint8" bitLength="2"> | ||
<validValue name="V1" val="0" /> | ||
<validValue name="V2" val="1" /> | ||
<validValue name="V3" val="2" /> | ||
</enum> | ||
<int name="SomeInt" type="uint8" bitLength="6" | ||
</bitfield> | ||
... | ||
</message> | ||
</schema> | ||
``` | ||
In order to keep old client code compiling it is possible to introduce | ||
alias to the `SomeEnum` member of the [<bitfield>](../fields/bitfield.md) | ||
like this: | ||
``` | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<schema ...> | ||
<message name="Msg1" id="0x1"> | ||
<fields> | ||
<bitfield name="F1" | ||
<enum name="SomeEnum" type="uint8" bitLength="2"> | ||
... | ||
</enum> | ||
<int name="SomeInt" type="uint8" bitLength="6" | ||
</bitfield> | ||
... | ||
</fields> | ||
<alias name="SomeEnum" field="$F1.SomeEnum" /> | ||
</message> | ||
</schema> | ||
``` | ||
There can be any number of different **<alias>** nodes. The elements | ||
that are allowed to have **<alias>**-es are [<message>](../messages/messages.md), | ||
[<interface>](../interfaces/interfaces.md), and [<bundle>](../fields/bundle.md). | ||
|
||
#### Description | ||
The **<alias>** node may also have **description** | ||
[property](../intro/properties.md) which is expected to find its way into | ||
the generated code as a comment for the relevant access functions. | ||
``` | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<schema ...> | ||
<message name="Msg1" id="1"> | ||
... | ||
<alias name="SomeField" field="SomeOtherField"> | ||
<description> | ||
Some long | ||
multiline | ||
description | ||
</description> | ||
</alias> | ||
</message> | ||
</schema> | ||
``` | ||
|
||
#### More on Aliases in <message>-es | ||
When a new [<message>](../messages/messages.md) is defined it can | ||
copy all the fields from other already defined [<message>](../messages/messages.md) | ||
(using **copyFieldsFrom** [property](../intro/properties.md)). | ||
By default all the [<alias>](../aliases/aliases.md) definitions are also copied. | ||
It is possible to modify this default behavior by using **copyFieldsAliases** | ||
[property](../intro/properties.md) with [boolean](../intro/boolean.md) value. | ||
``` | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<schema ...> | ||
<message name="Msg1" id="1"> | ||
... | ||
</message> | ||
<message name="Msg2" id="2" copyFieldsAliases="false"> | ||
... | ||
</message> | ||
</schema> | ||
``` | ||
|
||
#### More on Aliases in <interface>-es | ||
Similar to [<message>](../messages/messages.md)-es | ||
[<interface>](../interfaces/interfaces.md) can also use **copyFieldsFrom** | ||
[property](../intro/properties.md) to copy its field from some other | ||
[<interface>](../interfaces/interfaces.md) definition and have all | ||
the aliases copied by default. The control of such default copying behavior | ||
is also done by using **copyFieldsAliases** | ||
[property](../intro/properties.md) with [boolean](../intro/boolean.md) value. | ||
``` | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<schema ...> | ||
<interface name="Interface1"> | ||
... | ||
</interface> | ||
<interface name="Interface2" copyFieldsAliases="false"> | ||
... | ||
</interface> | ||
</schema> | ||
``` | ||
|
||
#### More on Aliases in <bundle>-es | ||
When a new [<bundle>](../fields/bundle.md) field is defined it can | ||
reuse definition of already defined other [<bundle>](../fields/bundle.md) | ||
(using **reuse** [property](../intro/properties.md)). | ||
By default all the [<alias>](../aliases/aliases.md) definitions are also copied. | ||
It is possible to modify this default behavior by using **reuseAliases** | ||
[property](../intro/properties.md) with [boolean](../intro/boolean.md) value. | ||
``` | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<schema ...> | ||
<fields> | ||
<bundle name="B1"> | ||
... | ||
<alias .../> | ||
<alias .../> | ||
</bundle> | ||
<bundle name="B2" reuse="B1" reuseAliases="false"> | ||
... | ||
</bundle> | ||
</fields> | ||
</schema> | ||
``` | ||
|
||
Use [properties table](../appendix/alias.md) for future references. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## Properties of <alias> | ||
Refer to [Aliases](../aliases/aliases.md) chapter for detailed description. | ||
Introduced in DSL version **3**. | ||
|
||
|Property Name|Allowed type / value|DSL Version|Required|Default Value|Description| | ||
|:-----------:|:------------------:|:---------:|:------:|:-----------:|-----------| | ||
|**name**|[name](../intro/names.md) string|3|yes||Name of the alias.| | ||
|**description**|string|3|no||Human readable description of the alias.| | ||
|**field**|relative [reference](../intro/references.md) string|3|yes||Reference to the aliased field, must start with `$` character.| | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
## Properties of <bundle> Field | ||
The **<bundle>** field has all the [common](fields.md) properties. | ||
Refer to [<bundle> Field](../fields/bundle.md) chapter | ||
The **<bundle>** field has all the [common](fields.md) properties as | ||
well as ones listed below. Refer to [<bundle> Field](../fields/bundle.md) chapter | ||
for detailed description. | ||
|
||
The **<bundle>** field also allows listing of member fields using | ||
**<members>** child XML element. | ||
|Property Name|Allowed type / value|DSL Version|Required|Default Value|Description| | ||
|:-----------:|:------------------:|:---------:|:------:|:-----------:|-----------| | ||
|**reuseAliases**|[bool](../intro/boolean.md)|3|no|true|Control copy of the defined [aliases](../aliases/aliases.md) from reused other [<bundle>](../fields/bundle.md) when **reuse** property is used.| | ||
|
||
Extra child XML elements allowed: | ||
|
||
|XML Element|DSL Version|Description| | ||
|:---------:|:---------:|-----------| | ||
|**<members>**|1|Wraps member fields.| | ||
|**<alias>**|3|Alias names for other member fields. See [Aliases](../aliases/aliases.md) for more info.| | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"title" : "CommsDSL Specification", | ||
"author" : "Alex Robenko ([email protected])" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters