<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def wrap(data):
 """ Try to decode data into a message, might return None if the data is invalid. """

    try:
        cmdid = data[0]
    except IndexError:
        log.warning('data is empty')
        return None

    try:
        message_type = CMDID_MESSAGE[cmdid]
    except KeyError:
        log.error('unknown cmdid %s', cmdid)
        return None

    try:
        message = message_type(data)
    except ValueError:
        log.error('trying to decode invalid message')
        return None

    return message