binary-layout
binary-layout copied to clipboard
Nested structure as an array?
Hi,
The project is really awesome for me to parsing on-disk filesystem data, it's not too complex compared to nom, but still supported nested structures.
However I am hitting a case where I have something like this in C:
struct btrfs_root_backup {
/* Some u8/u16/u32/u64 etc. */
};
struct btrfs_super_block {
/* Some other u8/u16/u32/u64 */
struct btrfs_root_backup backup_roots[4];
}
In above case, how can I specify the nested rust structure for btrfs_super_block::backup_roots[4]?
Tried something like the following:
define_layout!(btrfs_super_block, LittleEndian, {
csum: [u8; BTRFS_CSUM_SIZE],
...
super_roots: [btrfs_root_backup::NestedView; 4],
});
But of course it failed to compile.
For now I can easily workaround it by just defining super_roots into 4 members, but I'd like to know if there is any better solution.
Thanks, Qu
Hi, thanks for reaching out. The only array type currently supported is [u8]. Any other array types aren't supported yet, see the README.
Nested views in arrays sound like the natural follow-up once general array types are supported. But as mentioned in the README, I likely won't have time to add this feature. But I'm willing to review and accept PRs.
Do you have a rough idea on how to implement arrays of primitives?
Turns out I need both: arrays of primitives and arrays of nested views.