def decode(byte_data, encoding='utf-8'):
    """
    Decode the byte data to a string if not None.

    :param bytes byte_data: the data to decode

    :rtype: str
    """
    if byte_data is None:
        return None
    return byte_data.decode(encoding, errors='replace')