I've noticed that when I implement some binary format, I spend most of the time creating duplicate and dumb code. For example, for a simple package binary format, I might do the following:
- Create some structures to describe the format.
- Create code to read the format. This is usually just calling some "read" function on each member of the structure.
- Create code to write the format. This is usually just calling some "write" function on each member of the structure.
- Sometimes, I also create code to calculate the size of parts of the format. Again, this is usually just calling some "size" function on each member of the structure.