From e7f234202ec69ba5c0fb4e8deb4a18164c3a4d5a Mon Sep 17 00:00:00 2001 From: godotg Date: Sat, 6 Jul 2024 10:59:14 +0800 Subject: [PATCH] feat[kotlin]: cut down kotlin protocol --- .../serializer/CutDownArraySerializer.java | 248 +++++++----------- .../serializer/CutDownListSerializer.java | 177 ++++++------- .../serializer/CutDownMapSerializer.java | 195 ++++++-------- .../serializer/CutDownSetSerializer.java | 140 ++++------ .../src/main/resources/kotlin/ByteBuffer.kt | 190 +++++++------- 5 files changed, 403 insertions(+), 547 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 90974a05..5f45e60e 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownArraySerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownArraySerializer.java @@ -50,8 +50,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeBooleanArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeBooleanArray({})", objectStr)).append(LS); break; case Lua: @@ -63,11 +62,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteBooleanArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeBooleanArray({});", objectStr)).append(LS); break; default: @@ -79,8 +74,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeBooleanBoxArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeBooleanArray({})", objectStr)).append(LS); break; case Lua: @@ -92,10 +86,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteBooleanArray({})", objectStr)).append(LS); break; - case Cpp: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeBooleanArray({});", objectStr)).append(LS); break; default: @@ -107,8 +98,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeByteArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeByteArray({})", objectStr)).append(LS); break; case Lua: @@ -120,11 +110,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteByteArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeByteArray({});", objectStr)).append(LS); break; default: @@ -136,8 +122,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeByteBoxArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeByteArray({})", objectStr)).append(LS); break; case Lua: @@ -149,10 +134,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteByteArray({})", objectStr)).append(LS); break; - case Cpp: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeByteArray({});", objectStr)).append(LS); break; default: @@ -164,8 +146,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeShortArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeShortArray({})", objectStr)).append(LS); break; case Lua: @@ -177,11 +158,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteShortArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeShortArray({});", objectStr)).append(LS); break; default: @@ -193,8 +170,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeShortBoxArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeShortArray({})", objectStr)).append(LS); break; case Lua: @@ -206,10 +182,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteShortArray({})", objectStr)).append(LS); break; - case Cpp: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeShortArray({});", objectStr)).append(LS); break; default: @@ -221,8 +194,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeIntArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeIntArray({})", objectStr)).append(LS); break; case Lua: @@ -234,11 +206,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteIntArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeIntArray({});", objectStr)).append(LS); break; default: @@ -250,8 +218,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeIntBoxArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeIntArray({})", objectStr)).append(LS); break; case Lua: @@ -263,10 +230,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteIntArray({})", objectStr)).append(LS); break; - case Cpp: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeIntArray({});", objectStr)).append(LS); break; default: @@ -278,8 +242,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeLongArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeLongArray({})", objectStr)).append(LS); break; case Lua: @@ -291,11 +254,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteLongArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeLongArray({});", objectStr)).append(LS); break; default: @@ -307,8 +266,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeLongBoxArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeLongArray({})", objectStr)).append(LS); break; case Lua: @@ -320,10 +278,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteLongArray({})", objectStr)).append(LS); break; - case Cpp: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeLongArray({});", objectStr)).append(LS); break; default: @@ -335,8 +290,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeFloatArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeFloatArray({})", objectStr)).append(LS); break; case Lua: @@ -348,11 +302,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteFloatArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeFloatArray({});", objectStr)).append(LS); break; default: @@ -364,8 +314,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeFloatBoxArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeFloatArray({})", objectStr)).append(LS); break; case Lua: @@ -377,10 +326,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteFloatArray({})", objectStr)).append(LS); break; - case Cpp: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeFloatArray({});", objectStr)).append(LS); break; default: @@ -392,8 +338,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeDoubleArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeDoubleArray({})", objectStr)).append(LS); break; case Lua: @@ -405,11 +350,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteDoubleArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeDoubleArray({});", objectStr)).append(LS); break; default: @@ -421,8 +362,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeDoubleBoxArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeDoubleArray({})", objectStr)).append(LS); break; case Lua: @@ -434,10 +374,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteDoubleArray({})", objectStr)).append(LS); break; - case Cpp: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeDoubleArray({});", objectStr)).append(LS); break; default: @@ -449,8 +386,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeStringArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeStringArray({})", objectStr)).append(LS); break; case Lua: @@ -462,11 +398,7 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteStringArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeStringArray({});", objectStr)).append(LS); break; default: @@ -494,13 +426,10 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Cpp: builder.append(StringUtils.format("buffer.writePacketArray<{}>({}, {});", protocolName, objectStr, protocolId)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writePacketArray({}, {});", objectStr, protocolId)).append(LS); break; - case Golang: - case Protobuf: + case Golang, Protobuf, Java, Kotlin, Scala: default: flag = false; } @@ -547,9 +476,10 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readBooleanArray();", array)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readBooleanArray()", array)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readBooleanArray();", array)).append(LS); break; default: @@ -579,9 +509,10 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Cpp: builder.append(StringUtils.format("auto {} = buffer.readBooleanArray();", array)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readBooleanArray()", array)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readBooleanArray();", array)).append(LS); break; default: @@ -614,9 +545,10 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readByteArray();", array)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readByteArray()", array)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readByteArray();", array)).append(LS); break; default: @@ -646,9 +578,10 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Cpp: builder.append(StringUtils.format("auto {} = buffer.readByteArray();", array)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readByteArray()", array)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readByteArray();", array)).append(LS); break; default: @@ -681,9 +614,10 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readShortArray();", array)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readShortArray()", array)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readShortArray();", array)).append(LS); break; default: @@ -713,9 +647,10 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Cpp: builder.append(StringUtils.format("auto {} = buffer.readShortArray();", array)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readShortArray()", array)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readShortArray();", array)).append(LS); break; default: @@ -748,9 +683,10 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readIntArray();", array)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readIntArray()", array)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readIntArray();", array)).append(LS); break; default: @@ -780,9 +716,10 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Cpp: builder.append(StringUtils.format("auto {} = buffer.readIntArray();", array)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readIntArray()", array)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readIntArray();", array)).append(LS); break; default: @@ -815,9 +752,10 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readLongArray();", array)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readLongArray()", array)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readLongArray();", array)).append(LS); break; default: @@ -847,9 +785,10 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Cpp: builder.append(StringUtils.format("auto {} = buffer.readLongArray();", array)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readLongArray()", array)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readLongArray();", array)).append(LS); break; default: @@ -882,9 +821,10 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readFloatArray();", array)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readFloatArray()", array)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readFloatArray();", array)).append(LS); break; default: @@ -914,9 +854,10 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Cpp: builder.append(StringUtils.format("auto {} = buffer.readFloatArray();", array)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readFloatArray()", array)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readFloatArray();", array)).append(LS); break; default: @@ -949,9 +890,10 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readDoubleArray();", array)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readDoubleArray()", array)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readDoubleArray();", array)).append(LS); break; default: @@ -981,9 +923,10 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Cpp: builder.append(StringUtils.format("auto {} = buffer.readDoubleArray();", array)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readDoubleArray()", array)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readDoubleArray();", array)).append(LS); break; default: @@ -1016,9 +959,10 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readStringArray();", array)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readStringArray()", array)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readStringArray();", array)).append(LS); break; default: @@ -1046,14 +990,10 @@ public class CutDownArraySerializer implements ICutDownSerializer { case Cpp: builder.append(StringUtils.format("auto {} = buffer.readPacketArray<{}>({});", array, protocolName, protocolId)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readPacketArray({});", array, protocolId)).append(LS); break; - case Golang: - case Protobuf: - case Enhance: + case Golang, Java, Kotlin, Scala, Protobuf, Enhance: default: flag = false; } 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 ca58352f..fc7f7e36 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownListSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownListSerializer.java @@ -49,8 +49,7 @@ public class CutDownListSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeBooleanList($1, (List){});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case GdScript, Python: builder.append(StringUtils.format("buffer.writeBooleanArray({})", objectStr)).append(LS); break; case Lua: @@ -62,13 +61,12 @@ public class CutDownListSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteBooleanArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeBooleanList({});", objectStr)).append(LS); break; + case Kotlin: + builder.append(StringUtils.format("buffer.writeBooleanList({})", objectStr)).append(LS); + break; default: flag = false; } @@ -78,8 +76,7 @@ public class CutDownListSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeByteList($1, (List){});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case GdScript, Python: builder.append(StringUtils.format("buffer.writeByteArray({})", objectStr)).append(LS); break; case Lua: @@ -91,13 +88,13 @@ public class CutDownListSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteByteArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeByteList({});", objectStr)).append(LS); break; + case Kotlin: + builder.append(StringUtils.format("buffer.writeByteList({})", objectStr)).append(LS); + break; + default: flag = false; } @@ -107,8 +104,7 @@ public class CutDownListSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeShortList($1, (List){});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case GdScript, Python: builder.append(StringUtils.format("buffer.writeShortArray({})", objectStr)).append(LS); break; case Lua: @@ -120,13 +116,12 @@ public class CutDownListSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteShortArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeShortList({});", objectStr)).append(LS); break; + case Kotlin: + builder.append(StringUtils.format("buffer.writeShortList({})", objectStr)).append(LS); + break; default: flag = false; } @@ -136,8 +131,7 @@ public class CutDownListSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeIntList($1, (List){});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case GdScript, Python: builder.append(StringUtils.format("buffer.writeIntArray({})", objectStr)).append(LS); break; case Lua: @@ -149,13 +143,12 @@ public class CutDownListSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteIntArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeIntList({});", objectStr)).append(LS); break; + case Kotlin: + builder.append(StringUtils.format("buffer.writeIntList({})", objectStr)).append(LS); + break; default: flag = false; } @@ -165,8 +158,7 @@ public class CutDownListSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeLongList($1, (List){});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case GdScript, Python: builder.append(StringUtils.format("buffer.writeLongArray({})", objectStr)).append(LS); break; case Lua: @@ -178,13 +170,12 @@ public class CutDownListSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteLongArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeLongList({});", objectStr)).append(LS); break; + case Kotlin: + builder.append(StringUtils.format("buffer.writeLongList({})", objectStr)).append(LS); + break; default: flag = false; } @@ -195,8 +186,7 @@ public class CutDownListSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeFloatList($1, (List){});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case GdScript, Python: builder.append(StringUtils.format("buffer.writeFloatArray({})", objectStr)).append(LS); break; case Lua: @@ -208,13 +198,12 @@ public class CutDownListSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteFloatArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeFloatList({});", objectStr)).append(LS); break; + case Kotlin: + builder.append(StringUtils.format("buffer.writeFloatList({})", objectStr)).append(LS); + break; default: flag = false; } @@ -225,8 +214,7 @@ public class CutDownListSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeDoubleList($1, (List){});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case GdScript, Python: builder.append(StringUtils.format("buffer.writeDoubleArray({})", objectStr)).append(LS); break; case Lua: @@ -238,13 +226,12 @@ public class CutDownListSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteDoubleArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeDoubleList({});", objectStr)).append(LS); break; + case Kotlin: + builder.append(StringUtils.format("buffer.writeDoubleList({})", objectStr)).append(LS); + break; default: flag = false; } @@ -255,8 +242,7 @@ public class CutDownListSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeStringList($1, (List){});", EnhanceUtils.byteBufUtils, objectStr)); break; - case GdScript: - case Python: + case GdScript, Python: builder.append(StringUtils.format("buffer.writeStringArray({})", objectStr)).append(LS); break; case Lua: @@ -268,13 +254,12 @@ public class CutDownListSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteStringArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeStringList({});", objectStr)).append(LS); break; + case Kotlin: + builder.append(StringUtils.format("buffer.writeStringList({})", objectStr)).append(LS); + break; default: flag = false; } @@ -287,8 +272,7 @@ public class CutDownListSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writePacketList($1, (List){}, {});", EnhanceUtils.byteBufUtils, objectStr, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(protocolId))); break; - case GdScript: - case Python: + case GdScript, Python: builder.append(StringUtils.format("buffer.writePacketArray({}, {})", objectStr, protocolId)).append(LS); break; case Lua: @@ -297,17 +281,16 @@ public class CutDownListSerializer implements ICutDownSerializer { case CSharp: builder.append(StringUtils.format("buffer.WritePacketList({}, {});", objectStr, protocolId)).append(LS); break; - case Cpp: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writePacketList({}, {});", objectStr, protocolId)).append(LS); break; case Java: builder.append(StringUtils.format("buffer.writePacketList({}, (short) {});", objectStr, protocolId)).append(LS); break; - case Golang: - case Protobuf: + case Kotlin: + builder.append(StringUtils.format("buffer.writePacketList({}, {})", objectStr, protocolId)).append(LS); + break; + case Golang, Protobuf: default: flag = false; } @@ -353,9 +336,10 @@ public class CutDownListSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readBooleanList();", list)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readBooleanList()", list)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readBooleanList();", list)).append(LS); break; default: @@ -388,9 +372,10 @@ public class CutDownListSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readByteList();", list)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readByteList()", list)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readByteList();", list)).append(LS); break; default: @@ -423,9 +408,10 @@ public class CutDownListSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readShortList();", list)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readShortList()", list)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readShortList();", list)).append(LS); break; default: @@ -458,9 +444,10 @@ public class CutDownListSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readIntList();", list)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readIntList()", list)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readIntList();", list)).append(LS); break; default: @@ -493,9 +480,10 @@ public class CutDownListSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readLongList();", list)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readLongList()", list)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readLongList();", list)).append(LS); break; default: @@ -528,9 +516,10 @@ public class CutDownListSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readFloatList();", list)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readFloatList()", list)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readFloatList();", list)).append(LS); break; default: @@ -563,9 +552,10 @@ public class CutDownListSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readDoubleList();", list)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readDoubleList()", list)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readDoubleList();", list)).append(LS); break; default: @@ -598,9 +588,10 @@ public class CutDownListSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readStringList();", list)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readStringList()", list)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readStringList();", list)).append(LS); break; default: @@ -633,13 +624,13 @@ public class CutDownListSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readPacketList({}.class, (short) {});", list, protocolName, protocolId)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readPacketList({}::class.java, {})", list, protocolName, protocolId)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readPacketList({});", list, protocolId)).append(LS); break; - case Golang: - case Protobuf: + case Golang, Protobuf: default: flag = false; } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownMapSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownMapSerializer.java index f67237ae..022b31dc 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownMapSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownMapSerializer.java @@ -56,8 +56,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeIntIntMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr)); return true; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeIntIntMap({})", objectStr)).append(LS); return true; case Lua: @@ -69,11 +68,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteIntIntMap({})", objectStr)).append(LS); return true; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeIntIntMap({});", objectStr)).append(LS); return true; } @@ -82,8 +77,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeIntLongMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr)); return true; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeIntLongMap({})", objectStr)).append(LS); return true; case Lua: @@ -95,11 +89,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteIntLongMap({})", objectStr)).append(LS); return true; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeIntLongMap({});", objectStr)).append(LS); return true; } @@ -108,8 +98,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeIntStringMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr)); return true; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeIntStringMap({})", objectStr)).append(LS); return true; case Lua: @@ -121,11 +110,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteIntStringMap({})", objectStr)).append(LS); return true; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeIntStringMap({});", objectStr)).append(LS); return true; } @@ -135,8 +120,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeIntPacketMap($1, (Map){}, {});", EnhanceUtils.byteBufUtils, objectStr, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(protocolId))); return true; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeIntPacketMap({}, {})", objectStr, protocolId)).append(LS); return true; case Lua: @@ -145,10 +129,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case CSharp: builder.append(StringUtils.format("buffer.WriteIntPacketMap({}, {});", objectStr, protocolId)).append(LS); return true; - case Cpp: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeIntPacketMap({}, {});", objectStr, protocolId)).append(LS); return true; case Java: @@ -165,8 +146,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeLongIntMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr)); return true; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeLongIntMap({})", objectStr)).append(LS); return true; case Lua: @@ -178,11 +158,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteLongIntMap({})", objectStr)).append(LS); return true; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeLongIntMap({});", objectStr)).append(LS); return true; } @@ -191,8 +167,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeLongLongMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr)); return true; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeLongLongMap({})", objectStr)).append(LS); return true; case Lua: @@ -204,11 +179,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteLongLongMap({})", objectStr)).append(LS); return true; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeLongLongMap({});", objectStr)).append(LS); return true; } @@ -217,8 +188,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeLongStringMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr)); return true; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeLongStringMap({})", objectStr)).append(LS); return true; case Lua: @@ -230,11 +200,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteLongStringMap({})", objectStr)).append(LS); return true; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeLongStringMap({});", objectStr)).append(LS); return true; } @@ -244,8 +210,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeLongPacketMap($1, (Map){}, {});", EnhanceUtils.byteBufUtils, objectStr, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(protocolId))); return true; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeLongPacketMap({}, {})", objectStr, protocolId)).append(LS); return true; case Lua: @@ -254,10 +219,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case CSharp: builder.append(StringUtils.format("buffer.WriteLongPacketMap({}, {});", objectStr, protocolId)).append(LS); return true; - case Cpp: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeLongPacketMap({}, {});", objectStr, protocolId)).append(LS); return true; case Java: @@ -274,8 +236,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeStringIntMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr)); return true; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeStringIntMap({})", objectStr)).append(LS); return true; case Lua: @@ -287,11 +248,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteStringIntMap({})", objectStr)).append(LS); return true; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeStringIntMap({});", objectStr)).append(LS); return true; } @@ -300,8 +257,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeStringLongMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr)); return true; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeStringLongMap({})", objectStr)).append(LS); return true; case Lua: @@ -313,11 +269,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteStringLongMap({})", objectStr)).append(LS); return true; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeStringLongMap({});", objectStr)).append(LS); return true; } @@ -326,8 +278,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeStringStringMap($1, (Map){});", EnhanceUtils.byteBufUtils, objectStr)); return true; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeStringStringMap({})", objectStr)).append(LS); return true; case Lua: @@ -339,11 +290,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteStringStringMap({})", objectStr)).append(LS); return true; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeStringStringMap({});", objectStr)).append(LS); return true; } @@ -353,8 +300,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Enhance: builder.append(StringUtils.format("{}.writeStringPacketMap($1, (Map){}, {});", EnhanceUtils.byteBufUtils, objectStr, EnhanceUtils.getProtocolRegistrationFieldNameByProtocolId(protocolId))); return true; - case GdScript: - case Python: + case Kotlin, GdScript, Python: builder.append(StringUtils.format("buffer.writeStringPacketMap({}, {})", objectStr, protocolId)).append(LS); return true; case Lua: @@ -363,17 +309,13 @@ public class CutDownMapSerializer implements ICutDownSerializer { case CSharp: builder.append(StringUtils.format("buffer.WriteStringPacketMap({}, {});", objectStr, protocolId)).append(LS); return true; - case Cpp: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeStringPacketMap({}, {});", objectStr, protocolId)).append(LS); return true; case Java: builder.append(StringUtils.format("buffer.writeStringPacketMap({}, (short) {});", objectStr, protocolId)).append(LS); return true; - case Golang: - case Protobuf: + case Golang, Protobuf: default: } } @@ -420,9 +362,10 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readIntIntMap();", map)).append(LS); return map; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readIntIntMap()", map)).append(LS); + return map; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readIntIntMap();", map)).append(LS); return map; } @@ -452,9 +395,10 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readIntLongMap();", map)).append(LS); return map; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readIntLongMap()", map)).append(LS); + return map; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readIntLongMap();", map)).append(LS); return map; } @@ -484,9 +428,10 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readIntStringMap();", map)).append(LS); return map; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readIntStringMap()", map)).append(LS); + return map; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readIntStringMap();", map)).append(LS); return map; } @@ -515,9 +460,10 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readIntPacketMap({}.class, (short) {});", map, protocolName, protocolId)).append(LS); return map; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readIntPacketMap({}::class.java, {})", map, protocolName, protocolId)).append(LS); + return map; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readIntPacketMap({});", map, protocolId)).append(LS); return map; case Golang: @@ -551,9 +497,10 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readLongIntMap();", map)).append(LS); return map; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readLongIntMap()", map)).append(LS); + return map; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readLongIntMap();", map)).append(LS); return map; } @@ -583,9 +530,10 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readLongLongMap();", map)).append(LS); return map; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readLongLongMap()", map)).append(LS); + return map; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readLongLongMap();", map)).append(LS); return map; } @@ -615,9 +563,10 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readLongStringMap();", map)).append(LS); return map; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readLongStringMap()", map)).append(LS); + return map; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readLongStringMap();", map)).append(LS); return map; } @@ -646,9 +595,10 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readLongPacketMap({}.class, (short) {});", map, protocolName, protocolId)).append(LS); return map; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readLongPacketMap({}::class.java, {})", map, protocolName, protocolId)).append(LS); + return map; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readLongPacketMap({});", map, protocolId)).append(LS); return map; case Golang: @@ -683,9 +633,10 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readStringIntMap();", map)).append(LS); return map; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readStringIntMap()", map)).append(LS); + return map; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readStringIntMap();", map)).append(LS); return map; } @@ -715,9 +666,10 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readStringLongMap();", map)).append(LS); return map; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readStringLongMap()", map)).append(LS); + return map; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readStringLongMap();", map)).append(LS); return map; } @@ -747,9 +699,10 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readStringStringMap();", map)).append(LS); return map; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readStringStringMap()", map)).append(LS); + return map; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readStringStringMap();", map)).append(LS); return map; } @@ -778,13 +731,13 @@ public class CutDownMapSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readStringPacketMap({}.class, (short) {});", map, protocolName, protocolId)).append(LS); return map; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readStringPacketMap({}::class.java, {})", map, protocolName, protocolId)).append(LS); + return map; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readStringPacketMap({});", map, protocolId)).append(LS); return map; - case Golang: - case Protobuf: + case Golang, Protobuf: default: } } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownSetSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownSetSerializer.java index 6b926fde..0063e3e1 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownSetSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownSetSerializer.java @@ -53,7 +53,7 @@ public class CutDownSetSerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeBooleanArray({})", objectStr)).append(LS); break; - case Python: + case Python, Kotlin: builder.append(StringUtils.format("buffer.writeBooleanSet({})", objectStr)).append(LS); break; case Lua: @@ -65,11 +65,7 @@ public class CutDownSetSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteBooleanArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeBooleanSet({});", objectStr)).append(LS); break; default: @@ -84,7 +80,7 @@ public class CutDownSetSerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeByteArray({})", objectStr)).append(LS); break; - case Python: + case Python, Kotlin: builder.append(StringUtils.format("buffer.writeByteSet({})", objectStr)).append(LS); break; case Lua: @@ -96,11 +92,7 @@ public class CutDownSetSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteByteArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeByteSet({});", objectStr)).append(LS); break; default: @@ -115,7 +107,7 @@ public class CutDownSetSerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeShortArray({})", objectStr)).append(LS); break; - case Python: + case Python, Kotlin: builder.append(StringUtils.format("buffer.writeShortSet({})", objectStr)).append(LS); break; case Lua: @@ -127,11 +119,7 @@ public class CutDownSetSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteShortArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeShortSet({});", objectStr)).append(LS); break; default: @@ -146,7 +134,7 @@ public class CutDownSetSerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeIntArray({})", objectStr)).append(LS); break; - case Python: + case Python, Kotlin: builder.append(StringUtils.format("buffer.writeIntSet({})", objectStr)).append(LS); break; case Lua: @@ -158,11 +146,7 @@ public class CutDownSetSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteIntArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeIntSet({});", objectStr)).append(LS); break; default: @@ -177,7 +161,7 @@ public class CutDownSetSerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeLongArray({})", objectStr)).append(LS); break; - case Python: + case Python, Kotlin: builder.append(StringUtils.format("buffer.writeLongSet({})", objectStr)).append(LS); break; case Lua: @@ -189,11 +173,7 @@ public class CutDownSetSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteLongArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeLongSet({});", objectStr)).append(LS); break; default: @@ -208,7 +188,7 @@ public class CutDownSetSerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeFloatArray({})", objectStr)).append(LS); break; - case Python: + case Python, Kotlin: builder.append(StringUtils.format("buffer.writeFloatSet({})", objectStr)).append(LS); break; case Lua: @@ -220,11 +200,7 @@ public class CutDownSetSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteFloatArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeFloatSet({});", objectStr)).append(LS); break; default: @@ -239,7 +215,7 @@ public class CutDownSetSerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeDoubleArray({})", objectStr)).append(LS); break; - case Python: + case Python, Kotlin: builder.append(StringUtils.format("buffer.writeDoubleSet({})", objectStr)).append(LS); break; case Lua: @@ -251,11 +227,7 @@ public class CutDownSetSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteDoubleArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeDoubleSet({});", objectStr)).append(LS); break; default: @@ -270,7 +242,7 @@ public class CutDownSetSerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeStringArray({})", objectStr)).append(LS); break; - case Python: + case Python, Kotlin: builder.append(StringUtils.format("buffer.writeStringSet({})", objectStr)).append(LS); break; case Lua: @@ -282,11 +254,7 @@ public class CutDownSetSerializer implements ICutDownSerializer { case Golang: builder.append(StringUtils.format("buffer.WriteStringArray({})", objectStr)).append(LS); break; - case Cpp: - case Java: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, Java, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writeStringSet({});", objectStr)).append(LS); break; default: @@ -304,7 +272,7 @@ public class CutDownSetSerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writePacketArray({}, {})", objectStr, protocolId)).append(LS); break; - case Python: + case Python, Kotlin: builder.append(StringUtils.format("buffer.writePacketSet({}, {})", objectStr, protocolId)).append(LS); break; case Lua: @@ -313,17 +281,13 @@ public class CutDownSetSerializer implements ICutDownSerializer { case CSharp: builder.append(StringUtils.format("buffer.WritePacketSet({}, {});", objectStr, protocolId)).append(LS); break; - case Cpp: - case JavaScript: - case EcmaScript: - case TypeScript: + case Cpp, JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("buffer.writePacketSet({}, {});", objectStr, protocolId)).append(LS); break; case Java: builder.append(StringUtils.format("buffer.writePacketSet({}, (short) {});", objectStr, protocolId)).append(LS); break; - case Golang: - case Protobuf: + case Golang, Protobuf: default: flag = false; } @@ -369,9 +333,10 @@ public class CutDownSetSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readBooleanSet();", set)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readBooleanSet()", set)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readBooleanSet();", set)).append(LS); break; default: @@ -404,9 +369,10 @@ public class CutDownSetSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readByteSet();", set)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readByteSet()", set)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readByteSet();", set)).append(LS); break; default: @@ -439,9 +405,10 @@ public class CutDownSetSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readShortSet();", set)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readShortSet()", set)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readShortSet();", set)).append(LS); break; default: @@ -474,9 +441,10 @@ public class CutDownSetSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readIntSet();", set)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readIntSet()", set)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readIntSet();", set)).append(LS); break; default: @@ -509,9 +477,10 @@ public class CutDownSetSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readLongSet();", set)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readLongSet()", set)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readLongSet();", set)).append(LS); break; default: @@ -544,9 +513,10 @@ public class CutDownSetSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readFloatSet();", set)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readFloatSet()", set)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readFloatSet();", set)).append(LS); break; default: @@ -579,9 +549,10 @@ public class CutDownSetSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readDoubleSet();", set)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readDoubleSet()", set)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readDoubleSet();", set)).append(LS); break; default: @@ -614,9 +585,10 @@ public class CutDownSetSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readStringSet();", set)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readStringSet()", set)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readStringSet();", set)).append(LS); break; default: @@ -649,13 +621,13 @@ public class CutDownSetSerializer implements ICutDownSerializer { case Java: builder.append(StringUtils.format("var {} = buffer.readPacketSet({}.class, (short) {});", set, protocolName, protocolId)).append(LS); break; - case JavaScript: - case EcmaScript: - case TypeScript: + case Kotlin: + builder.append(StringUtils.format("val {} = buffer.readPacketSet({}::class.java, {})", set, protocolName, protocolId)).append(LS); + break; + case JavaScript, EcmaScript, TypeScript: builder.append(StringUtils.format("const {} = buffer.readPacketSet({});", set, protocolId)).append(LS); break; - case Golang: - case Protobuf: + case Golang, Protobuf: default: flag = false; } diff --git a/protocol/src/main/resources/kotlin/ByteBuffer.kt b/protocol/src/main/resources/kotlin/ByteBuffer.kt index d508b52f..6b9644ec 100644 --- a/protocol/src/main/resources/kotlin/ByteBuffer.kt +++ b/protocol/src/main/resources/kotlin/ByteBuffer.kt @@ -352,8 +352,8 @@ class ByteBuffer { return String(bytes, DEFAULT_CHARSET) } - fun writeBooleanArray(array: BooleanArray?) { - if (array == null || array.size == 0) { + fun writeBooleanArray(array: Array) { + if (array.size == 0) { writeInt(0) } else { writeInt(array.size) @@ -364,9 +364,9 @@ class ByteBuffer { } } - fun readBooleanArray(): BooleanArray { + fun readBooleanArray(): Array { val size = readInt() - val array = BooleanArray(size) + val array = Array(size) { init -> false } if (size > 0) { for (index in 0 until size) { array[index] = readBool() @@ -375,8 +375,8 @@ class ByteBuffer { return array } - fun writeByteArray(array: ByteArray?) { - if (array == null || array.size == 0) { + fun writeByteArray(array: Array) { + if (array.size == 0) { writeInt(0) } else { writeInt(array.size) @@ -387,9 +387,9 @@ class ByteBuffer { } } - fun readByteArray(): ByteArray { + fun readByteArray(): Array { val size = readInt() - val array = ByteArray(size) + val array = Array(size) { init -> 0 } if (size > 0) { for (index in 0 until size) { array[index] = readByte() @@ -398,8 +398,8 @@ class ByteBuffer { return array } - fun writeShortArray(array: ShortArray?) { - if (array == null || array.size == 0) { + fun writeShortArray(array: Array) { + if (array.size == 0) { writeInt(0) } else { writeInt(array.size) @@ -410,9 +410,9 @@ class ByteBuffer { } } - fun readShortArray(): ShortArray { + fun readShortArray(): Array { val size = readInt() - val array = ShortArray(size) + val array = Array(size) { init -> 0 } if (size > 0) { for (index in 0 until size) { array[index] = readShort() @@ -421,8 +421,8 @@ class ByteBuffer { return array } - fun writeIntArray(array: IntArray?) { - if (array == null || array.size == 0) { + fun writeIntArray(array: Array) { + if (array.size == 0) { writeInt(0) } else { writeInt(array.size) @@ -433,9 +433,9 @@ class ByteBuffer { } } - fun readIntArray(): IntArray { + fun readIntArray(): Array { val size = readInt() - val array = IntArray(size) + val array = Array(size) { init -> 0 } if (size > 0) { for (index in 0 until size) { array[index] = readInt() @@ -444,8 +444,8 @@ class ByteBuffer { return array } - fun writeLongArray(array: LongArray?) { - if (array == null || array.size == 0) { + fun writeLongArray(array: Array) { + if (array.size == 0) { writeInt(0) } else { writeInt(array.size) @@ -456,9 +456,9 @@ class ByteBuffer { } } - fun readLongArray(): LongArray { + fun readLongArray(): Array { val size = readInt() - val array = LongArray(size) + val array = Array(size) { init -> 0 } if (size > 0) { for (index in 0 until size) { array[index] = readLong() @@ -467,8 +467,8 @@ class ByteBuffer { return array } - fun writeFloatArray(array: FloatArray?) { - if (array == null || array.size == 0) { + fun writeFloatArray(array: Array) { + if (array.size == 0) { writeInt(0) } else { writeInt(array.size) @@ -479,9 +479,9 @@ class ByteBuffer { } } - fun readFloatArray(): FloatArray { + fun readFloatArray(): Array { val size = readInt() - val array = FloatArray(size) + val array = Array(size) { init -> 0F } if (size > 0) { for (index in 0 until size) { array[index] = readFloat() @@ -490,8 +490,8 @@ class ByteBuffer { return array } - fun writeDoubleArray(array: DoubleArray?) { - if (array == null || array.size == 0) { + fun writeDoubleArray(array: Array) { + if (array.size == 0) { writeInt(0) } else { writeInt(array.size) @@ -502,9 +502,9 @@ class ByteBuffer { } } - fun readDoubleArray(): DoubleArray { + fun readDoubleArray(): Array { val size = readInt() - val array = DoubleArray(size) + val array = Array(size) { init -> 0.0 } if (size > 0) { for (index in 0 until size) { array[index] = readDouble() @@ -513,8 +513,8 @@ class ByteBuffer { return array } - fun writeStringArray(array: Array?) { - if (array == null || array.size == 0) { + fun writeStringArray(array: Array) { + if (array.size == 0) { writeInt(0) } else { writeInt(array.size) @@ -525,9 +525,9 @@ class ByteBuffer { } } - fun readStringArray(): Array { + fun readStringArray(): Array { val size = readInt() - val array = arrayOfNulls(size) + val array = Array(size) { init -> "" } if (size > 0) { for (index in 0 until size) { array[index] = readString() @@ -536,8 +536,8 @@ class ByteBuffer { return array } - fun writeBooleanList(list: List?) { - if (list == null || list.isEmpty()) { + fun writeBooleanList(list: List) { + if (list.isEmpty()) { writeInt(0) } else { writeInt(list.size) @@ -558,8 +558,8 @@ class ByteBuffer { return list } - fun writeByteList(list: List?) { - if (list == null || list.isEmpty()) { + fun writeByteList(list: List) { + if (list.isEmpty()) { writeInt(0) } else { writeInt(list.size) @@ -580,8 +580,8 @@ class ByteBuffer { return list } - fun writeShortList(list: List?) { - if (list == null || list.isEmpty()) { + fun writeShortList(list: List) { + if (list.isEmpty()) { writeInt(0) } else { writeInt(list.size) @@ -602,8 +602,8 @@ class ByteBuffer { return list } - fun writeIntList(list: List?) { - if (list == null || list.isEmpty()) { + fun writeIntList(list: List) { + if (list.isEmpty()) { writeInt(0) } else { writeInt(list.size) @@ -624,8 +624,8 @@ class ByteBuffer { return list } - fun writeLongList(list: List?) { - if (list == null || list.isEmpty()) { + fun writeLongList(list: List) { + if (list.isEmpty()) { writeInt(0) } else { writeInt(list.size) @@ -646,8 +646,8 @@ class ByteBuffer { return list } - fun writeFloatList(list: List?) { - if (list == null || list.isEmpty()) { + fun writeFloatList(list: List) { + if (list.isEmpty()) { writeInt(0) } else { writeInt(list.size) @@ -668,8 +668,8 @@ class ByteBuffer { return list } - fun writeDoubleList(list: List?) { - if (list == null || list.isEmpty()) { + fun writeDoubleList(list: List) { + if (list.isEmpty()) { writeInt(0) } else { writeInt(list.size) @@ -690,8 +690,8 @@ class ByteBuffer { return list } - fun writeStringList(list: List?) { - if (list == null || list.isEmpty()) { + fun writeStringList(list: List) { + if (list.isEmpty()) { writeInt(0) } else { writeInt(list.size) @@ -712,8 +712,8 @@ class ByteBuffer { return list } - fun writePacketList(list: List<*>?, protocolId: Short) { - if (list == null || list.isEmpty()) { + fun writePacketList(list: List<*>, protocolId: Short) { + if (list.isEmpty()) { writeInt(0) } else { val protocolRegistration = ProtocolManager.getProtocol(protocolId) @@ -724,7 +724,7 @@ class ByteBuffer { } } - fun readPacketList(clazz: Class?, protocolId: Short): List { + fun readPacketList(clazz: Class, protocolId: Short): List { val size = readInt() val list: MutableList = ArrayList() if (size > 0) { @@ -736,8 +736,8 @@ class ByteBuffer { return list } - fun writeBooleanSet(set: Set?) { - if (set == null || set.isEmpty()) { + fun writeBooleanSet(set: Set) { + if (set.isEmpty()) { writeInt(0) } else { writeInt(set.size) @@ -758,8 +758,8 @@ class ByteBuffer { return set } - fun writeShortSet(set: Set?) { - if (set == null || set.isEmpty()) { + fun writeShortSet(set: Set) { + if (set.isEmpty()) { writeInt(0) } else { writeInt(set.size) @@ -780,8 +780,8 @@ class ByteBuffer { return set } - fun writeIntSet(set: Set?) { - if (set == null || set.isEmpty()) { + fun writeIntSet(set: Set) { + if (set.isEmpty()) { writeInt(0) } else { writeInt(set.size) @@ -802,8 +802,8 @@ class ByteBuffer { return set } - fun writeLongSet(set: Set?) { - if (set == null || set.isEmpty()) { + fun writeLongSet(set: Set) { + if (set.isEmpty()) { writeInt(0) } else { writeInt(set.size) @@ -824,8 +824,8 @@ class ByteBuffer { return set } - fun writeFloatSet(set: Set?) { - if (set == null || set.isEmpty()) { + fun writeFloatSet(set: Set) { + if (set.isEmpty()) { writeInt(0) } else { writeInt(set.size) @@ -846,8 +846,8 @@ class ByteBuffer { return set } - fun writeDoubleSet(set: Set?) { - if (set == null || set.isEmpty()) { + fun writeDoubleSet(set: Set) { + if (set.isEmpty()) { writeInt(0) } else { writeInt(set.size) @@ -868,8 +868,8 @@ class ByteBuffer { return set } - fun writeStringSet(set: Set?) { - if (set == null || set.isEmpty()) { + fun writeStringSet(set: Set) { + if (set.isEmpty()) { writeInt(0) } else { writeInt(set.size) @@ -890,8 +890,8 @@ class ByteBuffer { return set } - fun writePacketSet(set: Set<*>?, protocolId: Short) { - if (set == null || set.isEmpty()) { + fun writePacketSet(set: Set<*>, protocolId: Short) { + if (set.isEmpty()) { writeInt(0) } else { val protocolRegistration = ProtocolManager.getProtocol(protocolId) @@ -902,7 +902,7 @@ class ByteBuffer { } } - fun readPacketSet(clazz: Class?, protocolId: Short): Set { + fun readPacketSet(clazz: Class, protocolId: Short): Set { val size = readInt() val set: MutableSet = HashSet() if (size > 0) { @@ -914,8 +914,8 @@ class ByteBuffer { return set } - fun writeIntIntMap(map: Map?) { - if (map == null || map.isEmpty()) { + fun writeIntIntMap(map: Map) { + if (map.isEmpty()) { writeInt(0) } else { writeInt(map.size) @@ -939,8 +939,8 @@ class ByteBuffer { return map } - fun writeIntLongMap(map: Map?) { - if (map == null || map.isEmpty()) { + fun writeIntLongMap(map: Map) { + if (map.isEmpty()) { writeInt(0) } else { writeInt(map.size) @@ -964,8 +964,8 @@ class ByteBuffer { return map } - fun writeIntStringMap(map: Map?) { - if (map == null || map.isEmpty()) { + fun writeIntStringMap(map: Map) { + if (map.isEmpty()) { writeInt(0) } else { writeInt(map.size) @@ -989,8 +989,8 @@ class ByteBuffer { return map } - fun writeIntPacketMap(map: Map?, protocolId: Short) { - if (map == null || map.isEmpty()) { + fun writeIntPacketMap(map: Map, protocolId: Short) { + if (map.isEmpty()) { writeInt(0) } else { val protocolRegistration = ProtocolManager.getProtocol(protocolId) @@ -1002,7 +1002,7 @@ class ByteBuffer { } } - fun readIntPacketMap(clazz: Class?, protocolId: Short): Map { + fun readIntPacketMap(clazz: Class, protocolId: Short): Map { val size = readInt() val map: MutableMap = HashMap() if (size > 0) { @@ -1016,8 +1016,8 @@ class ByteBuffer { return map } - fun writeLongIntMap(map: Map?) { - if (map == null || map.isEmpty()) { + fun writeLongIntMap(map: Map) { + if (map.isEmpty()) { writeInt(0) } else { writeInt(map.size) @@ -1041,8 +1041,8 @@ class ByteBuffer { return map } - fun writeLongLongMap(map: Map?) { - if (map == null || map.isEmpty()) { + fun writeLongLongMap(map: Map) { + if (map.isEmpty()) { writeInt(0) } else { writeInt(map.size) @@ -1066,8 +1066,8 @@ class ByteBuffer { return map } - fun writeLongStringMap(map: Map?) { - if (map == null || map.isEmpty()) { + fun writeLongStringMap(map: Map) { + if (map.isEmpty()) { writeInt(0) } else { writeInt(map.size) @@ -1091,8 +1091,8 @@ class ByteBuffer { return map } - fun writeLongPacketMap(map: Map?, protocolId: Short) { - if (map == null || map.isEmpty()) { + fun writeLongPacketMap(map: Map, protocolId: Short) { + if (map.isEmpty()) { writeInt(0) } else { val protocolRegistration = ProtocolManager.getProtocol(protocolId) @@ -1104,7 +1104,7 @@ class ByteBuffer { } } - fun readLongPacketMap(clazz: Class?, protocolId: Short): Map { + fun readLongPacketMap(clazz: Class, protocolId: Short): Map { val size = readInt() val map: MutableMap = HashMap() if (size > 0) { @@ -1118,8 +1118,8 @@ class ByteBuffer { return map } - fun writeStringIntMap(map: Map?) { - if (map == null || map.isEmpty()) { + fun writeStringIntMap(map: Map) { + if (map.isEmpty()) { writeInt(0) } else { writeInt(map.size) @@ -1143,8 +1143,8 @@ class ByteBuffer { return map } - fun writeStringLongMap(map: Map?) { - if (map == null || map.isEmpty()) { + fun writeStringLongMap(map: Map) { + if (map.isEmpty()) { writeInt(0) } else { writeInt(map.size) @@ -1168,8 +1168,8 @@ class ByteBuffer { return map } - fun writeStringStringMap(map: Map?) { - if (map == null || map.isEmpty()) { + fun writeStringStringMap(map: Map) { + if (map.isEmpty()) { writeInt(0) } else { writeInt(map.size) @@ -1193,8 +1193,8 @@ class ByteBuffer { return map } - fun writeStringPacketMap(map: Map?, protocolId: Short) { - if (map == null || map.isEmpty()) { + fun writeStringPacketMap(map: Map, protocolId: Short) { + if (map.isEmpty()) { writeInt(0) } else { val protocolRegistration = ProtocolManager.getProtocol(protocolId) @@ -1206,7 +1206,7 @@ class ByteBuffer { } } - fun readStringPacketMap(clazz: Class?, protocolId: Short): Map { + fun readStringPacketMap(clazz: Class, protocolId: Short): Map { val size = readInt() val map: MutableMap = HashMap() if (size > 0) {