snappy · API

snappy.crc32c

CRC-32C (Castagnoli, polynomial 0x1EDC6F41 / reflected 0x82F63B78), init/xorout 0xFFFFFFFF. Table-driven with a slice-by-8 fast path.

This is the checksum the Snappy framing format masks and stores per chunk — not the same polynomial as plain CRC-32 (gzip/zlib/PNG use 0xEDB88320; do not reuse hashes.mojo's crc32 here).

crc32c(data, seed=0) matches the well-known check value crc32c(b"123456789") == 0xE3069283. Passing a previous result as seed chains across buffers: crc32c(b, seed=crc32c(a)) == crc32c(a + b).

Structs

Crc32c

struct Crc32c

Incremental CRC-32C. seed is the previous crc32c result (0 to start).

Implements Copyable, Movable

__init__

def __init__(out self, seed: UInt32 = UInt32(0))

update

def update(mut self, data: Span[UInt8])

finish

def finish(self) -> UInt32

Functions

crc32c

def crc32c(data: Span[UInt8], seed: UInt32 = UInt32(0)) -> UInt32

mask_crc32c

def mask_crc32c(crc: UInt32) -> UInt32

Snappy framing-format masking: rotate right 15, then add a magic constant (mod 2**32). Never store or compare a raw crc32c in a frame — always mask on write, unmask on read.

unmask_crc32c

def unmask_crc32c(masked: UInt32) -> UInt32

Inverse of mask_crc32c.