def write_tlv(data):
tlv = b'<STR_LIT>'<EOL>for key, value in data.items():<EOL><INDENT>tag = bytes([int(key)])<EOL>length = len(value)<EOL>pos = <NUM_LIT:0><EOL>while pos < len(value):<EOL><INDENT>size = min(length, <NUM_LIT:255>)<EOL>tlv += tag<EOL>tlv += bytes([size])<EOL>tlv += value[pos:pos+size]<EOL>pos += size<EOL>length -= size<EOL><DEDENT><DEDENT>return tlv<EOL>
Convert a dict to TLV8 bytes.