From 61de26693536fe7749bc0b464e2f4fc1e4b20937 Mon Sep 17 00:00:00 2001 From: godotg Date: Sun, 14 Jul 2024 18:26:03 +0800 Subject: [PATCH] ref[protocol]: rename writeBoolean/readBoolean to writeBool/readBool --- .../com/zfoo/net/packet/PacketService.java | 6 +- .../zfoo/protocol/buffer/ByteBufUtils.java | 44 ++++++------- .../serializer/CutDownArraySerializer.java | 66 +++++++++---------- .../serializer/CutDownListSerializer.java | 36 +++++----- .../serializer/CutDownSetSerializer.java | 36 +++++----- .../enhance/EnhanceBoolSerializer.java | 8 +-- .../serializer/java/CodeGenerateJava.java | 2 +- .../serializer/reflect/BoolSerializer.java | 4 +- .../src/main/resources/java/ByteBuffer.java | 21 +++--- .../java/ProtocolRegistrationTemplate.java | 2 +- protocol/src/test/kotlin/Main.java | 2 +- 11 files changed, 116 insertions(+), 111 deletions(-) diff --git a/net/src/main/java/com/zfoo/net/packet/PacketService.java b/net/src/main/java/com/zfoo/net/packet/PacketService.java index 9269dae1..eaa58ffc 100644 --- a/net/src/main/java/com/zfoo/net/packet/PacketService.java +++ b/net/src/main/java/com/zfoo/net/packet/PacketService.java @@ -152,7 +152,7 @@ public class PacketService implements IPacketService { // 解析包体 var packet = ProtocolManager.read(buffer); // 解析包的附加包 - var hasAttachment = ByteBufUtils.tryReadBoolean(buffer); + var hasAttachment = ByteBufUtils.tryReadBool(buffer); var attachment = hasAttachment ? (ProtocolManager.read(buffer)) : null; return DecodedPacketInfo.valueOf(packet, attachment); } @@ -174,9 +174,9 @@ public class PacketService implements IPacketService { // 写入包的附加包attachment if (attachment == null) { - ByteBufUtils.writeBoolean(buffer, false); + ByteBufUtils.writeBool(buffer, false); } else { - ByteBufUtils.writeBoolean(buffer, true); + ByteBufUtils.writeBool(buffer, true); // 写入包的附加包attachment ProtocolManager.write(buffer, attachment); } diff --git a/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java b/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java index 94624f9d..11d261de 100644 --- a/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java @@ -71,23 +71,23 @@ public abstract class ByteBufUtils { } //---------------------------------boolean-------------------------------------- - public static void writeBoolean(ByteBuf byteBuf, boolean value) { + public static void writeBool(ByteBuf byteBuf, boolean value) { byteBuf.writeBoolean(value); } - public static boolean readBoolean(ByteBuf byteBuf) { + public static boolean readBool(ByteBuf byteBuf) { return byteBuf.readBoolean(); } - public static boolean tryReadBoolean(ByteBuf byteBuf) { - return byteBuf.isReadable() && readBoolean(byteBuf); + public static boolean tryReadBool(ByteBuf byteBuf) { + return byteBuf.isReadable() && readBool(byteBuf); } - public static void writeBooleanBox(ByteBuf byteBuf, Boolean value) { + public static void writeBoolBox(ByteBuf byteBuf, Boolean value) { byteBuf.writeBoolean(value != null && value); } - public static Boolean readBooleanBox(ByteBuf byteBuf) { + public static Boolean readBoolBox(ByteBuf byteBuf) { return byteBuf.readBoolean(); } @@ -698,7 +698,7 @@ public abstract class ByteBufUtils { } //---------------------------------boolean-------------------------------------- - public static void writeBooleanArray(ByteBuf byteBuf, boolean[] array) { + public static void writeBoolArray(ByteBuf byteBuf, boolean[] array) { if (array == null) { byteBuf.writeByte(0); return; @@ -712,7 +712,7 @@ public abstract class ByteBufUtils { byteBuf.writeBytes(bytes); } - public static boolean[] readBooleanArray(ByteBuf byteBuf) { + public static boolean[] readBoolArray(ByteBuf byteBuf) { var length = readInt(byteBuf); var bytes = new byte[CollectionUtils.comfortableByteLength(length)]; var array = new boolean[length]; @@ -723,54 +723,54 @@ public abstract class ByteBufUtils { return array; } - public static void writeBooleanBoxArray(ByteBuf byteBuf, Boolean[] array) { + public static void writeBoolBoxArray(ByteBuf byteBuf, Boolean[] array) { if (array == null) { byteBuf.writeByte(0); return; } writeInt(byteBuf, array.length); for (var value : array) { - writeBooleanBox(byteBuf, value); + writeBoolBox(byteBuf, value); } } - public static Boolean[] readBooleanBoxArray(ByteBuf byteBuf) { + public static Boolean[] readBoolBoxArray(ByteBuf byteBuf) { var length = readInt(byteBuf); var array = new Boolean[CollectionUtils.comfortableByteLength(length)]; for (var i = 0; i < length; i++) { - array[i] = readBooleanBox(byteBuf); + array[i] = readBoolBox(byteBuf); } return array; } - public static void writeBooleanCollection(ByteBuf byteBuf, Collection collection) { + public static void writeBoolCollection(ByteBuf byteBuf, Collection collection) { if (collection == null) { byteBuf.writeByte(0); return; } writeInt(byteBuf, collection.size()); for (var value : collection) { - writeBooleanBox(byteBuf, value); + writeBoolBox(byteBuf, value); } } - public static void writeBooleanList(ByteBuf byteBuf, List list) { - writeBooleanCollection(byteBuf, list); + public static void writeBoolList(ByteBuf byteBuf, List list) { + writeBoolCollection(byteBuf, list); } - public static List readBooleanList(ByteBuf byteBuf) { - return new ArrayListBoolean(readBooleanArray(byteBuf)); + public static List readBoolList(ByteBuf byteBuf) { + return new ArrayListBoolean(readBoolArray(byteBuf)); } - public static void writeBooleanSet(ByteBuf byteBuf, Set set) { - writeBooleanCollection(byteBuf, set); + public static void writeBoolSet(ByteBuf byteBuf, Set set) { + writeBoolCollection(byteBuf, set); } - public static Set readBooleanSet(ByteBuf byteBuf) { + public static Set readBoolSet(ByteBuf byteBuf) { var length = readInt(byteBuf); Set set = CollectionUtils.newSet(length); for (var i = 0; i < length; i++) { - set.add(readBooleanBox(byteBuf)); + set.add(readBoolBox(byteBuf)); } return set; } 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 0355551b..6ba71992 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownArraySerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownArraySerializer.java @@ -48,25 +48,25 @@ public class CutDownArraySerializer implements ICutDownSerializer { case "boolean": switch (language) { case Enhance: - builder.append(StringUtils.format("{}.writeBooleanArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); + builder.append(StringUtils.format("{}.writeBoolArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); break; case Kotlin, Scala, GdScript, Python: - builder.append(StringUtils.format("buffer.writeBooleanArray({})", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.writeBoolArray({})", objectStr)).append(LS); break; case Lua: - builder.append(StringUtils.format("buffer:writeBooleanArray({})", objectStr)).append(LS); + builder.append(StringUtils.format("buffer:writeBoolArray({})", objectStr)).append(LS); break; case Php: builder.append(StringUtils.format("$buffer->writeBoolArray({});", objectStr)).append(LS); break; case CSharp: - builder.append(StringUtils.format("buffer.WriteBooleanArray({});", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.WriteBoolArray({});", objectStr)).append(LS); break; case Golang: - builder.append(StringUtils.format("buffer.WriteBooleanArray({})", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.WriteBoolArray({})", objectStr)).append(LS); break; case Cpp, Java, JavaScript, EcmaScript, TypeScript: - builder.append(StringUtils.format("buffer.writeBooleanArray({});", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.writeBoolArray({});", objectStr)).append(LS); break; default: flag = false; @@ -75,25 +75,25 @@ public class CutDownArraySerializer implements ICutDownSerializer { case "Boolean": switch (language) { case Enhance: - builder.append(StringUtils.format("{}.writeBooleanBoxArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); + builder.append(StringUtils.format("{}.writeBoolBoxArray($1, {});", EnhanceUtils.byteBufUtils, objectStr)); break; case Kotlin, Scala, GdScript, Python: - builder.append(StringUtils.format("buffer.writeBooleanArray({})", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.writeBoolArray({})", objectStr)).append(LS); break; case Lua: - builder.append(StringUtils.format("buffer:writeBooleanArray({})", objectStr)).append(LS); + builder.append(StringUtils.format("buffer:writeBoolArray({})", objectStr)).append(LS); break; case Php: builder.append(StringUtils.format("$buffer->writeBoolArray({});", objectStr)).append(LS); break; case CSharp: - builder.append(StringUtils.format("buffer.WriteBooleanArray({});", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.WriteBoolArray({});", objectStr)).append(LS); break; case Golang: - builder.append(StringUtils.format("buffer.WriteBooleanArray({})", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.WriteBoolArray({})", objectStr)).append(LS); break; case Cpp, JavaScript, EcmaScript, TypeScript: - builder.append(StringUtils.format("buffer.writeBooleanArray({});", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.writeBoolArray({});", objectStr)).append(LS); break; default: flag = false; @@ -501,41 +501,41 @@ public class CutDownArraySerializer implements ICutDownSerializer { case "boolean": switch (language) { case Enhance: - builder.append(StringUtils.format("{}[] {} = {}.readBooleanArray($1);", arrayName, array, EnhanceUtils.byteBufUtils)); + builder.append(StringUtils.format("{}[] {} = {}.readBoolArray($1);", arrayName, array, EnhanceUtils.byteBufUtils)); break; case GdScript: - builder.append(StringUtils.format("var {} = buffer.readBooleanArray()", array)).append(LS); + builder.append(StringUtils.format("var {} = buffer.readBoolArray()", array)).append(LS); break; case Python: - builder.append(StringUtils.format("{} = buffer.readBooleanArray()", array)).append(LS); + builder.append(StringUtils.format("{} = buffer.readBoolArray()", array)).append(LS); break; case Lua: - builder.append(StringUtils.format("local {} = buffer:readBooleanArray()", array)).append(LS); + builder.append(StringUtils.format("local {} = buffer:readBoolArray()", array)).append(LS); break; case Php: array = "$" + array; builder.append(StringUtils.format("{} = $buffer->readBoolArray();", array)).append(LS); break; case CSharp: - builder.append(StringUtils.format("var {} = buffer.ReadBooleanArray();", array)).append(LS); + builder.append(StringUtils.format("var {} = buffer.ReadBoolArray();", array)).append(LS); break; case Golang: - builder.append(StringUtils.format("var {} = buffer.ReadBooleanArray()", array)).append(LS); + builder.append(StringUtils.format("var {} = buffer.ReadBoolArray()", array)).append(LS); break; case Cpp: - builder.append(StringUtils.format("auto {} = buffer.readBooleanArray();", array)).append(LS); + builder.append(StringUtils.format("auto {} = buffer.readBoolArray();", array)).append(LS); break; case Java: - builder.append(StringUtils.format("var {} = buffer.readBooleanArray();", array)).append(LS); + builder.append(StringUtils.format("var {} = buffer.readBoolArray();", array)).append(LS); break; case Kotlin: - builder.append(StringUtils.format("val {} = buffer.readBooleanArray()", array)).append(LS); + builder.append(StringUtils.format("val {} = buffer.readBoolArray()", array)).append(LS); break; case Scala: - builder.append(StringUtils.format("val {} = buffer.readBooleanArray", array)).append(LS); + builder.append(StringUtils.format("val {} = buffer.readBoolArray", array)).append(LS); break; case JavaScript, EcmaScript, TypeScript: - builder.append(StringUtils.format("const {} = buffer.readBooleanArray();", array)).append(LS); + builder.append(StringUtils.format("const {} = buffer.readBoolArray();", array)).append(LS); break; default: flag = false; @@ -544,38 +544,38 @@ public class CutDownArraySerializer implements ICutDownSerializer { case "Boolean": switch (language) { case Enhance: - builder.append(StringUtils.format("{}[] {} = {}.readBooleanBoxArray($1);", arrayName, array, EnhanceUtils.byteBufUtils)); + builder.append(StringUtils.format("{}[] {} = {}.readBoolBoxArray($1);", arrayName, array, EnhanceUtils.byteBufUtils)); break; case GdScript: - builder.append(StringUtils.format("var {} = buffer.readBooleanArray()", array)).append(LS); + builder.append(StringUtils.format("var {} = buffer.readBoolArray()", array)).append(LS); break; case Python: - builder.append(StringUtils.format("{} = buffer.readBooleanArray()", array)).append(LS); + builder.append(StringUtils.format("{} = buffer.readBoolArray()", array)).append(LS); break; case Lua: - builder.append(StringUtils.format("local {} = buffer:readBooleanArray()", array)).append(LS); + builder.append(StringUtils.format("local {} = buffer:readBoolArray()", array)).append(LS); break; case Php: array = "$" + array; builder.append(StringUtils.format("{} = $buffer->readBoolArray();", array)).append(LS); break; case CSharp: - builder.append(StringUtils.format("var {} = buffer.ReadBooleanArray();", array)).append(LS); + builder.append(StringUtils.format("var {} = buffer.ReadBoolArray();", array)).append(LS); break; case Golang: - builder.append(StringUtils.format("var {} = buffer.ReadBooleanArray()", array)).append(LS); + builder.append(StringUtils.format("var {} = buffer.ReadBoolArray()", array)).append(LS); break; case Cpp: - builder.append(StringUtils.format("auto {} = buffer.readBooleanArray();", array)).append(LS); + builder.append(StringUtils.format("auto {} = buffer.readBoolArray();", array)).append(LS); break; case Kotlin: - builder.append(StringUtils.format("val {} = buffer.readBooleanArray()", array)).append(LS); + builder.append(StringUtils.format("val {} = buffer.readBoolArray()", array)).append(LS); break; case Scala: - builder.append(StringUtils.format("val {} = buffer.readBooleanArray", array)).append(LS); + builder.append(StringUtils.format("val {} = buffer.readBoolArray", array)).append(LS); break; case JavaScript, EcmaScript, TypeScript: - builder.append(StringUtils.format("const {} = buffer.readBooleanArray();", array)).append(LS); + builder.append(StringUtils.format("const {} = buffer.readBoolArray();", array)).append(LS); break; 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 16c052f1..81f3426a 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownListSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownListSerializer.java @@ -47,28 +47,28 @@ public class CutDownListSerializer implements ICutDownSerializer { case "Boolean": switch (language) { case Enhance: - builder.append(StringUtils.format("{}.writeBooleanList($1, (List){});", EnhanceUtils.byteBufUtils, objectStr)); + builder.append(StringUtils.format("{}.writeBoolList($1, (List){});", EnhanceUtils.byteBufUtils, objectStr)); break; case GdScript, Python: - builder.append(StringUtils.format("buffer.writeBooleanArray({})", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.writeBoolArray({})", objectStr)).append(LS); break; case Lua: - builder.append(StringUtils.format("buffer:writeBooleanArray({})", objectStr)).append(LS); + builder.append(StringUtils.format("buffer:writeBoolArray({})", objectStr)).append(LS); break; case Php: builder.append(StringUtils.format("$buffer->writeBoolArray({});", objectStr)).append(LS); break; case CSharp: - builder.append(StringUtils.format("buffer.WriteBooleanList({});", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.WriteBoolList({});", objectStr)).append(LS); break; case Golang: - builder.append(StringUtils.format("buffer.WriteBooleanArray({})", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.WriteBoolArray({})", objectStr)).append(LS); break; case Cpp, Java, JavaScript, EcmaScript, TypeScript: - builder.append(StringUtils.format("buffer.writeBooleanList({});", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.writeBoolList({});", objectStr)).append(LS); break; case Kotlin, Scala: - builder.append(StringUtils.format("buffer.writeBooleanList({})", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.writeBoolList({})", objectStr)).append(LS); break; default: flag = false; @@ -340,41 +340,41 @@ public class CutDownListSerializer implements ICutDownSerializer { case "Boolean": switch (language) { case Enhance: - builder.append(StringUtils.format("List {} = {}.readBooleanList($1);", list, EnhanceUtils.byteBufUtils)); + builder.append(StringUtils.format("List {} = {}.readBoolList($1);", list, EnhanceUtils.byteBufUtils)); break; case GdScript: - builder.append(StringUtils.format("var {} = buffer.readBooleanArray()", list)).append(LS); + builder.append(StringUtils.format("var {} = buffer.readBoolArray()", list)).append(LS); break; case Python: - builder.append(StringUtils.format("{} = buffer.readBooleanArray()", list)).append(LS); + builder.append(StringUtils.format("{} = buffer.readBoolArray()", list)).append(LS); break; case Lua: - builder.append(StringUtils.format("local {} = buffer:readBooleanArray()", list)).append(LS); + builder.append(StringUtils.format("local {} = buffer:readBoolArray()", list)).append(LS); break; case Php: list = "$" + list; builder.append(StringUtils.format("{} = buffer->readBoolArray();", list)).append(LS); break; case CSharp: - builder.append(StringUtils.format("var {} = buffer.ReadBooleanList();", list)).append(LS); + builder.append(StringUtils.format("var {} = buffer.ReadBoolList();", list)).append(LS); break; case Golang: - builder.append(StringUtils.format("var {} = buffer.ReadBooleanArray()", list)).append(LS); + builder.append(StringUtils.format("var {} = buffer.ReadBoolArray()", list)).append(LS); break; case Cpp: - builder.append(StringUtils.format("auto {} = buffer.readBooleanList();", list)).append(LS); + builder.append(StringUtils.format("auto {} = buffer.readBoolList();", list)).append(LS); break; case Java: - builder.append(StringUtils.format("var {} = buffer.readBooleanList();", list)).append(LS); + builder.append(StringUtils.format("var {} = buffer.readBoolList();", list)).append(LS); break; case Kotlin: - builder.append(StringUtils.format("val {} = buffer.readBooleanList()", list)).append(LS); + builder.append(StringUtils.format("val {} = buffer.readBoolList()", list)).append(LS); break; case Scala: - builder.append(StringUtils.format("val {} = buffer.readBooleanList", list)).append(LS); + builder.append(StringUtils.format("val {} = buffer.readBoolList", list)).append(LS); break; case JavaScript, EcmaScript, TypeScript: - builder.append(StringUtils.format("const {} = buffer.readBooleanList();", list)).append(LS); + builder.append(StringUtils.format("const {} = buffer.readBoolList();", list)).append(LS); break; default: flag = false; 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 5d2ec931..91477a35 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownSetSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownSetSerializer.java @@ -48,28 +48,28 @@ public class CutDownSetSerializer implements ICutDownSerializer { case "Boolean": switch (language) { case Enhance: - builder.append(StringUtils.format("{}.writeBooleanSet($1, (Set){});", EnhanceUtils.byteBufUtils, objectStr)); + builder.append(StringUtils.format("{}.writeBoolSet($1, (Set){});", EnhanceUtils.byteBufUtils, objectStr)); break; case GdScript: - builder.append(StringUtils.format("buffer.writeBooleanArray({})", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.writeBoolArray({})", objectStr)).append(LS); break; case Python, Kotlin, Scala: - builder.append(StringUtils.format("buffer.writeBooleanSet({})", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.writeBoolSet({})", objectStr)).append(LS); break; case Lua: - builder.append(StringUtils.format("buffer:writeBooleanArray({})", objectStr)).append(LS); + builder.append(StringUtils.format("buffer:writeBoolArray({})", objectStr)).append(LS); break; case Php: builder.append(StringUtils.format("$buffer->writeBoolArray({});", objectStr)).append(LS); break; case CSharp: - builder.append(StringUtils.format("buffer.WriteBooleanSet({});", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.WriteBoolSet({});", objectStr)).append(LS); break; case Golang: - builder.append(StringUtils.format("buffer.WriteBooleanArray({})", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.WriteBoolArray({})", objectStr)).append(LS); break; case Cpp, Java, JavaScript, EcmaScript, TypeScript: - builder.append(StringUtils.format("buffer.writeBooleanSet({});", objectStr)).append(LS); + builder.append(StringUtils.format("buffer.writeBoolSet({});", objectStr)).append(LS); break; default: flag = false; @@ -337,41 +337,41 @@ public class CutDownSetSerializer implements ICutDownSerializer { case "Boolean": switch (language) { case Enhance: - builder.append(StringUtils.format("Set {} = {}.readBooleanSet($1);", set, EnhanceUtils.byteBufUtils)); + builder.append(StringUtils.format("Set {} = {}.readBoolSet($1);", set, EnhanceUtils.byteBufUtils)); break; case GdScript: - builder.append(StringUtils.format("var {} = buffer.readBooleanArray()", set)).append(LS); + builder.append(StringUtils.format("var {} = buffer.readBoolArray()", set)).append(LS); break; case Python: - builder.append(StringUtils.format("{} = buffer.readBooleanSet()", set)).append(LS); + builder.append(StringUtils.format("{} = buffer.readBoolSet()", set)).append(LS); break; case Lua: - builder.append(StringUtils.format("local {} = buffer:readBooleanArray()", set)).append(LS); + builder.append(StringUtils.format("local {} = buffer:readBoolArray()", set)).append(LS); break; case Php: set = "$" + set; builder.append(StringUtils.format("{} = $buffer->readBoolArray();", set)).append(LS); break; case CSharp: - builder.append(StringUtils.format("var {} = buffer.ReadBooleanSet();", set)).append(LS); + builder.append(StringUtils.format("var {} = buffer.ReadBoolSet();", set)).append(LS); break; case Golang: - builder.append(StringUtils.format("var {} = buffer.ReadBooleanArray()", set)).append(LS); + builder.append(StringUtils.format("var {} = buffer.ReadBoolArray()", set)).append(LS); break; case Cpp: - builder.append(StringUtils.format("auto {} = buffer.readBooleanSet();", set)).append(LS); + builder.append(StringUtils.format("auto {} = buffer.readBoolSet();", set)).append(LS); break; case Java: - builder.append(StringUtils.format("var {} = buffer.readBooleanSet();", set)).append(LS); + builder.append(StringUtils.format("var {} = buffer.readBoolSet();", set)).append(LS); break; case Kotlin: - builder.append(StringUtils.format("val {} = buffer.readBooleanSet()", set)).append(LS); + builder.append(StringUtils.format("val {} = buffer.readBoolSet()", set)).append(LS); break; case Scala: - builder.append(StringUtils.format("val {} = buffer.readBooleanSet", set)).append(LS); + builder.append(StringUtils.format("val {} = buffer.readBoolSet", set)).append(LS); break; case JavaScript, EcmaScript, TypeScript: - builder.append(StringUtils.format("const {} = buffer.readBooleanSet();", set)).append(LS); + builder.append(StringUtils.format("const {} = buffer.readBoolSet();", set)).append(LS); break; default: flag = false; diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/enhance/EnhanceBoolSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/enhance/EnhanceBoolSerializer.java index 19186f9e..2bdd1d5d 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/enhance/EnhanceBoolSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/enhance/EnhanceBoolSerializer.java @@ -28,9 +28,9 @@ public class EnhanceBoolSerializer implements IEnhanceSerializer { @Override public void writeObject(StringBuilder builder, String objectStr, Field field, IFieldRegistration fieldRegistration) { if (isPrimitiveField(field)) { - builder.append(StringUtils.format("{}.writeBoolean($1, {});", EnhanceUtils.byteBufUtils, objectStr)); + builder.append(StringUtils.format("{}.writeBool($1, {});", EnhanceUtils.byteBufUtils, objectStr)); } else { - builder.append(StringUtils.format("{}.writeBooleanBox($1, (Boolean){});", EnhanceUtils.byteBufUtils, objectStr)); + builder.append(StringUtils.format("{}.writeBoolBox($1, (Boolean){});", EnhanceUtils.byteBufUtils, objectStr)); } } @@ -38,9 +38,9 @@ public class EnhanceBoolSerializer implements IEnhanceSerializer { public String readObject(StringBuilder builder, Field field, IFieldRegistration fieldRegistration) { var result = "result" + GenerateProtocolFile.localVariableId++; if (isPrimitiveField(field)) { - builder.append(StringUtils.format("boolean {} = {}.readBoolean($1);", result, EnhanceUtils.byteBufUtils)); + builder.append(StringUtils.format("boolean {} = {}.readBool($1);", result, EnhanceUtils.byteBufUtils)); } else { - builder.append(StringUtils.format("Boolean {} = {}.readBooleanBox($1);", result, EnhanceUtils.byteBufUtils)); + builder.append(StringUtils.format("Boolean {} = {}.readBoolBox($1);", result, EnhanceUtils.byteBufUtils)); } return result; } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/java/CodeGenerateJava.java b/protocol/src/main/java/com/zfoo/protocol/serializer/java/CodeGenerateJava.java index 0181f2ec..85285b68 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/java/CodeGenerateJava.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/java/CodeGenerateJava.java @@ -303,7 +303,7 @@ public class CodeGenerateJava implements ICodeGenerate { var fieldRegistrations = registration.getFieldRegistrations(); var javaBuilder = new StringBuilder(); if (registration.isCompatible()) { - javaBuilder.append("int beforeWriteIndex = buffer.writeOffset();").append(LS); + javaBuilder.append("int beforeWriteIndex = buffer.getWriteOffset();").append(LS); javaBuilder.append(StringUtils.format("buffer.writeInt({});", registration.getPredictionLength())).append(LS); } else { javaBuilder.append("buffer.writeInt(-1);").append(LS); diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/reflect/BoolSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/reflect/BoolSerializer.java index 2b4adb39..2d5751bb 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/reflect/BoolSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/reflect/BoolSerializer.java @@ -26,12 +26,12 @@ public class BoolSerializer implements ISerializer { @Override public void writeObject(ByteBuf buffer, Object object, IFieldRegistration fieldRegistration) { - ByteBufUtils.writeBooleanBox(buffer, (Boolean) object); + ByteBufUtils.writeBoolBox(buffer, (Boolean) object); } @Override public Object readObject(ByteBuf buffer, IFieldRegistration fieldRegistration) { - return ByteBufUtils.readBooleanBox(buffer); + return ByteBufUtils.readBoolBox(buffer); } @Override diff --git a/protocol/src/main/resources/java/ByteBuffer.java b/protocol/src/main/resources/java/ByteBuffer.java index a6ae9961..27cfafa6 100644 --- a/protocol/src/main/resources/java/ByteBuffer.java +++ b/protocol/src/main/resources/java/ByteBuffer.java @@ -37,7 +37,12 @@ public class ByteBuffer { } // -------------------------------------------------get/set------------------------------------------------- - public int writeOffset() { + + public byte[] getBuffer() { + return buffer; + } + + public int getWriteOffset() { return writeOffset; } @@ -49,7 +54,7 @@ public class ByteBuffer { writeOffset = writeIndex; } - public int readOffset() { + public int getReadOffset() { return readOffset; } @@ -382,7 +387,7 @@ public class ByteBuffer { return new String(bytes, DEFAULT_CHARSET); } - public void writeBooleanArray(boolean[] array) { + public void writeBoolArray(boolean[] array) { if ((array == null) || (array.length == 0)) { writeInt(0); } else { @@ -394,7 +399,7 @@ public class ByteBuffer { } } - public boolean[] readBooleanArray() { + public boolean[] readBoolArray() { int size = readInt(); boolean[] array = new boolean[size]; if (size > 0) { @@ -566,7 +571,7 @@ public class ByteBuffer { return array; } - public void writeBooleanList(List list) { + public void writeBoolList(List list) { if ((list == null) || list.isEmpty()) { writeInt(0); } else { @@ -577,7 +582,7 @@ public class ByteBuffer { } } - public List readBooleanList() { + public List readBoolList() { int size = readInt(); List list = new ArrayList<>(); if (size > 0) { @@ -766,7 +771,7 @@ public class ByteBuffer { return list; } - public void writeBooleanSet(Set set) { + public void writeBoolSet(Set set) { if ((set == null) || set.isEmpty()) { writeInt(0); } else { @@ -777,7 +782,7 @@ public class ByteBuffer { } } - public Set readBooleanSet() { + public Set readBoolSet() { int size = readInt(); Set set = new HashSet<>(); if (size > 0) { diff --git a/protocol/src/main/resources/java/ProtocolRegistrationTemplate.java b/protocol/src/main/resources/java/ProtocolRegistrationTemplate.java index 956fa17e..852efc77 100644 --- a/protocol/src/main/resources/java/ProtocolRegistrationTemplate.java +++ b/protocol/src/main/resources/java/ProtocolRegistrationTemplate.java @@ -20,7 +20,7 @@ class ${protocol_name}Registration implements IProtocolRegistration { if (length == 0) { return null; } - var beforeReadIndex = buffer.readOffset(); + var beforeReadIndex = buffer.getReadOffset(); var packet = new ${protocol_name}(); ${protocol_read_deserialization} if (length > 0) { diff --git a/protocol/src/test/kotlin/Main.java b/protocol/src/test/kotlin/Main.java index 5849c0ab..07a87b34 100644 --- a/protocol/src/test/kotlin/Main.java +++ b/protocol/src/test/kotlin/Main.java @@ -165,7 +165,7 @@ public class Main { var equal = 0; var notEqual = 0; - for (int i = 0; i < buffer.writeOffset(); i++) { + for (int i = 0; i < buffer.getWriteOffset(); i++) { var a = buffer.readByte(); var b = newBuffer.readByte(); if (a == b) {