CommsDSL Specification
  • Introduction
  • Version
  • Schema Definition
  • Multiple Files
  • Namespaces
  • Platforms
  • References
  • Properties
  • Numeric Values
  • Boolean Values
  • Names
  • Protocol Versioning
  • Schema
  • Fields
    • Common Properties of Fields
    • enum Field
    • int Field
    • set Field
    • bitfield Field
    • bundle Field
    • string Field
    • data Field
    • list Field
    • float Field
    • ref Field
    • optional Field
    • variant Field
    • Referencing Values of Other Fields
  • Messages
  • Interfaces
  • Aliases
  • Frames
    • Common Properties of Layers
    • payload Layer
    • id Layer
    • size Layer
    • sync Layer
    • checksum Layer
    • value Layer
    • custom Layer
  • Protocol Versioning Summary
  • Appendix
    • Properties of schema
    • Common Properties of Fields
    • Properties of enum Field
    • Properties of int Field
    • Properties of set Field
    • Properties of bitfield Field
    • Properties of bundle Field
    • Properties of string Field
    • Properties of data Field
    • Properties of list Field
    • Properties of float Field
    • Properties of ref Field
    • Properties of optional Field
    • Properties of variant Field
    • Units
    • Properties of message
    • Properties of interface
    • Properties of alias
    • Properties of frame
    • Common Properties of Layers
    • Properties of checksum Layer
    • Properties of value Layer
    • Properties of custom Layer
Powered by GitBook
On this page
  • Default Value
  • Fixed Length
  • Length Prefix

Was this helpful?

  1. Fields

data Field

Previousstring FieldNextlist Field

Last updated 5 years ago

Was this helpful?

This field stores and abstracts away value of a raw bytes data. The <data> field has all the properties as well as extra properties and elements described below.

<?xml version="1.0" encoding="UTF-8"?>
<schema ...>
    <fields>
        <data name="SomeDataField" />
    </fields>
</schema>

Such definition of the <data> does NOT have any limit on the length of the data, and will consume all the available bytes in the input buffer.

Default Value

The default value of the <data> field when constructed can be specified using defaultValue . The value of the property must be case-insestive string of hexadecimal values with even number of characters. The allowed ranges of the characters are: ['0' - '9'], and ['a' - 'f']. The ' ' (space) character is also allowed for convenient separation of the bytes. If not specified, defaults to empty data.

<?xml version="1.0" encoding="UTF-8"?>
<schema ...>
    <fields>
        <data name="SomeDataField" defaultValue="0123 45 67 89 ab cd eF" />
    </fields>
</schema>

The example above is expected to create approprate raw data abstracting field, containing 8 bytes: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef] when default constructed.

Fixed Length

In case the data value needs to be serialized using predefined fixed length, use length property to specify the required value.

<?xml version="1.0" encoding="UTF-8"?>
<schema ...>
    <fields>
        <data name="SomeDataField" length="16" />
    </fields>
</schema>

Length Prefix

<?xml version="1.0" encoding="UTF-8"?>
<schema ...>
    <fields>
        <data name="SomeDataField">
            <lengthPrefix>
                <int name="LengthPrefix" type="uint16" />
            </lengthPrefix>
        <data>
    </fields>
</schema>
<?xml version="1.0" encoding="UTF-8"?>
<schema ...>
    <fields>
        <int name="DataLengthPrefix" type="uint8" />
        <data name="SomeDataField" lengthPrefix="DataLengthPrefix" />
    </fields>
</schema>
<?xml version="1.0" encoding="UTF-8"?>
<schema ...>
    <fields>
        <bundle name=SomeBundle">
            <int name="DataLengthPrefixMember" type="uint16" />
            <int name="SomeOtherFieldMember" type="uint16" />
            <data name="SomeDataFieldMember" lengthPrefix="$DataLengthPrefixMember" />
        </bundle>
    </fields>

    <message name="Msg1" id="1">
        <int name="DataLengthPrefix" type="uint16" />
        <int name="SomeOtherField" type="uint16" />
        <data name="SomeDataField" lengthPrefix="$DataLengthPrefix" />
    </message>
</schema>

The code generator is expected to take the existence of such detached prefix into account and generate correct code for various field operations (read, write, etc...).

NOTE, that length and lengthPrefix properties are mutually exclusive, i.e. cannot be used together.

Many protocols prefix raw binary data with its length. The CommsDSL allows definition of such prefix using lengthPrefix child element, which must define prefix as field.

In case the prefix field is defined as external field, CommsDSL allows usage of lengthPrefix as , value of which contains name of the referenced field.

The CommsDSL also supports detached length prefix, when there are several other fields in the or in the between the length field and the <data>.

NOTE, the existence of $ prefix when specifying lengthPrefix value. It indicates that the referenced field is a sibling in the containing or the field.

Use for future references.

common
property
<int>
property
<message>
<bundle>
<message>
<bundle>
properties table