|
@@ -43,51 +43,44 @@ public class DelimiterJingWeiFrameDecoder extends ByteToMessageDecoder {
|
|
|
|
|
|
@Override
|
|
|
protected final void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
|
|
-
|
|
|
- int index = indexOf(in, delimiters);
|
|
|
- if (index <= 0) {
|
|
|
+ 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) {
|
|
|
- in.markReaderIndex();
|
|
|
// 按照逗号切割
|
|
|
int cutLength = 0;// 存储最后一次查询条件
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
int commaLength = in.forEachByte(in.readerIndex(), 30, FIND_COMMA);
|
|
|
if (commaLength <= 0) {
|
|
|
- in.resetReaderIndex();
|
|
|
+ in.readerIndex(beginIndex);
|
|
|
return;
|
|
|
} else {
|
|
|
cutLength = commaLength;
|
|
|
- in.readerIndex(cutLength + 1);
|
|
|
+ in.readerIndex(commaLength + 1);
|
|
|
}
|
|
|
}
|
|
|
- in.resetReaderIndex();
|
|
|
+ in.readerIndex(beginIndex);
|
|
|
// 标记数据
|
|
|
- if (in.readableBytes() < cutLength + 1) {
|
|
|
- return;
|
|
|
- } else {
|
|
|
- byte[] req = new byte[cutLength + 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();
|
|
|
- return;
|
|
|
- }
|
|
|
- // 语音数据
|
|
|
+ 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 readLength = cutLength + 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) {
|