I am reading a file that contains a dynamic array (length defined by a terminator) of variable length data structures, and I want the last element of the array to be marked as such in the template viewer. The data structure I’m reading is a bit more complicated but I came up with this as an example:
typedef enum <uint> { False, True} bool
int getTNameArraySize(){
local int64 pos = FTell()
local count = 0;
do {
len = ReadUInt(pos)
pos += len * sizeof(wchar_t) + sizeof(uint32);
count++;
} while(len > 0)
return count;
}
typedef struct {
uint32 len;
if(len == 0) {
wchar_t name = "EOF"; // Don't read any data
bool lastElement = True;
}
else {
wchar_t name[len] // Read len UTF-16 characters
bool lastElement = False;
}
} TName;
TName names[getTNameArraySize()];
This code has a number of problems that mean it doesn’t/can’t work how should I approach it?
The array name[len] doesn’t ends up being the size of the first string.
You are not allowed to assign values to template variables, so I can’t set the name to EOF if it’s the last empty element. Is there any way round this?
I think I could make lastElement a local variable and then turn on local variables. Can I do it just for this one? I don’t want to see all ‘len’ for example?
This code ends up reading the data twice, is there any way round that so that the array ends with its size the way a string does? I could be dealing with a pretty big array.
Is there a “right” way to approach this?
Thanks