package com.lingniu.ingest.codec;

/** BCC（异或校验）。GB/T 32960 与 JT/T 808 都使用此方式做帧尾校验。 */
public final class BccChecksum {

    private BccChecksum() {}

    public static byte compute(byte[] data, int offset, int length) {
        byte sum = 0;
        for (int i = offset; i < offset + length; i++) {
            sum ^= data[i];
        }
        return sum;
    }

    public static boolean verify(byte[] data, int offset, int length, byte expected) {
        return compute(data, offset, length) == expected;
    }
}
