var person = defineTLClass({ name:tl("String",1), sex:tl("Int",2), time:tl("Long",3), time:tl("Long",10) }); 168421 1--2 2--4 3--8 4--16 5--32 6--64 7--128 8--256 最多256个属性 8位 类型 8位 (1-8基本类型,9类对象,10 repeat类型) 属性编号 属性类型 属性数据 0x 00 FF 属性数据 1. 基本类型,直接bytes 2. String类型, bytes长度 + 内容(int + bytes) 3. Bytes类型, bytes长度 + 内容(int + bytes) 4. Repeat类型, bytes长度 + 内容(int + bytes) 5. ClassObject类型, bytes长度 + 内容(int + bytes) 6. Map类型。 bytes长度 + 内容(int + bytes) Map类型: Array [key value] key: keyType keyData (int + bytes) value :valueType valueData(int + bytes) readNextField(stream){ int fieldIndex = readNextBytes(1,stream).toInt32(); int fieldType = readNextBytes(1,stream).toInt32(); switch(fieldType){ case 1-7: int bytesLength = getBasicByteSize(fieldType); bytes content = readNextBytes(bytesLength); return toBasicType(content,fieldType); case "bytes":{ int bytesLength = readNextBytes(4).toInt32(); return readNextBytes(bytesLength).toBytes(); } case "string":{ int bytesLength = readNextByte(4).toInt32(); return readNextBytes(bytesLength).toString("utf-8"); } case "repeat":{ int bytesLength = readNextByte(4).toInt32(); bytes bytes_content = readNextBytes(bytesLength).toBytes(); int cur = 0; List<Object> objectList = new Array(); while(cur < bytesLength){ cur = cur + ...; objectList.add(readNextField(bytes_content)) } return objectList; } case "classObject":{ int bytesLength = readNextByte(4).toInt32(); objrct = readNextObject(bytesLength) } } return { fieldIndex:fieldIndex, fieldType:fieldType, byteSize:byteSize, fieldObject:ObjectContent }; }