feat[swift]: cut down array serialization of swift

This commit is contained in:
godotg
2024-07-28 21:34:23 +08:00
parent a10bf0402d
commit a685de104e
3 changed files with 298 additions and 25 deletions
@@ -53,7 +53,7 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeBoolArray(&{});", objectStr)).append(LS);
break;
case Kotlin, Scala, GdScript, Python, Ruby:
case Kotlin, Scala, GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeBoolArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -83,7 +83,7 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeBoolArray(&{});", objectStr)).append(LS);
break;
case Kotlin, Scala, GdScript, Python, Ruby:
case Kotlin, Scala, GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeBoolArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -113,7 +113,7 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeByteArray(&{});", objectStr)).append(LS);
break;
case Kotlin, Scala, GdScript, Python, Ruby:
case Kotlin, Scala, GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeByteArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -143,7 +143,7 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeByteArray(&{});", objectStr)).append(LS);
break;
case Kotlin, Scala, GdScript, Python, Ruby:
case Kotlin, Scala, GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeByteArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -173,7 +173,7 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeShortArray(&{});", objectStr)).append(LS);
break;
case Kotlin, Scala, GdScript, Python, Ruby:
case Kotlin, Scala, GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeShortArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -203,7 +203,7 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeShortArray(&{});", objectStr)).append(LS);
break;
case Kotlin, Scala, GdScript, Python, Ruby:
case Kotlin, Scala, GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeShortArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -233,7 +233,7 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeIntArray(&{});", objectStr)).append(LS);
break;
case Kotlin, Scala, GdScript, Python, Ruby:
case Kotlin, Scala, GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeIntArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -263,7 +263,7 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeIntArray(&{});", objectStr)).append(LS);
break;
case Kotlin, Scala, GdScript, Python, Ruby:
case Kotlin, Scala, GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeIntArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -293,7 +293,7 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeLongArray(&{});", objectStr)).append(LS);
break;
case Kotlin, Scala, GdScript, Python, Ruby:
case Kotlin, Scala, GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeLongArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -323,7 +323,7 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeLongArray(&{});", objectStr)).append(LS);
break;
case Kotlin, Scala, GdScript, Python, Ruby:
case Kotlin, Scala, GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeLongArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -353,7 +353,7 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeFloatArray(&{});", objectStr)).append(LS);
break;
case Kotlin, Scala, GdScript, Python, Ruby:
case Kotlin, Scala, GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeFloatArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -383,7 +383,7 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeFloatArray(&{});", objectStr)).append(LS);
break;
case Kotlin, Scala, GdScript, Python, Ruby:
case Kotlin, Scala, GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeFloatArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -413,7 +413,7 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeDoubleArray(&{});", objectStr)).append(LS);
break;
case Kotlin, Scala, GdScript, Python, Ruby:
case Kotlin, Scala, GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeDoubleArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -443,7 +443,7 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeDoubleArray(&{});", objectStr)).append(LS);
break;
case Kotlin, Scala, GdScript, Python, Ruby:
case Kotlin, Scala, GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeDoubleArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -473,7 +473,7 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeStringArray(&{});", objectStr)).append(LS);
break;
case Kotlin, Scala, GdScript, Python, Ruby:
case Kotlin, Scala, GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeStringArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -503,7 +503,7 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Enhance:
builder.append(StringUtils.format("{}.writePacketArray($1, {}, {});", EnhanceUtils.byteBufUtils, objectStr, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(protocolId)));
break;
case GdScript, Python, Ruby:
case GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writePacketArray({}, {})", objectStr, protocolId)).append(LS);
break;
case Lua:
@@ -550,6 +550,9 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readBoolArray();", array)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readBoolArray()", array)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readBoolArray()", array)).append(LS);
break;
@@ -596,6 +599,9 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readBoolArray();", array)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readBoolArray()", array)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readBoolArray()", array)).append(LS);
break;
@@ -642,6 +648,9 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readByteArray();", array)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readByteArray()", array)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readByteArray()", array)).append(LS);
break;
@@ -688,6 +697,9 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readByteArray();", array)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readByteArray()", array)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readByteArray()", array)).append(LS);
break;
@@ -734,6 +746,9 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readShortArray();", array)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readShortArray()", array)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readShortArray()", array)).append(LS);
break;
@@ -780,6 +795,9 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readShortArray();", array)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readShortArray()", array)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readShortArray()", array)).append(LS);
break;
@@ -826,6 +844,9 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readIntArray();", array)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readIntArray()", array)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readIntArray()", array)).append(LS);
break;
@@ -872,6 +893,9 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readIntArray();", array)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readIntArray()", array)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readIntArray()", array)).append(LS);
break;
@@ -918,6 +942,9 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readLongArray();", array)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readLongArray()", array)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readLongArray()", array)).append(LS);
break;
@@ -964,6 +991,9 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readLongArray();", array)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readLongArray()", array)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readLongArray()", array)).append(LS);
break;
@@ -1010,6 +1040,9 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readFloatArray();", array)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readFloatArray()", array)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readFloatArray()", array)).append(LS);
break;
@@ -1056,6 +1089,9 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readFloatArray();", array)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readFloatArray()", array)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readFloatArray()", array)).append(LS);
break;
@@ -1102,6 +1138,9 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readDoubleArray();", array)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readDoubleArray()", array)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readDoubleArray()", array)).append(LS);
break;
@@ -1148,6 +1187,9 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readDoubleArray();", array)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readDoubleArray()", array)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readDoubleArray()", array)).append(LS);
break;
@@ -1194,6 +1236,9 @@ public class CutDownArraySerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readStringArray();", array)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readStringArray()", array)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readStringArray()", array)).append(LS);
break;
@@ -1238,6 +1283,9 @@ public class CutDownArraySerializer implements ICutDownSerializer {
var protocolName = EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(protocolId);
switch (language) {
// Java不支持泛型的数组初始化,这里不做任何操作
case Swift:
builder.append(StringUtils.format("let {} = buffer.readPacketArray({}) as! Array<{}>", array, protocolId, protocolName)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readPacketArray({})", array, protocolId)).append(LS);
break;
@@ -52,7 +52,7 @@ public class CutDownListSerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeBoolArray(&{});", objectStr)).append(LS);
break;
case GdScript, Python, Ruby:
case GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeBoolArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -85,7 +85,7 @@ public class CutDownListSerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeByteArray(&{});", objectStr)).append(LS);
break;
case GdScript, Python, Ruby:
case GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeByteArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -119,7 +119,7 @@ public class CutDownListSerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeShortArray(&{});", objectStr)).append(LS);
break;
case GdScript, Python, Ruby:
case GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeShortArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -152,7 +152,7 @@ public class CutDownListSerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeIntArray(&{});", objectStr)).append(LS);
break;
case GdScript, Python, Ruby:
case GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeIntArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -185,7 +185,7 @@ public class CutDownListSerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeLongArray(&{});", objectStr)).append(LS);
break;
case GdScript, Python, Ruby:
case GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeLongArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -219,7 +219,7 @@ public class CutDownListSerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeFloatArray(&{});", objectStr)).append(LS);
break;
case GdScript, Python, Ruby:
case GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeFloatArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -253,7 +253,7 @@ public class CutDownListSerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeDoubleArray(&{});", objectStr)).append(LS);
break;
case GdScript, Python, Ruby:
case GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeDoubleArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -287,7 +287,7 @@ public class CutDownListSerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("buffer.writeStringArray(&{});", objectStr)).append(LS);
break;
case GdScript, Python, Ruby:
case GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writeStringArray({})", objectStr)).append(LS);
break;
case Lua:
@@ -320,7 +320,7 @@ public class CutDownListSerializer implements ICutDownSerializer {
case Enhance:
builder.append(StringUtils.format("{}.writePacketList($1, (List){}, {});", EnhanceUtils.byteBufUtils, objectStr, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(protocolId)));
break;
case GdScript, Python, Ruby:
case GdScript, Python, Ruby, Swift:
builder.append(StringUtils.format("buffer.writePacketArray({}, {})", objectStr, protocolId)).append(LS);
break;
case Lua:
@@ -369,6 +369,9 @@ public class CutDownListSerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readBoolArray();", list)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readBoolArray()", list)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readBoolArray()", list)).append(LS);
break;
@@ -415,6 +418,9 @@ public class CutDownListSerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readByteArray();", list)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readByteArray()", list)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readByteArray()", list)).append(LS);
break;
@@ -461,6 +467,9 @@ public class CutDownListSerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readShortArray();", list)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readShortArray()", list)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readShortArray()", list)).append(LS);
break;
@@ -507,6 +516,9 @@ public class CutDownListSerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readIntArray();", list)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readIntArray()", list)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readIntArray()", list)).append(LS);
break;
@@ -553,6 +565,9 @@ public class CutDownListSerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readLongArray();", list)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readLongArray()", list)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readLongArray()", list)).append(LS);
break;
@@ -599,6 +614,9 @@ public class CutDownListSerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readFloatArray();", list)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readFloatArray()", list)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readFloatArray()", list)).append(LS);
break;
@@ -645,6 +663,9 @@ public class CutDownListSerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readDoubleArray();", list)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readDoubleArray()", list)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readDoubleArray()", list)).append(LS);
break;
@@ -691,6 +712,9 @@ public class CutDownListSerializer implements ICutDownSerializer {
case Rust:
builder.append(StringUtils.format("let {} = buffer.readStringArray();", list)).append(LS);
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readStringArray()", list)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readStringArray()", list)).append(LS);
break;
@@ -737,6 +761,9 @@ public class CutDownListSerializer implements ICutDownSerializer {
case Enhance:
builder.append(StringUtils.format("List {} = {}.readPacketList($1, {});", list, EnhanceUtils.byteBufUtils, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(protocolId)));
break;
case Swift:
builder.append(StringUtils.format("let {} = buffer.readPacketArray({}) as! Array<{}>", list, protocolId, protocolName)).append(LS);
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readPacketArray({})", list, protocolId)).append(LS);
break;
@@ -371,4 +371,202 @@ class ByteBuffer {
let pro = ProtocolManager.getProtocol(protocolId)
return pro.read(self)
}
func writeBoolArray(_ array: Array<Bool>) {
if (array.isEmpty) {
writeInt(0)
} else {
writeInt(array.count)
for ele in array {
writeBool(ele)
}
}
}
func readBoolArray() -> Array<Bool> {
let size = readInt()
var array = Array<Bool>()
if (size > 0) {
for _ in 0..<size {
array.append(readBool())
}
}
return array
}
func writeByteArray(_ array: Array<Int8>) {
if (array.isEmpty) {
writeInt(0)
} else {
writeInt(array.count)
for ele in array {
writeByte(ele)
}
}
}
func readByteArray() -> Array<Int8> {
let size = readInt()
var array = Array<Int8>()
if (size > 0) {
for _ in 0..<size {
array.append(readByte())
}
}
return array
}
func writeShortArray(_ array: Array<Int16>) {
if (array.isEmpty) {
writeInt(0)
} else {
writeInt(array.count)
for ele in array {
writeShort(ele)
}
}
}
func readShortArray() -> Array<Int16> {
let size = readInt()
var array = Array<Int16>()
if (size > 0) {
for _ in 0..<size {
array.append(readShort())
}
}
return array
}
func writeIntArray(_ array: Array<Int>) {
if (array.isEmpty) {
writeInt(0)
} else {
writeInt(array.count)
for ele in array {
writeInt(ele)
}
}
}
func readIntArray() -> Array<Int> {
let size = readInt()
var array = Array<Int>()
if (size > 0) {
for _ in 0..<size {
array.append(readInt())
}
}
return array
}
func writeLongArray(_ array: Array<Int64>) {
if (array.isEmpty) {
writeInt(0)
} else {
writeInt(array.count)
for ele in array {
writeLong(ele)
}
}
}
func readLongArray() -> Array<Int64> {
let size = readInt()
var array = Array<Int64>()
if (size > 0) {
for _ in 0..<size {
array.append(readLong())
}
}
return array
}
func writeFloatArray(_ array: Array<Float32>) {
if (array.isEmpty) {
writeInt(0)
} else {
writeInt(array.count)
for ele in array {
writeFloat(ele)
}
}
}
func readFloatArray() -> Array<Float32> {
let size = readInt()
var array = Array<Float32>()
if (size > 0) {
for _ in 0..<size {
array.append(readFloat())
}
}
return array
}
func writeDoubleArray(_ array: Array<Float64>) {
if (array.isEmpty) {
writeInt(0)
} else {
writeInt(array.count)
for ele in array {
writeDouble(ele)
}
}
}
func readDoubleArray() -> Array<Float64> {
let size = readInt()
var array = Array<Float64>()
if (size > 0) {
for _ in 0..<size {
array.append(readDouble())
}
}
return array
}
func writeStringArray(_ array: Array<String>) {
if (array.isEmpty) {
writeInt(0)
} else {
writeInt(array.count)
for ele in array {
writeString(ele)
}
}
}
func readStringArray() -> Array<String> {
let size = readInt()
var array = Array<String>()
if (size > 0) {
for _ in 0..<size {
array.append(readString())
}
}
return array
}
func writePacketArray(_ array: Array<Any>, _ protocolId: Int) {
if (array.isEmpty) {
writeInt(0)
} else {
writeInt(array.count)
for ele in array {
writePacket(ele, protocolId)
}
}
}
func readPacketArray(_ protocolId: Int) -> Array<Any> {
let size = readInt()
var array = Array<Any>()
if (size > 0) {
for _ in 0..<size {
array.append(readPacket(protocolId))
}
}
return array
}
}