# ref Field

This field serves as reference (alias) to other fields. It can be used to avoid duplication of field definition for multiple messages.

```
<?xml version="1.0" encoding="UTF-8"? version="10">
<schema ...>
    <fields>
        <int name="SomeIntField" type="uint8" defaultValue="Special2">
            <displayName value="Some Int Field" />
            <special name="Special1" val="0" />
            <special name="Special2" val="0xff" />
        </int>
    </fields>

    <message name="Msg1" id="1">
        <ref field="SomeIntField" />
        ...
    </message>

    <message name="Msg2" id="2">
        <ref field="SomeIntField" name="RenamedIntField" />
    </message>
</schema>
```

The **\<ref>** field has all the [common](/commsdsl-specification/fields/common.md) properties. It also copies **name**, **displayName** and **semanticType** [properties](/commsdsl-specification/properties.md) from the referenced field and allows overriding them with new values. Note, that in the example above **\<ref>** field defined as a member of **Msg1** message hasn't provided any **name** value. It is allowed because it has taken a name of the referenced field (*SomeIntField*).

## Referencing the Field

The only extra property the **\<ref>** field has is **field** to specify a [reference](/commsdsl-specification/references.md) to other field.

## Length in Bits

Since **v2** of this specification it is allowed to use **\<ref>** field as member of the [\<bitfield>](/commsdsl-specification/fields/bitfield.md) field while referencing one of the allowed member types. In such case it is required to use **bitLength** property to specify length in bits.

```
<?xml version="1.0" encoding="UTF-8"?>
<schema name="MyProtocol" endian="big">
    <fields>
        <enum name="SomeEnum type="uint8">
            <validValue name="V1" val="0" />
            <validValue name="V2" val="1" />
            <validValue name="V3" val="2" />
        </enum>

        <bitfield name="SomeBitfield">
            <int name="SomeIntMember" type="uint8" bitLength="3" />
            <set name="SomeSetMember" bitLength="3">
                ...
            </set>
            <ref field="SomeEnum" bitLength="2" />
        </bitfield>
    </fields>
</schema>
```

Use [properties table](/commsdsl-specification/appendix/ref.md) for future references.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://alex-robenko.gitbook.io/commsdsl-specification/fields/ref.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
