mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-03 05:20:50 +00:00
test[gdscript]: compatible field of inside protocol class
This commit is contained in:
1 parent
778e1a5177
commit
1475e640c6
4 files changed
+41
-12
No files matched your search
@@ -25,11 +25,14 @@ func adjustPadding(predictionLength: int, beforeWriteIndex: int) -> void:
|
||||
setWriteOffset(currentWriteIndex)
|
||||
else:
|
||||
buffer.seek(currentWriteIndex - length)
|
||||
var retainedByteBuf = buffer.get_partial_data(length)
|
||||
buffer.seek(beforeWriteIndex)
|
||||
var retainedByteBuf = buffer.get_partial_data(length)[1]
|
||||
setWriteOffset(beforeWriteIndex)
|
||||
writeInt(length)
|
||||
buffer.seek(beforeWriteIndex + lengthCount)
|
||||
buffer.put_partial_data(retainedByteBuf)
|
||||
setWriteOffset(getWriteOffset() + length)
|
||||
var count = beforeWriteIndex + lengthCount + length
|
||||
buffer.seek(count)
|
||||
setWriteOffset(count)
|
||||
pass
|
||||
|
||||
func compatibleRead(beforeReadIndex: int, length: int) -> bool:
|
||||
|
||||
@@ -22,17 +22,20 @@ var m: Dictionary # Map<number, string>
|
||||
var mm: Dictionary # Map<number, ObjectA>
|
||||
var s: Array[int]
|
||||
var ssss: Array[String]
|
||||
var outCompatibleValue: int
|
||||
var outCompatibleValue2: int
|
||||
|
||||
func _to_string() -> String:
|
||||
const jsonTemplate = "{a:{}, aaa:{}, b:{}, c:{}, d:{}, e:{}, f:{}, g:{}, jj:'{}', kk:{}, l:{}, ll:{}, lll:{}, llll:{}, m:{}, mm:{}, s:{}, ssss:{}}"
|
||||
var params = [self.a, JSON.stringify(self.aaa), self.b, self.c, self.d, self.e, self.f, self.g, self.jj, self.kk, JSON.stringify(self.l), JSON.stringify(self.ll), JSON.stringify(self.lll), JSON.stringify(self.llll), JSON.stringify(self.m), JSON.stringify(self.mm), JSON.stringify(self.s), JSON.stringify(self.ssss)]
|
||||
const jsonTemplate = "{a:{}, aaa:{}, b:{}, c:{}, d:{}, e:{}, f:{}, g:{}, jj:'{}', kk:{}, l:{}, ll:{}, lll:{}, llll:{}, m:{}, mm:{}, s:{}, ssss:{}, outCompatibleValue:{}, outCompatibleValue2:{}}"
|
||||
var params = [self.a, JSON.stringify(self.aaa), self.b, self.c, self.d, self.e, self.f, self.g, self.jj, self.kk, JSON.stringify(self.l), JSON.stringify(self.ll), JSON.stringify(self.lll), JSON.stringify(self.llll), JSON.stringify(self.m), JSON.stringify(self.mm), JSON.stringify(self.s), JSON.stringify(self.ssss), self.outCompatibleValue, self.outCompatibleValue2]
|
||||
return jsonTemplate.format(params, "{}")
|
||||
|
||||
static func write(buffer, packet):
|
||||
if (packet == null):
|
||||
buffer.writeInt(0)
|
||||
return
|
||||
buffer.writeInt(-1)
|
||||
var beforeWriteIndex = buffer.getWriteOffset()
|
||||
buffer.writeInt(857)
|
||||
buffer.writeByte(packet.a)
|
||||
buffer.writeByteArray(packet.aaa)
|
||||
buffer.writeShort(packet.b)
|
||||
@@ -51,6 +54,9 @@ static func write(buffer, packet):
|
||||
buffer.writeIntPacketMap(packet.mm, 102)
|
||||
buffer.writeIntArray(packet.s)
|
||||
buffer.writeStringArray(packet.ssss)
|
||||
buffer.writeInt(packet.outCompatibleValue)
|
||||
buffer.writeInt(packet.outCompatibleValue2)
|
||||
buffer.adjustPadding(857, beforeWriteIndex)
|
||||
pass
|
||||
|
||||
static func read(buffer):
|
||||
@@ -95,6 +101,12 @@ static func read(buffer):
|
||||
packet.s = set16
|
||||
var set17 = buffer.readStringArray()
|
||||
packet.ssss = set17
|
||||
if buffer.compatibleRead(beforeReadIndex, length):
|
||||
var result18 = buffer.readInt()
|
||||
packet.outCompatibleValue = result18;
|
||||
if buffer.compatibleRead(beforeReadIndex, length):
|
||||
var result19 = buffer.readInt()
|
||||
packet.outCompatibleValue2 = result19;
|
||||
if (length > 0):
|
||||
buffer.setReadOffset(beforeReadIndex + length)
|
||||
return packet
|
||||
@@ -6,20 +6,24 @@ const ObjectB = preload("res://zfoogd/packet/ObjectB.gd")
|
||||
var a: int
|
||||
var m: Dictionary # Map<number, string>
|
||||
var objectB: ObjectB
|
||||
var innerCompatibleValue: int
|
||||
|
||||
func _to_string() -> String:
|
||||
const jsonTemplate = "{a:{}, m:{}, objectB:{}}"
|
||||
var params = [self.a, JSON.stringify(self.m), self.objectB]
|
||||
const jsonTemplate = "{a:{}, m:{}, objectB:{}, innerCompatibleValue:{}}"
|
||||
var params = [self.a, JSON.stringify(self.m), self.objectB, self.innerCompatibleValue]
|
||||
return jsonTemplate.format(params, "{}")
|
||||
|
||||
static func write(buffer, packet):
|
||||
if (packet == null):
|
||||
buffer.writeInt(0)
|
||||
return
|
||||
buffer.writeInt(-1)
|
||||
var 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)
|
||||
pass
|
||||
|
||||
static func read(buffer):
|
||||
@@ -34,6 +38,9 @@ static func read(buffer):
|
||||
packet.m = map1
|
||||
var result2 = buffer.readPacket(103)
|
||||
packet.objectB = result2
|
||||
if buffer.compatibleRead(beforeReadIndex, length):
|
||||
var result3 = buffer.readInt()
|
||||
packet.innerCompatibleValue = result3;
|
||||
if (length > 0):
|
||||
buffer.setReadOffset(beforeReadIndex + length)
|
||||
return packet
|
||||
@@ -3,18 +3,22 @@ const PROTOCOL_CLASS_NAME = "ObjectB"
|
||||
|
||||
|
||||
var flag: bool
|
||||
var innerCompatibleValue: int
|
||||
|
||||
func _to_string() -> String:
|
||||
const jsonTemplate = "{flag:{}}"
|
||||
var params = [self.flag]
|
||||
const jsonTemplate = "{flag:{}, innerCompatibleValue:{}}"
|
||||
var params = [self.flag, self.innerCompatibleValue]
|
||||
return jsonTemplate.format(params, "{}")
|
||||
|
||||
static func write(buffer, packet):
|
||||
if (packet == null):
|
||||
buffer.writeInt(0)
|
||||
return
|
||||
buffer.writeInt(-1)
|
||||
var beforeWriteIndex = buffer.getWriteOffset()
|
||||
buffer.writeInt(4)
|
||||
buffer.writeBool(packet.flag)
|
||||
buffer.writeInt(packet.innerCompatibleValue)
|
||||
buffer.adjustPadding(4, beforeWriteIndex)
|
||||
pass
|
||||
|
||||
static func read(buffer):
|
||||
@@ -25,6 +29,9 @@ static func read(buffer):
|
||||
var packet = buffer.newInstance(PROTOCOL_ID)
|
||||
var result0 = buffer.readBool()
|
||||
packet.flag = result0
|
||||
if buffer.compatibleRead(beforeReadIndex, length):
|
||||
var result1 = buffer.readInt()
|
||||
packet.innerCompatibleValue = result1;
|
||||
if (length > 0):
|
||||
buffer.setReadOffset(beforeReadIndex + length)
|
||||
return packet
|
||||
Reference in new issue
Block a user