> For the complete documentation index, see [llms.txt](https://alex-robenko.gitbook.io/commsdsl-specification/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alex-robenko.gitbook.io/commsdsl-specification/frames/size.md).

# size Layer

The **\<size>** layer represents **remaining** serialization length of the [frame](/commsdsl-specification/frames.md) until the end of [\<payload>](/commsdsl-specification/frames/payload.md). The [frame](/commsdsl-specification/frames.md) definition must **NOT** contain more than one **\<size>** layer.

```
<?xml version="1.0" encoding="UTF-8"?>
<schema ...>
    <frame name="ProtocolFrame">
        <size name="Size">
            <int name="SizeField" type="uint16" />
        </size>
        <id name="Id">
            <int name="IdField" type="uint8" />  
        </id>
        <payload name="Data" />
    </frame>
</schema>
```

Some protocols may specify that the field of the **\<size>** layer contains its own length as well. The **CommsDSL** allows implementation of such case by adding usage of **serOffset** property to the field of the **\<size>** layer.

```
<?xml version="1.0" encoding="UTF-8"?>
<schema ...>
    <frame name="ProtocolFrame">
        <size name="Size">
            <int name="SizeField" type="uint16" serOffset="2" displayOffset="2"/>
        </size>
        <id name="Id">
            <int name="IdField" type="uint8" />  
        </id>
        <payload name="Data" />
    </frame>
</schema>
```

The example below implements `ID (2 bytes) | SIZE (2 bytes) | PAYLOAD` framing where `SIZE` value includes length of the header (`ID` + `SIZE`) in addition to the length of `PAYLOAD`.

```
<?xml version="1.0" encoding="UTF-8"?>
<schema ...>
    <frame name="ProtocolFrame">
        <id name="Id">
            <int name="IdField" type="uint16" />  
        </id>
        <size name="Size">
            <int name="SizeField" type="uint16" serOffset="4" displayOffset="4"/>
        </size>
        <payload name="Data" />
    </frame>
</schema>
```

Also **NOTE** that **\<size>** layer specifies number of **remaining** bytes **until the end of** [**\<payload>**](/commsdsl-specification/frames/payload.md) **layer**. There are protocols that append some kind of [\<checksum>](/commsdsl-specification/frames/checksum.md) after the payload. In order to include them in the value of the **\<size>** layer, also use **serOffset** property.

```
<?xml version="1.0" encoding="UTF-8"?>
<schema ...>
    <frame name="ProtocolFrame">
        <size name="Size">
            <int name="SizeField" type="uint16" serOffset="2" displayOffset="2"/>
        </size>
        <id name="Id">
            <int name="IdField" type="uint8" />  
        </id>
        <payload name="Data" />
        <checksum ...>
            <int name="ChecksumField" type="uint16" />
        </checksum>
    </frame>
</schema>
```

The **\<size>** layer doesn't have any extra properties in addition to [common](/commsdsl-specification/frames/common.md) ones.
