LengthFieldBasedFrameDecoder 参数说明

LengthFieldBasedFrameDecoder 参数说明
举例
数据包格式为
body长度(4个)+14个字节的版本说明(字符串)+body
那么LengthFieldBasedFrameDecoder的参数为

new LengthFieldBasedFrameDecoder1(ByteOrder.LittleEndian, int.MaxValue, 0, 4, 14, 18, true)

他的构造函数是

LengthFieldBasedFrameDecoder1(ByteOrder byteOrder, int maxFrameLength, int lengthFieldOffset, int lengthFieldLength, int lengthAdjustment, int initialBytesToStrip, bool failFast)


lengthFieldOffset=0,即长度的偏移字节为零。放在首字节。
lengthFieldLength=4,长度4个字节。
lengthAdjustment=14,即修正字节是14,也就是包头长度18-4(4个包头长度),body长度本身不包含包头长度,所以用来计算实际帧长度的左右。

initialBytesToStrip=18,即跳过包头18个字节。直接读取body.如果要验证包头的参数。则不能跳过

原文地址:https://www.cnblogs.com/ruxia/p/12058505.html