Returns <v> as packed string.

def pack_int(v):
    """ Returns <v> as packed string. """
    if v == 0:
        return "\0"
    ret = ''
    while v > 0:
        c = v & 127
        v >>= 7
        if v != 0:
            c = c | 128
        ret += chr(c)
    return ret