import pickle


def message_encode(msg):
    """
    Encodes the message object.

    This method compresses the message payload and then serializes the whole
    message object into bytes, using pickle.

    Args:
        msg: the message to encode.
    """
    msg.payload.encode()
    return pickle.dumps(msg)