'Parse a string of TLV-encoded options.'

def tlv_parse(self, raw):

    ret = {}
    while raw:
        [tag] = struct.unpack('B', raw[0])
        if (tag == 0):
            raw = raw[1:]
            continue
        if (tag == 255):
            break
        [length] = struct.unpack('B', raw[1])
        value = raw[2:(2 + length)]
        raw = raw[(2 + length):]
        if (tag in ret):
            ret[tag].append(value)
        else:
            ret[tag] = [value]
    return ret
