From 0547c0d7279e143d87ff56c172688bf6efbdb146 Mon Sep 17 00:00:00 2001 From: sun Date: Wed, 27 Sep 2023 17:05:03 +0800 Subject: [PATCH] fix[protocol]: null point --- .../main/java/com/zfoo/protocol/buffer/ByteBufUtils.java | 6 ------ .../java/com/zfoo/protocol/registration/EnhanceUtils.java | 1 + .../zfoo/protocol/registration/ProtocolRegistration.java | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) 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 e68008877..f362bebbe 100644 --- a/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java @@ -430,12 +430,6 @@ public static Character readCharBox(ByteBuf byteBuf) { //----------------------------------------------------------------------- //---------------------------------以下方法会被字节码生成的代码调用-------------------------------------- - public static boolean writePacketFlag(ByteBuf byteBuf, Object packet) { - boolean flag = packet == null; - byteBuf.writeBoolean(!flag); - return flag; - } - public static void writePacketCollection(ByteBuf byteBuf, Collection collection, IProtocolRegistration protocolRegistration) { if (collection == null) { byteBuf.writeByte(0); diff --git a/protocol/src/main/java/com/zfoo/protocol/registration/EnhanceUtils.java b/protocol/src/main/java/com/zfoo/protocol/registration/EnhanceUtils.java index ae0ca7f99..93b2effed 100644 --- a/protocol/src/main/java/com/zfoo/protocol/registration/EnhanceUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/registration/EnhanceUtils.java @@ -183,6 +183,7 @@ private static String writeMethodBody(ProtocolRegistration registration) { var builder = new StringBuilder(); builder.append("{"); + builder.append("if ($2 == null) { $1.writeByte(0); return; }"); builder.append(StringUtils.format("{} packet = ({})$2;", packetClazz.getName(), packetClazz.getName())); if (registration.isCompatible()) { builder.append("int beforeWriteIndex = $1.writerIndex();"); diff --git a/protocol/src/main/java/com/zfoo/protocol/registration/ProtocolRegistration.java b/protocol/src/main/java/com/zfoo/protocol/registration/ProtocolRegistration.java index d18df2024..32d15d025 100644 --- a/protocol/src/main/java/com/zfoo/protocol/registration/ProtocolRegistration.java +++ b/protocol/src/main/java/com/zfoo/protocol/registration/ProtocolRegistration.java @@ -74,7 +74,7 @@ public Constructor protocolConstructor() { public void write(ByteBuf byteBuf, Object packet) { if (packet == null) { // equals with ByteBufUtils.writeInt(byteBuf, 0); - ByteBufUtils.writeByte(byteBuf, (byte) 0); + byteBuf.writeByte(0); return; }