Restructure things a bit to make way for a state machine.
Don't throw in decode_packet, set res.error.