From d71e3d1d8d58795399ee662381ad122fe43fdf31 Mon Sep 17 00:00:00 2001 From: godotg Date: Tue, 12 Dec 2023 12:59:20 +0800 Subject: [PATCH] test[typescript]: add IByteBuffer interface to ByteBuffer --- .../registration/ProtocolAnalysis.java | 4 +- .../src/test/typescript/zfoots/IByteBuffer.ts | 117 ++++++ .../typescript/zfoots/buffer/ByteBuffer.ts | 347 +++++++++--------- .../typescript/zfoots/packet/ComplexObject.ts | 5 +- .../typescript/zfoots/packet/EmptyObject.ts | 5 +- .../typescript/zfoots/packet/NormalObject.ts | 15 +- .../test/typescript/zfoots/packet/ObjectA.ts | 15 +- .../test/typescript/zfoots/packet/ObjectB.ts | 15 +- .../typescript/zfoots/packet/SimpleObject.ts | 5 +- .../typescript/zfoots/packet/VeryBigObject.ts | 5 +- 10 files changed, 314 insertions(+), 219 deletions(-) create mode 100644 protocol/src/test/typescript/zfoots/IByteBuffer.ts diff --git a/protocol/src/main/java/com/zfoo/protocol/registration/ProtocolAnalysis.java b/protocol/src/main/java/com/zfoo/protocol/registration/ProtocolAnalysis.java index 76e4dc81..71cce6d7 100644 --- a/protocol/src/main/java/com/zfoo/protocol/registration/ProtocolAnalysis.java +++ b/protocol/src/main/java/com/zfoo/protocol/registration/ProtocolAnalysis.java @@ -66,8 +66,8 @@ public class ProtocolAnalysis { * EN: Temp field, name reserved keywords, The name of the protocol cannot be named with the following name * CN: 临时变量,启动完成就会销毁,协议名称保留字符,即协议的名称不能用以下名称命名 */ - private static Set protocolReserved = Set.of("Buffer", "ByteBuf", "ByteBuffer", "LittleEndianByteBuffer", "NormalByteBuffer" - , "IProtocol", "IProtocolRegistration", "ProtocolManager", "IFieldRegistration" + private static Set protocolReserved = Set.of("IProtocol", "IProtocolRegistration", "ProtocolManager", "IFieldRegistration" + , "Buffer", "ByteBuf", "IByteBuffer", "ByteBuffer", "LittleEndianByteBuffer", "NormalByteBuffer" , "ByteBufUtils", "ArrayUtils", "CollectionUtils" , "Boolean", "Byte", "Short", "Integer", "Long", "Float", "Double", "String", "Character", "Object" , "Collections", "Iterator", "List", "ArrayList", "Map", "HashMap", "Set", "HashSet" diff --git a/protocol/src/test/typescript/zfoots/IByteBuffer.ts b/protocol/src/test/typescript/zfoots/IByteBuffer.ts new file mode 100644 index 00000000..9f05c328 --- /dev/null +++ b/protocol/src/test/typescript/zfoots/IByteBuffer.ts @@ -0,0 +1,117 @@ +interface IByteBuffer { + adjustPadding(predictionLength: number, beforeWriteIndex: number): void + compatibleRead(beforeReadIndex: number, length: number): boolean + setWriteOffset(writeOffset: number): void + getWriteOffset(): number + setReadOffset(readOffset: number): void + getReadOffset(): number + getCapacity(): number + ensureCapacity(minCapacity: number): void + isReadable(): boolean + writeBytes(byteArray: ArrayBuffer): void + toBytes(): ArrayBuffer + writeBoolean(value: boolean): void + readBoolean(): boolean + writeByte(value: number): void + readByte(): number + writeShort(value: number): void + readShort(): number + writeRawInt(value: number): void + readRawInt(): number + writeInt(value: number): void + writeIntCount(value: number): number + readInt(): number + writeLong(value: number): void + readLong(): number + writeFloat(value: number): void + readFloat(): number + writeDouble(value: number): void + readDouble(): number + writeString(value: string): void + readString(): string + writePacket(packet: any, protocolId: number): void + readPacket(protocolId: number): any + writeBooleanArray(array: Array | null): void + readBooleanArray(): boolean[] + writeByteArray(array: Array | null): void + readByteArray(): number[] + writeShortArray(array: Array | null): void + readShortArray(): number[] + writeIntArray(array: Array | null): void + readIntArray(): number[] + writeLongArray(array: Array | null): void + readLongArray(): number[] + writeFloatArray(array: Array | null): void + readFloatArray(): number[] + writeDoubleArray(array: Array | null): void + readDoubleArray(): number[] + writeStringArray(array: Array | null): void + readStringArray(): string[] + writePacketArray(array: Array | null, protocolId: number): void + readPacketArray(protocolId: number): any + // ---------------------------------------------list------------------------------------------- + writeBooleanList(list: Array | null): void + readBooleanList(): boolean[] + writeByteList(list: Array | null): void + readByteList(): number[] + writeShortList(list: Array | null): void + readShortList(): number[] + writeIntList(list: Array | null): void + readIntList(): number[] + writeLongList(list: Array | null): void + readLongList(): number[] + writeFloatList(list: Array | null): void + readFloatList(): number[] + writeDoubleList(list: Array | null): void + readDoubleList(): number[] + writeStringList(list: Array | null): void + readStringList(): string[] + writePacketList(list: Array | null, protocolId: number): void + readPacketList(protocolId: number): any[] + // ---------------------------------------------set------------------------------------------- + writeBooleanSet(set: Set | null): void + readBooleanSet(): Set + writeByteSet(set: Set | null): void + readByteSet(): Set + writeShortSet(set: Set | null): void + readShortSet(): Set + writeIntSet(set: Set | null): void + readIntSet(): Set + writeLongSet(set: Set | null): void + readLongSet(): Set + writeFloatSet(set: Set | null): void + readFloatSet(): Set + writeDoubleSet(set: Set | null): void + readDoubleSet(): Set + writeStringSet(set: Set | null): void + readStringSet(): Set + writePacketSet(set: Set | null, protocolId: number): void + readPacketSet(protocolId: number): Set + // ---------------------------------------------map------------------------------------------- + writeIntIntMap(map: Map | null): void + readIntIntMap(): Map + writeIntLongMap(map: Map | null): void + readIntLongMap(): Map + writeIntStringMap(map: Map | null): void + readIntStringMap(): Map + writeIntPacketMap(map: Map | null, protocolId: number): void + readIntPacketMap(protocolId: number): Map + writeLongIntMap(map: Map | null): void + readLongIntMap(): Map + writeLongLongMap(map: Map | null): void + readLongLongMap(): Map + writeLongStringMap(map: Map | null): void + readLongStringMap(): Map + writeLongPacketMap(map: Map | null, protocolId: number): any + readLongPacketMap(protocolId: number): Map + writeStringIntMap(map: Map | null): void + readStringIntMap(): Map + writeStringLongMap(map: Map | null): void + readStringLongMap(): Map + writeStringStringMap(map: Map | null): void + readStringStringMap(): Map + writeStringPacketMap(map: Map | null, protocolId: number): void + readStringPacketMap(protocolId: number): Map +} + +export default IByteBuffer; \ No newline at end of file diff --git a/protocol/src/test/typescript/zfoots/buffer/ByteBuffer.ts b/protocol/src/test/typescript/zfoots/buffer/ByteBuffer.ts index 6fddbc1a..dfa71c26 100644 --- a/protocol/src/test/typescript/zfoots/buffer/ByteBuffer.ts +++ b/protocol/src/test/typescript/zfoots/buffer/ByteBuffer.ts @@ -1,3 +1,4 @@ +import IByteBuffer from "../IByteBuffer"; import ProtocolManager from "../ProtocolManager"; import {writeInt64, readInt64} from "./Longbits"; @@ -44,7 +45,7 @@ function decodeZigzagInt(n: number) { } -class ByteBuffer { +class ByteBuffer implements IByteBuffer{ writeOffset: number; readOffset: number; buffer: ArrayBuffer; @@ -388,21 +389,15 @@ class ByteBuffer { return value; } - writePacketFlag(value: any): boolean { - const flag = (value === null) || (value === undefined); - this.writeBoolean(!flag); - return flag; - }; - - writePacket(packet: any, protocolId: number) { + writePacket(packet: any, protocolId: number): void { const protocolRegistration = ProtocolManager.getProtocol(protocolId); protocolRegistration.write(this, packet); - }; + } readPacket(protocolId: number): any { const protocolRegistration = ProtocolManager.getProtocol(protocolId); return protocolRegistration.read(this); - }; + } writeBooleanArray(array: Array | null) { if (array === null) { @@ -413,9 +408,9 @@ class ByteBuffer { this.writeBoolean(element); }); } - }; + } - readBooleanArray(): any { + readBooleanArray(): Array { const array: boolean[] = []; const length = this.readInt(); if (length > 0) { @@ -424,9 +419,9 @@ class ByteBuffer { } } return array; - }; + } - writeByteArray(array: Array | null) { + writeByteArray(array: Array | null): void { if (array === null) { this.writeInt(0); } else { @@ -435,9 +430,9 @@ class ByteBuffer { this.writeByte(element); }); } - }; + } - readByteArray(): any { + readByteArray(): Array { const array: number[] = []; const length = this.readInt(); if (length > 0) { @@ -446,9 +441,9 @@ class ByteBuffer { } } return array; - }; + } - writeShortArray(array: Array | null) { + writeShortArray(array: Array | null): void { if (array === null) { this.writeInt(0); } else { @@ -457,9 +452,9 @@ class ByteBuffer { this.writeShort(element); }); } - }; + } - readShortArray(): any { + readShortArray(): number[] { const array: number[] = []; const length = this.readInt(); if (length > 0) { @@ -468,9 +463,9 @@ class ByteBuffer { } } return array; - }; + } - writeIntArray(array: Array | null) { + writeIntArray(array: Array | null): void { if (array === null) { this.writeInt(0); } else { @@ -479,9 +474,9 @@ class ByteBuffer { this.writeInt(element); }); } - }; + } - readIntArray(): any { + readIntArray(): number[] { const array: number[] = []; const length = this.readInt(); if (length > 0) { @@ -490,9 +485,9 @@ class ByteBuffer { } } return array; - }; + } - writeLongArray(array: Array | null) { + writeLongArray(array: Array | null): void { if (array === null) { this.writeInt(0); } else { @@ -501,9 +496,9 @@ class ByteBuffer { this.writeLong(element); }); } - }; + } - readLongArray(): any { + readLongArray(): number[] { const array: number[] = []; const length = this.readInt(); if (length > 0) { @@ -512,9 +507,9 @@ class ByteBuffer { } } return array; - }; + } - writeFloatArray(array: Array | null) { + writeFloatArray(array: Array | null): void { if (array === null) { this.writeInt(0); } else { @@ -523,9 +518,9 @@ class ByteBuffer { this.writeFloat(element); }); } - }; + } - readFloatArray(): any { + readFloatArray(): number[] { const array: number[] = []; const length = this.readInt(); if (length > 0) { @@ -534,9 +529,9 @@ class ByteBuffer { } } return array; - }; + } - writeDoubleArray(array: Array | null) { + writeDoubleArray(array: Array | null): void { if (array === null) { this.writeInt(0); } else { @@ -545,9 +540,9 @@ class ByteBuffer { this.writeDouble(element); }); } - }; + } - readDoubleArray(): any { + readDoubleArray(): number[] { const array: number[] = []; const length = this.readInt(); if (length > 0) { @@ -556,9 +551,9 @@ class ByteBuffer { } } return array; - }; + } - writeStringArray(array: Array | null) { + writeStringArray(array: Array | null): void { if (array === null) { this.writeInt(0); } else { @@ -567,9 +562,9 @@ class ByteBuffer { this.writeString(element); }); } - }; + } - readStringArray(): any { + readStringArray(): string[] { const array: string[] = []; const length = this.readInt(); if (length > 0) { @@ -578,9 +573,9 @@ class ByteBuffer { } } return array; - }; + } - writePacketArray(array: Array | null, protocolId: number) { + writePacketArray(array: Array | null, protocolId: number): void { if (array === null) { this.writeInt(0); } else { @@ -590,9 +585,9 @@ class ByteBuffer { protocolRegistration.write(this, element); }); } - }; + } - readPacketArray(protocolId: number): any { + readPacketArray(protocolId: number): any[] { const array: any[] = []; const length = this.readInt(); if (length > 0) { @@ -602,83 +597,83 @@ class ByteBuffer { } } return array; - }; + } // ---------------------------------------------list------------------------------------------- - writeBooleanList(list: any) { + writeBooleanList(list: Array | null): void { this.writeBooleanArray(list); - }; + } - readBooleanList(): any { + readBooleanList(): boolean[] { return this.readBooleanArray(); - }; + } - writeByteList(list: any) { + writeByteList(list: Array | null): void { this.writeByteArray(list); - }; + } - readByteList(): any { + readByteList(): number[] { return this.readByteArray(); - }; + } - writeShortList(list: any) { + writeShortList(list: Array | null): void { this.writeShortArray(list); - }; + } - readShortList(): any { + readShortList(): number[] { return this.readShortArray(); - }; + } - writeIntList(list: any) { + writeIntList(list: Array | null): void { this.writeIntArray(list); - }; + } - readIntList(): any { + readIntList(): number[] { return this.readIntArray(); - }; + } - writeLongList(list: any) { + writeLongList(list: Array | null): void { this.writeLongArray(list); - }; + } - readLongList(): any { + readLongList(): number[] { return this.readLongArray(); - }; + } - writeFloatList(list: any) { + writeFloatList(list: Array | null): void { this.writeFloatArray(list); - }; + } - readFloatList(): any { + readFloatList(): number[] { return this.readFloatArray(); - }; + } - writeDoubleList(list: any) { + writeDoubleList(list: Array | null): void { this.writeDoubleArray(list); - }; + } - readDoubleList(): any { + readDoubleList(): number[] { return this.readDoubleArray(); - }; + } - writeStringList(list: any) { + writeStringList(list: Array | null): void { this.writeStringArray(list); - }; + } - readStringList(): any { + readStringList(): string[] { return this.readStringArray(); - }; + } - writePacketList(list: any, protocolId: number) { + writePacketList(list: Array | null, protocolId: number): void { this.writePacketArray(list, protocolId); - }; + } - readPacketList(protocolId: number): any { + readPacketList(protocolId: number): any[] { return this.readPacketArray(protocolId); - }; + } // ---------------------------------------------set------------------------------------------- - writeBooleanSet(set: Set | null) { + writeBooleanSet(set: Set | null): void { if (set === null) { this.writeInt(0); } else { @@ -687,13 +682,13 @@ class ByteBuffer { this.writeBoolean(element); }); } - }; + } - readBooleanSet(): any { + readBooleanSet(): Set { return new Set(this.readBooleanArray()); - }; + } - writeByteSet(set: Set | null) { + writeByteSet(set: Set | null): void { if (set === null) { this.writeInt(0); } else { @@ -702,13 +697,13 @@ class ByteBuffer { this.writeByte(element); }); } - }; + } - readByteSet(): any { + readByteSet(): Set { return new Set(this.readByteArray()); - }; + } - writeShortSet(set: Set | null) { + writeShortSet(set: Set | null): void { if (set === null) { this.writeInt(0); } else { @@ -717,13 +712,13 @@ class ByteBuffer { this.writeShort(element); }); } - }; + } - readShortSet(): any { + readShortSet(): Set { return new Set(this.readShortArray()); - }; + } - writeIntSet(set: Set | null) { + writeIntSet(set: Set | null): void { if (set === null) { this.writeInt(0); } else { @@ -732,13 +727,13 @@ class ByteBuffer { this.writeInt(element); }); } - }; + } - readIntSet(): any { + readIntSet(): Set { return new Set(this.readIntArray()); - }; + } - writeLongSet(set: Set | null) { + writeLongSet(set: Set | null): void { if (set === null) { this.writeInt(0); } else { @@ -747,13 +742,13 @@ class ByteBuffer { this.writeLong(element); }); } - }; + } - readLongSet(): any { + readLongSet(): Set { return new Set(this.readLongArray()); - }; + } - writeFloatSet(set: Set | null) { + writeFloatSet(set: Set | null): void { if (set === null) { this.writeInt(0); } else { @@ -762,13 +757,13 @@ class ByteBuffer { this.writeFloat(element); }); } - }; + } - readFloatSet(): any { + readFloatSet(): Set { return new Set(this.readFloatArray()); - }; + } - writeDoubleSet(set: Set | null) { + writeDoubleSet(set: Set | null): void { if (set === null) { this.writeInt(0); } else { @@ -777,13 +772,13 @@ class ByteBuffer { this.writeDouble(element); }); } - }; + } - readDoubleSet(): any { + readDoubleSet(): Set { return new Set(this.readDoubleArray()); - }; + } - writeStringSet(set: Set | null) { + writeStringSet(set: Set | null): void { if (set === null) { this.writeInt(0); } else { @@ -792,13 +787,13 @@ class ByteBuffer { this.writeString(element); }); } - }; + } - readStringSet(): any { + readStringSet(): Set { return new Set(this.readStringArray()); - }; + } - writePacketSet(set: Set | null, protocolId: number) { + writePacketSet(set: Set | null, protocolId: number): void { if (set === null) { this.writeInt(0); } else { @@ -808,14 +803,14 @@ class ByteBuffer { protocolRegistration.write(this, element); }); } - }; + } - readPacketSet(protocolId: number): any { + readPacketSet(protocolId: number): Set { return new Set(this.readPacketArray(protocolId)); - }; + } // ---------------------------------------------map------------------------------------------- - writeIntIntMap(map: Map | null) { + writeIntIntMap(map: Map | null): void { if (map === null) { this.writeInt(0); } else { @@ -825,10 +820,10 @@ class ByteBuffer { this.writeInt(value); }); } - }; + } - readIntIntMap(): any { - const map = new Map(); + readIntIntMap(): Map { + const map = new Map(); const size = this.readInt(); if (size > 0) { for (let index = 0; index < size; index++) { @@ -838,9 +833,9 @@ class ByteBuffer { } } return map; - }; + } - writeIntLongMap(map: Map | null) { + writeIntLongMap(map: Map | null): void { if (map === null) { this.writeInt(0); } else { @@ -850,10 +845,10 @@ class ByteBuffer { this.writeLong(value); }); } - }; + } - readIntLongMap(): any { - const map = new Map(); + readIntLongMap(): Map { + const map = new Map(); const size = this.readInt(); if (size > 0) { for (let index = 0; index < size; index++) { @@ -863,9 +858,9 @@ class ByteBuffer { } } return map; - }; + } - writeIntStringMap(map: Map | null) { + writeIntStringMap(map: Map | null): void { if (map === null) { this.writeInt(0); } else { @@ -875,10 +870,10 @@ class ByteBuffer { this.writeString(value); }); } - }; + } - readIntStringMap(): any { - const map = new Map(); + readIntStringMap(): Map { + const map = new Map(); const size = this.readInt(); if (size > 0) { for (let index = 0; index < size; index++) { @@ -888,9 +883,9 @@ class ByteBuffer { } } return map; - }; + } - writeIntPacketMap(map: Map | null, protocolId: number) { + writeIntPacketMap(map: Map | null, protocolId: number): void { if (map === null) { this.writeInt(0); } else { @@ -901,10 +896,10 @@ class ByteBuffer { protocolRegistration.write(this, value); }); } - }; + } - readIntPacketMap(protocolId: number): any { - const map = new Map(); + readIntPacketMap(protocolId: number): Map { + const map = new Map(); const size = this.readInt(); if (size > 0) { const protocolRegistration = ProtocolManager.getProtocol(protocolId); @@ -915,9 +910,9 @@ class ByteBuffer { } } return map; - }; + } - writeLongIntMap(map: Map | null) { + writeLongIntMap(map: Map | null): void { if (map === null) { this.writeInt(0); } else { @@ -927,10 +922,10 @@ class ByteBuffer { this.writeInt(value); }); } - }; + } - readLongIntMap(): any { - const map = new Map(); + readLongIntMap(): Map { + const map = new Map(); const size = this.readInt(); if (size > 0) { for (let index = 0; index < size; index++) { @@ -940,9 +935,9 @@ class ByteBuffer { } } return map; - }; + } - writeLongLongMap(map: Map | null) { + writeLongLongMap(map: Map | null): void { if (map === null) { this.writeInt(0); } else { @@ -952,10 +947,10 @@ class ByteBuffer { this.writeLong(value); }); } - }; + } - readLongLongMap(): any { - const map = new Map(); + readLongLongMap(): Map { + const map = new Map(); const size = this.readInt(); if (size > 0) { for (let index = 0; index < size; index++) { @@ -965,9 +960,9 @@ class ByteBuffer { } } return map; - }; + } - writeLongStringMap(map: Map | null) { + writeLongStringMap(map: Map | null): void { if (map === null) { this.writeInt(0); } else { @@ -977,10 +972,10 @@ class ByteBuffer { this.writeString(value); }); } - }; + } - readLongStringMap(): any { - const map = new Map(); + readLongStringMap(): Map { + const map = new Map(); const size = this.readInt(); if (size > 0) { for (let index = 0; index < size; index++) { @@ -990,7 +985,7 @@ class ByteBuffer { } } return map; - }; + } writeLongPacketMap(map: Map | null, protocolId: number): any { if (map === null) { @@ -1003,10 +998,10 @@ class ByteBuffer { protocolRegistration.write(this, value); }); } - }; + } - readLongPacketMap(protocolId: number): any { - const map = new Map(); + readLongPacketMap(protocolId: number): Map { + const map = new Map(); const size = this.readInt(); if (size > 0) { const protocolRegistration = ProtocolManager.getProtocol(protocolId); @@ -1017,9 +1012,9 @@ class ByteBuffer { } } return map; - }; + } - writeStringIntMap(map: Map | null) { + writeStringIntMap(map: Map | null): void { if (map === null) { this.writeInt(0); } else { @@ -1029,10 +1024,10 @@ class ByteBuffer { this.writeInt(value); }); } - }; + } - readStringIntMap(): any { - const map = new Map(); + readStringIntMap(): Map { + const map = new Map(); const size = this.readInt(); if (size > 0) { for (let index = 0; index < size; index++) { @@ -1042,9 +1037,9 @@ class ByteBuffer { } } return map; - }; + } - writeStringLongMap(map: Map | null) { + writeStringLongMap(map: Map | null): void { if (map === null) { this.writeInt(0); } else { @@ -1054,10 +1049,10 @@ class ByteBuffer { this.writeLong(value); }); } - }; + } - readStringLongMap(): any { - const map = new Map(); + readStringLongMap(): Map { + const map = new Map(); const size = this.readInt(); if (size > 0) { for (let index = 0; index < size; index++) { @@ -1067,9 +1062,9 @@ class ByteBuffer { } } return map; - }; + } - writeStringStringMap(map: Map | null) { + writeStringStringMap(map: Map | null): void { if (map === null) { this.writeInt(0); } else { @@ -1079,10 +1074,10 @@ class ByteBuffer { this.writeString(value); }); } - }; + } - readStringStringMap(): any { - const map = new Map(); + readStringStringMap(): Map { + const map = new Map(); const size = this.readInt(); if (size > 0) { for (let index = 0; index < size; index++) { @@ -1092,9 +1087,9 @@ class ByteBuffer { } } return map; - }; + } - writeStringPacketMap(map: Map | null, protocolId: number) { + writeStringPacketMap(map: Map | null, protocolId: number): void { if (map === null) { this.writeInt(0); } else { @@ -1105,10 +1100,10 @@ class ByteBuffer { protocolRegistration.write(this, value); }); } - }; + } - readStringPacketMap(protocolId: number): any { - const map = new Map(); + readStringPacketMap(protocolId: number): Map { + const map = new Map(); const size = this.readInt(); if (size > 0) { const protocolRegistration = ProtocolManager.getProtocol(protocolId); @@ -1119,7 +1114,7 @@ class ByteBuffer { } } return map; - }; + } } export default ByteBuffer; diff --git a/protocol/src/test/typescript/zfoots/packet/ComplexObject.ts b/protocol/src/test/typescript/zfoots/packet/ComplexObject.ts index dcd5a15d..5d7e999d 100644 --- a/protocol/src/test/typescript/zfoots/packet/ComplexObject.ts +++ b/protocol/src/test/typescript/zfoots/packet/ComplexObject.ts @@ -1,3 +1,4 @@ +import IByteBuffer from '../IByteBuffer'; import ObjectA from './ObjectA'; // 复杂的对象,包括了各种复杂的结构,数组,List,Set,Map @@ -63,7 +64,7 @@ class ComplexObject { return ComplexObject.PROTOCOL_ID; } - static write(buffer: any, packet: ComplexObject | null) { + static write(buffer: IByteBuffer, packet: ComplexObject | null) { if (packet === null) { buffer.writeInt(0); return; @@ -237,7 +238,7 @@ class ComplexObject { buffer.adjustPadding(36962, beforeWriteIndex); } - static read(buffer: any): ComplexObject | null { + static read(buffer: IByteBuffer): ComplexObject | null { const length = buffer.readInt(); if (length === 0) { return null; diff --git a/protocol/src/test/typescript/zfoots/packet/EmptyObject.ts b/protocol/src/test/typescript/zfoots/packet/EmptyObject.ts index b5931124..9fb40491 100644 --- a/protocol/src/test/typescript/zfoots/packet/EmptyObject.ts +++ b/protocol/src/test/typescript/zfoots/packet/EmptyObject.ts @@ -1,3 +1,4 @@ +import IByteBuffer from '../IByteBuffer'; class EmptyObject { @@ -10,7 +11,7 @@ class EmptyObject { return EmptyObject.PROTOCOL_ID; } - static write(buffer: any, packet: EmptyObject | null) { + static write(buffer: IByteBuffer, packet: EmptyObject | null) { if (packet === null) { buffer.writeInt(0); return; @@ -18,7 +19,7 @@ class EmptyObject { buffer.writeInt(-1); } - static read(buffer: any): EmptyObject | null { + static read(buffer: IByteBuffer): EmptyObject | null { const length = buffer.readInt(); if (length === 0) { return null; diff --git a/protocol/src/test/typescript/zfoots/packet/NormalObject.ts b/protocol/src/test/typescript/zfoots/packet/NormalObject.ts index 0286e9bd..ef26c1a7 100644 --- a/protocol/src/test/typescript/zfoots/packet/NormalObject.ts +++ b/protocol/src/test/typescript/zfoots/packet/NormalObject.ts @@ -1,3 +1,4 @@ +import IByteBuffer from '../IByteBuffer'; import ObjectA from './ObjectA'; @@ -21,7 +22,6 @@ class NormalObject { mm: Map = new Map(); s: Set = new Set(); ssss: Set = new Set(); - outCompatibleValue: number = 0; static PROTOCOL_ID: number = 101; @@ -29,13 +29,12 @@ class NormalObject { return NormalObject.PROTOCOL_ID; } - static write(buffer: any, packet: NormalObject | null) { + static write(buffer: IByteBuffer, packet: NormalObject | null) { if (packet === null) { buffer.writeInt(0); return; } - const beforeWriteIndex = buffer.getWriteOffset(); - buffer.writeInt(854); + buffer.writeInt(-1); buffer.writeByte(packet.a); buffer.writeByteArray(packet.aaa); buffer.writeShort(packet.b); @@ -54,11 +53,9 @@ class NormalObject { buffer.writeIntPacketMap(packet.mm, 102); buffer.writeIntSet(packet.s); buffer.writeStringSet(packet.ssss); - buffer.writeInt(packet.outCompatibleValue); - buffer.adjustPadding(854, beforeWriteIndex); } - static read(buffer: any): NormalObject | null { + static read(buffer: IByteBuffer): NormalObject | null { const length = buffer.readInt(); if (length === 0) { return null; @@ -101,10 +98,6 @@ class NormalObject { packet.s = set16; const set17 = buffer.readStringSet(); packet.ssss = set17; - if (buffer.compatibleRead(beforeReadIndex, length)) { - const result18 = buffer.readInt(); - packet.outCompatibleValue = result18; - } if (length > 0) { buffer.setReadOffset(beforeReadIndex + length); } diff --git a/protocol/src/test/typescript/zfoots/packet/ObjectA.ts b/protocol/src/test/typescript/zfoots/packet/ObjectA.ts index 98f15386..4323aabc 100644 --- a/protocol/src/test/typescript/zfoots/packet/ObjectA.ts +++ b/protocol/src/test/typescript/zfoots/packet/ObjectA.ts @@ -1,3 +1,4 @@ +import IByteBuffer from '../IByteBuffer'; import ObjectB from './ObjectB'; @@ -6,7 +7,6 @@ class ObjectA { a: number = 0; m: Map = new Map(); objectB: ObjectB | null = null; - innerCompatibleValue: number = 0; static PROTOCOL_ID: number = 102; @@ -14,21 +14,18 @@ class ObjectA { return ObjectA.PROTOCOL_ID; } - static write(buffer: any, packet: ObjectA | null) { + static write(buffer: IByteBuffer, packet: ObjectA | null) { if (packet === null) { buffer.writeInt(0); return; } - const beforeWriteIndex = buffer.getWriteOffset(); - buffer.writeInt(201); + buffer.writeInt(-1); buffer.writeInt(packet.a); buffer.writeIntStringMap(packet.m); buffer.writePacket(packet.objectB, 103); - buffer.writeInt(packet.innerCompatibleValue); - buffer.adjustPadding(201, beforeWriteIndex); } - static read(buffer: any): ObjectA | null { + static read(buffer: IByteBuffer): ObjectA | null { const length = buffer.readInt(); if (length === 0) { return null; @@ -41,10 +38,6 @@ class ObjectA { packet.m = map1; const result2 = buffer.readPacket(103); packet.objectB = result2; - if (buffer.compatibleRead(beforeReadIndex, length)) { - const result3 = buffer.readInt(); - packet.innerCompatibleValue = result3; - } if (length > 0) { buffer.setReadOffset(beforeReadIndex + length); } diff --git a/protocol/src/test/typescript/zfoots/packet/ObjectB.ts b/protocol/src/test/typescript/zfoots/packet/ObjectB.ts index 32ba3574..7fbf4c6e 100644 --- a/protocol/src/test/typescript/zfoots/packet/ObjectB.ts +++ b/protocol/src/test/typescript/zfoots/packet/ObjectB.ts @@ -1,9 +1,9 @@ +import IByteBuffer from '../IByteBuffer'; class ObjectB { flag: boolean = false; - innerCompatibleValue: number = 0; static PROTOCOL_ID: number = 103; @@ -11,19 +11,16 @@ class ObjectB { return ObjectB.PROTOCOL_ID; } - static write(buffer: any, packet: ObjectB | null) { + static write(buffer: IByteBuffer, packet: ObjectB | null) { if (packet === null) { buffer.writeInt(0); return; } - const beforeWriteIndex = buffer.getWriteOffset(); - buffer.writeInt(4); + buffer.writeInt(-1); buffer.writeBoolean(packet.flag); - buffer.writeInt(packet.innerCompatibleValue); - buffer.adjustPadding(4, beforeWriteIndex); } - static read(buffer: any): ObjectB | null { + static read(buffer: IByteBuffer): ObjectB | null { const length = buffer.readInt(); if (length === 0) { return null; @@ -32,10 +29,6 @@ class ObjectB { const packet = new ObjectB(); const result0 = buffer.readBoolean(); packet.flag = result0; - if (buffer.compatibleRead(beforeReadIndex, length)) { - const result1 = buffer.readInt(); - packet.innerCompatibleValue = result1; - } if (length > 0) { buffer.setReadOffset(beforeReadIndex + length); } diff --git a/protocol/src/test/typescript/zfoots/packet/SimpleObject.ts b/protocol/src/test/typescript/zfoots/packet/SimpleObject.ts index d96fd70e..05e194fe 100644 --- a/protocol/src/test/typescript/zfoots/packet/SimpleObject.ts +++ b/protocol/src/test/typescript/zfoots/packet/SimpleObject.ts @@ -1,3 +1,4 @@ +import IByteBuffer from '../IByteBuffer'; class SimpleObject { @@ -11,7 +12,7 @@ class SimpleObject { return SimpleObject.PROTOCOL_ID; } - static write(buffer: any, packet: SimpleObject | null) { + static write(buffer: IByteBuffer, packet: SimpleObject | null) { if (packet === null) { buffer.writeInt(0); return; @@ -21,7 +22,7 @@ class SimpleObject { buffer.writeBoolean(packet.g); } - static read(buffer: any): SimpleObject | null { + static read(buffer: IByteBuffer): SimpleObject | null { const length = buffer.readInt(); if (length === 0) { return null; diff --git a/protocol/src/test/typescript/zfoots/packet/VeryBigObject.ts b/protocol/src/test/typescript/zfoots/packet/VeryBigObject.ts index ccb66f03..c7dd6c9c 100644 --- a/protocol/src/test/typescript/zfoots/packet/VeryBigObject.ts +++ b/protocol/src/test/typescript/zfoots/packet/VeryBigObject.ts @@ -1,3 +1,4 @@ +import IByteBuffer from '../IByteBuffer'; import ObjectA from './ObjectA'; @@ -3354,7 +3355,7 @@ class VeryBigObject { return VeryBigObject.PROTOCOL_ID; } - static write(buffer: any, packet: VeryBigObject | null) { + static write(buffer: IByteBuffer, packet: VeryBigObject | null) { if (packet === null) { buffer.writeInt(0); return; @@ -6706,7 +6707,7 @@ class VeryBigObject { buffer.writeStringSet(packet.ssss9); } - static read(buffer: any): VeryBigObject | null { + static read(buffer: IByteBuffer): VeryBigObject | null { const length = buffer.readInt(); if (length === 0) { return null;