解码器拆分

This commit is contained in:
Guoqs
2024-11-27 14:32:51 +08:00
parent 9b95a07d8b
commit cd252d5ed1
8 changed files with 143 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
package com.jsowell.netty.decoder;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
@@ -107,7 +108,12 @@ public class YunKuaiChongDecoder extends ByteToMessageDecoder {
// 读取 data 数据 最后+2是帧校验域长度
ByteBuf frame = buffer.retainedSlice(beginReader, HEADER_LENGTH_68 + 1 + length + 2);
buffer.readerIndex(beginReader + HEADER_LENGTH_68 + 1 + length + 2);
out.add(frame);
// 转为YKCDataProtocol对象
byte[] bytes = new byte[HEADER_LENGTH_68 + 1 + length + 2];
frame.readBytes(bytes);
YKCDataProtocol ykcDataProtocol = new YKCDataProtocol(bytes);
out.add(ykcDataProtocol);
}
// 处理DNY协议消息