def encode(char_data, encoding='utf-8'):
    """
    Encode the parameter as a byte string.

    :param char_data:

    :rtype: bytes
    """
    if type(char_data) is unicode:
        return char_data.encode(encoding, 'replace')
    else:
        return char_data
Encode the parameter as a byte string.

    :param char_data:

    :rtype: bytes