mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-11 02:23:42 +00:00
test[es]: EcmaScript protocol test
This commit is contained in:
@@ -18,6 +18,8 @@ class NormalObject {
|
||||
mm = new Map(); // Map<number, ObjectA>
|
||||
s = new Set(); // Set<number>
|
||||
ssss = new Set(); // Set<string>
|
||||
outCompatibleValue = 0; // number
|
||||
outCompatibleValue2 = 0; // number
|
||||
|
||||
static PROTOCOL_ID = 101;
|
||||
|
||||
@@ -30,7 +32,8 @@ class NormalObject {
|
||||
buffer.writeInt(0);
|
||||
return;
|
||||
}
|
||||
buffer.writeInt(-1);
|
||||
const beforeWriteIndex = buffer.getWriteOffset();
|
||||
buffer.writeInt(857);
|
||||
buffer.writeByte(packet.a);
|
||||
buffer.writeByteArray(packet.aaa);
|
||||
buffer.writeShort(packet.b);
|
||||
@@ -49,6 +52,9 @@ class NormalObject {
|
||||
buffer.writeIntPacketMap(packet.mm, 102);
|
||||
buffer.writeIntSet(packet.s);
|
||||
buffer.writeStringSet(packet.ssss);
|
||||
buffer.writeInt(packet.outCompatibleValue);
|
||||
buffer.writeInt(packet.outCompatibleValue2);
|
||||
buffer.adjustPadding(857, beforeWriteIndex);
|
||||
}
|
||||
|
||||
static read(buffer) {
|
||||
@@ -94,6 +100,14 @@ 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 (buffer.compatibleRead(beforeReadIndex, length)) {
|
||||
const result19 = buffer.readInt();
|
||||
packet.outCompatibleValue2 = result19;
|
||||
}
|
||||
if (length > 0) {
|
||||
buffer.setReadOffset(beforeReadIndex + length);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ class ObjectA {
|
||||
a = 0; // number
|
||||
m = new Map(); // Map<number, string>
|
||||
objectB = null; // ObjectB | null
|
||||
innerCompatibleValue = 0; // number
|
||||
|
||||
static PROTOCOL_ID = 102;
|
||||
|
||||
@@ -15,10 +16,13 @@ class ObjectA {
|
||||
buffer.writeInt(0);
|
||||
return;
|
||||
}
|
||||
buffer.writeInt(-1);
|
||||
const beforeWriteIndex = buffer.getWriteOffset();
|
||||
buffer.writeInt(201);
|
||||
buffer.writeInt(packet.a);
|
||||
buffer.writeIntStringMap(packet.m);
|
||||
buffer.writePacket(packet.objectB, 103);
|
||||
buffer.writeInt(packet.innerCompatibleValue);
|
||||
buffer.adjustPadding(201, beforeWriteIndex);
|
||||
}
|
||||
|
||||
static read(buffer) {
|
||||
@@ -34,6 +38,10 @@ 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,6 +1,7 @@
|
||||
|
||||
class ObjectB {
|
||||
flag = false; // boolean
|
||||
innerCompatibleValue = 0; // number
|
||||
|
||||
static PROTOCOL_ID = 103;
|
||||
|
||||
@@ -13,8 +14,11 @@ class ObjectB {
|
||||
buffer.writeInt(0);
|
||||
return;
|
||||
}
|
||||
buffer.writeInt(-1);
|
||||
const beforeWriteIndex = buffer.getWriteOffset();
|
||||
buffer.writeInt(4);
|
||||
buffer.writeBoolean(packet.flag);
|
||||
buffer.writeInt(packet.innerCompatibleValue);
|
||||
buffer.adjustPadding(4, beforeWriteIndex);
|
||||
}
|
||||
|
||||
static read(buffer) {
|
||||
@@ -26,6 +30,10 @@ 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user