From 456fc9c652d69ee83352301527effe0b3ef2a5f6 Mon Sep 17 00:00:00 2001 From: sun Date: Wed, 27 Sep 2023 15:57:02 +0800 Subject: [PATCH] perf[protocol]: fix string default value --- protocol/src/main/java/com/zfoo/protocol/ProtocolManager.java | 4 ++++ .../protocol/serializer/enhance/EnhanceStringSerializer.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/protocol/src/main/java/com/zfoo/protocol/ProtocolManager.java b/protocol/src/main/java/com/zfoo/protocol/ProtocolManager.java index 4a68b6fe3..8b0ec6363 100644 --- a/protocol/src/main/java/com/zfoo/protocol/ProtocolManager.java +++ b/protocol/src/main/java/com/zfoo/protocol/ProtocolManager.java @@ -65,6 +65,9 @@ public static void write(ByteBuf buffer, Object packet) { /** * deserialization a packet from the buffer + *

+ * byte[] convert to ByteBuf using Unpooled.wrappedBuffer(byte[]) in netty + * ByteBuf convert to byte[] using ByteBufUtils.readAllBytes(ByteBuf) in zfoo */ public static Object read(ByteBuf buffer) { return protocols[ByteBufUtils.readShort(buffer)].read(buffer); @@ -81,6 +84,7 @@ public static IProtocolRegistration getProtocol(Class protocolClass) { public static ProtocolModule moduleByProtocolId(short id) { return modules[protocols[id].module()]; } + public static ProtocolModule moduleByProtocol(Class clazz) { return moduleByProtocolId(protocolId(clazz)); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/enhance/EnhanceStringSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/enhance/EnhanceStringSerializer.java index 3bbde9151..bbbcfb2a4 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/enhance/EnhanceStringSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/enhance/EnhanceStringSerializer.java @@ -40,7 +40,7 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration @Override public String defaultValue(StringBuilder builder, Field field, IFieldRegistration fieldRegistration) { var result = "result" + GenerateProtocolFile.index.getAndIncrement(); - builder.append(StringUtils.format("String {} = \"\"", result)); + builder.append(StringUtils.format("String {} = \"\";", result)); return result; }