import struct


def unpack(format, buf):
    """Both unpack and delete. Convert single-element tuples to their element"""
    result = struct.unpack_from(format, buf)
    if len(result) == 1:
        result = result[0]
    del buf[:struct.calcsize(format)]
    return result