WIP refactor message encoding and test.