Function Reference

This page lists all the built-in functions available for templates.

I/O Functions

void BigEndian()
void LittleEndian()

Select big-endian or little-endian mode. You can switch back and forth within the same template to declare fields with different byte orders.

Little-endian mode is selected by default.

bool IsBigEndian()
bool IsLittleEndian()

Check whether big-endian or little-endian mode is selected.

bool FEof()

Returns true if the read position is at the end of the file.

int64_t FileSize()

Returns the length of the file in bytes.

void FSeek(int64_t offset)

Moves the read position relative to the start of the file.

The read position is used for reading data and defining new variables.

void FSkip(int64_t offset)

Moves the read position relative to its current offset.

int64_t FTell()

Returns the current read position in the file.

int8_t ReadI8(int64_t offset = FTell())
uint8_t ReadU8(int64_t offset = FTell())
int16_t ReadI16(int64_t offset = FTell())
uint16_t ReadU16(int64_t offset = FTell())
int32_t ReadI32(int64_t offset = FTell())
uint32_t ReadU32(int64_t offset = FTell())
int64_t ReadI64(int64_t offset = FTell())
uint64_t ReadU64(int64_t offset = FTell())
float ReadFloat(float offset = FTell())
double ReadDouble(double offset = FTell())

The ReadXXX() functions read a value from the document and return it. The offset parameter is optional and defaults to the current read position.

Calling any of these functions with an invalid offset will result in a template error.

void Printf(string format, ...)

Writes a message to the application console. The message will also be shown in the output window if the template encounters an error.

void Error(string format, ...)

Aborts template execution with the given error message, for example because of an error or inconsistency detected in the file.

Array Functions

int64_t ArrayLength(any array type array)

Returns the number of elements in the given array.

void ArrayResize(any_array_type array, int64_t num_elements, <struct arguments>)

The ArrayResize() function changes the size of the given array. Any new elements will be initialised to their default values and any removed elements will be erased. If the array elements are a struct type, <struct arguments> are passed through as the arguments to the new struct elements.

This function can be called to incrementally increase the size of an array being read from the document, but not if any variables have been defined after the array.

void ArrayExtend(any_array_type array, int64_t num_elements = 1, <struct arguments>)

Equivalent to ArrayResize(array, ArrayLength(array) + num_elements).