Untested implementation of the outer layer of header decoding

This exposes all the new decoder code to Perl. As yet untested and more
than a bit shaky. Not the pinnacle of interface design either.