@@ -77,7 +77,7 @@ specified using **defaultMode** <<intro-properties, property>>.
77
77
[[fields-optional-existence-conditions]]
78
78
==== Existence Condition ====
79
79
Many 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
81
81
some kind of flags field (see <<fields-set, **<set>** >>) where some bit specifies
82
82
whether other field that follows exists or not. Such conditions can be expressed
83
83
using **cond** <<intro-properties, property>>.
@@ -92,13 +92,13 @@ using **cond** <<intro-properties, property>>.
92
92
<optional name="Val1" defaultMode="missing" cond="$Flags.Val1Exists">
93
93
<int name="ActVal1" type="uint32" />
94
94
</optional>
95
- </fields >
95
+ </message >
96
96
</schema>
97
97
----
98
98
**NOTE**, that **cond** property can be used only for **<optional>** field
99
99
that is a member of a <<fields-bundle, <bundle> >> or a
100
100
<<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
102
102
reference other **sibling** field. Such reference is always prefixed with `$` character
103
103
to indicate that the field is a **sibling** of the **<optional>** and
104
104
not some external field.
@@ -129,7 +129,7 @@ For example:
129
129
<optional name="F3" defaultMode="exists" cond="$F1 < $F2">
130
130
<int name="WrappedF3" type="uint32" />
131
131
</optional>
132
- </fields >
132
+ </message >
133
133
</schema>
134
134
----
135
135
The `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
146
146
<bit name="B0" idx="0" />
147
147
<bit name="B1" idx="1" />
148
148
</set>
149
- </fitfield >
149
+ </bitfield >
150
150
<optional name="F2" defaultMode="missing" cond="$F1.Mem2.B0">
151
151
<int name="WrappedF2" type="uint32" />
152
152
</optional>
153
153
<optional name="F3" defaultMode="exists" cond="!$F1.Mem2.B1">
154
154
<int name="WrappedF3" type="uint32" />
155
155
</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>
157
182
</schema>
158
183
----
159
184
@@ -171,7 +196,7 @@ as the reference to a sibling field described above.
171
196
<bit name="B0" idx="0" />
172
197
<bit name="B1" idx="1" />
173
198
</set>
174
- </fitfield >
199
+ </bitfield >
175
200
</interface>
176
201
177
202
<message name="Msg1" id="1">
@@ -181,7 +206,7 @@ as the reference to a sibling field described above.
181
206
<optional name="F2" defaultMode="exists" cond="!%Flags.Mem2.B1">
182
207
<int name="WrappedF2" type="uint32" />
183
208
</optional>
184
- </fields >
209
+ </message >
185
210
</schema>
186
211
----
187
212
**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
191
216
Usage of the wrong **<interface>** class with the missing referenced
192
217
field in the end application may result in compilation errors.
193
218
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
+
194
267
[[fields-optional-multiple-existence-conditions]]
195
268
==== Multiple Existence Conditions ====
196
269
The **CommsDSL** also allows usage of multiple existence condition statements. However,
@@ -253,7 +326,8 @@ place in the input buffer.
253
326
==== Missing On Invalid ====
254
327
Similar to <<fields-optional-missing-on-failed-read, missingOnReadFail>>, but with a bit of different
255
328
flavour, 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
257
331
during the __read__ operation, the **<optional>** field must be marked as "missing" and
258
332
reading of the following fields must continue from the place in the input buffer as if the __read__
259
333
operation of the **<optional>** field didn't take place.
0 commit comments