@@ -77,7 +77,7 @@ specified using **defaultMode** <<intro-properties, property>>.
7777[[fields-optional-existence-conditions]]
7878==== Existence Condition ====
7979Many protocols introduce optional fields, and the existence of such fields
80- depend on the value of some other field. Classic example would be having
80+ depends on the value of some other field. Classic example would be having
8181some kind of flags field (see <<fields-set, **<set>** >>) where some bit specifies
8282whether other field that follows exists or not. Such conditions can be expressed
8383using **cond** <<intro-properties, property>>.
@@ -92,13 +92,13 @@ using **cond** <<intro-properties, property>>.
9292 <optional name="Val1" defaultMode="missing" cond="$Flags.Val1Exists">
9393 <int name="ActVal1" type="uint32" />
9494 </optional>
95- </fields >
95+ </message >
9696</schema>
9797----
9898**NOTE**, that **cond** property can be used only for **<optional>** field
9999that is a member of a <<fields-bundle, <bundle> >> or a
100100<<messages-messages, <message> >>. The **cond** expression
101- specifies condition when the **<optional>** field exists, and must always
101+ specifies condition when the **<optional>** field exists, and is expected to
102102reference other **sibling** field. Such reference is always prefixed with `$` character
103103to indicate that the field is a **sibling** of the **<optional>** and
104104not some external field.
@@ -129,7 +129,7 @@ For example:
129129 <optional name="F3" defaultMode="exists" cond="$F1 < $F2">
130130 <int name="WrappedF3" type="uint32" />
131131 </optional>
132- </fields >
132+ </message >
133133</schema>
134134----
135135The `F3` above exists, only if value of **F1** is less than value of **F2**
@@ -146,14 +146,39 @@ Deep (nested) conditions are also expected to be supported by the code generator
146146 <bit name="B0" idx="0" />
147147 <bit name="B1" idx="1" />
148148 </set>
149- </fitfield >
149+ </bitfield >
150150 <optional name="F2" defaultMode="missing" cond="$F1.Mem2.B0">
151151 <int name="WrappedF2" type="uint32" />
152152 </optional>
153153 <optional name="F3" defaultMode="exists" cond="!$F1.Mem2.B1">
154154 <int name="WrappedF3" type="uint32" />
155155 </optional>
156- </fields>
156+ </message>
157+ </schema>
158+ ----
159+
160+ When referencing the member of another `<optional>` field in the existence condition,
161+ a check that the wrapping `<optional>` field **exists** in addition to the
162+ actual specified condition is automatically implied.
163+ [source,xml]
164+ ----
165+ <?xml version="1.0" encoding="UTF-8"?>
166+ <schema ...>
167+ <message name="Msg1" id="1">
168+ <set name="F1">
169+ <bit name="B0" idx="0" />
170+ <bit name="B1" idx="1" />
171+ </set>
172+ <optional name="F2" defaultMode="missing" cond="$F1.B0">
173+ <set name="WrappedF2">
174+ <bit name="B0" idx="0" />
175+ <bit name="B1" idx="1" />
176+ </set>
177+ </optional>
178+ <optional name="F3" defaultMode="exists" cond="!$F2.WrappedF2.B1">
179+ <int name="WrappedF3" type="uint32" />
180+ </optional>
181+ </message>
157182</schema>
158183----
159184
@@ -171,7 +196,7 @@ as the reference to a sibling field described above.
171196 <bit name="B0" idx="0" />
172197 <bit name="B1" idx="1" />
173198 </set>
174- </fitfield >
199+ </bitfield >
175200 </interface>
176201
177202 <message name="Msg1" id="1">
@@ -181,7 +206,7 @@ as the reference to a sibling field described above.
181206 <optional name="F2" defaultMode="exists" cond="!%Flags.Mem2.B1">
182207 <int name="WrappedF2" type="uint32" />
183208 </optional>
184- </fields >
209+ </message >
185210</schema>
186211----
187212**WARNING**: The **CommsDSL** specification supports multiple interfaces and doesn't impose any restriction
@@ -191,6 +216,54 @@ the referenced field. The code generator may also not impose many restrictions o
191216Usage of the wrong **<interface>** class with the missing referenced
192217field in the end application may result in compilation errors.
193218
219+ Since **v6.1** of this specification comparing the size of the collection type fields (
220+ **<data>**, **<string>**, and **<list>**) is also supported. The size check condition is determined
221+ by the usage of the `#` character after the one indicating sibling (`$`) or interface (`%`) reference.
222+ [source,xml]
223+ ----
224+ <?xml version="1.0" encoding="UTF-8"?>
225+ <schema ...>
226+ <message name="Msg1" id="1">
227+ <data name="F1">
228+ <lengthPrefix>
229+ <int name="Length" type="uint8" />
230+ </lengthPrefix>
231+ </data>
232+ <optional name="F2" defaultMode="missing" cond="$#F1 != 0">
233+ <int name="ActF1" type="uint32" />
234+ </optional>
235+ </message>
236+ </schema>
237+ ----
238+ In the example above the `F2` field exists if `F1` is not empty, i.e. its size is not `0`.
239+
240+ Also since **v6.1** of this specification check whether the previously encountered **<optional>** field
241+ exists is also supporting in another **<optional>** field condition. Such check is determined by the
242+ usage of the `?` character after the one indicating sibling (`$`) or interface (`%`) reference.
243+
244+ [source,xml]
245+ ----
246+ <?xml version="1.0" encoding="UTF-8"?>
247+ <schema ...>
248+ <message name="Msg1" id="1">
249+ <set name="F1">
250+ <bit name="B0" idx="0" />
251+ <bit name="B1" idx="1" />
252+ </set>
253+ <optional name="F2" defaultMode="missing" cond="$F1.B0">
254+ <set name="ActF2">
255+ <bit name="B0" idx="0" />
256+ <bit name="B1" idx="1" />
257+ </set>
258+ </optional>
259+ <optional name="F3" defaultMode="exists" cond="!$?F2">
260+ <int name="ActF3" type="uint32" />
261+ </optional>
262+ </fields>
263+ </schema>
264+ ----
265+ In the example above `F3` exists when `F2` is missing.
266+
194267[[fields-optional-multiple-existence-conditions]]
195268==== Multiple Existence Conditions ====
196269The **CommsDSL** also allows usage of multiple existence condition statements. However,
@@ -253,7 +326,8 @@ place in the input buffer.
253326==== Missing On Invalid ====
254327Similar to <<fields-optional-missing-on-failed-read, missingOnReadFail>>, but with a bit of different
255328flavour, the property **missingOnInvalid** insures that the **<optional>** field is marked as
256- "missing" when the held field's value is invalid. If case of recognition the invalid value
329+ "missing" when the held field's value is invalid (applicable to the __refresh__ operation).
330+ In case of recognition of the invalid value
257331during the __read__ operation, the **<optional>** field must be marked as "missing" and
258332reading of the following fields must continue from the place in the input buffer as if the __read__
259333operation of the **<optional>** field didn't take place.
0 commit comments