Reads a packed integer from the fileobj <f>.

def read_packed_int(f):
    """ Reads a packed integer from the fileobj <f>. """
    ret = 0
    s = 0
    while True:
        b = ord(f.read(1))
        ret |= (b & 127) << s
        s += 7
        if b & 128 == 0:
            break
    return ret