Implemented message serialize method.