Referencing Values of Other Fields
Last updated
Was this helpful?
Last updated
Was this helpful?
Quite often there is a need to reuse (or reference) some other values already defined and used for some other fields. The v1 of this specification allowed referencing the external validValue-s only, while v2 of this specification extends such functionality to other fields as well. In general, when the other field is referenced its defaultValue is taken, unless inner value is referenced, such as validValue of the field or special value of the field.
Any specified <validValue> can be referenced by other numeric fields (not only <enum>) when specifying value of some property. To reference it, the <enum> name must be specified followed by a . (dot) and name of the chosen <validValue>
In the example above the defaultValue of the SomeIntField will be 5.
When is referenced by its name, its defaultValue is taken.
In the example above the defaultValue of the SomeIntField is 10, the value of the S1 special is 5 (equals to defaultValue of SomeEnumField), and value of the S2 special is 0.
In the example above defaultValue of SomeEnumField is 0, validValue Val1 equals to 5, and validValue Val2 equals to 10.
Also the defaultValue of SomeFloatField is 5.0, while value of its S1 special is 10.0.
In the example above the defaultValue of SomeOtherSetField is false (same as defaultValue of SomeSetField), the reservedValue of SetOtherField is true (same as defaultValue of SomeSetField.B0), and the defaultValue of SomeOtherSetField.B5" is false (same as defaultValue of SomeSetField.B1*).
The definition above will result in defaultValue of SomeFloatField to be 1.0.
In the example above defaultValue of SomeOtherFloatField is inf, while value of SomeOtherFloatField.S1 special is nan.
In the example above the defaultValue of SomeOtherString field is hello.
If there is a need to define a genuine string value that starts with ^
character, then there is a need to escape it with \
.
In the example above the defaultValue of SomeOtherString field is ^SomeString.
The question may arise what if a genuine value string needs to start with \^
. In this case just add additional \
at the front.
In the example above the defaultValue of SomeOtherString field is \^SomeString.
The bottom line: any prefix sequence of \
followed by the ^
will result in drop of one \
in the final string value. In case there is any other character used in the middle, the string value remains as is.
In the example above the defaultValue of String1 field is \SomeString because there is no ^
character after \
and the defaultValue of String2 field is .\^SomeString because the sequence of \
is interrupted by .
.
In the example above the displayName property of a message is expected to be the same as displayName property of appropriate ≶validValue> of MsgId enum. Referencing common value insures that the change to the name (if happens) propagates to appropriate fields.
The defaultValue of SomeOtherData will be 0x12 0x34 0x56
.
In the example above the defaultValue of SomeOtherInt is 5, same as the value of SomeInt.S1.
In the example above the defaultValue of SomeIntField is 5.
NOTE that there is a need to reference internal member field by name.
Floating point fields can also reference values defined in fields.
Similar to the inner value of field can be referenced by other numeric fields.
The defaultValue property of any element of the field can also be referenced.
Other numeric fields, such as , , and can also reference boolean values of , which will result in numeric values been either 0 or 1.
Similar to it is possible to reference values used in defaultValue property and/or as <special> value.
When referencing values of fields there is a need to differentiate between a reference to external field and a genuine string value. To do so the ^
prefix was introduced. If a property value, that requires a string, starts with ^
it means external reference and error must be reported if referenced field is not found.
NOTE, that string referenced can be useful when field is used to specify numeric message IDs.
When referencing values of fields there is also a need to differentiate between a reference to external field and a genuine data value. For example the string abcd
can be interpreted as valid field name as well as valid hexadecimal bytes. As the result there is also a need to use ^
prefix (just like with <string> values) to indicate external reference.
The field is there to create an alias to other field. The CommsDSL allows retrieving value for the field as if it was retrieved from the referenced field.
In case referenced field resides in a namespace, add it to the reference string as well. The same rules apply.
The CommsDSL also allows referencing values from member fields of a or a .
There are two forms of fields. One references external field, another defines it as a member.
In case the field references external field it can NOT be used for value reference. The one that defines optional field internally as a child element, can.