diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/typescript/TsBoolSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/typescript/TsBoolSerializer.java index 0f1e67008..048ab4839 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/typescript/TsBoolSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/typescript/TsBoolSerializer.java @@ -35,14 +35,14 @@ public Triple field(Field field, IFieldRegistration fiel @Override public void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration) { GenerateProtocolFile.addTab(builder, deep); - builder.append(StringUtils.format("buffer.writeBoolean({});", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.writeBool({});", objectStr)).append(LS); } @Override public String readObject(StringBuilder builder, int deep, Field field, IFieldRegistration fieldRegistration) { String result = "result" + GenerateProtocolFile.localVariableId++; GenerateProtocolFile.addTab(builder, deep); - builder.append(StringUtils.format("const {} = buffer.readBoolean(); ", result)).append(LS); + builder.append(StringUtils.format("const {} = buffer.readBool(); ", result)).append(LS); return result; } } diff --git a/protocol/src/main/resources/typescript/IByteBuffer.ts b/protocol/src/main/resources/typescript/IByteBuffer.ts index 9f05c3284..1c8846c73 100644 --- a/protocol/src/main/resources/typescript/IByteBuffer.ts +++ b/protocol/src/main/resources/typescript/IByteBuffer.ts @@ -1,6 +1,7 @@ interface IByteBuffer { adjustPadding(predictionLength: number, beforeWriteIndex: number): void compatibleRead(beforeReadIndex: number, length: number): boolean + getBuffer(): ArrayBuffer; setWriteOffset(writeOffset: number): void getWriteOffset(): number setReadOffset(readOffset: number): void @@ -10,8 +11,8 @@ interface IByteBuffer { isReadable(): boolean writeBytes(byteArray: ArrayBuffer): void toBytes(): ArrayBuffer - writeBoolean(value: boolean): void - readBoolean(): boolean + writeBool(value: boolean): void + readBool(): boolean writeByte(value: number): void readByte(): number writeShort(value: number): void @@ -31,8 +32,8 @@ interface IByteBuffer { readString(): string writePacket(packet: any, protocolId: number): void readPacket(protocolId: number): any - writeBooleanArray(array: Array | null): void - readBooleanArray(): boolean[] + writeBoolArray(array: Array | null): void + readBoolArray(): boolean[] writeByteArray(array: Array | null): void readByteArray(): number[] writeShortArray(array: Array | null): void @@ -50,8 +51,8 @@ interface IByteBuffer { writePacketArray(array: Array | null, protocolId: number): void readPacketArray(protocolId: number): any // ---------------------------------------------list------------------------------------------- - writeBooleanList(list: Array | null): void - readBooleanList(): boolean[] + writeBoolList(list: Array | null): void + readBoolList(): boolean[] writeByteList(list: Array | null): void readByteList(): number[] writeShortList(list: Array | null): void @@ -69,8 +70,8 @@ interface IByteBuffer { writePacketList(list: Array | null, protocolId: number): void readPacketList(protocolId: number): any[] // ---------------------------------------------set------------------------------------------- - writeBooleanSet(set: Set | null): void - readBooleanSet(): Set + writeBoolSet(set: Set | null): void + readBoolSet(): Set writeByteSet(set: Set | null): void readByteSet(): Set writeShortSet(set: Set | null): void diff --git a/protocol/src/main/resources/typescript/buffer/ByteBuffer.ts b/protocol/src/main/resources/typescript/buffer/ByteBuffer.ts index 8b727ec67..38eac709b 100644 --- a/protocol/src/main/resources/typescript/buffer/ByteBuffer.ts +++ b/protocol/src/main/resources/typescript/buffer/ByteBuffer.ts @@ -84,6 +84,10 @@ class ByteBuffer implements IByteBuffer{ return length !== -1 && this.getReadOffset() < length + beforeReadIndex; } + getBuffer(): ArrayBuffer { + return this.buffer; + } + setWriteOffset(writeOffset: number): void { if (writeOffset > this.buffer.byteLength) { throw new Error('index out of bounds exception:readerIndex:' + this.readOffset + @@ -142,7 +146,7 @@ class ByteBuffer implements IByteBuffer{ return result; } - writeBoolean(value: boolean): void { + writeBool(value: boolean): void { if (!(value === true || value === false)) { throw new Error('value must be true of false'); } @@ -155,7 +159,7 @@ class ByteBuffer implements IByteBuffer{ this.writeOffset++; } - readBoolean(): boolean { + readBool(): boolean { const value = this.bufferView.getInt8(this.readOffset); this.readOffset++; return (value === 1); @@ -403,23 +407,23 @@ class ByteBuffer implements IByteBuffer{ return protocolRegistration.read(this); } - writeBooleanArray(array: Array | null) { + writeBoolArray(array: Array | null) { if (array === null) { this.writeInt(0); } else { this.writeInt(array.length); array.forEach(element => { - this.writeBoolean(element); + this.writeBool(element); }); } } - readBooleanArray(): Array { + readBoolArray(): Array { const array: boolean[] = []; const length = this.readInt(); if (length > 0) { for (let index = 0; index < length; index++) { - array.push(this.readBoolean()); + array.push(this.readBool()); } } return array; @@ -604,12 +608,12 @@ class ByteBuffer implements IByteBuffer{ } // ---------------------------------------------list------------------------------------------- - writeBooleanList(list: Array | null): void { - this.writeBooleanArray(list); + writeBoolList(list: Array | null): void { + this.writeBoolArray(list); } - readBooleanList(): boolean[] { - return this.readBooleanArray(); + readBoolList(): boolean[] { + return this.readBoolArray(); } writeByteList(list: Array | null): void { @@ -677,19 +681,19 @@ class ByteBuffer implements IByteBuffer{ } // ---------------------------------------------set------------------------------------------- - writeBooleanSet(set: Set | null): void { + writeBoolSet(set: Set | null): void { if (set === null) { this.writeInt(0); } else { this.writeInt(set.size); set.forEach(element => { - this.writeBoolean(element); + this.writeBool(element); }); } } - readBooleanSet(): Set { - return new Set(this.readBooleanArray()); + readBoolSet(): Set { + return new Set(this.readBoolArray()); } writeByteSet(set: Set | null): void { diff --git a/protocol/src/test/typescript/main.ts b/protocol/src/test/typescript/main.ts index d46c34366..d767c3802 100644 --- a/protocol/src/test/typescript/main.ts +++ b/protocol/src/test/typescript/main.ts @@ -17,12 +17,11 @@ function assert(flag: boolean): void { // 如果是在idea中运行,需要先安装插件:Run Configuration for TypeScript console.log("Hello world"); - -// const data = fs.readFileSync('D:\\Project\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-no-compatible.bytes'); -// const data = fs.readFileSync('D:\\Project\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-out-compatible.bytes'); -// const data = fs.readFileSync('D:\\Project\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-inner-compatible.bytes'); -// const data = fs.readFileSync('D:\\Project\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-out-inner-compatible.bytes'); -const data = fs.readFileSync('D:\\Project\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-out-inner-inner-compatible.bytes'); +// const data = fs.readFileSync('C:\\github\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-no-compatible.bytes'); +// const data = fs.readFileSync('C:\\github\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-out-compatible.bytes'); +// const data = fs.readFileSync('C:\\github\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-inner-compatible.bytes'); +// const data = fs.readFileSync('C:\\github\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-out-inner-compatible.bytes'); +const data = fs.readFileSync('C:\\github\\zfoo\\protocol\\src\\test\\resources\\compatible\\normal-out-inner-inner-compatible.bytes'); const arrayBytes = new Uint8Array(data.length); data.copy(arrayBytes, 0, 0, data.length); @@ -61,8 +60,8 @@ assert(buffer.getCapacity() == 128) // boolean const testBoolean = [false, true]; testBoolean.forEach((value) => { - buffer.writeBoolean(value); - assert(buffer.readBoolean() == value); + buffer.writeBool(value); + assert(buffer.readBool() == value); }); assert(buffer.writeOffset == testBoolean.length); diff --git a/protocol/src/test/typescript/zfoots/IByteBuffer.ts b/protocol/src/test/typescript/zfoots/IByteBuffer.ts index 9f05c3284..1c8846c73 100644 --- a/protocol/src/test/typescript/zfoots/IByteBuffer.ts +++ b/protocol/src/test/typescript/zfoots/IByteBuffer.ts @@ -1,6 +1,7 @@ interface IByteBuffer { adjustPadding(predictionLength: number, beforeWriteIndex: number): void compatibleRead(beforeReadIndex: number, length: number): boolean + getBuffer(): ArrayBuffer; setWriteOffset(writeOffset: number): void getWriteOffset(): number setReadOffset(readOffset: number): void @@ -10,8 +11,8 @@ interface IByteBuffer { isReadable(): boolean writeBytes(byteArray: ArrayBuffer): void toBytes(): ArrayBuffer - writeBoolean(value: boolean): void - readBoolean(): boolean + writeBool(value: boolean): void + readBool(): boolean writeByte(value: number): void readByte(): number writeShort(value: number): void @@ -31,8 +32,8 @@ interface IByteBuffer { readString(): string writePacket(packet: any, protocolId: number): void readPacket(protocolId: number): any - writeBooleanArray(array: Array | null): void - readBooleanArray(): boolean[] + writeBoolArray(array: Array | null): void + readBoolArray(): boolean[] writeByteArray(array: Array | null): void readByteArray(): number[] writeShortArray(array: Array | null): void @@ -50,8 +51,8 @@ interface IByteBuffer { writePacketArray(array: Array | null, protocolId: number): void readPacketArray(protocolId: number): any // ---------------------------------------------list------------------------------------------- - writeBooleanList(list: Array | null): void - readBooleanList(): boolean[] + writeBoolList(list: Array | null): void + readBoolList(): boolean[] writeByteList(list: Array | null): void readByteList(): number[] writeShortList(list: Array | null): void @@ -69,8 +70,8 @@ interface IByteBuffer { writePacketList(list: Array | null, protocolId: number): void readPacketList(protocolId: number): any[] // ---------------------------------------------set------------------------------------------- - writeBooleanSet(set: Set | null): void - readBooleanSet(): Set + writeBoolSet(set: Set | null): void + readBoolSet(): Set writeByteSet(set: Set | null): void readByteSet(): Set writeShortSet(set: Set | null): void diff --git a/protocol/src/test/typescript/zfoots/buffer/ByteBuffer.ts b/protocol/src/test/typescript/zfoots/buffer/ByteBuffer.ts index 48edd1752..3bee5e718 100644 --- a/protocol/src/test/typescript/zfoots/buffer/ByteBuffer.ts +++ b/protocol/src/test/typescript/zfoots/buffer/ByteBuffer.ts @@ -84,6 +84,10 @@ class ByteBuffer implements IByteBuffer{ return length !== -1 && this.getReadOffset() < length + beforeReadIndex; } + getBuffer(): ArrayBuffer { + return this.buffer; + } + setWriteOffset(writeOffset: number): void { if (writeOffset > this.buffer.byteLength) { throw new Error('index out of bounds exception:readerIndex:' + this.readOffset + @@ -142,7 +146,7 @@ class ByteBuffer implements IByteBuffer{ return result; } - writeBoolean(value: boolean): void { + writeBool(value: boolean): void { if (!(value === true || value === false)) { throw new Error('value must be true of false'); } @@ -155,7 +159,7 @@ class ByteBuffer implements IByteBuffer{ this.writeOffset++; } - readBoolean(): boolean { + readBool(): boolean { const value = this.bufferView.getInt8(this.readOffset); this.readOffset++; return (value === 1); @@ -403,23 +407,23 @@ class ByteBuffer implements IByteBuffer{ return protocolRegistration.read(this); } - writeBooleanArray(array: Array | null) { + writeBoolArray(array: Array | null) { if (array === null) { this.writeInt(0); } else { this.writeInt(array.length); array.forEach(element => { - this.writeBoolean(element); + this.writeBool(element); }); } } - readBooleanArray(): Array { + readBoolArray(): Array { const array: boolean[] = []; const length = this.readInt(); if (length > 0) { for (let index = 0; index < length; index++) { - array.push(this.readBoolean()); + array.push(this.readBool()); } } return array; @@ -604,12 +608,12 @@ class ByteBuffer implements IByteBuffer{ } // ---------------------------------------------list------------------------------------------- - writeBooleanList(list: Array | null): void { - this.writeBooleanArray(list); + writeBoolList(list: Array | null): void { + this.writeBoolArray(list); } - readBooleanList(): boolean[] { - return this.readBooleanArray(); + readBoolList(): boolean[] { + return this.readBoolArray(); } writeByteList(list: Array | null): void { @@ -677,19 +681,19 @@ class ByteBuffer implements IByteBuffer{ } // ---------------------------------------------set------------------------------------------- - writeBooleanSet(set: Set | null): void { + writeBoolSet(set: Set | null): void { if (set === null) { this.writeInt(0); } else { this.writeInt(set.size); set.forEach(element => { - this.writeBoolean(element); + this.writeBool(element); }); } } - readBooleanSet(): Set { - return new Set(this.readBooleanArray()); + readBoolSet(): Set { + return new Set(this.readBoolArray()); } writeByteSet(set: Set | null): void { diff --git a/protocol/src/test/typescript/zfoots/buffer/Long.ts b/protocol/src/test/typescript/zfoots/buffer/Long.ts index 86e76ee2f..7acaf35f8 100644 --- a/protocol/src/test/typescript/zfoots/buffer/Long.ts +++ b/protocol/src/test/typescript/zfoots/buffer/Long.ts @@ -12,36 +12,6 @@ type WasmExports = { let wasm: WasmExports; -try { - // nodejs环境无法使用 - // wasm = new WebAssembly.Instance( - // new WebAssembly.Module( - // new Uint8Array([ - // 0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 2, 96, 0, 1, 127, 96, 4, 127, 127, - // 127, 127, 1, 127, 3, 7, 6, 0, 1, 1, 1, 1, 1, 6, 6, 1, 127, 1, 65, 0, 11, - // 7, 50, 6, 3, 109, 117, 108, 0, 1, 5, 100, 105, 118, 95, 115, 0, 2, 5, - // 100, 105, 118, 95, 117, 0, 3, 5, 114, 101, 109, 95, 115, 0, 4, 5, 114, - // 101, 109, 95, 117, 0, 5, 8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0, - // 10, 191, 1, 6, 4, 0, 35, 0, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, - // 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, - // 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, - // 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 127, - // 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, - // 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, - // 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, - // 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, - // 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, - // 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, - // 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, - // 11, - // ]) - // ), - // {} - // ).exports as WasmExports; -} catch { - // no wasm support -} - export class Long { /** * Signed zero. diff --git a/protocol/src/test/typescript/zfoots/packet/ComplexObject.ts b/protocol/src/test/typescript/zfoots/packet/ComplexObject.ts index 02efdec88..8f0c2de0a 100644 --- a/protocol/src/test/typescript/zfoots/packet/ComplexObject.ts +++ b/protocol/src/test/typescript/zfoots/packet/ComplexObject.ts @@ -95,10 +95,10 @@ export class ComplexObjectRegistration implements IProtocolRegistration { } const beforeWriteIndex = buffer.getWriteOffset(); buffer.writeInt(4); - buffer.writeBoolean(packet.flag); + buffer.writeBool(packet.flag); buffer.writeInt(packet.innerCompatibleValue); buffer.adjustPadding(4, beforeWriteIndex); } @@ -31,7 +31,7 @@ export class ObjectBRegistration implements IProtocolRegistration { } const beforeReadIndex = buffer.getReadOffset(); const packet = new ObjectB(); - const result0 = buffer.readBoolean(); + const result0 = buffer.readBool(); packet.flag = result0; if (buffer.compatibleRead(beforeReadIndex, length)) { const result1 = buffer.readInt(); diff --git a/protocol/src/test/typescript/zfoots/packet/SimpleObject.ts b/protocol/src/test/typescript/zfoots/packet/SimpleObject.ts index db01b7671..c04323c03 100644 --- a/protocol/src/test/typescript/zfoots/packet/SimpleObject.ts +++ b/protocol/src/test/typescript/zfoots/packet/SimpleObject.ts @@ -19,7 +19,7 @@ export class SimpleObjectRegistration implements IProtocolRegistration 0) { buffer.setReadOffset(beforeReadIndex + length); diff --git a/protocol/src/test/typescript/zfoots/packet/VeryBigObject.ts b/protocol/src/test/typescript/zfoots/packet/VeryBigObject.ts index 9fe2dcda0..4c9ed34e4 100644 --- a/protocol/src/test/typescript/zfoots/packet/VeryBigObject.ts +++ b/protocol/src/test/typescript/zfoots/packet/VeryBigObject.ts @@ -5473,358 +5473,358 @@ export class VeryBigObjectRegistration implements IProtocolRegistration