Implemented message serialization.