RelativeFromField

Description:

This method figures out how much data has been consumed between the start of the field in the "Field that contains length" parameter and the current bit position. Note that this method is inclusive, which means if you need to find out how much data has been consumed not including the data in the first parameter field, you will need to include the size of that field as the second parameter.

RelativeFromField is useful when decoding protocols that carry multiple objects or functions in a frame and there may be extra data at the end of an object that you want to put into a field but you don't know how much there is. For example, each object starts with a 1 byte length field. There are variable length fields between the length field and the current bit position where you want to put your data field. You can use this construction to find out the correct size for the field:

FIELD consume_data (RelativeFromField length) IF (MoreBytesInSegment length) (StringOfHex 64) "Data"

Usually used in conjunction with the Boolean method MoreByteInSegment so that the field doesn't show up if there isn't any extra data.

Parameters:

[Required]

Field

"Field that contains length"


[Required]

Int

"Size of Parameter Field in Bytes"

(Default value: 0)

Example:

FIELD unknown_or_undecoded_bytes (RelativeFromField length 2) IF (MoreBytesToDecode length 2) (StringOfHex) "Unknown Bytes"