This was a quick attempt to get a nicer python syntax for un/packing binary data structures. This requires python 3 because now we can get ordered data about the declared items using the __prepare__ meta-class-method. I also use here class descriptors for making the array syntax nicer (instead of char[2] you can use array(char, 2)). I was going to use abstract meta classes (ABC) for the types but decided it was overkill :) . This is really a quick version so there is much that can be improved but as a POC I think it works very well. I would be interested in seeing the syntax with a metaclass being used by something like the peach or construct python modules.

I only have 2 basic types but it is trivial to add the rest. Adding substruct's (as in a class inside a class) should be doable but might require fixing up the metaclass up a bit. Once you've got that doing unions is trivial. The hardest feature still missing is being able to do element dependencies like: msNumOfNumbers = dword msItems = dword[msNumOfNumbers] but I think that will require some major restructuring. I might fixup the code to allow it if I need it/have time for it. Feel free to take this code and improve it or do with it what you want. Comments would be appreciated.