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
  • Member Fields
  • Endian

Was this helpful?

  1. Fields

bitfield Field

Previousset FieldNextbundle Field

Last updated 5 years ago

Was this helpful?

The <bitfield> is a container field, which allows wrapped member fields to be serialized using limited number of bits (instead of bytes). The supported fields, that can be members of the <bitfield>, are:

Since v2 of the specification it is also allowed to use field, which references one of the field types above.

The <bitfield> field has all the properties as well as extra properties and elements described below.

Member Fields

Member fields need to be listed as children XML elements of the <bitfield>. Every such member is expected to use bitLength property to specify its serialization length in bits. If it is not specified, then length in bits is calculated automatically as length in bytes multiplied by 8.

<?xml version="1.0" encoding="UTF-8"?>
<schema name="MyProtocol" endian="big">
    <fields>
        <bitfield name="SomeBitfield">
            <int name="SomeIntMember" type="uint8" bitLength="3" />
            <set name="SomeSetMember" bitLength="3">
                ...
            </set>
            <enum name="SomeEnumMember" type="uint8" bitLength="2">
                ...
            </enum>
        </bitfield>
    </fields>
</schema>

NOTE that summary of all the lengths in bits of all the members must be divisible by 8 and mustn't exceed 64 bits, otherwise the code generator must report an error.

The members of <bitfield> must be listed in order starting from the least significant bit. In the example above SomeIntMember occupies bits [0 - 2], SomeSetMember occupies bits [3 - 5], and SomeEnumMember occupies bits [6 -7].

<?xml version="1.0" encoding="UTF-8"?>
<schema name="MyProtocol" endian="big">
    <fields>
        <bitfield name="SomeBitfield">
            <displayName value="Proper Bitfield Name" />
            <members>
                <int name="SomeIntMember" type="uint8" bitLength="3" />
                <set name="SomeSetMember" bitLength="3">
                    ...
                </set>
                <enum name="SomeEnumMember" type="uint8" bitLength="2">
                    ...
                </enum>
            </members>
        </bitfield>
    </fields>
</schema>

Endian

<?xml version="1.0" encoding="UTF-8"?>
<schema name="MyProtocol" endian="big">
    <fields>
        <bitfield name="SomeBitfield" endian="little">
            ...
        </bitfield>
    </fields>
</schema>

If there is any other defined as XML child of the <bitfield>, then all the members must be wrapped in <members> XML element for separation.

When serializing, the <bitfield> object needs to combine the values of all the members into single unsigned raw value of appropriate length, and write the received value using appropriate endian. By default endian of the is used, unless it is overridden using extra endian property of the <bitfield> field.

Use for future references.

<enum>
<int>
<set>
<ref>
common
property
schema
properties table