mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-24 02:26:23 +00:00
test[typescript]: add IByteBuffer interface to ByteBuffer
This commit is contained in:
@@ -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<String> protocolReserved = Set.of("Buffer", "ByteBuf", "ByteBuffer", "LittleEndianByteBuffer", "NormalByteBuffer"
|
||||
, "IProtocol", "IProtocolRegistration", "ProtocolManager", "IFieldRegistration"
|
||||
private static Set<String> 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"
|
||||
|
||||
@@ -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<boolean> | null): void
|
||||
readBooleanArray(): boolean[]
|
||||
writeByteArray(array: Array<number> | null): void
|
||||
readByteArray(): number[]
|
||||
writeShortArray(array: Array<number> | null): void
|
||||
readShortArray(): number[]
|
||||
writeIntArray(array: Array<number> | null): void
|
||||
readIntArray(): number[]
|
||||
writeLongArray(array: Array<number> | null): void
|
||||
readLongArray(): number[]
|
||||
writeFloatArray(array: Array<number> | null): void
|
||||
readFloatArray(): number[]
|
||||
writeDoubleArray(array: Array<number> | null): void
|
||||
readDoubleArray(): number[]
|
||||
writeStringArray(array: Array<string> | null): void
|
||||
readStringArray(): string[]
|
||||
writePacketArray(array: Array<any> | null, protocolId: number): void
|
||||
readPacketArray(protocolId: number): any
|
||||
// ---------------------------------------------list-------------------------------------------
|
||||
writeBooleanList(list: Array<boolean> | null): void
|
||||
readBooleanList(): boolean[]
|
||||
writeByteList(list: Array<number> | null): void
|
||||
readByteList(): number[]
|
||||
writeShortList(list: Array<number> | null): void
|
||||
readShortList(): number[]
|
||||
writeIntList(list: Array<number> | null): void
|
||||
readIntList(): number[]
|
||||
writeLongList(list: Array<number> | null): void
|
||||
readLongList(): number[]
|
||||
writeFloatList(list: Array<number> | null): void
|
||||
readFloatList(): number[]
|
||||
writeDoubleList(list: Array<number> | null): void
|
||||
readDoubleList(): number[]
|
||||
writeStringList(list: Array<string> | null): void
|
||||
readStringList(): string[]
|
||||
writePacketList(list: Array<any> | null, protocolId: number): void
|
||||
readPacketList(protocolId: number): any[]
|
||||
// ---------------------------------------------set-------------------------------------------
|
||||
writeBooleanSet(set: Set<boolean> | null): void
|
||||
readBooleanSet(): Set<boolean>
|
||||
writeByteSet(set: Set<number> | null): void
|
||||
readByteSet(): Set<number>
|
||||
writeShortSet(set: Set<number> | null): void
|
||||
readShortSet(): Set<number>
|
||||
writeIntSet(set: Set<number> | null): void
|
||||
readIntSet(): Set<number>
|
||||
writeLongSet(set: Set<number> | null): void
|
||||
readLongSet(): Set<number>
|
||||
writeFloatSet(set: Set<number> | null): void
|
||||
readFloatSet(): Set<number>
|
||||
writeDoubleSet(set: Set<number> | null): void
|
||||
readDoubleSet(): Set<number>
|
||||
writeStringSet(set: Set<string> | null): void
|
||||
readStringSet(): Set<string>
|
||||
writePacketSet(set: Set<any> | null, protocolId: number): void
|
||||
readPacketSet(protocolId: number): Set<any>
|
||||
// ---------------------------------------------map-------------------------------------------
|
||||
writeIntIntMap(map: Map<number, number> | null): void
|
||||
readIntIntMap(): Map<number, number>
|
||||
writeIntLongMap(map: Map<number, number> | null): void
|
||||
readIntLongMap(): Map<number, number>
|
||||
writeIntStringMap(map: Map<number, string> | null): void
|
||||
readIntStringMap(): Map<number, string>
|
||||
writeIntPacketMap(map: Map<number, any> | null, protocolId: number): void
|
||||
readIntPacketMap(protocolId: number): Map<number, any>
|
||||
writeLongIntMap(map: Map<number, number> | null): void
|
||||
readLongIntMap(): Map<number, number>
|
||||
writeLongLongMap(map: Map<number, number> | null): void
|
||||
readLongLongMap(): Map<number, number>
|
||||
writeLongStringMap(map: Map<number, string> | null): void
|
||||
readLongStringMap(): Map<number, string>
|
||||
writeLongPacketMap(map: Map<number, any> | null, protocolId: number): any
|
||||
readLongPacketMap(protocolId: number): Map<number, any>
|
||||
writeStringIntMap(map: Map<string, number> | null): void
|
||||
readStringIntMap(): Map<string, number>
|
||||
writeStringLongMap(map: Map<string, number> | null): void
|
||||
readStringLongMap(): Map<string, number>
|
||||
writeStringStringMap(map: Map<string, string> | null): void
|
||||
readStringStringMap(): Map<string, string>
|
||||
writeStringPacketMap(map: Map<string, any> | null, protocolId: number): void
|
||||
readStringPacketMap(protocolId: number): Map<string, any>
|
||||
}
|
||||
|
||||
export default IByteBuffer;
|
||||
@@ -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<boolean> | null) {
|
||||
if (array === null) {
|
||||
@@ -413,9 +408,9 @@ class ByteBuffer {
|
||||
this.writeBoolean(element);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
readBooleanArray(): any {
|
||||
readBooleanArray(): Array<boolean> {
|
||||
const array: boolean[] = [];
|
||||
const length = this.readInt();
|
||||
if (length > 0) {
|
||||
@@ -424,9 +419,9 @@ class ByteBuffer {
|
||||
}
|
||||
}
|
||||
return array;
|
||||
};
|
||||
}
|
||||
|
||||
writeByteArray(array: Array<number> | null) {
|
||||
writeByteArray(array: Array<number> | null): void {
|
||||
if (array === null) {
|
||||
this.writeInt(0);
|
||||
} else {
|
||||
@@ -435,9 +430,9 @@ class ByteBuffer {
|
||||
this.writeByte(element);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
readByteArray(): any {
|
||||
readByteArray(): Array<number> {
|
||||
const array: number[] = [];
|
||||
const length = this.readInt();
|
||||
if (length > 0) {
|
||||
@@ -446,9 +441,9 @@ class ByteBuffer {
|
||||
}
|
||||
}
|
||||
return array;
|
||||
};
|
||||
}
|
||||
|
||||
writeShortArray(array: Array<number> | null) {
|
||||
writeShortArray(array: Array<number> | 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<number> | null) {
|
||||
writeIntArray(array: Array<number> | 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<number> | null) {
|
||||
writeLongArray(array: Array<number> | 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<number> | null) {
|
||||
writeFloatArray(array: Array<number> | 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<number> | null) {
|
||||
writeDoubleArray(array: Array<number> | 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<string> | null) {
|
||||
writeStringArray(array: Array<string> | 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<any> | null, protocolId: number) {
|
||||
writePacketArray(array: Array<any> | 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<boolean> | null): void {
|
||||
this.writeBooleanArray(list);
|
||||
};
|
||||
}
|
||||
|
||||
readBooleanList(): any {
|
||||
readBooleanList(): boolean[] {
|
||||
return this.readBooleanArray();
|
||||
};
|
||||
}
|
||||
|
||||
writeByteList(list: any) {
|
||||
writeByteList(list: Array<number> | null): void {
|
||||
this.writeByteArray(list);
|
||||
};
|
||||
}
|
||||
|
||||
readByteList(): any {
|
||||
readByteList(): number[] {
|
||||
return this.readByteArray();
|
||||
};
|
||||
}
|
||||
|
||||
writeShortList(list: any) {
|
||||
writeShortList(list: Array<number> | null): void {
|
||||
this.writeShortArray(list);
|
||||
};
|
||||
}
|
||||
|
||||
readShortList(): any {
|
||||
readShortList(): number[] {
|
||||
return this.readShortArray();
|
||||
};
|
||||
}
|
||||
|
||||
writeIntList(list: any) {
|
||||
writeIntList(list: Array<number> | null): void {
|
||||
this.writeIntArray(list);
|
||||
};
|
||||
}
|
||||
|
||||
readIntList(): any {
|
||||
readIntList(): number[] {
|
||||
return this.readIntArray();
|
||||
};
|
||||
}
|
||||
|
||||
writeLongList(list: any) {
|
||||
writeLongList(list: Array<number> | null): void {
|
||||
this.writeLongArray(list);
|
||||
};
|
||||
}
|
||||
|
||||
readLongList(): any {
|
||||
readLongList(): number[] {
|
||||
return this.readLongArray();
|
||||
};
|
||||
}
|
||||
|
||||
writeFloatList(list: any) {
|
||||
writeFloatList(list: Array<number> | null): void {
|
||||
this.writeFloatArray(list);
|
||||
};
|
||||
}
|
||||
|
||||
readFloatList(): any {
|
||||
readFloatList(): number[] {
|
||||
return this.readFloatArray();
|
||||
};
|
||||
}
|
||||
|
||||
writeDoubleList(list: any) {
|
||||
writeDoubleList(list: Array<number> | null): void {
|
||||
this.writeDoubleArray(list);
|
||||
};
|
||||
}
|
||||
|
||||
readDoubleList(): any {
|
||||
readDoubleList(): number[] {
|
||||
return this.readDoubleArray();
|
||||
};
|
||||
}
|
||||
|
||||
writeStringList(list: any) {
|
||||
writeStringList(list: Array<string> | null): void {
|
||||
this.writeStringArray(list);
|
||||
};
|
||||
}
|
||||
|
||||
readStringList(): any {
|
||||
readStringList(): string[] {
|
||||
return this.readStringArray();
|
||||
};
|
||||
}
|
||||
|
||||
writePacketList(list: any, protocolId: number) {
|
||||
writePacketList(list: Array<any> | null, protocolId: number): void {
|
||||
this.writePacketArray(list, protocolId);
|
||||
};
|
||||
}
|
||||
|
||||
readPacketList(protocolId: number): any {
|
||||
readPacketList(protocolId: number): any[] {
|
||||
return this.readPacketArray(protocolId);
|
||||
};
|
||||
}
|
||||
|
||||
// ---------------------------------------------set-------------------------------------------
|
||||
writeBooleanSet(set: Set<boolean> | null) {
|
||||
writeBooleanSet(set: Set<boolean> | null): void {
|
||||
if (set === null) {
|
||||
this.writeInt(0);
|
||||
} else {
|
||||
@@ -687,13 +682,13 @@ class ByteBuffer {
|
||||
this.writeBoolean(element);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
readBooleanSet(): any {
|
||||
readBooleanSet(): Set<boolean> {
|
||||
return new Set(this.readBooleanArray());
|
||||
};
|
||||
}
|
||||
|
||||
writeByteSet(set: Set<number> | null) {
|
||||
writeByteSet(set: Set<number> | null): void {
|
||||
if (set === null) {
|
||||
this.writeInt(0);
|
||||
} else {
|
||||
@@ -702,13 +697,13 @@ class ByteBuffer {
|
||||
this.writeByte(element);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
readByteSet(): any {
|
||||
readByteSet(): Set<number> {
|
||||
return new Set(this.readByteArray());
|
||||
};
|
||||
}
|
||||
|
||||
writeShortSet(set: Set<number> | null) {
|
||||
writeShortSet(set: Set<number> | null): void {
|
||||
if (set === null) {
|
||||
this.writeInt(0);
|
||||
} else {
|
||||
@@ -717,13 +712,13 @@ class ByteBuffer {
|
||||
this.writeShort(element);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
readShortSet(): any {
|
||||
readShortSet(): Set<number> {
|
||||
return new Set(this.readShortArray());
|
||||
};
|
||||
}
|
||||
|
||||
writeIntSet(set: Set<number> | null) {
|
||||
writeIntSet(set: Set<number> | null): void {
|
||||
if (set === null) {
|
||||
this.writeInt(0);
|
||||
} else {
|
||||
@@ -732,13 +727,13 @@ class ByteBuffer {
|
||||
this.writeInt(element);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
readIntSet(): any {
|
||||
readIntSet(): Set<number> {
|
||||
return new Set(this.readIntArray());
|
||||
};
|
||||
}
|
||||
|
||||
writeLongSet(set: Set<number> | null) {
|
||||
writeLongSet(set: Set<number> | null): void {
|
||||
if (set === null) {
|
||||
this.writeInt(0);
|
||||
} else {
|
||||
@@ -747,13 +742,13 @@ class ByteBuffer {
|
||||
this.writeLong(element);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
readLongSet(): any {
|
||||
readLongSet(): Set<number> {
|
||||
return new Set(this.readLongArray());
|
||||
};
|
||||
}
|
||||
|
||||
writeFloatSet(set: Set<number> | null) {
|
||||
writeFloatSet(set: Set<number> | null): void {
|
||||
if (set === null) {
|
||||
this.writeInt(0);
|
||||
} else {
|
||||
@@ -762,13 +757,13 @@ class ByteBuffer {
|
||||
this.writeFloat(element);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
readFloatSet(): any {
|
||||
readFloatSet(): Set<number> {
|
||||
return new Set(this.readFloatArray());
|
||||
};
|
||||
}
|
||||
|
||||
writeDoubleSet(set: Set<number> | null) {
|
||||
writeDoubleSet(set: Set<number> | null): void {
|
||||
if (set === null) {
|
||||
this.writeInt(0);
|
||||
} else {
|
||||
@@ -777,13 +772,13 @@ class ByteBuffer {
|
||||
this.writeDouble(element);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
readDoubleSet(): any {
|
||||
readDoubleSet(): Set<number> {
|
||||
return new Set(this.readDoubleArray());
|
||||
};
|
||||
}
|
||||
|
||||
writeStringSet(set: Set<string> | null) {
|
||||
writeStringSet(set: Set<string> | null): void {
|
||||
if (set === null) {
|
||||
this.writeInt(0);
|
||||
} else {
|
||||
@@ -792,13 +787,13 @@ class ByteBuffer {
|
||||
this.writeString(element);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
readStringSet(): any {
|
||||
readStringSet(): Set<string> {
|
||||
return new Set(this.readStringArray());
|
||||
};
|
||||
}
|
||||
|
||||
writePacketSet(set: Set<any> | null, protocolId: number) {
|
||||
writePacketSet(set: Set<any> | 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<any> {
|
||||
return new Set(this.readPacketArray(protocolId));
|
||||
};
|
||||
}
|
||||
|
||||
// ---------------------------------------------map-------------------------------------------
|
||||
writeIntIntMap(map: Map<number, number> | null) {
|
||||
writeIntIntMap(map: Map<number, number> | 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<number, number> {
|
||||
const map = new Map<number, number>();
|
||||
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<number, number> | null) {
|
||||
writeIntLongMap(map: Map<number, number> | 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<number, number> {
|
||||
const map = new Map<number, number>();
|
||||
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<number, string> | null) {
|
||||
writeIntStringMap(map: Map<number, string> | 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<number, string> {
|
||||
const map = new Map<number, string>();
|
||||
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<number, any> | null, protocolId: number) {
|
||||
writeIntPacketMap(map: Map<number, any> | 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<number, any> {
|
||||
const map = new Map<number, any>();
|
||||
const size = this.readInt();
|
||||
if (size > 0) {
|
||||
const protocolRegistration = ProtocolManager.getProtocol(protocolId);
|
||||
@@ -915,9 +910,9 @@ class ByteBuffer {
|
||||
}
|
||||
}
|
||||
return map;
|
||||
};
|
||||
}
|
||||
|
||||
writeLongIntMap(map: Map<number, number> | null) {
|
||||
writeLongIntMap(map: Map<number, number> | 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<number, number> {
|
||||
const map = new Map<number, number>();
|
||||
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<number, number> | null) {
|
||||
writeLongLongMap(map: Map<number, number> | 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<number, number> {
|
||||
const map = new Map<number, number>();
|
||||
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<number, string> | null) {
|
||||
writeLongStringMap(map: Map<number, string> | 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<number, string> {
|
||||
const map = new Map<number, string>();
|
||||
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<number, any> | 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<number, any> {
|
||||
const map = new Map<number, any>();
|
||||
const size = this.readInt();
|
||||
if (size > 0) {
|
||||
const protocolRegistration = ProtocolManager.getProtocol(protocolId);
|
||||
@@ -1017,9 +1012,9 @@ class ByteBuffer {
|
||||
}
|
||||
}
|
||||
return map;
|
||||
};
|
||||
}
|
||||
|
||||
writeStringIntMap(map: Map<string, number> | null) {
|
||||
writeStringIntMap(map: Map<string, number> | 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<string, number> {
|
||||
const map = new Map<string, number>();
|
||||
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<string, number> | null) {
|
||||
writeStringLongMap(map: Map<string, number> | 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<string, number> {
|
||||
const map = new Map<string, number>();
|
||||
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<string, string> | null) {
|
||||
writeStringStringMap(map: Map<string, string> | 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<string, string> {
|
||||
const map = new Map<string, string>();
|
||||
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<string, any> | null, protocolId: number) {
|
||||
writeStringPacketMap(map: Map<string, any> | 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<string, any> {
|
||||
const map = new Map<string, any>();
|
||||
const size = this.readInt();
|
||||
if (size > 0) {
|
||||
const protocolRegistration = ProtocolManager.getProtocol(protocolId);
|
||||
@@ -1119,7 +1114,7 @@ class ByteBuffer {
|
||||
}
|
||||
}
|
||||
return map;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default ByteBuffer;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import IByteBuffer from '../IByteBuffer';
|
||||
import ObjectA from './ObjectA';
|
||||
|
||||
|
||||
@@ -21,7 +22,6 @@ class NormalObject {
|
||||
mm: Map<number, ObjectA> = new Map();
|
||||
s: Set<number> = new Set();
|
||||
ssss: Set<string> = 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);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import IByteBuffer from '../IByteBuffer';
|
||||
import ObjectB from './ObjectB';
|
||||
|
||||
|
||||
@@ -6,7 +7,6 @@ class ObjectA {
|
||||
a: number = 0;
|
||||
m: Map<number, string> = 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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user