Skip to content

Commit

Permalink
feat[swift]: cut down array serialization of swift
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Jul 28, 2024
1 parent a10bf04 commit a685de1
Show file tree
Hide file tree
Showing 3 changed files with 298 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public boolean writeObject(StringBuilder builder, String objectStr, Field field,
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:
Expand Down Expand Up @@ -83,7 +83,7 @@ public boolean writeObject(StringBuilder builder, String objectStr, Field field,
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:
Expand Down Expand Up @@ -113,7 +113,7 @@ public boolean writeObject(StringBuilder builder, String objectStr, Field field,
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:
Expand Down Expand Up @@ -143,7 +143,7 @@ public boolean writeObject(StringBuilder builder, String objectStr, Field field,
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:
Expand Down Expand Up @@ -173,7 +173,7 @@ public boolean writeObject(StringBuilder builder, String objectStr, Field field,
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:
Expand Down Expand Up @@ -203,7 +203,7 @@ public boolean writeObject(StringBuilder builder, String objectStr, Field field,
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:
Expand Down Expand Up @@ -233,7 +233,7 @@ public boolean writeObject(StringBuilder builder, String objectStr, Field field,
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:
Expand Down Expand Up @@ -263,7 +263,7 @@ public boolean writeObject(StringBuilder builder, String objectStr, Field field,
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:
Expand Down Expand Up @@ -293,7 +293,7 @@ public boolean writeObject(StringBuilder builder, String objectStr, Field field,
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:
Expand Down Expand Up @@ -323,7 +323,7 @@ public boolean writeObject(StringBuilder builder, String objectStr, Field field,
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:
Expand Down Expand Up @@ -353,7 +353,7 @@ public boolean writeObject(StringBuilder builder, String objectStr, Field field,
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:
Expand Down Expand Up @@ -383,7 +383,7 @@ public boolean writeObject(StringBuilder builder, String objectStr, Field field,
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:
Expand Down Expand Up @@ -413,7 +413,7 @@ public boolean writeObject(StringBuilder builder, String objectStr, Field field,
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:
Expand Down Expand Up @@ -443,7 +443,7 @@ public boolean writeObject(StringBuilder builder, String objectStr, Field field,
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:
Expand Down Expand Up @@ -473,7 +473,7 @@ public boolean writeObject(StringBuilder builder, String objectStr, Field field,
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:
Expand Down Expand Up @@ -503,7 +503,7 @@ public boolean writeObject(StringBuilder builder, String objectStr, Field field,
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:
Expand Down Expand Up @@ -550,6 +550,9 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration
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;
Expand Down Expand Up @@ -596,6 +599,9 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration
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;
Expand Down Expand Up @@ -642,6 +648,9 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration
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;
Expand Down Expand Up @@ -688,6 +697,9 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration
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;
Expand Down Expand Up @@ -734,6 +746,9 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration
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;
Expand Down Expand Up @@ -780,6 +795,9 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration
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;
Expand Down Expand Up @@ -826,6 +844,9 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration
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;
Expand Down Expand Up @@ -872,6 +893,9 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration
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;
Expand Down Expand Up @@ -918,6 +942,9 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration
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;
Expand Down Expand Up @@ -964,6 +991,9 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration
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;
Expand Down Expand Up @@ -1010,6 +1040,9 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration
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;
Expand Down Expand Up @@ -1056,6 +1089,9 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration
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;
Expand Down Expand Up @@ -1102,6 +1138,9 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration
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;
Expand Down Expand Up @@ -1148,6 +1187,9 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration
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;
Expand Down Expand Up @@ -1194,6 +1236,9 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration
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;
Expand Down Expand Up @@ -1238,6 +1283,9 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration
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;
Expand Down
Loading

0 comments on commit a685de1

Please sign in to comment.