Skip to content

Commit c80dae2

Browse files
committed
Added "Ensuring Serialization Length" section to the "Messages" chapter.
1 parent 801131c commit c80dae2

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

fields/optional.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ specified using **defaultMode** <<intro-properties, property>>.
7272
</schema>
7373
----
7474

75+
[[fields-optional-existence-conditions]]
7576
==== Existence Condition ====
7677
Many protocols introduce optional fields, and the existence of such fields
7778
depend on the value of some other field. Classic example would be having

intro/names.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Almost every element has a required **name** <<intro-properties, property>>. Provided
44
value will be used to generate appropriate classes and/or relevant access functions.
55
As the result, the chosen names must be only alphanumeric and
6-
`_' (underscore) characters, but also mustn't start with a number.
6+
'_' (underscore) characters, but also mustn't start with a number.
77
The provided value is case sensitive. However, the code generator is allowed
88
to change the case of to first letter of the provided value. It is up to the
99
code generator to choose whether to use **camelCase** or **PascalCase** when

messages/messages.adoc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,31 @@ Sometimes an existing member field may be renamed and/or moved. It is possible t
382382
create alias names for the fields to keep the old client code being able to compile
383383
and work. Please refer to <<aliases-aliases, Aliases>> chapter for more details.
384384

385+
[[messages-ensuring-serialization-length]]
386+
=== Ensuring Serialization Length ===
387+
Many protocol specifications indicate the expected message serialization length, especially
388+
when message has fixed length. The **CommsDSL** allows specifying expected minimal length
389+
using **validateMinLength** property with <<intro-numeric, unsigned>> value to help avoid some copy-paste or typo errors
390+
at the time of schema parsing rather than debugging generated incorrect code.
391+
[source,xml]
392+
----
393+
<?xml version="1.0" encoding="UTF-8"?>
394+
<schema ...>
395+
<message name="Msg1" id="1" validateMinLength="6">
396+
<int name="F1" type="uint32" />
397+
<int name="F2" type="int16" />
398+
<optional name="F3" defaultMode="exist">
399+
<int name="F3Field" type="uint8" />
400+
</optional>
401+
</message>
402+
</schema>
403+
----
404+
Note, that <<fields-optional, &lt;optional&gt; >> field is always expected to have 0 minimal length regardless
405+
of its <<fields-optional-existence-conditions, existence conditions>>.
406+
407+
Also note, that the value of **validateMinLength** is the expected serialization length of
408+
message fields __without__ the fields of the <<frames-frames, &lt;frame&gt; >>.
409+
385410
[[messages-ensuring-overriding-code-injection]]
386411
=== Ensuring Overriding Code Injection ===
387412
Similar to <<fields-common-ensuring-overriding-code-injection, fields>> the default code

0 commit comments

Comments
 (0)