Rearranged the packet and serial code to make more sense

This mostly just reimplements the best parts of the discarded branch:

> discard-encapsulated-packets

There may still be some work needed.
Implemented the serialization switch statement