CRCs of up to 64 bits from their parameters or by name, combined across pieces, with fast CRC-32, CRC-32C and CRC-64/XZ.
moon add gaato/crc///|
test {
// The three that formats use most, as values and as plain functions.
inspect(@crc.crc32.checksum(b"123456789"), content="3421780262")
inspect(@crc.crc32c_update(0, b"123456789"), content="3808858755")
// Any CRC of the catalogue by name, or from its parameters.
let modbus = @crc.Crc::named("CRC-16/MODBUS").unwrap()
inspect(modbus.checksum(b"123456789"), content="19255")
let custom = @crc.Crc::new(
width=16,
poly=0x8005,
init=0xFFFF,
reflect_in=true,
)
inspect(custom.checksum(b"123456789"), content="19255")
// In pieces: a running digest, or a CRC continued from the one so far.
let d = @crc.crc32.digest()
d.write(b"1234")
d.write(b"56789")
inspect(d.value(), content="3421780262")
let head = @crc.crc32.checksum(b"1234")
inspect(@crc.crc32.update(head, b"56789"), content="3421780262")
// The CRC of the two pieces one after the other, from theirs and the
// second's length, without the data.
let tail = @crc.crc32.checksum(b"56789")
inspect(@crc.crc32.combine(head, tail, 5), content="3421780262")
}pub struct Crc {
width : Int
poly : UInt64
init : UInt64
reflect_in : Bool
reflect_out : Bool
xor_out : UInt64
// private fields
}pub struct Digest {
// private fields
}fn crc32_update(crc : UInt, data : BytesView) -> UIntfn crc32c_update(crc : UInt, data : BytesView) -> UIntfn crc64_xz_update(crc : UInt64, data : BytesView) -> UInt64Install
Download zipCRCs of up to 64 bits from their parameters or by name, combined across pieces, with fast CRC-32, CRC-32C and CRC-64/XZ.