Ver Fonte

去掉 in.resetIndex

jianghouwei há 6 anos atrás
pai
commit
d2c233bf27

+ 26 - 28
src/main/java/com/tidecloud/dataacceptance/service/DelimiterJingWeiFrameDecoder.java

@@ -43,44 +43,42 @@ public class DelimiterJingWeiFrameDecoder extends ByteToMessageDecoder {
 
     @Override
     protected final void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
-        int beginIndex = in.readerIndex();
         if (in.readableBytes() < 10) {
             return;
         }
         ByteBuf[] tag_AP07 = new ByteBuf[]{TAG_AP07.slice(TAG_AP07.readerIndex(), TAG_AP07.readableBytes())};// 语音标记符号
         int frameLength = indexOf(in, tag_AP07);
         if (frameLength > 0) { // 语音包
-            synchronized (this) {
-                // 按照逗号切割
-                int cutLength = 0;// 存储最后一次查询条件
-                for (int i = 0; i < 5; i++) {
-                    int commaLength = in.forEachByte(in.readerIndex(), 30, FIND_COMMA);
-                    if (commaLength <= 0) {
-                        in.readerIndex(beginIndex);
-                        return;
-                    } else {
-                        cutLength = commaLength;
-                        in.readerIndex(commaLength + 1);
-                    }
-                }
-                in.readerIndex(beginIndex);
-                // 标记数据
-                int headLength = cutLength - beginIndex;
-                byte[] req = new byte[headLength + 1];
-                in.readBytes(req);
-                String msg = new String(req, "UTF-8");
-                String[] msgArr = msg.split(",");
-                Integer length = Integer.valueOf(msgArr[4]);
-                if (in.readableBytes() < length) {
-                    in.resetReaderIndex();
+            int beginIndex = in.readerIndex();
+            // 按照逗号切割
+            int cutLength = 0;// 存储最后一次查询条件
+            for (int i = 0; i < 5; i++) {
+                int commaLength = in.forEachByte(in.readerIndex(), 30, FIND_COMMA);
+                if (commaLength <= 0) {
+                    in.readerIndex(beginIndex);
                     return;
+                } else {
+                    cutLength = commaLength;
+                    in.readerIndex(commaLength + 1);
                 }
-                // 语音数据
+            }
+            in.readerIndex(beginIndex);
+            // 标记数据
+            int headLength = cutLength - beginIndex;
+            byte[] req = new byte[headLength + 1];
+            in.readBytes(req);
+            String msg = new String(req, "UTF-8");
+            String[] msgArr = msg.split(",");
+            Integer length = Integer.valueOf(msgArr[4]);
+            if (in.readableBytes() <= length) {
                 in.readerIndex(beginIndex);
-                int readLength = headLength + 1 + length + 1;
-                Object decoded = decode(readLength, ctx, in);
-                out.add(decoded);
+                return;
             }
+            // 语音数据
+            in.readerIndex(beginIndex);
+            int readLength = headLength + 1 + length + 1;
+            Object decoded = decode(readLength, ctx, in);
+            out.add(decoded);
         } else {// 是其他包
             Object decoded = decode(ctx, in);
             if (decoded != null) {