I'm trying to write a library in Zig that reads file formats designed for the Xbox 360, which use both big-endian and little-endian values.
Ideally, I want to be able to seek the reader, change the endianness of the reader, and read byte-by-byte like so:
reader.seekTo(0);
var foo = reader.readByte();
reader.setEndian(Endian.big);
var bar = reader.readInt(u32);
// etc.
References:
If there's a better way, it would be nice to see an example that can at least handle two of the three. Doing it in a completely different way might be kind of hard to manage.
Searching the docs, I've found that I can either...
- Use the
Filetype, callseekToon that, and read all the bytes of the file to a buffer array. This doesn't appear to expose a way to set the endian or read other types, leaving me to do all of that manually. - Or create a
Readerfrom thatFileand callreadByteorreadInt(ReturnType, Endian, usize)on that. But this doesn't appear to exposeseekTo.
Related: https://discord.com/channels/605571803288698900/1167211222911942666
I may be wrong but this didn't seem to solve my issue entirely either.