import struct


def intread(buf):
    """Unpacks the given buffer to an integer"""
    try:
        if isinstance(buf,int):
            return buf
        l = len(buf)
        if l == 1:
            return buf[0]
        elif l <= 4:
            tmp = buf + b'\x00'*(4-l)
            return struct.unpack('<I', tmp)[0]
        else:
            tmp = buf + b'\x00'*(8-l)
            return struct.unpack('<Q', tmp)[0]
    except:
        raise