Skip to content

Commit c8195ef

Browse files
committed
Updated tutorial2 with mention of the size comparison and existing conditions check in the <optional> field.
1 parent 7d6bc1a commit c8195ef

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

tutorials/tutorial2/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,6 +2625,44 @@ void ClientSession::sendMsg14()
26252625
sendMessage(msg);
26262626
}
26272627
```
2628+
2629+
Also since **v6.1** of the [CommsDSL](https://github.com/commschamp/CommsDSL-Specification)
2630+
specification it is allowed to check the size of the sequence fields like `<string>`, `<data>`,
2631+
or `<list>` int the `<optional>` field conditions. To do so there is a need to use `#` character
2632+
after the sibling field reference prefix `$`.
2633+
The `Msg18` message (defined inside [dsl/msg18.xml](dsl/msg18.xml) and implemented in
2634+
[include/tutorial2/message/Msg18.h](include/tutorial2/message/Msg18.h)) demonstrates that.
2635+
```xml
2636+
<message name="Msg18" id="MsgId.M18" displayName="Message 18">
2637+
<string name="F1">
2638+
<lengthPrefix>
2639+
<int name="Length" type="uint8" />
2640+
</lengthPrefix>
2641+
</string>
2642+
<optional name="F2" cond="$#F1 != 0" defaultMode="missing">
2643+
<int name="ActF2" type="uint16" />
2644+
</optional>
2645+
...
2646+
</message>
2647+
```
2648+
In the example above the optional field `F2` exists if the size of the `F1` is not 0, i.e.
2649+
it is not empty.
2650+
2651+
The **v6.1** of the [CommsDSL](https://github.com/commschamp/CommsDSL-Specification) specification
2652+
also allows check of whether the mode of the previously encountered `<optional>` field is **exists**.
2653+
To do so there is a need to use `?` character after the sibling field reference prefix `$`.
2654+
```xml
2655+
<message name="Msg18" id="MsgId.M18" displayName="Message 18">
2656+
...
2657+
<optional name="F2" cond="$#F1 != 0" defaultMode="missing">
2658+
<int name="ActF2" type="uint16" />
2659+
</optional>
2660+
<optional name="F3" cond="!$?F2" defaultMode="exists">
2661+
<int name="ActF3" type="uint8" />
2662+
</optional>
2663+
</message>
2664+
```
2665+
In the example above the optional field `F3` exists if the `F2` does NOT exist (due to negation operator `!`).
26282666

26292667
## Reusing Fields Definitions
26302668
In many cases some fields may share some portions of their definitions. To avoid various

tutorials/tutorial2/src/ClientSession.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ void ClientSession::handle(Msg18& msg)
346346
}
347347
std::cout << std::endl;
348348

349+
if (m_currentStage != CommsStage_Msg18) {
350+
std::cerr << "ERROR: Unexpected message received: " << std::endl;
351+
return;
352+
}
353+
349354
doNextStage();
350355
}
351356

0 commit comments

Comments
 (0)