kaitai-io / kaitai_struct_formats

Kaitai Struct: library of binary file formats (.ksy)
http://formats.kaitai.io
712 stars 203 forks source link

games/renderware_binary_stream: add atomic struct definition #633

Closed Ithamar closed 1 year ago

Ithamar commented 2 years ago

Atomic is commonly the top level section in DFF files. This makes geometry is parsable in many older RenderWare game files.

KOLANICH commented 1 year ago

A brief reminder: IMHO it makes sense to implement flags as a struct of bit fields, not as a struct of instances where values are manually shifted, ANDed, and compared to 1 or 0.

generalmimon commented 1 year ago

@KOLANICH:

IMHO it makes sense to implement flags as a struct of bit fields

I'd generally agree, but it's not a hard-and-fast rule for me. Using bit-sized integers is obviously the most declarative way (which is a good thing), which allows it to work best for serialization as well (you can directly set the fields that will be written, as opposed to having to manually set the bits of flags - which also forces you to duplicate the bit shifts/masks in the application code - when the value instances would be used).

But if the flags are too sparse (which is this case, because there are only 2 known bits in 32), I don't mind using the value instances to unpack the 4-byte flags integer. The benefit is that all the bits are still accessible by their original bit masks.

Maybe it's still better to use bit integers even for sparse flags, I'm not sure.

Ithamar commented 1 year ago

I've added the flags now too, using bit-sized integers. I tend to use the raw ksy files as format documentation, and bit fields make more sense then masks/shifts, though it does require to understand kaitai's bit field endianness magic ;)