def struct_fmt(size, signed=False):
    """
    Helper that returns the format for struct.pack, given a size and
    a signedness

    >>> struct_fmt(4, False)
    'I'
    >>> struct_fmt(8, True)
    'q'
    """
    formats = {(1): 'b', (2): 'h', (4): 'i', (8): 'q'}
    assert size in formats, 'unknown size'
    if not signed:
        return formats[size].upper()
    else:
        return formats[size]
