mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-23 18:25:50 +00:00
test[protocol]: gdscript protocol test
This commit is contained in:
@@ -13,7 +13,7 @@ var readOffset: int = 0
|
||||
func _init():
|
||||
buffer.big_endian = true
|
||||
|
||||
func adjustPadding(predictionLength: int, beforeWriteIndex: int) -> void:
|
||||
func adjustPadding(predictionLength: int, beforeWriteIndex: int):
|
||||
var currentWriteIndex = writeOffset
|
||||
var predictionCount = writeIntCount(predictionLength)
|
||||
var length = currentWriteIndex - beforeWriteIndex - predictionCount
|
||||
@@ -24,7 +24,7 @@ func adjustPadding(predictionLength: int, beforeWriteIndex: int) -> void:
|
||||
writeInt(length)
|
||||
setWriteOffset(currentWriteIndex)
|
||||
else:
|
||||
# get_partial_data of StreamPeerBuffer is deep clone
|
||||
# get_partial_data of StreamPeerBuffer is deep clone
|
||||
buffer.seek(currentWriteIndex - length)
|
||||
var retainedByteBuf = buffer.get_partial_data(length)[1]
|
||||
setWriteOffset(beforeWriteIndex)
|
||||
@@ -43,7 +43,7 @@ func compatibleRead(beforeReadIndex: int, length: int) -> bool:
|
||||
func getBuffer() -> StreamPeerBuffer:
|
||||
return buffer
|
||||
|
||||
func setWriteOffset(writeIndex: int) -> void:
|
||||
func setWriteOffset(writeIndex: int):
|
||||
if (writeIndex > buffer.get_size()):
|
||||
var template = "writeIndex[{}] out of bounds exception: readOffset: {}, writeOffset: {} (expected: 0 <= readOffset <= writeOffset <= capacity: {})"
|
||||
printerr(template.format([writeIndex, readOffset, writeOffset, buffer.get_size()], "{}"))
|
||||
@@ -54,7 +54,7 @@ func setWriteOffset(writeIndex: int) -> void:
|
||||
func getWriteOffset() -> int:
|
||||
return writeOffset
|
||||
|
||||
func setReadOffset(readIndex: int) -> void:
|
||||
func setReadOffset(readIndex: int):
|
||||
if (readIndex > writeOffset):
|
||||
var template = "readIndex[{}] out of bounds exception: readOffset: {}, writeOffset: {} (expected: 0 <= readOffset <= writeOffset <= capacity: {})"
|
||||
printerr(template.format([readIndex, readOffset, writeOffset, buffer.size()], "{}"))
|
||||
@@ -71,7 +71,7 @@ func isReadable() -> bool:
|
||||
func toBytes() -> PackedByteArray:
|
||||
return buffer.data_array.slice(0, writeOffset)
|
||||
|
||||
func newInstance(protocolId: int):
|
||||
func newInstance(protocolId: int) -> Object:
|
||||
return ProtocolManager.newInstance(protocolId)
|
||||
|
||||
# -------------------------------------------------write/read-------------------------------------------------
|
||||
@@ -84,7 +84,7 @@ func writeBytes(value: PackedByteArray):
|
||||
func readBytes(length: int) -> PackedByteArray:
|
||||
return buffer.data_array.slice(0, length)
|
||||
|
||||
func writeBool(value: bool) -> void:
|
||||
func writeBool(value: bool):
|
||||
var byte: int = 1 if value else 0
|
||||
buffer.seek(writeOffset)
|
||||
buffer.put_8(byte)
|
||||
@@ -97,7 +97,7 @@ func readBool() -> bool:
|
||||
readOffset += 1
|
||||
return byte == 1
|
||||
|
||||
func writeByte(value: int) -> void:
|
||||
func writeByte(value: int):
|
||||
buffer.seek(writeOffset)
|
||||
buffer.put_8(value)
|
||||
writeOffset += 1
|
||||
@@ -109,7 +109,7 @@ func readByte() -> int:
|
||||
readOffset += 1
|
||||
return value
|
||||
|
||||
func writeShort(value: int) -> void:
|
||||
func writeShort(value: int):
|
||||
buffer.seek(writeOffset)
|
||||
buffer.put_16(value)
|
||||
writeOffset += 2
|
||||
@@ -121,7 +121,7 @@ func readShort() -> int:
|
||||
readOffset += 2
|
||||
return value
|
||||
|
||||
func writeRawInt(value) -> void:
|
||||
func writeRawInt(value):
|
||||
buffer.seek(writeOffset)
|
||||
buffer.put_32(value)
|
||||
writeOffset += 4
|
||||
@@ -133,7 +133,7 @@ func readRawInt() -> int:
|
||||
readOffset += 4
|
||||
return value
|
||||
|
||||
func writeInt(value) -> void:
|
||||
func writeInt(value):
|
||||
if !(minInt <= value && value <= maxInt):
|
||||
printerr("value must range between minInt:-2147483648 and maxInt:2147483647")
|
||||
return
|
||||
@@ -158,7 +158,7 @@ func writeIntCount(value: int) -> int:
|
||||
func readInt() -> int:
|
||||
return readLong()
|
||||
|
||||
func writeLong(longValue: int) -> void:
|
||||
func writeLong(longValue: int):
|
||||
var value: int = (longValue << 1) ^ (longValue >> 63)
|
||||
|
||||
if (value >> 7 == 0):
|
||||
@@ -257,7 +257,7 @@ func readLong() -> int:
|
||||
return mask ^ -(value & 1)
|
||||
|
||||
|
||||
func writeFloat(value: float) -> void:
|
||||
func writeFloat(value: float):
|
||||
buffer.seek(writeOffset)
|
||||
buffer.put_float(value)
|
||||
writeOffset += 4
|
||||
@@ -269,7 +269,7 @@ func readFloat() -> float:
|
||||
readOffset += 4
|
||||
return value
|
||||
|
||||
func writeDouble(value: float) -> void:
|
||||
func writeDouble(value: float):
|
||||
buffer.seek(writeOffset)
|
||||
buffer.put_double(value)
|
||||
writeOffset += 8
|
||||
@@ -282,7 +282,7 @@ func readDouble() -> float:
|
||||
return value
|
||||
|
||||
|
||||
func writeString(value: String) -> void:
|
||||
func writeString(value: String):
|
||||
if (value == null || value.length() ==0):
|
||||
writeInt(0)
|
||||
return
|
||||
@@ -309,7 +309,7 @@ func writePacket(packet, protocolId):
|
||||
protocolRegistration.write(self, packet)
|
||||
pass
|
||||
|
||||
func readPacket(protocolId):
|
||||
func readPacket(protocolId) -> Object:
|
||||
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
|
||||
return protocolRegistration.read(self)
|
||||
|
||||
@@ -356,7 +356,7 @@ func writeShortArray(array):
|
||||
writeShort(element)
|
||||
pass
|
||||
|
||||
func readShortArray():
|
||||
func readShortArray() -> Array[int]:
|
||||
var array: Array[int] = []
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -373,7 +373,7 @@ func writeIntArray(array):
|
||||
writeInt(element)
|
||||
pass
|
||||
|
||||
func readIntArray():
|
||||
func readIntArray() -> Array[int]:
|
||||
var array: Array[int] = []
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -390,7 +390,7 @@ func writeLongArray(array):
|
||||
writeLong(element)
|
||||
pass
|
||||
|
||||
func readLongArray():
|
||||
func readLongArray() -> Array[int]:
|
||||
var array: Array[int] = []
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -407,7 +407,7 @@ func writeFloatArray(array):
|
||||
writeFloat(element)
|
||||
pass
|
||||
|
||||
func readFloatArray():
|
||||
func readFloatArray() -> Array[float]:
|
||||
var array: Array[float] = []
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -424,7 +424,7 @@ func writeDoubleArray(array):
|
||||
writeDouble(element)
|
||||
pass
|
||||
|
||||
func readDoubleArray():
|
||||
func readDoubleArray() -> Array[float]:
|
||||
var array: Array[float] = []
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -441,7 +441,7 @@ func writeStringArray(array):
|
||||
writeString(element)
|
||||
pass
|
||||
|
||||
func readStringArray():
|
||||
func readStringArray() -> Array[String]:
|
||||
var array: Array[String] = []
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -459,7 +459,7 @@ func writePacketArray(array, protocolId):
|
||||
protocolRegistration.write(self, element)
|
||||
pass
|
||||
|
||||
func readPacketArray(protocolId):
|
||||
func readPacketArray(protocolId) -> Array:
|
||||
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
|
||||
var protocol = ProtocolManager.getProtocolClass(protocolId)
|
||||
var array = Array([], typeof(protocol), StringName("RefCounted"), protocol)
|
||||
@@ -487,7 +487,7 @@ func writeIntIntMap(map):
|
||||
writeInt(map[key])
|
||||
pass
|
||||
|
||||
func readIntIntMap():
|
||||
func readIntIntMap() -> Dictionary[int, int]:
|
||||
var map: Dictionary[int, int] = {}
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -507,7 +507,7 @@ func writeIntLongMap(map):
|
||||
writeLong(map[key])
|
||||
pass
|
||||
|
||||
func readIntLongMap():
|
||||
func readIntLongMap() -> Dictionary[int, int]:
|
||||
var map: Dictionary[int, int] = {}
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -527,7 +527,7 @@ func writeIntStringMap(map):
|
||||
writeString(map[key])
|
||||
pass
|
||||
|
||||
func readIntStringMap():
|
||||
func readIntStringMap() -> Dictionary[int, String]:
|
||||
var map: Dictionary[int, String] = {}
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -548,7 +548,7 @@ func writeIntPacketMap(map, protocolId):
|
||||
protocolRegistration.write(self, map[key])
|
||||
pass
|
||||
|
||||
func readIntPacketMap(protocolId):
|
||||
func readIntPacketMap(protocolId) -> Dictionary:
|
||||
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
|
||||
var protocol = ProtocolManager.getProtocolClass(protocolId)
|
||||
var map = Dictionary({}, TYPE_INT, "", null, typeof(protocol), StringName("RefCounted"), protocol)
|
||||
@@ -570,7 +570,7 @@ func writeLongIntMap(map):
|
||||
writeInt(map[key])
|
||||
pass
|
||||
|
||||
func readLongIntMap():
|
||||
func readLongIntMap() -> Dictionary[int, int]:
|
||||
var map: Dictionary[int, int] = {}
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -590,7 +590,7 @@ func writeLongLongMap(map):
|
||||
writeLong(map[key])
|
||||
pass
|
||||
|
||||
func readLongLongMap():
|
||||
func readLongLongMap() -> Dictionary[int, int]:
|
||||
var map: Dictionary[int, int] = {}
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -610,7 +610,7 @@ func writeLongStringMap(map):
|
||||
writeString(map[key])
|
||||
pass
|
||||
|
||||
func readLongStringMap():
|
||||
func readLongStringMap() -> Dictionary[int, String]:
|
||||
var map: Dictionary[int, String] = {}
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -631,7 +631,7 @@ func writeLongPacketMap(map, protocolId):
|
||||
protocolRegistration.write(self, map[key])
|
||||
pass
|
||||
|
||||
func readLongPacketMap(protocolId):
|
||||
func readLongPacketMap(protocolId) -> Dictionary:
|
||||
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
|
||||
var protocol = ProtocolManager.getProtocolClass(protocolId)
|
||||
var map = Dictionary({}, TYPE_INT, "", null, typeof(protocol), StringName("RefCounted"), protocol)
|
||||
@@ -653,7 +653,7 @@ func writeStringIntMap(map):
|
||||
writeInt(map[key])
|
||||
pass
|
||||
|
||||
func readStringIntMap():
|
||||
func readStringIntMap() -> Dictionary[String, String]:
|
||||
var map: Dictionary[String, String] = {}
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -673,7 +673,7 @@ func writeStringLongMap(map):
|
||||
writeLong(map[key])
|
||||
pass
|
||||
|
||||
func readStringLongMap():
|
||||
func readStringLongMap() -> Dictionary[String, int]:
|
||||
var map: Dictionary[String, int] = {}
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -693,7 +693,7 @@ func writeStringStringMap(map):
|
||||
writeString(map[key])
|
||||
pass
|
||||
|
||||
func readStringStringMap():
|
||||
func readStringStringMap() -> Dictionary[String, String]:
|
||||
var map: Dictionary[String, String] = {}
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -714,7 +714,7 @@ func writeStringPacketMap(map, protocolId):
|
||||
protocolRegistration.write(self, map[key])
|
||||
pass
|
||||
|
||||
func readStringPacketMap(protocolId):
|
||||
func readStringPacketMap(protocolId) -> Dictionary:
|
||||
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
|
||||
var protocol = ProtocolManager.getProtocolClass(protocolId)
|
||||
var map = Dictionary({}, TYPE_STRING, "", null, typeof(protocol), StringName("RefCounted"), protocol)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const ProtocolManager = preload("res://zfoogd/ProtocolManager.gd")
|
||||
const ProtocolManager = preload("./ProtocolManager.gd")
|
||||
|
||||
const EMPTY: String = ""
|
||||
|
||||
@@ -13,7 +13,7 @@ var readOffset: int = 0
|
||||
func _init():
|
||||
buffer.big_endian = true
|
||||
|
||||
func adjustPadding(predictionLength: int, beforeWriteIndex: int) -> void:
|
||||
func adjustPadding(predictionLength: int, beforeWriteIndex: int):
|
||||
var currentWriteIndex = writeOffset
|
||||
var predictionCount = writeIntCount(predictionLength)
|
||||
var length = currentWriteIndex - beforeWriteIndex - predictionCount
|
||||
@@ -24,7 +24,7 @@ func adjustPadding(predictionLength: int, beforeWriteIndex: int) -> void:
|
||||
writeInt(length)
|
||||
setWriteOffset(currentWriteIndex)
|
||||
else:
|
||||
# get_partial_data of StreamPeerBuffer is deep clone
|
||||
# get_partial_data of StreamPeerBuffer is deep clone
|
||||
buffer.seek(currentWriteIndex - length)
|
||||
var retainedByteBuf = buffer.get_partial_data(length)[1]
|
||||
setWriteOffset(beforeWriteIndex)
|
||||
@@ -43,7 +43,7 @@ func compatibleRead(beforeReadIndex: int, length: int) -> bool:
|
||||
func getBuffer() -> StreamPeerBuffer:
|
||||
return buffer
|
||||
|
||||
func setWriteOffset(writeIndex: int) -> void:
|
||||
func setWriteOffset(writeIndex: int):
|
||||
if (writeIndex > buffer.get_size()):
|
||||
var template = "writeIndex[{}] out of bounds exception: readOffset: {}, writeOffset: {} (expected: 0 <= readOffset <= writeOffset <= capacity: {})"
|
||||
printerr(template.format([writeIndex, readOffset, writeOffset, buffer.get_size()], "{}"))
|
||||
@@ -54,7 +54,7 @@ func setWriteOffset(writeIndex: int) -> void:
|
||||
func getWriteOffset() -> int:
|
||||
return writeOffset
|
||||
|
||||
func setReadOffset(readIndex: int) -> void:
|
||||
func setReadOffset(readIndex: int):
|
||||
if (readIndex > writeOffset):
|
||||
var template = "readIndex[{}] out of bounds exception: readOffset: {}, writeOffset: {} (expected: 0 <= readOffset <= writeOffset <= capacity: {})"
|
||||
printerr(template.format([readIndex, readOffset, writeOffset, buffer.size()], "{}"))
|
||||
@@ -71,7 +71,7 @@ func isReadable() -> bool:
|
||||
func toBytes() -> PackedByteArray:
|
||||
return buffer.data_array.slice(0, writeOffset)
|
||||
|
||||
func newInstance(protocolId: int):
|
||||
func newInstance(protocolId: int) -> Object:
|
||||
return ProtocolManager.newInstance(protocolId)
|
||||
|
||||
# -------------------------------------------------write/read-------------------------------------------------
|
||||
@@ -84,7 +84,7 @@ func writeBytes(value: PackedByteArray):
|
||||
func readBytes(length: int) -> PackedByteArray:
|
||||
return buffer.data_array.slice(0, length)
|
||||
|
||||
func writeBool(value: bool) -> void:
|
||||
func writeBool(value: bool):
|
||||
var byte: int = 1 if value else 0
|
||||
buffer.seek(writeOffset)
|
||||
buffer.put_8(byte)
|
||||
@@ -97,7 +97,7 @@ func readBool() -> bool:
|
||||
readOffset += 1
|
||||
return byte == 1
|
||||
|
||||
func writeByte(value: int) -> void:
|
||||
func writeByte(value: int):
|
||||
buffer.seek(writeOffset)
|
||||
buffer.put_8(value)
|
||||
writeOffset += 1
|
||||
@@ -109,7 +109,7 @@ func readByte() -> int:
|
||||
readOffset += 1
|
||||
return value
|
||||
|
||||
func writeShort(value: int) -> void:
|
||||
func writeShort(value: int):
|
||||
buffer.seek(writeOffset)
|
||||
buffer.put_16(value)
|
||||
writeOffset += 2
|
||||
@@ -121,7 +121,7 @@ func readShort() -> int:
|
||||
readOffset += 2
|
||||
return value
|
||||
|
||||
func writeRawInt(value) -> void:
|
||||
func writeRawInt(value):
|
||||
buffer.seek(writeOffset)
|
||||
buffer.put_32(value)
|
||||
writeOffset += 4
|
||||
@@ -133,7 +133,7 @@ func readRawInt() -> int:
|
||||
readOffset += 4
|
||||
return value
|
||||
|
||||
func writeInt(value) -> void:
|
||||
func writeInt(value):
|
||||
if !(minInt <= value && value <= maxInt):
|
||||
printerr("value must range between minInt:-2147483648 and maxInt:2147483647")
|
||||
return
|
||||
@@ -158,7 +158,7 @@ func writeIntCount(value: int) -> int:
|
||||
func readInt() -> int:
|
||||
return readLong()
|
||||
|
||||
func writeLong(longValue: int) -> void:
|
||||
func writeLong(longValue: int):
|
||||
var value: int = (longValue << 1) ^ (longValue >> 63)
|
||||
|
||||
if (value >> 7 == 0):
|
||||
@@ -257,7 +257,7 @@ func readLong() -> int:
|
||||
return mask ^ -(value & 1)
|
||||
|
||||
|
||||
func writeFloat(value: float) -> void:
|
||||
func writeFloat(value: float):
|
||||
buffer.seek(writeOffset)
|
||||
buffer.put_float(value)
|
||||
writeOffset += 4
|
||||
@@ -269,7 +269,7 @@ func readFloat() -> float:
|
||||
readOffset += 4
|
||||
return value
|
||||
|
||||
func writeDouble(value: float) -> void:
|
||||
func writeDouble(value: float):
|
||||
buffer.seek(writeOffset)
|
||||
buffer.put_double(value)
|
||||
writeOffset += 8
|
||||
@@ -282,7 +282,7 @@ func readDouble() -> float:
|
||||
return value
|
||||
|
||||
|
||||
func writeString(value: String) -> void:
|
||||
func writeString(value: String):
|
||||
if (value == null || value.length() ==0):
|
||||
writeInt(0)
|
||||
return
|
||||
@@ -309,7 +309,7 @@ func writePacket(packet, protocolId):
|
||||
protocolRegistration.write(self, packet)
|
||||
pass
|
||||
|
||||
func readPacket(protocolId):
|
||||
func readPacket(protocolId) -> Object:
|
||||
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
|
||||
return protocolRegistration.read(self)
|
||||
|
||||
@@ -356,7 +356,7 @@ func writeShortArray(array):
|
||||
writeShort(element)
|
||||
pass
|
||||
|
||||
func readShortArray():
|
||||
func readShortArray() -> Array[int]:
|
||||
var array: Array[int] = []
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -373,7 +373,7 @@ func writeIntArray(array):
|
||||
writeInt(element)
|
||||
pass
|
||||
|
||||
func readIntArray():
|
||||
func readIntArray() -> Array[int]:
|
||||
var array: Array[int] = []
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -390,7 +390,7 @@ func writeLongArray(array):
|
||||
writeLong(element)
|
||||
pass
|
||||
|
||||
func readLongArray():
|
||||
func readLongArray() -> Array[int]:
|
||||
var array: Array[int] = []
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -407,7 +407,7 @@ func writeFloatArray(array):
|
||||
writeFloat(element)
|
||||
pass
|
||||
|
||||
func readFloatArray():
|
||||
func readFloatArray() -> Array[float]:
|
||||
var array: Array[float] = []
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -424,7 +424,7 @@ func writeDoubleArray(array):
|
||||
writeDouble(element)
|
||||
pass
|
||||
|
||||
func readDoubleArray():
|
||||
func readDoubleArray() -> Array[float]:
|
||||
var array: Array[float] = []
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -441,7 +441,7 @@ func writeStringArray(array):
|
||||
writeString(element)
|
||||
pass
|
||||
|
||||
func readStringArray():
|
||||
func readStringArray() -> Array[String]:
|
||||
var array: Array[String] = []
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -459,7 +459,7 @@ func writePacketArray(array, protocolId):
|
||||
protocolRegistration.write(self, element)
|
||||
pass
|
||||
|
||||
func readPacketArray(protocolId):
|
||||
func readPacketArray(protocolId) -> Array:
|
||||
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
|
||||
var protocol = ProtocolManager.getProtocolClass(protocolId)
|
||||
var array = Array([], typeof(protocol), StringName("RefCounted"), protocol)
|
||||
@@ -487,7 +487,7 @@ func writeIntIntMap(map):
|
||||
writeInt(map[key])
|
||||
pass
|
||||
|
||||
func readIntIntMap():
|
||||
func readIntIntMap() -> Dictionary[int, int]:
|
||||
var map: Dictionary[int, int] = {}
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -507,7 +507,7 @@ func writeIntLongMap(map):
|
||||
writeLong(map[key])
|
||||
pass
|
||||
|
||||
func readIntLongMap():
|
||||
func readIntLongMap() -> Dictionary[int, int]:
|
||||
var map: Dictionary[int, int] = {}
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -527,7 +527,7 @@ func writeIntStringMap(map):
|
||||
writeString(map[key])
|
||||
pass
|
||||
|
||||
func readIntStringMap():
|
||||
func readIntStringMap() -> Dictionary[int, String]:
|
||||
var map: Dictionary[int, String] = {}
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -548,7 +548,7 @@ func writeIntPacketMap(map, protocolId):
|
||||
protocolRegistration.write(self, map[key])
|
||||
pass
|
||||
|
||||
func readIntPacketMap(protocolId):
|
||||
func readIntPacketMap(protocolId) -> Dictionary:
|
||||
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
|
||||
var protocol = ProtocolManager.getProtocolClass(protocolId)
|
||||
var map = Dictionary({}, TYPE_INT, "", null, typeof(protocol), StringName("RefCounted"), protocol)
|
||||
@@ -570,7 +570,7 @@ func writeLongIntMap(map):
|
||||
writeInt(map[key])
|
||||
pass
|
||||
|
||||
func readLongIntMap():
|
||||
func readLongIntMap() -> Dictionary[int, int]:
|
||||
var map: Dictionary[int, int] = {}
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -590,7 +590,7 @@ func writeLongLongMap(map):
|
||||
writeLong(map[key])
|
||||
pass
|
||||
|
||||
func readLongLongMap():
|
||||
func readLongLongMap() -> Dictionary[int, int]:
|
||||
var map: Dictionary[int, int] = {}
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -610,7 +610,7 @@ func writeLongStringMap(map):
|
||||
writeString(map[key])
|
||||
pass
|
||||
|
||||
func readLongStringMap():
|
||||
func readLongStringMap() -> Dictionary[int, String]:
|
||||
var map: Dictionary[int, String] = {}
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -631,7 +631,7 @@ func writeLongPacketMap(map, protocolId):
|
||||
protocolRegistration.write(self, map[key])
|
||||
pass
|
||||
|
||||
func readLongPacketMap(protocolId):
|
||||
func readLongPacketMap(protocolId) -> Dictionary:
|
||||
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
|
||||
var protocol = ProtocolManager.getProtocolClass(protocolId)
|
||||
var map = Dictionary({}, TYPE_INT, "", null, typeof(protocol), StringName("RefCounted"), protocol)
|
||||
@@ -653,7 +653,7 @@ func writeStringIntMap(map):
|
||||
writeInt(map[key])
|
||||
pass
|
||||
|
||||
func readStringIntMap():
|
||||
func readStringIntMap() -> Dictionary[String, String]:
|
||||
var map: Dictionary[String, String] = {}
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -673,7 +673,7 @@ func writeStringLongMap(map):
|
||||
writeLong(map[key])
|
||||
pass
|
||||
|
||||
func readStringLongMap():
|
||||
func readStringLongMap() -> Dictionary[String, int]:
|
||||
var map: Dictionary[String, int] = {}
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -693,7 +693,7 @@ func writeStringStringMap(map):
|
||||
writeString(map[key])
|
||||
pass
|
||||
|
||||
func readStringStringMap():
|
||||
func readStringStringMap() -> Dictionary[String, String]:
|
||||
var map: Dictionary[String, String] = {}
|
||||
var size = readInt()
|
||||
if (size > 0):
|
||||
@@ -714,7 +714,7 @@ func writeStringPacketMap(map, protocolId):
|
||||
protocolRegistration.write(self, map[key])
|
||||
pass
|
||||
|
||||
func readStringPacketMap(protocolId):
|
||||
func readStringPacketMap(protocolId) -> Dictionary:
|
||||
var protocolRegistration = ProtocolManager.getProtocol(protocolId)
|
||||
var protocol = ProtocolManager.getProtocolClass(protocolId)
|
||||
var map = Dictionary({}, TYPE_STRING, "", null, typeof(protocol), StringName("RefCounted"), protocol)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
const EmptyObject = preload("res://zfoogd/packet/EmptyObject.gd")
|
||||
const VeryBigObject = preload("res://zfoogd/packet/VeryBigObject.gd")
|
||||
const ComplexObject = preload("res://zfoogd/packet/ComplexObject.gd")
|
||||
const NormalObject = preload("res://zfoogd/packet/NormalObject.gd")
|
||||
const ObjectA = preload("res://zfoogd/packet/ObjectA.gd")
|
||||
const ObjectB = preload("res://zfoogd/packet/ObjectB.gd")
|
||||
const SimpleObject = preload("res://zfoogd/packet/SimpleObject.gd")
|
||||
const EmptyObject = preload("./packet/EmptyObject.gd")
|
||||
const VeryBigObject = preload("./packet/VeryBigObject.gd")
|
||||
const ComplexObject = preload("./packet/ComplexObject.gd")
|
||||
const NormalObject = preload("./packet/NormalObject.gd")
|
||||
const ObjectA = preload("./packet/ObjectA.gd")
|
||||
const ObjectB = preload("./packet/ObjectB.gd")
|
||||
const SimpleObject = preload("./packet/SimpleObject.gd")
|
||||
|
||||
static var protocols: Dictionary[int, RefCounted] = {}
|
||||
static var protocolClassMap: Dictionary[int, Object] = {}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
const ByteBuffer = preload("res://zfoogd/ByteBuffer.gd")
|
||||
const ObjectA = preload("res://zfoogd/packet/ObjectA.gd")
|
||||
const ObjectB = preload("res://zfoogd/packet/ObjectB.gd")
|
||||
class_name ComplexObject
|
||||
|
||||
const ByteBuffer = preload("../ByteBuffer.gd")
|
||||
const ObjectA = preload("./ObjectA.gd")
|
||||
const ObjectB = preload("./ObjectB.gd")
|
||||
|
||||
# 复杂的对象,包括了各种复杂的结构,数组,List,Set,Map
|
||||
# byte类型,最简单的整形
|
||||
@@ -60,16 +62,13 @@ var myObject: ObjectA
|
||||
func protocolId() -> int:
|
||||
return 100
|
||||
|
||||
func get_class_name() -> String:
|
||||
return "ComplexObject"
|
||||
|
||||
func _to_string() -> String:
|
||||
const jsonTemplate = "{a:{}, aa:{}, aaa:{}, aaaa:{}, b:{}, bb:{}, bbb:{}, bbbb:{}, c:{}, cc:{}, ccc:{}, cccc:{}, d:{}, dd:{}, ddd:{}, dddd:{}, e:{}, ee:{}, eee:{}, eeee:{}, f:{}, ff:{}, fff:{}, ffff:{}, g:{}, gg:{}, ggg:{}, gggg:{}, jj:'{}', jjj:{}, kk:{}, kkk:{}, l:{}, ll:{}, lll:{}, llll:{}, lllll:{}, m:{}, mm:{}, mmm:{}, mmmm:{}, mmmmm:{}, s:{}, ss:{}, sss:{}, ssss:{}, sssss:{}, myCompatible:{}, myObject:{}}"
|
||||
var params = [self.a, self.aa, JSON.stringify(self.aaa), JSON.stringify(self.aaaa), self.b, self.bb, JSON.stringify(self.bbb), JSON.stringify(self.bbbb), self.c, self.cc, JSON.stringify(self.ccc), JSON.stringify(self.cccc), self.d, self.dd, JSON.stringify(self.ddd), JSON.stringify(self.dddd), self.e, self.ee, JSON.stringify(self.eee), JSON.stringify(self.eeee), self.f, self.ff, JSON.stringify(self.fff), JSON.stringify(self.ffff), self.g, self.gg, JSON.stringify(self.ggg), JSON.stringify(self.gggg), self.jj, JSON.stringify(self.jjj), self.kk, JSON.stringify(self.kkk), JSON.stringify(self.l), JSON.stringify(self.ll), JSON.stringify(self.lll), JSON.stringify(self.llll), JSON.stringify(self.lllll), self.m, self.mm, JSON.stringify(self.mmm), JSON.stringify(self.mmmm), JSON.stringify(self.mmmmm), JSON.stringify(self.s), JSON.stringify(self.ss), JSON.stringify(self.sss), JSON.stringify(self.ssss), JSON.stringify(self.sssss), self.myCompatible, self.myObject]
|
||||
return jsonTemplate.format(params, "{}")
|
||||
|
||||
class ComplexObjectRegistration:
|
||||
func write(buffer: ByteBuffer, packet: Object):
|
||||
func write(buffer: ByteBuffer, packet: ComplexObject):
|
||||
if (packet == null):
|
||||
buffer.writeInt(0)
|
||||
return
|
||||
@@ -213,12 +212,12 @@ class ComplexObjectRegistration:
|
||||
buffer.adjustPadding(36962, beforeWriteIndex)
|
||||
pass
|
||||
|
||||
func read(buffer: ByteBuffer):
|
||||
func read(buffer: ByteBuffer) -> ComplexObject:
|
||||
var length = buffer.readInt()
|
||||
if (length == 0):
|
||||
return null
|
||||
var beforeReadIndex = buffer.getReadOffset()
|
||||
var packet = buffer.newInstance(100)
|
||||
var packet: ComplexObject = buffer.newInstance(100)
|
||||
var result0 = buffer.readByte()
|
||||
packet.a = result0
|
||||
var result1 = buffer.readByte()
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
const ByteBuffer = preload("res://zfoogd/ByteBuffer.gd")
|
||||
class_name EmptyObject
|
||||
|
||||
const ByteBuffer = preload("../ByteBuffer.gd")
|
||||
|
||||
|
||||
|
||||
@@ -6,28 +8,25 @@ const ByteBuffer = preload("res://zfoogd/ByteBuffer.gd")
|
||||
func protocolId() -> int:
|
||||
return 0
|
||||
|
||||
func get_class_name() -> String:
|
||||
return "EmptyObject"
|
||||
|
||||
func _to_string() -> String:
|
||||
const jsonTemplate = "{}"
|
||||
var params = []
|
||||
return jsonTemplate.format(params, "{}")
|
||||
|
||||
class EmptyObjectRegistration:
|
||||
func write(buffer: ByteBuffer, packet: Object):
|
||||
func write(buffer: ByteBuffer, packet: EmptyObject):
|
||||
if (packet == null):
|
||||
buffer.writeInt(0)
|
||||
return
|
||||
buffer.writeInt(-1)
|
||||
pass
|
||||
|
||||
func read(buffer: ByteBuffer):
|
||||
func read(buffer: ByteBuffer) -> EmptyObject:
|
||||
var length = buffer.readInt()
|
||||
if (length == 0):
|
||||
return null
|
||||
var beforeReadIndex = buffer.getReadOffset()
|
||||
var packet = buffer.newInstance(0)
|
||||
var packet: EmptyObject = buffer.newInstance(0)
|
||||
|
||||
if (length > 0):
|
||||
buffer.setReadOffset(beforeReadIndex + length)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
const ByteBuffer = preload("res://zfoogd/ByteBuffer.gd")
|
||||
const ObjectA = preload("res://zfoogd/packet/ObjectA.gd")
|
||||
const ObjectB = preload("res://zfoogd/packet/ObjectB.gd")
|
||||
class_name NormalObject
|
||||
|
||||
const ByteBuffer = preload("../ByteBuffer.gd")
|
||||
const ObjectA = preload("./ObjectA.gd")
|
||||
const ObjectB = preload("./ObjectB.gd")
|
||||
|
||||
# 常规的对象,取所有语言语法的交集,基本上所有语言都支持下面的语法
|
||||
var a: int
|
||||
@@ -26,16 +28,13 @@ var ssss: Array[String]
|
||||
func protocolId() -> int:
|
||||
return 101
|
||||
|
||||
func get_class_name() -> String:
|
||||
return "NormalObject"
|
||||
|
||||
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), self.m, self.mm, JSON.stringify(self.s), JSON.stringify(self.ssss)]
|
||||
return jsonTemplate.format(params, "{}")
|
||||
|
||||
class NormalObjectRegistration:
|
||||
func write(buffer: ByteBuffer, packet: Object):
|
||||
func write(buffer: ByteBuffer, packet: NormalObject):
|
||||
if (packet == null):
|
||||
buffer.writeInt(0)
|
||||
return
|
||||
@@ -60,12 +59,12 @@ class NormalObjectRegistration:
|
||||
buffer.writeStringArray(packet.ssss)
|
||||
pass
|
||||
|
||||
func read(buffer: ByteBuffer):
|
||||
func read(buffer: ByteBuffer) -> NormalObject:
|
||||
var length = buffer.readInt()
|
||||
if (length == 0):
|
||||
return null
|
||||
var beforeReadIndex = buffer.getReadOffset()
|
||||
var packet = buffer.newInstance(101)
|
||||
var packet: NormalObject = buffer.newInstance(101)
|
||||
var result0 = buffer.readByte()
|
||||
packet.a = result0
|
||||
var array1 = buffer.readByteArray()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
const ByteBuffer = preload("res://zfoogd/ByteBuffer.gd")
|
||||
const ObjectB = preload("res://zfoogd/packet/ObjectB.gd")
|
||||
class_name ObjectA
|
||||
|
||||
const ByteBuffer = preload("../ByteBuffer.gd")
|
||||
const ObjectB = preload("./ObjectB.gd")
|
||||
|
||||
|
||||
var a: int
|
||||
@@ -9,16 +11,13 @@ var objectB: ObjectB
|
||||
func protocolId() -> int:
|
||||
return 102
|
||||
|
||||
func get_class_name() -> String:
|
||||
return "ObjectA"
|
||||
|
||||
func _to_string() -> String:
|
||||
const jsonTemplate = "{a:{}, m:{}, objectB:{}}"
|
||||
var params = [self.a, self.m, self.objectB]
|
||||
return jsonTemplate.format(params, "{}")
|
||||
|
||||
class ObjectARegistration:
|
||||
func write(buffer: ByteBuffer, packet: Object):
|
||||
func write(buffer: ByteBuffer, packet: ObjectA):
|
||||
if (packet == null):
|
||||
buffer.writeInt(0)
|
||||
return
|
||||
@@ -28,12 +27,12 @@ class ObjectARegistration:
|
||||
buffer.writePacket(packet.objectB, 103)
|
||||
pass
|
||||
|
||||
func read(buffer: ByteBuffer):
|
||||
func read(buffer: ByteBuffer) -> ObjectA:
|
||||
var length = buffer.readInt()
|
||||
if (length == 0):
|
||||
return null
|
||||
var beforeReadIndex = buffer.getReadOffset()
|
||||
var packet = buffer.newInstance(102)
|
||||
var packet: ObjectA = buffer.newInstance(102)
|
||||
var result0 = buffer.readInt()
|
||||
packet.a = result0
|
||||
var map1 = buffer.readIntStringMap()
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
const ByteBuffer = preload("res://zfoogd/ByteBuffer.gd")
|
||||
class_name ObjectB
|
||||
|
||||
const ByteBuffer = preload("../ByteBuffer.gd")
|
||||
|
||||
|
||||
var flag: bool
|
||||
@@ -6,16 +8,13 @@ var flag: bool
|
||||
func protocolId() -> int:
|
||||
return 103
|
||||
|
||||
func get_class_name() -> String:
|
||||
return "ObjectB"
|
||||
|
||||
func _to_string() -> String:
|
||||
const jsonTemplate = "{flag:{}}"
|
||||
var params = [self.flag]
|
||||
return jsonTemplate.format(params, "{}")
|
||||
|
||||
class ObjectBRegistration:
|
||||
func write(buffer: ByteBuffer, packet: Object):
|
||||
func write(buffer: ByteBuffer, packet: ObjectB):
|
||||
if (packet == null):
|
||||
buffer.writeInt(0)
|
||||
return
|
||||
@@ -23,12 +22,12 @@ class ObjectBRegistration:
|
||||
buffer.writeBool(packet.flag)
|
||||
pass
|
||||
|
||||
func read(buffer: ByteBuffer):
|
||||
func read(buffer: ByteBuffer) -> ObjectB:
|
||||
var length = buffer.readInt()
|
||||
if (length == 0):
|
||||
return null
|
||||
var beforeReadIndex = buffer.getReadOffset()
|
||||
var packet = buffer.newInstance(103)
|
||||
var packet: ObjectB = buffer.newInstance(103)
|
||||
var result0 = buffer.readBool()
|
||||
packet.flag = result0
|
||||
if (length > 0):
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
const ByteBuffer = preload("res://zfoogd/ByteBuffer.gd")
|
||||
class_name SimpleObject
|
||||
|
||||
const ByteBuffer = preload("../ByteBuffer.gd")
|
||||
|
||||
|
||||
var c: int
|
||||
@@ -7,16 +9,13 @@ var g: bool
|
||||
func protocolId() -> int:
|
||||
return 104
|
||||
|
||||
func get_class_name() -> String:
|
||||
return "SimpleObject"
|
||||
|
||||
func _to_string() -> String:
|
||||
const jsonTemplate = "{c:{}, g:{}}"
|
||||
var params = [self.c, self.g]
|
||||
return jsonTemplate.format(params, "{}")
|
||||
|
||||
class SimpleObjectRegistration:
|
||||
func write(buffer: ByteBuffer, packet: Object):
|
||||
func write(buffer: ByteBuffer, packet: SimpleObject):
|
||||
if (packet == null):
|
||||
buffer.writeInt(0)
|
||||
return
|
||||
@@ -25,12 +24,12 @@ class SimpleObjectRegistration:
|
||||
buffer.writeBool(packet.g)
|
||||
pass
|
||||
|
||||
func read(buffer: ByteBuffer):
|
||||
func read(buffer: ByteBuffer) -> SimpleObject:
|
||||
var length = buffer.readInt()
|
||||
if (length == 0):
|
||||
return null
|
||||
var beforeReadIndex = buffer.getReadOffset()
|
||||
var packet = buffer.newInstance(104)
|
||||
var packet: SimpleObject = buffer.newInstance(104)
|
||||
var result0 = buffer.readInt()
|
||||
packet.c = result0
|
||||
var result1 = buffer.readBool()
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user