Skip to content

TableBasedRegister

A CRC register which uses a precomputed lookup table. It trades a bit of memory and setup time for significantly faster checksum calculation compared to Register.

from crc import Crc8, TableBasedRegister

register = TableBasedRegister(Crc8.CCITT)

register.init()
register.update(bytes([0, 1, 2, 3, 4, 5]))
assert register.digest() == 0xBC

Tip

Building the lookup table happens once per register, so create the register once and reuse it. See raw registers for a guide.

Bases: BasicRegister

Lookup table based crc register.

Info

This register type will be much faster than a simple bit by bit based crc register like Register.

__getitem__(index)

Gets a single byte of the register.

Parameters:

Name Type Description Default
index int

byte which shall be returned.

required

Returns:

Type Description
int

The byte at the specified index.

Raises:

Type Description
IndexError

Invalid index for this register.

__init__(configuration)

Creates a new table based crc register.

Parameters:

Name Type Description Default
configuration Configuration

used for the crc algorithm.

required
Attention

Creating a table based register initially might take some extra time, due to the fact that some lookup tables need to be calculated/initialized.

__len__()

Returns:

Type Description
int

The width of the register.

digest()

See AbstractRegister.digest

init()

See AbstractRegister.init

reverse()

See AbstractRegister.digest

update(data)

See AbstractRegister.update