Did a bunch of optimizations to the code: checking __class__ directly (instead of isinstance), saving len() to var, using xrange on Py2, using iteritems instead of items on Py2, making alias to struct.pack and struct.unpack.