Methods for encoding/decoding requests & responses, and for discovering message type

By 'discovering message type' I mean peeking into a packet with PeekMessageType.
With this commit it should be possible to accept different message types on
the same interface and dispatch them correctly.