From 3604630c2b2559231ed67dd128ab63090c6b2d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E4=B8=99?= Date: Sat, 15 Mar 2025 22:54:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=91=E5=BF=AB=E5=85=85?= =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E6=B6=88=E6=81=AF=E5=A4=84=E7=90=86=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../YunKuaiChongProtocolMessageProcessor.java | 28 ++++--------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/jcpp-protocol-yunkuaichong/src/main/java/sanbing/jcpp/protocol/yunkuaichong/YunKuaiChongProtocolMessageProcessor.java b/jcpp-protocol-yunkuaichong/src/main/java/sanbing/jcpp/protocol/yunkuaichong/YunKuaiChongProtocolMessageProcessor.java index 53b0109..499915d 100644 --- a/jcpp-protocol-yunkuaichong/src/main/java/sanbing/jcpp/protocol/yunkuaichong/YunKuaiChongProtocolMessageProcessor.java +++ b/jcpp-protocol-yunkuaichong/src/main/java/sanbing/jcpp/protocol/yunkuaichong/YunKuaiChongProtocolMessageProcessor.java @@ -76,20 +76,16 @@ public class YunKuaiChongProtocolMessageProcessor extends ProtocolMessageProcess ByteBuf in = Unpooled.copiedBuffer(msg); - in.markReaderIndex(); - - findStartFlag(in); - // 判断是否可以读取报头,8个字节 - if (in.readableBytes() < 6) { - in.resetReaderIndex(); + if (in.readableBytes() < 8) { + in.release(); return; } // 起始标识, 固定为0x68 int startFlag = in.readUnsignedByte(); if (startFlag != 0x68) { - in.resetReaderIndex(); + in.release(); return; } @@ -108,7 +104,7 @@ public class YunKuaiChongProtocolMessageProcessor extends ProtocolMessageProcess // 判断是否可以读取消息体,N-4个字节 int msgBodyLength = dataLength - 4; if (in.readableBytes() < msgBodyLength) { - in.resetReaderIndex(); + in.release(); return; } @@ -118,14 +114,13 @@ public class YunKuaiChongProtocolMessageProcessor extends ProtocolMessageProcess // 判断是否可以读取校验和, 2个字节 if (in.readableBytes() < 2) { - in.resetReaderIndex(); + in.release(); return; } byte[] byCheckSum = new byte[2]; in.readBytes(byCheckSum); - ByteBuf csTemp = Unpooled.buffer(); - csTemp.writeBytes(byCheckSum); + ByteBuf csTemp = Unpooled.copiedBuffer(byCheckSum); // 校验校验和 int checkSum = csTemp.readUnsignedShort(); @@ -211,16 +206,5 @@ public class YunKuaiChongProtocolMessageProcessor extends ProtocolMessageProcess downlinkCmdExe.execute(session, message, protocolContext); } - private static void findStartFlag(ByteBuf buf) { - int count = buf.readableBytes(); - for (int index = buf.readerIndex(); index < count - 1; index++) { - if (buf.getByte(index) == (byte) 0x68) { - buf.readerIndex(index); - return; - } - } - buf.resetReaderIndex(); - } - }