Add unit tests for Encode, Prepare and Decode. Fix issues found during
unit testing.
Remove MessageType and just use uint8.