Change vid encoding so that we only encode to base 64 on serialization.

This made some existing logic feel more difficult than it should,
so added enum encoding and encode and decode methods
to make it easier to make encoding transformations.

Added a couple of TODOs - one as a reminder that JSON deserialisation
is incomplete, the other because I did not understand the code.

Also changed a couple of asserts to runtime checks (more
are needed).

Signature serialization becomes a little more regular.

I've tried to keep to the existing code style, but there are inevitably
going to be some slip-ups. There were some trade-offs of
minimal allocation vs code simplicity (notably in inspect_packet,
which allocates much more than before, but I suspect it's
not likely to be a bottleneck).