Skip to content

Commit

Permalink
fix[protocol]: null point
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Sep 27, 2023
1 parent 0d051e7 commit 0547c0d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 0547c0d

Please sign in to comment.