Size Methods Example

Size Methods set the iOutput variable to the number of bits determined to be the size of the field. Here is an example in a method that sizes a null-terminated string of 8-bit characters:

SIZE

METHOD String___

/* size is from current byte to the first null */

CODE

{

int iEndPtr = iofsbytCurrentPosition;

while ((iEndPtr < inbytAvailableLayer-1) &&

(abytLayer[iEndPtr] != 0))

iEndPtr++;

iOutput = (iEndPtr-iofsbytCurrentPosition+1)*8;

}

ENDCODE

Many Size Methods take a parameter that identifies a unit of measure (bit, byte, etc.). The Fixed method serves as a good example of this:

SIZE

METHOD Fixed___

/* returns the number of bits specified */

CODE

iOutput = iParam1 * SizeOfUnitsInBits (eParam2);

ENDCODE

PARAM "Number (in units)" int

PARAM "Units" list {Bit Bits Nibble Nibbles Byte Bytes Octet Octets Word Words Dword Dwords Qword Qwords} = Bytes

Notice the defaulting of the second parameter to "Bytes".