18045010223
2025-07-07 0d3a683a0c97154b1f2e6657398664537e4e3e82
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package org.yzh.protocol.commons;
 
import io.netty.buffer.ByteBuf;
 
public class JTUtils {
 
    /**
     * BCC校验(异或校验)
     */
    public static byte bcc(ByteBuf byteBuf, int tailOffset) {
        byte cs = 0;
        int readerIndex = byteBuf.readerIndex();
        int writerIndex = byteBuf.writerIndex() + tailOffset;
        while (readerIndex < writerIndex)
            cs ^= byteBuf.getByte(readerIndex++);
        return cs;
    }
 
    public static int headerLength(int version, boolean isSubpackage) {
        if (version > 0)
            return isSubpackage ? 21 : 17;
        else
            return isSubpackage ? 16 : 12;
    }
}