mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-07 19:40:07 +08:00
update 重构
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.jsowell.netty.decoder;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 自定义LengthFieldBasedFrameDecoder
|
||||
*/
|
||||
@Slf4j
|
||||
public class MyLengthFieldBasedFrameDecoder extends LengthFieldBasedFrameDecoder {
|
||||
/*
|
||||
构造方法
|
||||
maxFrameLength:指定解码器所能处理的数据包的最大长度,超过该长度则抛出 TooLongFrameException 异常;
|
||||
lengthFieldOffset:指定长度字段的起始位置;
|
||||
lengthFieldLength:指定长度字段的长度:目前支持1(byte)、2(short)、3(3个byte)、4(int)、8(Long)
|
||||
lengthAdjustment:指定长度字段所表示的消息长度值与实际长度值之间的差值,可以用于调整解码器的计算和提高灵活性。
|
||||
initialBytesToStrip:指定解码器在将数据包分离出来后,跳过的字节数,因为这些字节通常不属于消息体内容,而是协议头或其他控制信息。
|
||||
lengthAdjustment(可正可负)需要满足以下的计算关系:
|
||||
*/
|
||||
public MyLengthFieldBasedFrameDecoder() {
|
||||
super(208, 1, 1, 0, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
|
||||
return super.decode(ctx, in);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user