happyleavesaoc / aoc-mgz

Age of Empires II recorded game parsing and summarization in Python 3.
MIT License
197 stars 42 forks source link

pad actions to actual size in "full" parser #28

Closed Skazu closed 4 years ago

Skazu commented 4 years ago

This pull requests solves #24 by simply ensuring that as much bytes are getting read as "length" defines. It simply adds a padding if not all bytes were consumed (and thus ignores all exceeding bytes!).

This behaviour is more or less equal to the fast parser:

    length, = struct.unpack('<I', data.read(4))
    action_id = int.from_bytes(data.read(1), 'little')
    action_bytes = data.read(length - 1)
    data.read(4)

I've tested it with DE records and it allows me to parse as many operations as the fast-parser does.

happyleavesaoc commented 4 years ago

Thanks, this is a nice and clean solution to the problem of DE actions somewhat regularly changing (as long as they don't remove fields).

Context for those reading: