FixedUpTo

Description:

FixedUpTo methods return the fixed value given in the first parameter "Number", unless that would put the pointer past the absolute end point given by the "Length field" and "Offset" parameters. The absolute end point is found by starting immediately after the field in "Length field", adding the value of "Length field" and subtracting the value of "Offset". If the value in "Number" puts the pointer past the absolute end point, the size is truncated to the absolute end point.

Parameters:

[Required]

Int

"Number (in units)"


[Required]

Field

"Length field"


[Optional]

Int

"Offset:

(Default value: 0)

[Optional]

List

"Units"

(Default value: Bytes)

List values:

Bit

Bits

Times

Nibble

Nibbles

Byte

Bytes

Octet

Octets

Word

Words

Dword

Dwords

Qword

Qwords

Example:

FIELD length (Fixed 1 Byte) (Decimal) "Length"

FIELD address (FixedUpTo 6 length 5) (Hex) "Address"

Assume the value in "length" is 10. Starting after the length field, the absolute end point is 10-5=5 bytes from the length field. The address field, which is right after the length field, is 6 bytes long, except that this is 1byte past the absolute end point. Instead of being set at 6 bytes, the size of "address" is set to 5. If the value of "length" was 14, the absolute end point would be 14-5 =9 bytes from the end of "length". In this case, the size of the address field would be set to 6, because this does not go past the absolute end point.

This method handles cases where bad data may cause a group to overflow, which is particularly a problem with repeated groups.