pref[net]:解码修改

This commit is contained in:
37Sir
2021-06-08 11:09:32 +08:00
parent 2222a56e8c
commit 382f214ec7
2 changed files with 9 additions and 8 deletions
@@ -52,9 +52,8 @@ public class TcpPacketCodecHandler extends ByteToMessageCodec<EncodedPacketInfo>
// 如果长度非法,则抛出异常断开连接
if (length < 0) {
throw new IllegalArgumentException(StringUtils
.format("[session:{}]的包头长度[length:{}]非法"
, SessionUtils.sessionInfo(ctx), length));
throw new IllegalArgumentException(StringUtils.format("[session:{}]的包头长度[length:{}]非法"
, SessionUtils.sessionInfo(ctx), length));
}
// ByteBuf里的数据太小
@@ -63,8 +62,9 @@ public class TcpPacketCodecHandler extends ByteToMessageCodec<EncodedPacketInfo>
return;
}
var tmpByteBuf = in.readRetainedSlice(length);
ByteBuf tmpByteBuf = null;
try {
tmpByteBuf = in.readRetainedSlice(length);
DecodedPacketInfo packetInfo = NetContext.getPacketService().read(tmpByteBuf);
out.add(packetInfo);
} catch (Exception e) {
@@ -60,9 +60,8 @@ public class WebSocketCodecHandler extends MessageToMessageCodec<WebSocketFrame,
// 如果长度非法,则抛出异常断开连接
if (length < 0) {
throw new IllegalArgumentException(StringUtils
.format("[session:{}]的包头长度[length:{}]非法"
, SessionUtils.sessionInfo(channelHandlerContext), length));
throw new IllegalArgumentException(StringUtils.format("[session:{}]的包头长度[length:{}]非法"
, SessionUtils.sessionInfo(channelHandlerContext), length));
}
// ByteBuf里的数据太小
@@ -70,8 +69,10 @@ public class WebSocketCodecHandler extends MessageToMessageCodec<WebSocketFrame,
in.resetReaderIndex();
return;
}
var tmpByteBuf = in.readRetainedSlice(length);
ByteBuf tmpByteBuf = null;
try {
tmpByteBuf = in.readRetainedSlice(length);
DecodedPacketInfo packetInfo = NetContext.getPacketService().read(tmpByteBuf);
list.add(packetInfo);
} catch (Exception e) {