Variable number of structures #1494
Replies: 2 comments
-
Generally all sorts of loops are implemented using arrays. If you need access to the current index, use |
Beta Was this translation helpful? Give feedback.
-
I ran into a similar case where I was trying to parse a file that packaged together multiple files. The package file started with a header that listed each file's name, offset, and size, then stored the contents of each file after the header. I was able to encode each file as a struct, where the struct had some it its data in the header, but was able to reference the contents of the file later down in the package file. struct file {
u8 name_info[0x20];
u32 offset;
u32 size;
// \/ This is the important line
u8 data[size] @ offset;
};
struct fpk {
u32 magic;
u32 num_files;
file files[num_files];
};
fpk fpk @ 0x0; In your case, since some entries may not have data, you could try something like this: struct file {
u8 name_info[0x20];
u32 offset;
u32 size;
// \/ These are the important lines
if (offset != 0x0)
u8 data[size] @ offset;
};
struct fpk {
u32 magic;
u32 num_files;
file files[num_files];
};
fpk fpk @ 0x0; |
Beta Was this translation helpful? Give feedback.
-
I have a question about how to parse a certain type of file. The file is structured list this:
Top level
Each of the sections above is a contains pointers to where the data actually is in the file. So, for example, layer1 would contain a pointer to where the layer data was in the file. Some of the pointers will be 0 if that layer/sample isn't used.
So I don't understand how to loop through these to get the data. I can get all the pointers, but how do I use these to go pick off the data for each layer/sample and display it in the pattern data window?
Beta Was this translation helpful? Give feedback.
All reactions