Refactor protocolstate to make it independent of the decoder / encoder