def struct_dict(struct):
    """
    take a ctypes.Structure and return its field/value pairs
    as a dict.
    """
    get_pair = lambda field_type: (
        field_type[0], getattr(struct, field_type[0]))
    return dict(list(map(get_pair, struct._fields_)))