From a685de104e8626fdf092f34a410649e5549a7e78 Mon Sep 17 00:00:00 2001 From: godotg Date: Sun, 28 Jul 2024 21:34:23 +0800 Subject: [PATCH] feat[swift]: cut down array serialization of swift --- .../serializer/CutDownArraySerializer.java | 80 +++++-- .../serializer/CutDownListSerializer.java | 45 +++- .../src/main/resources/swift/ByteBuffer.swift | 198 ++++++++++++++++++ 3 files changed, 298 insertions(+), 25 deletions(-) diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownArraySerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownArraySerializer.java index 2b64ba53..932a6944 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownArraySerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownArraySerializer.java @@ -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; diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownListSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownListSerializer.java index f3147c3c..1cdedc4e 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownListSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownListSerializer.java @@ -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; diff --git a/protocol/src/main/resources/swift/ByteBuffer.swift b/protocol/src/main/resources/swift/ByteBuffer.swift index d2bfd309..b5d4d1db 100644 --- a/protocol/src/main/resources/swift/ByteBuffer.swift +++ b/protocol/src/main/resources/swift/ByteBuffer.swift @@ -371,4 +371,202 @@ class ByteBuffer { let pro = ProtocolManager.getProtocol(protocolId) return pro.read(self) } + + func writeBoolArray(_ array: Array) { + if (array.isEmpty) { + writeInt(0) + } else { + writeInt(array.count) + for ele in array { + writeBool(ele) + } + } + } + + func readBoolArray() -> Array { + let size = readInt() + var array = Array() + if (size > 0) { + for _ in 0..) { + if (array.isEmpty) { + writeInt(0) + } else { + writeInt(array.count) + for ele in array { + writeByte(ele) + } + } + } + + func readByteArray() -> Array { + let size = readInt() + var array = Array() + if (size > 0) { + for _ in 0..) { + if (array.isEmpty) { + writeInt(0) + } else { + writeInt(array.count) + for ele in array { + writeShort(ele) + } + } + } + + func readShortArray() -> Array { + let size = readInt() + var array = Array() + if (size > 0) { + for _ in 0..) { + if (array.isEmpty) { + writeInt(0) + } else { + writeInt(array.count) + for ele in array { + writeInt(ele) + } + } + } + + func readIntArray() -> Array { + let size = readInt() + var array = Array() + if (size > 0) { + for _ in 0..) { + if (array.isEmpty) { + writeInt(0) + } else { + writeInt(array.count) + for ele in array { + writeLong(ele) + } + } + } + + func readLongArray() -> Array { + let size = readInt() + var array = Array() + if (size > 0) { + for _ in 0..) { + if (array.isEmpty) { + writeInt(0) + } else { + writeInt(array.count) + for ele in array { + writeFloat(ele) + } + } + } + + func readFloatArray() -> Array { + let size = readInt() + var array = Array() + if (size > 0) { + for _ in 0..) { + if (array.isEmpty) { + writeInt(0) + } else { + writeInt(array.count) + for ele in array { + writeDouble(ele) + } + } + } + + func readDoubleArray() -> Array { + let size = readInt() + var array = Array() + if (size > 0) { + for _ in 0..) { + if (array.isEmpty) { + writeInt(0) + } else { + writeInt(array.count) + for ele in array { + writeString(ele) + } + } + } + + func readStringArray() -> Array { + let size = readInt() + var array = Array() + if (size > 0) { + for _ in 0.., _ protocolId: Int) { + if (array.isEmpty) { + writeInt(0) + } else { + writeInt(array.count) + for ele in array { + writePacket(ele, protocolId) + } + } + } + + func readPacketArray(_ protocolId: Int) -> Array { + let size = readInt() + var array = Array() + if (size > 0) { + for _ in 0..