code: def wrap(data):
      
      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
docs: Try to decode data into a message, might return None if the data is invalid.