External packet decoding.

This moves packet decoding to an external module.
Also adds testing of the packet decoding.