1078-修复分包消息处理

This commit is contained in:
648540858
2024-05-18 05:59:23 +08:00
parent 7ddf066878
commit b0e25ef784
4 changed files with 28 additions and 1 deletions

View File

@@ -82,4 +82,13 @@ public class MultiPacket {
public void setByteBuf(ByteBuf byteBuf) {
this.byteBuf = byteBuf;
}
@Override
public String toString() {
return "MultiPacket{" +
"消息头=" + header +
", 包序号=" + number +
", 分包数量=" + count +
'}';
}
}

View File

@@ -25,7 +25,8 @@ public enum MultiPacketManager {
* 增加待合并的分包,如果分包接受完毕会返回完整的数据包
*/
public ByteBuf add(MultiPacket packet) {
String key = packet.getHeader().getTerminalId() + "/" + packet.getHeader().getSn();
String key = packet.getHeader().getMsgId() + "/" + packet.getHeader().getTerminalId();
logger.debug("分包消息: \n{}", packet);
List<MultiPacket> multiPackets = packetMap.computeIfAbsent(key, k -> new ArrayList<>(packet.getCount()));
multiPackets.add(packet);
packetTimeMap.put(key, System.currentTimeMillis());