<peek> Element Reference

The <peek> element provides access to data ahead in the message. This information can then be referenced in expressions.

Attributes
NameFormatDescription
length (required)ExpressionThe length of data to use for evaluation.
name (required)string
offset (required)size_tThe number of bits to peek ahead.

Detail

In some protocols a field cannot be decoded correctly until a subsequent field is known. The <peek> element provides a solution for this situation.

    <?xml version="1.0" encoding="iso-8859-1" ?>
    <xddl>
     <comment>peek into switch element</comment>
     <structure>
      <peek name="pd" offset="4" length="4"/>
      <switch expr="pd">
        <case value="0">
          <field length="4" name="security header"/>
          <field length="4" name="protocol descriminator"/>
        </case>
        <case value="1">
          <field length="4" name="bearer identity"/>
          <field length="4" name="protocol descriminator"/>
        </case>
       </switch>
     </structure>
    </xddl>

    peek.xddl

The above example illustrates a typical use of the <peek> element. Notice the <peek> "looks into" each of the <case> elements to determine what its value should be. Then the <switch> can be properly evaluated.

There are some restrictions when using <peek>. Every possibly path must have a field that can be evaluated. This means in the above example if there were another <case> element that only had one 4-bit field then the document would not be valid.

Also, there cannot be any variable length attributes between the <peek> and the offset. This means all the length expressions must be integers as long as the <peek> is being evaluated:

    <?xml version="1.0" encoding="iso-8859-1" ?>
    <xddl>
     <comment>peek over expression -- error</comment>
     <structure>
      <field name="num" length="8"/>
      <peek name="pd" offset="4" length="4"/>
      <switch expr="pd">
        <case value="0">
          <!-- this next field causes validation error! -->
          <field length="4 * num" name="security header"/>
          <field length="4" name="protocol descriminator"/>
        </case>
        <case value="1">
          <field length="4" name="bearer identity"/>
          <field length="4" name="protocol descriminator"/>
        </case>
       </switch>
     </structure>
    </xddl>

    peek_ex.xddl

This example is a modification of the first example. Here the security header field has a variable length of4 * num, where num is a previously declared field. This causes the document to fail validation.