Rewrite protocol

Now we use a simple state machine for deserialization and a plain old
buffer for serialization, rather than struct copying.

We also don't have to care about endianness differences anymore.