Byte arrays are introduced in version 5.15. This is a new value type in addition to previously supported boolean
, integer
, floating-point
, string
and reference value types.
Byte arrays represent contiguous ranges in memory and usually contain unstructured data. The following operations are supported on byte arrays:
References are implicitly converted to byte arrays if they are used in the expression with other byte arrays. See example below.
Byte arrays may be specified as immediate values using the following syntax:
struct Header
{
unsigned char Signature[3];
$assert(Signature == { 0x20, 0xff, 0xfe }); // Immediate byte array
// Note the implicit conversion between the array field and byte array.
// Array field is first automatically converted to reference and then implicitly converted to
// byte array
};
Other value types may be explicitly converted to byte array using the array() function.
Arrays may be compared for equality and inequality. Arrays also support the following operators: <
, >
, <=
and >=
for which lexicographical comparison is used.
An individual element of byte array may be taken using the element() function.
A portion of an array may be extracted using the subarray() function.
A length() function returns the number of bytes in an array. This function also works with strings, returning the length of the string.
A find() function allows you to search for an occurrence of one byte array within another one. This function also works with strings.