def get_data_format_and_size(data, data_type):
    """
    Internal function to convert data_type to the corresponding struct.pack format string
    as per https://docs.python.org/2/library/struct.html#format-characters

    Function contributed by awm102 on GitHub.  Amy moved this to DroneSensorParser to be
    more general, edited a bit to fit within the drone sensor parser as well.

    :param data: the data that will be packed. Not actually used here unless the data_type is string, then
                 it is used to calculate the data size.
    :param data_type: a string representing the data type
    :return: a tuple of a string representing the struct.pack format for the data type and an int representing
             the number of bytes
    """
    if data_type == 'u8' or data_type == 'enum':
        format_char = '<B'
        data_size = 1
    elif data_type == 'i8':
        format_char = '<b'
        data_size = 1
    elif data_type == 'u16':
        format_char = '<H'
        data_size = 2
    elif data_type == 'i16':
        format_char = '<h'
        data_size = 2
    elif data_type == 'u32':
        format_char = '<I'
        data_size = 4
    elif data_type == 'i32':
        format_char = '<i'
        data_size = 4
    elif data_type == 'u64':
        format_char = '<Q'
        data_size = 8
    elif data_type == 'i64':
        format_char = '<q'
        data_size = 8
    elif data_type == 'float':
        format_char = '<f'
        data_size = 4
    elif data_type == 'double':
        format_char = '<d'
        data_size = 8
    elif data_type == 'string':
        format_char = '<s'
        data_size = len(data)
    else:
        format_char = ''
        data_size = 0
    return format_char, data_size
