def simpletlv_unpack(data):
    """Unpacks a simpletlv coded string into a list of 3-tuples (tag, length,
    newvalue)."""
    result = []
    rest = data
    while rest != '':
        tag = ord(rest[0])
        if tag == 0 or tag == 0xff:
            raise ValueError

        length = ord(rest[1])
        if length == 0xff:
            length = (ord(rest[2]) << 8) + ord(rest[3])
            newvalue = rest[4:4+length]
            rest = rest[4+length:]
        else:
            newvalue = rest[2:2+length]
            rest = rest[2+length:]
        result.append((tag, length, newvalue))

    return result