Implement message writer.

(I'm guessing the masking is related to making the protocol opaque to proxies, and not about any sort of security)