fix[protocol]: null point

This commit is contained in:
sun
2023-09-27 17:05:03 +08:00
parent 0d051e7ef9
commit 0547c0d727
3 changed files with 2 additions and 7 deletions
@@ -430,12 +430,6 @@ public abstract class ByteBufUtils {
//-----------------------------------------------------------------------
//---------------------------------以下方法会被字节码生成的代码调用--------------------------------------
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);
@@ -183,6 +183,7 @@ public abstract class EnhanceUtils {
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();");
@@ -74,7 +74,7 @@ public class ProtocolRegistration implements IProtocolRegistration {
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;
}