mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-09-03 06:19:37 +00:00
feat[ts]: compatible typescript inside class
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import EmptyObject from './packet/EmptyObject';
|
||||
import VeryBigObject from './packet/VeryBigObject';
|
||||
import ComplexObject from './packet/ComplexObject';
|
||||
import NormalObject from './packet/NormalObject';
|
||||
import ObjectA from './packet/ObjectA';
|
||||
@@ -7,6 +9,8 @@ import SimpleObject from './packet/SimpleObject';
|
||||
const protocols = new Map<number, any>();
|
||||
|
||||
// initProtocol
|
||||
protocols.set(0, EmptyObject);
|
||||
protocols.set(1, VeryBigObject);
|
||||
protocols.set(100, ComplexObject);
|
||||
protocols.set(101, NormalObject);
|
||||
protocols.set(102, ObjectA);
|
||||
@@ -17,7 +21,7 @@ class ProtocolManager {
|
||||
static getProtocol(protocolId: number): any {
|
||||
const protocol = protocols.get(protocolId);
|
||||
if (protocol === null) {
|
||||
throw new Error('[protocolId:' + protocolId + ']协议不存在');
|
||||
throw '[protocolId:' + protocolId + ']协议不存在';
|
||||
}
|
||||
return protocol;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import ProtocolManager from "../ProtocolManager";
|
||||
|
||||
const Longbits = require('./longbits.js');
|
||||
import {writeInt64, readInt64} from "./Longbits";
|
||||
|
||||
const empty_str = '';
|
||||
const initSize = 128;
|
||||
@@ -13,13 +13,13 @@ const maxInt = 2147483647;
|
||||
const minInt = -2147483648;
|
||||
|
||||
// UTF-8编码与解码
|
||||
const encoder = new TextEncoder('utf-8');
|
||||
const decoder = new TextDecoder('utf-8');
|
||||
// const encoder = new TextEncoder();
|
||||
// const decoder = new TextDecoder();
|
||||
|
||||
// nodejs的测试环境需要用以下方式特殊处理
|
||||
// const util = require('util');
|
||||
// const encoder = new util.TextEncoder('utf-8');
|
||||
// const decoder = new util.TextDecoder('utf-8');
|
||||
const util = require('util');
|
||||
const encoder = new util.TextEncoder('utf-8');
|
||||
const decoder = new util.TextDecoder('utf-8');
|
||||
|
||||
// 在js中long可以支持的最大值
|
||||
// const maxLong = 9007199254740992;
|
||||
@@ -57,6 +57,24 @@ class ByteBuffer {
|
||||
this.bufferView = new DataView(this.buffer, 0, this.buffer.byteLength);
|
||||
}
|
||||
|
||||
adjustPadding(predictionLength: number, beforeWriteIndex: number): void {
|
||||
const currentWriteIndex = this.writeOffset;
|
||||
const predictionCount = this.writeIntCount(predictionLength);
|
||||
const length = currentWriteIndex - beforeWriteIndex - predictionCount;
|
||||
const lengthCount = this.writeIntCount(length);
|
||||
const padding = lengthCount - predictionCount;
|
||||
if (padding == 0) {
|
||||
this.setWriteOffset(beforeWriteIndex);
|
||||
this.writeInt(length);
|
||||
this.setWriteOffset(currentWriteIndex);
|
||||
} else {
|
||||
const retainedByteBuf = this.buffer.slice(currentWriteIndex - length, currentWriteIndex);
|
||||
this.setWriteOffset(beforeWriteIndex);
|
||||
this.writeInt(length);
|
||||
this.writeBytes(retainedByteBuf);
|
||||
}
|
||||
}
|
||||
|
||||
setWriteOffset(writeOffset: number): void {
|
||||
if (writeOffset > this.buffer.byteLength) {
|
||||
throw new Error('index out of bounds exception:readerIndex:' + this.readOffset +
|
||||
@@ -66,6 +84,10 @@ class ByteBuffer {
|
||||
this.writeOffset = writeOffset;
|
||||
}
|
||||
|
||||
getWriteOffset(): number {
|
||||
return this.writeOffset;
|
||||
}
|
||||
|
||||
setReadOffset(readOffset: number): void {
|
||||
if (readOffset > this.writeOffset) {
|
||||
throw new Error('index out of bounds exception:readerIndex:' + this.readOffset +
|
||||
@@ -75,6 +97,10 @@ class ByteBuffer {
|
||||
this.readOffset = readOffset;
|
||||
}
|
||||
|
||||
getReadOffset(): number {
|
||||
return this.readOffset;
|
||||
}
|
||||
|
||||
getCapacity(): number {
|
||||
return this.buffer.byteLength - this.writeOffset;
|
||||
}
|
||||
@@ -209,6 +235,25 @@ class ByteBuffer {
|
||||
this.writeByte(value >>> 28);
|
||||
}
|
||||
|
||||
writeIntCount(value: number): number {
|
||||
if (!(minInt <= value && value <= maxInt)) {
|
||||
throw new Error('value must range between minInt:-2147483648 and maxInt:2147483647');
|
||||
}
|
||||
if (value >>> 7 === 0) {
|
||||
return 1;
|
||||
}
|
||||
if (value >>> 14 === 0) {
|
||||
return 2;
|
||||
}
|
||||
if (value >>> 21 === 0) {
|
||||
return 3;
|
||||
}
|
||||
if (value >>> 28 === 0) {
|
||||
return 4;
|
||||
}
|
||||
return 5;
|
||||
}
|
||||
|
||||
readInt(): number {
|
||||
let b = this.readByte();
|
||||
let value = b & 0x7F;
|
||||
@@ -238,7 +283,7 @@ class ByteBuffer {
|
||||
}
|
||||
this.ensureCapacity(9);
|
||||
|
||||
Longbits.writeInt64(this, value);
|
||||
writeInt64(this, value);
|
||||
}
|
||||
|
||||
readLong(): number {
|
||||
@@ -280,7 +325,7 @@ class ByteBuffer {
|
||||
}
|
||||
}
|
||||
}
|
||||
return Longbits.readInt64(new Uint8Array(buffer.slice(0, count))).toString();
|
||||
return readInt64(new Uint8Array(buffer.slice(0, count))).toNumber();
|
||||
}
|
||||
|
||||
writeFloat(value: number): void {
|
||||
@@ -313,18 +358,6 @@ class ByteBuffer {
|
||||
return value;
|
||||
}
|
||||
|
||||
writeChar(value: string): void {
|
||||
if (value === null || value === undefined || value.length === 0) {
|
||||
this.writeString(empty_str);
|
||||
return;
|
||||
}
|
||||
this.writeString(value.charAt(0));
|
||||
}
|
||||
|
||||
readChar(): string {
|
||||
return this.readString();
|
||||
}
|
||||
|
||||
writeString(value: string): void {
|
||||
if (value === null || value === undefined || value.trim().length === 0) {
|
||||
this.writeInt(0);
|
||||
@@ -378,7 +411,7 @@ class ByteBuffer {
|
||||
};
|
||||
|
||||
readBooleanArray(): any {
|
||||
const array = [];
|
||||
const array: boolean[] = [];
|
||||
const length = this.readInt();
|
||||
if (length > 0) {
|
||||
for (let index = 0; index < length; index++) {
|
||||
@@ -400,7 +433,7 @@ class ByteBuffer {
|
||||
};
|
||||
|
||||
readByteArray(): any {
|
||||
const array = [];
|
||||
const array: number[] = [];
|
||||
const length = this.readInt();
|
||||
if (length > 0) {
|
||||
for (let index = 0; index < length; index++) {
|
||||
@@ -422,7 +455,7 @@ class ByteBuffer {
|
||||
};
|
||||
|
||||
readShortArray(): any {
|
||||
const array = [];
|
||||
const array: number[] = [];
|
||||
const length = this.readInt();
|
||||
if (length > 0) {
|
||||
for (let index = 0; index < length; index++) {
|
||||
@@ -444,7 +477,7 @@ class ByteBuffer {
|
||||
};
|
||||
|
||||
readIntArray(): any {
|
||||
const array = [];
|
||||
const array: number[] = [];
|
||||
const length = this.readInt();
|
||||
if (length > 0) {
|
||||
for (let index = 0; index < length; index++) {
|
||||
@@ -466,7 +499,7 @@ class ByteBuffer {
|
||||
};
|
||||
|
||||
readLongArray(): any {
|
||||
const array = [];
|
||||
const array: number[] = [];
|
||||
const length = this.readInt();
|
||||
if (length > 0) {
|
||||
for (let index = 0; index < length; index++) {
|
||||
@@ -488,7 +521,7 @@ class ByteBuffer {
|
||||
};
|
||||
|
||||
readFloatArray(): any {
|
||||
const array = [];
|
||||
const array: number[] = [];
|
||||
const length = this.readInt();
|
||||
if (length > 0) {
|
||||
for (let index = 0; index < length; index++) {
|
||||
@@ -510,7 +543,7 @@ class ByteBuffer {
|
||||
};
|
||||
|
||||
readDoubleArray(): any {
|
||||
const array = [];
|
||||
const array: number[] = [];
|
||||
const length = this.readInt();
|
||||
if (length > 0) {
|
||||
for (let index = 0; index < length; index++) {
|
||||
@@ -532,7 +565,7 @@ class ByteBuffer {
|
||||
};
|
||||
|
||||
readStringArray(): any {
|
||||
const array = [];
|
||||
const array: string[] = [];
|
||||
const length = this.readInt();
|
||||
if (length > 0) {
|
||||
for (let index = 0; index < length; index++) {
|
||||
@@ -542,28 +575,6 @@ class ByteBuffer {
|
||||
return array;
|
||||
};
|
||||
|
||||
writeCharArray(array: Array<string> | null) {
|
||||
if (array === null) {
|
||||
this.writeInt(0);
|
||||
} else {
|
||||
this.writeInt(array.length);
|
||||
array.forEach(element => {
|
||||
this.writeChar(element);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
readCharArray(): any {
|
||||
const array = [];
|
||||
const length = this.readInt();
|
||||
if (length > 0) {
|
||||
for (let index = 0; index < length; index++) {
|
||||
array.push(this.readChar());
|
||||
}
|
||||
}
|
||||
return array;
|
||||
};
|
||||
|
||||
writePacketArray(array: Array<any> | null, protocolId: number) {
|
||||
if (array === null) {
|
||||
this.writeInt(0);
|
||||
@@ -577,7 +588,7 @@ class ByteBuffer {
|
||||
};
|
||||
|
||||
readPacketArray(protocolId: number): any {
|
||||
const array = [];
|
||||
const array: any[] = [];
|
||||
const length = this.readInt();
|
||||
if (length > 0) {
|
||||
const protocolRegistration = ProtocolManager.getProtocol(protocolId);
|
||||
@@ -653,14 +664,6 @@ class ByteBuffer {
|
||||
return this.readStringArray();
|
||||
};
|
||||
|
||||
writeCharList(list: any) {
|
||||
this.writeCharArray(list);
|
||||
};
|
||||
|
||||
readCharList(): any {
|
||||
return this.readCharArray();
|
||||
};
|
||||
|
||||
writePacketList(list: any, protocolId: number) {
|
||||
this.writePacketArray(list, protocolId);
|
||||
};
|
||||
@@ -790,21 +793,6 @@ class ByteBuffer {
|
||||
return new Set(this.readStringArray());
|
||||
};
|
||||
|
||||
writeCharSet(set: Set<string> | null) {
|
||||
if (set === null) {
|
||||
this.writeInt(0);
|
||||
} else {
|
||||
this.writeInt(set.size);
|
||||
set.forEach(element => {
|
||||
this.writeChar(element);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
readCharSet(): any {
|
||||
return new Set(this.readCharArray());
|
||||
};
|
||||
|
||||
writePacketSet(set: Set<any> | null, protocolId: number) {
|
||||
if (set === null) {
|
||||
this.writeInt(0);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+60
-74
@@ -1,7 +1,6 @@
|
||||
// from protobuf
|
||||
const Long = require('./long.js')
|
||||
// from https://github.com/hornta/long-ts
|
||||
import {Long} from "./Long";
|
||||
|
||||
module.exports = LongBits;
|
||||
|
||||
/**
|
||||
* Constructs new long bits.
|
||||
@@ -11,101 +10,92 @@ module.exports = LongBits;
|
||||
* @param {number} lo Low 32 bits, unsigned
|
||||
* @param {number} hi High 32 bits, unsigned
|
||||
*/
|
||||
function LongBits(lo, hi) {
|
||||
// note that the casts below are theoretically unnecessary as of today, but older statically
|
||||
// generated converter code might still call the ctor with signed 32bits. kept for compat.
|
||||
class Longbits {
|
||||
lo: number;
|
||||
hi: number;
|
||||
|
||||
/**
|
||||
* Low bits.
|
||||
* @type {number}
|
||||
*/
|
||||
constructor(lo:number, hi:number) {
|
||||
this.lo = lo >>> 0;
|
||||
|
||||
/**
|
||||
* High bits.
|
||||
* @type {number}
|
||||
*/
|
||||
this.hi = hi >>> 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Zig-zag encodes this long bits.
|
||||
* @returns {util.LongBits} `this`
|
||||
*/
|
||||
LongBits.prototype.zzEncode = function zzEncode() {
|
||||
/**
|
||||
* Zig-zag encodes this long bits.
|
||||
*/
|
||||
zzEncode(): Longbits {
|
||||
const mask = this.hi >> 31;
|
||||
this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0;
|
||||
this.lo = (this.lo << 1 ^ mask) >>> 0;
|
||||
return this;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Zig-zag decodes this long bits.
|
||||
* @returns {util.LongBits} `this`
|
||||
*/
|
||||
LongBits.prototype.zzDecode = function zzDecode() {
|
||||
/**
|
||||
* Zig-zag decodes this long bits.
|
||||
*/
|
||||
zzDecode(): Longbits {
|
||||
const mask = -(this.lo & 1);
|
||||
this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0;
|
||||
this.hi = (this.hi >>> 1 ^ mask) >>> 0;
|
||||
return this;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts this long bits to a long.
|
||||
* @param {boolean} [unsigned=false] Whether unsigned or not
|
||||
* @returns {Long} Long
|
||||
*/
|
||||
LongBits.prototype.toLong = function toLong(unsigned) {
|
||||
|
||||
/**
|
||||
* Converts this long bits to a long.
|
||||
*/
|
||||
toLong(unsigned): Long {
|
||||
return new Long(this.lo | 0, this.hi | 0, Boolean(unsigned));
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Zero bits.
|
||||
* @memberof util.LongBits
|
||||
* @type {util.LongBits}
|
||||
*/
|
||||
const zero = LongBits.zero = new LongBits(0, 0);
|
||||
|
||||
function from(value) {
|
||||
/**
|
||||
* Constructs new long bits from the specified number.
|
||||
*/
|
||||
static from(value: any) {
|
||||
if (typeof value === 'number') {
|
||||
return fromNumber(value);
|
||||
return Longbits.fromNumber(value as number);
|
||||
}
|
||||
if (typeof value === 'string' || value instanceof String) {
|
||||
value = Long.fromString(value);
|
||||
value = Long.fromString(value as string);
|
||||
}
|
||||
return value.low || value.high ? new LongBits(value.low >>> 0, value.high >>> 0) : zero;
|
||||
}
|
||||
return value.low || value.high ? new Longbits(value.low >>> 0, value.high >>> 0) : zero;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs new long bits from the specified number.
|
||||
* @param {number} value Value
|
||||
* @returns {util.LongBits} Instance
|
||||
*/
|
||||
function fromNumber(value) {
|
||||
/**
|
||||
* Constructs new long bits from the specified number.
|
||||
*/
|
||||
static fromNumber(value: number): Longbits {
|
||||
if (value === 0) {
|
||||
return zero;
|
||||
return zero;
|
||||
}
|
||||
const sign = value < 0;
|
||||
if (sign) {
|
||||
value = -value;
|
||||
value = -value;
|
||||
}
|
||||
let lo = value >>> 0;
|
||||
let hi = (value - lo) / 4294967296 >>> 0;
|
||||
if (sign) {
|
||||
hi = ~hi >>> 0;
|
||||
lo = ~lo >>> 0;
|
||||
if (++lo > 4294967295) {
|
||||
lo = 0;
|
||||
if (++hi > 4294967295) {
|
||||
hi = 0;
|
||||
}
|
||||
hi = ~hi >>> 0;
|
||||
lo = ~lo >>> 0;
|
||||
if (++lo > 4294967295) {
|
||||
lo = 0;
|
||||
if (++hi > 4294967295) {
|
||||
hi = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new LongBits(lo, hi);
|
||||
return new Longbits(lo, hi);
|
||||
}
|
||||
}
|
||||
|
||||
function writeVarint64(byteBuffer, value) {
|
||||
|
||||
|
||||
/**
|
||||
* Zero bits.
|
||||
*/
|
||||
const zero = new Longbits(0, 0);
|
||||
|
||||
|
||||
function writeVarint64(byteBuffer: any, value: Longbits) {
|
||||
let count = 0;
|
||||
while (value.hi) {
|
||||
byteBuffer.writeByte(value.lo & 127 | 128);
|
||||
@@ -125,9 +115,9 @@ function writeVarint64(byteBuffer, value) {
|
||||
byteBuffer.writeByte(value.lo);
|
||||
}
|
||||
|
||||
function readLongVarint(buffer) {
|
||||
function readLongVarint(buffer: any) {
|
||||
// tends to deopt with local vars for octet etc.
|
||||
const bits = new LongBits(0, 0);
|
||||
const bits = new Longbits(0, 0);
|
||||
let i = 0;
|
||||
const len = buffer.length;
|
||||
let pos = 0;
|
||||
@@ -175,15 +165,11 @@ function readLongVarint(buffer) {
|
||||
return bits;
|
||||
}
|
||||
|
||||
function writeInt64(byteBuffer, value) {
|
||||
const bits = from(value).zzEncode();
|
||||
export function writeInt64(byteBuffer: any, value: any) {
|
||||
const bits = Longbits.from(value).zzEncode();
|
||||
writeVarint64(byteBuffer, bits);
|
||||
}
|
||||
|
||||
function readInt64(buffer) {
|
||||
export function readInt64(buffer: any): Long {
|
||||
return readLongVarint(buffer).zzDecode().toLong(false);
|
||||
}
|
||||
|
||||
LongBits.writeInt64 = writeInt64;
|
||||
|
||||
LongBits.readInt64 = readInt64;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,82 +1,75 @@
|
||||
import ObjectA from './ObjectA';
|
||||
|
||||
// 复杂的对象
|
||||
// 包括了各种复杂的结构,数组,List,Set,Map
|
||||
//
|
||||
// @author godotg
|
||||
// 复杂的对象,包括了各种复杂的结构,数组,List,Set,Map
|
||||
class ComplexObject {
|
||||
|
||||
// byte类型,最简单的整形
|
||||
a: number = 0;
|
||||
// byte的包装类型
|
||||
// 优先使用基础类型,包装类型会有装箱拆箱
|
||||
// byte的包装类型,优先使用基础类型,包装类型会有装箱拆箱
|
||||
aa: number = 0;
|
||||
// 数组类型
|
||||
aaa: Array<number> | null = null;
|
||||
aaaa: Array<number> | null = null;
|
||||
aaa: Array<number> = [];
|
||||
aaaa: Array<number> = [];
|
||||
b: number = 0;
|
||||
bb: number = 0;
|
||||
bbb: Array<number> | null = null;
|
||||
bbbb: Array<number> | null = null;
|
||||
bbb: Array<number> = [];
|
||||
bbbb: Array<number> = [];
|
||||
c: number = 0;
|
||||
cc: number = 0;
|
||||
ccc: Array<number> | null = null;
|
||||
cccc: Array<number> | null = null;
|
||||
ccc: Array<number> = [];
|
||||
cccc: Array<number> = [];
|
||||
d: number = 0;
|
||||
dd: number = 0;
|
||||
ddd: Array<number> | null = null;
|
||||
dddd: Array<number> | null = null;
|
||||
ddd: Array<number> = [];
|
||||
dddd: Array<number> = [];
|
||||
e: number = 0;
|
||||
ee: number = 0;
|
||||
eee: Array<number> | null = null;
|
||||
eeee: Array<number> | null = null;
|
||||
eee: Array<number> = [];
|
||||
eeee: Array<number> = [];
|
||||
f: number = 0;
|
||||
ff: number = 0;
|
||||
fff: Array<number> | null = null;
|
||||
ffff: Array<number> | null = null;
|
||||
fff: Array<number> = [];
|
||||
ffff: Array<number> = [];
|
||||
g: boolean = false;
|
||||
gg: boolean = false;
|
||||
ggg: Array<boolean> | null = null;
|
||||
gggg: Array<boolean> | null = null;
|
||||
h: string = '';
|
||||
hh: string = '';
|
||||
hhh: Array<string> | null = null;
|
||||
hhhh: Array<string> | null = null;
|
||||
ggg: Array<boolean> = [];
|
||||
gggg: Array<boolean> = [];
|
||||
jj: string = '';
|
||||
jjj: Array<string> | null = null;
|
||||
jjj: Array<string> = [];
|
||||
kk: ObjectA | null = null;
|
||||
kkk: Array<ObjectA> | null = null;
|
||||
l: Array<number> | null = null;
|
||||
ll: Array<Array<Array<number>>> | null = null;
|
||||
lll: Array<Array<ObjectA>> | null = null;
|
||||
llll: Array<string> | null = null;
|
||||
lllll: Array<Map<number, string>> | null = null;
|
||||
m: Map<number, string> | null = null;
|
||||
mm: Map<number, ObjectA> | null = null;
|
||||
mmm: Map<ObjectA, Array<number>> | null = null;
|
||||
mmmm: Map<Array<Array<ObjectA>>, Array<Array<Array<number>>>> | null = null;
|
||||
mmmmm: Map<Array<Map<number, string>>, Set<Map<number, string>>> | null = null;
|
||||
s: Set<number> | null = null;
|
||||
ss: Set<Set<Array<number>>> | null = null;
|
||||
sss: Set<Set<ObjectA>> | null = null;
|
||||
ssss: Set<string> | null = null;
|
||||
sssss: Set<Map<number, string>> | null = null;
|
||||
kkk: Array<ObjectA> = [];
|
||||
l: Array<number> = [];
|
||||
ll: Array<Array<Array<number>>> = [];
|
||||
lll: Array<Array<ObjectA>> = [];
|
||||
llll: Array<string> = [];
|
||||
lllll: Array<Map<number, string>> = [];
|
||||
m: Map<number, string> = new Map();
|
||||
mm: Map<number, ObjectA> = new Map();
|
||||
mmm: Map<ObjectA, Array<number>> = new Map();
|
||||
mmmm: Map<Array<Array<ObjectA>>, Array<Array<Array<number>>>> = new Map();
|
||||
mmmmm: Map<Array<Map<number, string>>, Set<Map<number, string>>> = new Map();
|
||||
s: Set<number> = new Set();
|
||||
ss: Set<Set<Array<number>>> = new Set();
|
||||
sss: Set<Set<ObjectA>> = new Set();
|
||||
ssss: Set<string> = new Set();
|
||||
sssss: Set<Map<number, string>> = new Set();
|
||||
// 如果要修改协议并且兼容老协议,需要加上Compatible注解,按照增加的顺序添加order
|
||||
myCompatible: number = 0;
|
||||
myObject: ObjectA | null = null;
|
||||
|
||||
static PROTOCOL_ID: number = 100;
|
||||
|
||||
protocolId(): number {
|
||||
return 100;
|
||||
return ComplexObject.PROTOCOL_ID;
|
||||
}
|
||||
|
||||
static write(buffer: any, packet: ComplexObject | null) {
|
||||
if (buffer.writePacketFlag(packet)) {
|
||||
return;
|
||||
}
|
||||
if (packet === null) {
|
||||
buffer.writeInt(0);
|
||||
return;
|
||||
}
|
||||
|
||||
const beforeWriteIndex = buffer.getWriteOffset();
|
||||
buffer.writeInt(128);
|
||||
buffer.writeByte(packet.a);
|
||||
buffer.writeByte(packet.aa);
|
||||
buffer.writeByteArray(packet.aaa);
|
||||
@@ -105,10 +98,6 @@ class ComplexObject {
|
||||
buffer.writeBoolean(packet.gg);
|
||||
buffer.writeBooleanArray(packet.ggg);
|
||||
buffer.writeBooleanArray(packet.gggg);
|
||||
buffer.writeChar(packet.h);
|
||||
buffer.writeChar(packet.hh);
|
||||
buffer.writeCharArray(packet.hhh);
|
||||
buffer.writeCharArray(packet.hhhh);
|
||||
buffer.writeString(packet.jj);
|
||||
buffer.writeStringArray(packet.jjj);
|
||||
buffer.writePacket(packet.kk, 102);
|
||||
@@ -245,12 +234,15 @@ class ComplexObject {
|
||||
}
|
||||
buffer.writeInt(packet.myCompatible);
|
||||
buffer.writePacket(packet.myObject, 102);
|
||||
buffer.adjustPadding(128, beforeWriteIndex);
|
||||
}
|
||||
|
||||
static read(buffer: any): ComplexObject | null {
|
||||
if (!buffer.readBoolean()) {
|
||||
const length = buffer.readInt();
|
||||
if (length === 0) {
|
||||
return null;
|
||||
}
|
||||
const readIndex = buffer.getReadOffset();
|
||||
const packet = new ComplexObject();
|
||||
const result19 = buffer.readByte();
|
||||
packet.a = result19;
|
||||
@@ -308,177 +300,170 @@ class ComplexObject {
|
||||
packet.ggg = array45;
|
||||
const array46 = buffer.readBooleanArray();
|
||||
packet.gggg = array46;
|
||||
const result47 = buffer.readChar();
|
||||
packet.h = result47;
|
||||
const result48 = buffer.readChar();
|
||||
packet.hh = result48;
|
||||
const array49 = buffer.readCharArray();
|
||||
packet.hhh = array49;
|
||||
const array50 = buffer.readCharArray();
|
||||
packet.hhhh = array50;
|
||||
const result51 = buffer.readString();
|
||||
packet.jj = result51;
|
||||
const array52 = buffer.readStringArray();
|
||||
packet.jjj = array52;
|
||||
const result53 = buffer.readPacket(102);
|
||||
packet.kk = result53;
|
||||
const array54 = buffer.readPacketArray(102);
|
||||
packet.kkk = array54;
|
||||
const list55 = buffer.readIntList();
|
||||
packet.l = list55;
|
||||
const result56 = new Array<Array<Array<number>>>();
|
||||
const size57 = buffer.readInt();
|
||||
if (size57 > 0) {
|
||||
for (let index58 = 0; index58 < size57; index58++) {
|
||||
const result59 = new Array<Array<number>>();
|
||||
const size60 = buffer.readInt();
|
||||
if (size60 > 0) {
|
||||
for (let index61 = 0; index61 < size60; index61++) {
|
||||
const list62 = buffer.readIntList();
|
||||
result59.push(list62);
|
||||
const result47 = buffer.readString();
|
||||
packet.jj = result47;
|
||||
const array48 = buffer.readStringArray();
|
||||
packet.jjj = array48;
|
||||
const result49 = buffer.readPacket(102);
|
||||
packet.kk = result49;
|
||||
const array50 = buffer.readPacketArray(102);
|
||||
packet.kkk = array50;
|
||||
const list51 = buffer.readIntList();
|
||||
packet.l = list51;
|
||||
const result52 = new Array<Array<Array<number>>>();
|
||||
const size53 = buffer.readInt();
|
||||
if (size53 > 0) {
|
||||
for (let index54 = 0; index54 < size53; index54++) {
|
||||
const result55 = new Array<Array<number>>();
|
||||
const size56 = buffer.readInt();
|
||||
if (size56 > 0) {
|
||||
for (let index57 = 0; index57 < size56; index57++) {
|
||||
const list58 = buffer.readIntList();
|
||||
result55.push(list58);
|
||||
}
|
||||
}
|
||||
result56.push(result59);
|
||||
result52.push(result55);
|
||||
}
|
||||
}
|
||||
packet.ll = result56;
|
||||
const result63 = new Array<Array<ObjectA>>();
|
||||
const size64 = buffer.readInt();
|
||||
if (size64 > 0) {
|
||||
for (let index65 = 0; index65 < size64; index65++) {
|
||||
const list66 = buffer.readPacketList(102);
|
||||
result63.push(list66);
|
||||
packet.ll = result52;
|
||||
const result59 = new Array<Array<ObjectA>>();
|
||||
const size60 = buffer.readInt();
|
||||
if (size60 > 0) {
|
||||
for (let index61 = 0; index61 < size60; index61++) {
|
||||
const list62 = buffer.readPacketList(102);
|
||||
result59.push(list62);
|
||||
}
|
||||
}
|
||||
packet.lll = result63;
|
||||
const list67 = buffer.readStringList();
|
||||
packet.llll = list67;
|
||||
const result68 = new Array<Map<number, string>>();
|
||||
const size69 = buffer.readInt();
|
||||
if (size69 > 0) {
|
||||
for (let index70 = 0; index70 < size69; index70++) {
|
||||
const map71 = buffer.readIntStringMap();
|
||||
result68.push(map71);
|
||||
packet.lll = result59;
|
||||
const list63 = buffer.readStringList();
|
||||
packet.llll = list63;
|
||||
const result64 = new Array<Map<number, string>>();
|
||||
const size65 = buffer.readInt();
|
||||
if (size65 > 0) {
|
||||
for (let index66 = 0; index66 < size65; index66++) {
|
||||
const map67 = buffer.readIntStringMap();
|
||||
result64.push(map67);
|
||||
}
|
||||
}
|
||||
packet.lllll = result68;
|
||||
const map72 = buffer.readIntStringMap();
|
||||
packet.m = map72;
|
||||
const map73 = buffer.readIntPacketMap(102);
|
||||
packet.mm = map73;
|
||||
const result74 = new Map<ObjectA, Array<number>>();
|
||||
const size75 = buffer.readInt();
|
||||
if (size75 > 0) {
|
||||
for (let index76 = 0; index76 < size75; index76++) {
|
||||
const result77 = buffer.readPacket(102);
|
||||
const list78 = buffer.readIntList();
|
||||
result74.set(result77, list78);
|
||||
packet.lllll = result64;
|
||||
const map68 = buffer.readIntStringMap();
|
||||
packet.m = map68;
|
||||
const map69 = buffer.readIntPacketMap(102);
|
||||
packet.mm = map69;
|
||||
const result70 = new Map<ObjectA, Array<number>>();
|
||||
const size71 = buffer.readInt();
|
||||
if (size71 > 0) {
|
||||
for (let index72 = 0; index72 < size71; index72++) {
|
||||
const result73 = buffer.readPacket(102);
|
||||
const list74 = buffer.readIntList();
|
||||
result70.set(result73, list74);
|
||||
}
|
||||
}
|
||||
packet.mmm = result74;
|
||||
const result79 = new Map<Array<Array<ObjectA>>, Array<Array<Array<number>>>>();
|
||||
const size80 = buffer.readInt();
|
||||
if (size80 > 0) {
|
||||
for (let index81 = 0; index81 < size80; index81++) {
|
||||
const result82 = new Array<Array<ObjectA>>();
|
||||
packet.mmm = result70;
|
||||
const result75 = new Map<Array<Array<ObjectA>>, Array<Array<Array<number>>>>();
|
||||
const size76 = buffer.readInt();
|
||||
if (size76 > 0) {
|
||||
for (let index77 = 0; index77 < size76; index77++) {
|
||||
const result78 = new Array<Array<ObjectA>>();
|
||||
const size79 = buffer.readInt();
|
||||
if (size79 > 0) {
|
||||
for (let index80 = 0; index80 < size79; index80++) {
|
||||
const list81 = buffer.readPacketList(102);
|
||||
result78.push(list81);
|
||||
}
|
||||
}
|
||||
const result82 = new Array<Array<Array<number>>>();
|
||||
const size83 = buffer.readInt();
|
||||
if (size83 > 0) {
|
||||
for (let index84 = 0; index84 < size83; index84++) {
|
||||
const list85 = buffer.readPacketList(102);
|
||||
result82.push(list85);
|
||||
}
|
||||
}
|
||||
const result86 = new Array<Array<Array<number>>>();
|
||||
const size87 = buffer.readInt();
|
||||
if (size87 > 0) {
|
||||
for (let index88 = 0; index88 < size87; index88++) {
|
||||
const result89 = new Array<Array<number>>();
|
||||
const size90 = buffer.readInt();
|
||||
if (size90 > 0) {
|
||||
for (let index91 = 0; index91 < size90; index91++) {
|
||||
const list92 = buffer.readIntList();
|
||||
result89.push(list92);
|
||||
const result85 = new Array<Array<number>>();
|
||||
const size86 = buffer.readInt();
|
||||
if (size86 > 0) {
|
||||
for (let index87 = 0; index87 < size86; index87++) {
|
||||
const list88 = buffer.readIntList();
|
||||
result85.push(list88);
|
||||
}
|
||||
}
|
||||
result86.push(result89);
|
||||
result82.push(result85);
|
||||
}
|
||||
}
|
||||
result79.set(result82, result86);
|
||||
result75.set(result78, result82);
|
||||
}
|
||||
}
|
||||
packet.mmmm = result79;
|
||||
const result93 = new Map<Array<Map<number, string>>, Set<Map<number, string>>>();
|
||||
const size94 = buffer.readInt();
|
||||
if (size94 > 0) {
|
||||
for (let index95 = 0; index95 < size94; index95++) {
|
||||
const result96 = new Array<Map<number, string>>();
|
||||
packet.mmmm = result75;
|
||||
const result89 = new Map<Array<Map<number, string>>, Set<Map<number, string>>>();
|
||||
const size90 = buffer.readInt();
|
||||
if (size90 > 0) {
|
||||
for (let index91 = 0; index91 < size90; index91++) {
|
||||
const result92 = new Array<Map<number, string>>();
|
||||
const size93 = buffer.readInt();
|
||||
if (size93 > 0) {
|
||||
for (let index94 = 0; index94 < size93; index94++) {
|
||||
const map95 = buffer.readIntStringMap();
|
||||
result92.push(map95);
|
||||
}
|
||||
}
|
||||
const result96 = new Set<Map<number, string>>();
|
||||
const size97 = buffer.readInt();
|
||||
if (size97 > 0) {
|
||||
for (let index98 = 0; index98 < size97; index98++) {
|
||||
const map99 = buffer.readIntStringMap();
|
||||
result96.push(map99);
|
||||
result96.add(map99);
|
||||
}
|
||||
}
|
||||
const result100 = new Set<Map<number, string>>();
|
||||
const size101 = buffer.readInt();
|
||||
if (size101 > 0) {
|
||||
for (let index102 = 0; index102 < size101; index102++) {
|
||||
const map103 = buffer.readIntStringMap();
|
||||
result100.add(map103);
|
||||
result89.set(result92, result96);
|
||||
}
|
||||
}
|
||||
packet.mmmmm = result89;
|
||||
const set100 = buffer.readIntSet();
|
||||
packet.s = set100;
|
||||
const result101 = new Set<Set<Array<number>>>();
|
||||
const size102 = buffer.readInt();
|
||||
if (size102 > 0) {
|
||||
for (let index103 = 0; index103 < size102; index103++) {
|
||||
const result104 = new Set<Array<number>>();
|
||||
const size105 = buffer.readInt();
|
||||
if (size105 > 0) {
|
||||
for (let index106 = 0; index106 < size105; index106++) {
|
||||
const list107 = buffer.readIntList();
|
||||
result104.add(list107);
|
||||
}
|
||||
}
|
||||
result93.set(result96, result100);
|
||||
result101.add(result104);
|
||||
}
|
||||
}
|
||||
packet.mmmmm = result93;
|
||||
const set104 = buffer.readIntSet();
|
||||
packet.s = set104;
|
||||
const result105 = new Set<Set<Array<number>>>();
|
||||
const size106 = buffer.readInt();
|
||||
if (size106 > 0) {
|
||||
for (let index107 = 0; index107 < size106; index107++) {
|
||||
const result108 = new Set<Array<number>>();
|
||||
const size109 = buffer.readInt();
|
||||
if (size109 > 0) {
|
||||
for (let index110 = 0; index110 < size109; index110++) {
|
||||
const list111 = buffer.readIntList();
|
||||
result108.add(list111);
|
||||
}
|
||||
}
|
||||
result105.add(result108);
|
||||
packet.ss = result101;
|
||||
const result108 = new Set<Set<ObjectA>>();
|
||||
const size109 = buffer.readInt();
|
||||
if (size109 > 0) {
|
||||
for (let index110 = 0; index110 < size109; index110++) {
|
||||
const set111 = buffer.readPacketSet(102);
|
||||
result108.add(set111);
|
||||
}
|
||||
}
|
||||
packet.ss = result105;
|
||||
const result112 = new Set<Set<ObjectA>>();
|
||||
const size113 = buffer.readInt();
|
||||
if (size113 > 0) {
|
||||
for (let index114 = 0; index114 < size113; index114++) {
|
||||
const set115 = buffer.readPacketSet(102);
|
||||
result112.add(set115);
|
||||
packet.sss = result108;
|
||||
const set112 = buffer.readStringSet();
|
||||
packet.ssss = set112;
|
||||
const result113 = new Set<Map<number, string>>();
|
||||
const size114 = buffer.readInt();
|
||||
if (size114 > 0) {
|
||||
for (let index115 = 0; index115 < size114; index115++) {
|
||||
const map116 = buffer.readIntStringMap();
|
||||
result113.add(map116);
|
||||
}
|
||||
}
|
||||
packet.sss = result112;
|
||||
const set116 = buffer.readStringSet();
|
||||
packet.ssss = set116;
|
||||
const result117 = new Set<Map<number, string>>();
|
||||
const size118 = buffer.readInt();
|
||||
if (size118 > 0) {
|
||||
for (let index119 = 0; index119 < size118; index119++) {
|
||||
const map120 = buffer.readIntStringMap();
|
||||
result117.add(map120);
|
||||
}
|
||||
packet.sssss = result113;
|
||||
if (length !== -1 && buffer.getReadOffset() - readIndex < length) {
|
||||
const result117 = buffer.readInt();
|
||||
packet.myCompatible = result117;
|
||||
}
|
||||
packet.sssss = result117;
|
||||
if (!buffer.isReadable()) {
|
||||
return packet;
|
||||
if (length !== -1 && buffer.getReadOffset() - readIndex < length) {
|
||||
const result118 = buffer.readPacket(102);
|
||||
packet.myObject = result118;
|
||||
}
|
||||
const result121 = buffer.readInt();
|
||||
packet.myCompatible = result121;
|
||||
if (!buffer.isReadable()) {
|
||||
return packet;
|
||||
if (length > 0) {
|
||||
buffer.setReadOffset(readIndex + length);
|
||||
}
|
||||
const result122 = buffer.readPacket(102);
|
||||
packet.myObject = result122;
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
|
||||
class EmptyObject {
|
||||
|
||||
|
||||
|
||||
static PROTOCOL_ID: number = 0;
|
||||
|
||||
protocolId(): number {
|
||||
return EmptyObject.PROTOCOL_ID;
|
||||
}
|
||||
|
||||
static write(buffer: any, packet: EmptyObject | null) {
|
||||
if (packet === null) {
|
||||
buffer.writeInt(0);
|
||||
return;
|
||||
}
|
||||
buffer.writeInt(-1);
|
||||
}
|
||||
|
||||
static read(buffer: any): EmptyObject | null {
|
||||
const length = buffer.readInt();
|
||||
if (length === 0) {
|
||||
return null;
|
||||
}
|
||||
const readIndex = buffer.getReadOffset();
|
||||
const packet = new EmptyObject();
|
||||
|
||||
if (length > 0) {
|
||||
buffer.setReadOffset(readIndex + length);
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
|
||||
export default EmptyObject;
|
||||
@@ -1,10 +1,10 @@
|
||||
import ObjectA from './ObjectA';
|
||||
|
||||
// @author godotg
|
||||
|
||||
class NormalObject {
|
||||
|
||||
a: number = 0;
|
||||
aaa: Array<number> | null = null;
|
||||
aaa: Array<number> = [];
|
||||
b: number = 0;
|
||||
c: number = 0;
|
||||
d: number = 0;
|
||||
@@ -13,27 +13,27 @@ class NormalObject {
|
||||
g: boolean = false;
|
||||
jj: string = '';
|
||||
kk: ObjectA | null = null;
|
||||
l: Array<number> | null = null;
|
||||
ll: Array<number> | null = null;
|
||||
lll: Array<ObjectA> | null = null;
|
||||
llll: Array<string> | null = null;
|
||||
m: Map<number, string> | null = null;
|
||||
mm: Map<number, ObjectA> | null = null;
|
||||
s: Set<number> | null = null;
|
||||
ssss: Set<string> | null = null;
|
||||
l: Array<number> = [];
|
||||
ll: Array<number> = [];
|
||||
lll: Array<ObjectA> = [];
|
||||
llll: Array<string> = [];
|
||||
m: Map<number, string> = new Map();
|
||||
mm: Map<number, ObjectA> = new Map();
|
||||
s: Set<number> = new Set();
|
||||
ssss: Set<string> = new Set();
|
||||
|
||||
static PROTOCOL_ID: number = 101;
|
||||
|
||||
protocolId(): number {
|
||||
return 101;
|
||||
return NormalObject.PROTOCOL_ID;
|
||||
}
|
||||
|
||||
static write(buffer: any, packet: NormalObject | null) {
|
||||
if (buffer.writePacketFlag(packet)) {
|
||||
return;
|
||||
}
|
||||
if (packet === null) {
|
||||
buffer.writeInt(0);
|
||||
return;
|
||||
}
|
||||
|
||||
buffer.writeInt(-1);
|
||||
buffer.writeByte(packet.a);
|
||||
buffer.writeByteArray(packet.aaa);
|
||||
buffer.writeShort(packet.b);
|
||||
@@ -55,9 +55,11 @@ class NormalObject {
|
||||
}
|
||||
|
||||
static read(buffer: any): NormalObject | null {
|
||||
if (!buffer.readBoolean()) {
|
||||
const length = buffer.readInt();
|
||||
if (length === 0) {
|
||||
return null;
|
||||
}
|
||||
const readIndex = buffer.getReadOffset();
|
||||
const packet = new NormalObject();
|
||||
const result0 = buffer.readByte();
|
||||
packet.a = result0;
|
||||
@@ -95,6 +97,9 @@ class NormalObject {
|
||||
packet.s = set16;
|
||||
const set17 = buffer.readStringSet();
|
||||
packet.ssss = set17;
|
||||
if (length > 0) {
|
||||
buffer.setReadOffset(readIndex + length);
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,35 @@
|
||||
import ObjectB from './ObjectB';
|
||||
|
||||
// @author godotg
|
||||
|
||||
class ObjectA {
|
||||
|
||||
a: number = 0;
|
||||
m: Map<number, string> | null = null;
|
||||
m: Map<number, string> = new Map();
|
||||
objectB: ObjectB | null = null;
|
||||
|
||||
static PROTOCOL_ID: number = 102;
|
||||
|
||||
protocolId(): number {
|
||||
return 102;
|
||||
return ObjectA.PROTOCOL_ID;
|
||||
}
|
||||
|
||||
static write(buffer: any, packet: ObjectA | null) {
|
||||
if (buffer.writePacketFlag(packet)) {
|
||||
return;
|
||||
}
|
||||
if (packet === null) {
|
||||
buffer.writeInt(0);
|
||||
return;
|
||||
}
|
||||
|
||||
buffer.writeInt(-1);
|
||||
buffer.writeInt(packet.a);
|
||||
buffer.writeIntStringMap(packet.m);
|
||||
buffer.writePacket(packet.objectB, 103);
|
||||
}
|
||||
|
||||
static read(buffer: any): ObjectA | null {
|
||||
if (!buffer.readBoolean()) {
|
||||
const length = buffer.readInt();
|
||||
if (length === 0) {
|
||||
return null;
|
||||
}
|
||||
const readIndex = buffer.getReadOffset();
|
||||
const packet = new ObjectA();
|
||||
const result0 = buffer.readInt();
|
||||
packet.a = result0;
|
||||
@@ -35,6 +37,9 @@ class ObjectA {
|
||||
packet.m = map1;
|
||||
const result2 = buffer.readPacket(103);
|
||||
packet.objectB = result2;
|
||||
if (length > 0) {
|
||||
buffer.setReadOffset(readIndex + length);
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,36 @@
|
||||
|
||||
// @author godotg
|
||||
|
||||
class ObjectB {
|
||||
|
||||
flag: boolean = false;
|
||||
|
||||
static PROTOCOL_ID: number = 103;
|
||||
|
||||
protocolId(): number {
|
||||
return 103;
|
||||
return ObjectB.PROTOCOL_ID;
|
||||
}
|
||||
|
||||
static write(buffer: any, packet: ObjectB | null) {
|
||||
if (buffer.writePacketFlag(packet)) {
|
||||
return;
|
||||
}
|
||||
if (packet === null) {
|
||||
buffer.writeInt(0);
|
||||
return;
|
||||
}
|
||||
|
||||
buffer.writeInt(-1);
|
||||
buffer.writeBoolean(packet.flag);
|
||||
}
|
||||
|
||||
static read(buffer: any): ObjectB | null {
|
||||
if (!buffer.readBoolean()) {
|
||||
const length = buffer.readInt();
|
||||
if (length === 0) {
|
||||
return null;
|
||||
}
|
||||
const readIndex = buffer.getReadOffset();
|
||||
const packet = new ObjectB();
|
||||
const result0 = buffer.readBoolean();
|
||||
packet.flag = result0;
|
||||
if (length > 0) {
|
||||
buffer.setReadOffset(readIndex + length);
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,40 @@
|
||||
|
||||
// @author godotg
|
||||
|
||||
class SimpleObject {
|
||||
|
||||
c: number = 0;
|
||||
g: boolean = false;
|
||||
|
||||
static PROTOCOL_ID: number = 104;
|
||||
|
||||
protocolId(): number {
|
||||
return 104;
|
||||
return SimpleObject.PROTOCOL_ID;
|
||||
}
|
||||
|
||||
static write(buffer: any, packet: SimpleObject | null) {
|
||||
if (buffer.writePacketFlag(packet)) {
|
||||
return;
|
||||
}
|
||||
if (packet === null) {
|
||||
buffer.writeInt(0);
|
||||
return;
|
||||
}
|
||||
|
||||
buffer.writeInt(-1);
|
||||
buffer.writeInt(packet.c);
|
||||
buffer.writeBoolean(packet.g);
|
||||
}
|
||||
|
||||
static read(buffer: any): SimpleObject | null {
|
||||
if (!buffer.readBoolean()) {
|
||||
const length = buffer.readInt();
|
||||
if (length === 0) {
|
||||
return null;
|
||||
}
|
||||
const readIndex = buffer.getReadOffset();
|
||||
const packet = new SimpleObject();
|
||||
const result0 = buffer.readInt();
|
||||
packet.c = result0;
|
||||
const result1 = buffer.readBoolean();
|
||||
packet.g = result1;
|
||||
if (length > 0) {
|
||||
buffer.setReadOffset(readIndex + length);
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user