pabigot  0.1.1
C++ support classes
Data Structures | Public Types | Public Member Functions | Data Fields | Static Public Attributes
pabigot::crc::Tabler< CRC > Class Template Reference

Class encapsulating everything necessary for table-driven CRC calculations. More...

#include </mnt/devel/pabigot-cxx/include/pabigot/crc.hpp>

Inheritance diagram for pabigot::crc::Tabler< CRC >:

Data Structures

struct  params
 Rocksoft^TM model parameters for the checksum algorithm supported by this type. More...
 

Public Types

using crc_type = CRC
 The underlying crc type.
 
using table_type = std::array< least_type, 256 >
 How the CRC table elements are stored.
 

Public Member Functions

uint8_t * store (least_type crc, uint8_t *bp) const
 Store a finalized CRC into a buffer in a way that enables crc::residue(). More...
 
constexpr fast_type append (uint8_t octet, fast_type crc=init) const
 Table-driven update of a CRC given a data octet. More...
 
template<typename InputIterator >
constexpr fast_type append (InputIterator first, InputIterator last, fast_type crc=init) const
 Table-driven calculation of a CRC from a sequence of octet values. More...
 
constexpr least_type finalize (fast_type crc) const
 Perform necessary post-processing to get the final checksum. More...
 

Data Fields

const table_type table
 The CRC table, indexed by unreflected input octet.
 

Static Public Attributes

static constexpr size_t size = CRC::size
 The number of bytes required to store a CRC value of #width bits.
 
static constexpr fast_type init = make_init()
 The CRC initial value in the form required for table calculations.
 
static constexpr least_type residue = CRC::residue()
 The value expected when calculating the finalized CRC over an aggregate of a message and its store()d checksum.
 

Detailed Description

template<typename CRC>
class pabigot::crc::Tabler< CRC >

Class encapsulating everything necessary for table-driven CRC calculations.

The table is an instance member; everything else is a constexpr class static member. Construct these as global objects at compile-time with definitions like:

constexpr auto crc = pabigot::crc::crc<32, 0x04c11db7, true, true, -1, -1>::instantiate_tabler();

Use them like:

uint8_t* cp = prepare_message(buf);
auto pre = crc.append(buf, cp);
const uint8_t* ep = crc.store(crc.finalize(pre), cp);
transmit(buf, ep);

On reception:

auto len = receive(buf);
if (crc.residue != crc.finalize(crc.append(buf, buf + len))) {
  // error in aggregate message
}

Member Function Documentation

◆ append() [1/2]

template<typename CRC >
template<typename InputIterator >
constexpr fast_type pabigot::crc::Tabler< CRC >::append ( InputIterator  first,
InputIterator  last,
fast_type  crc = init 
) const
inlineconstexpr

Table-driven calculation of a CRC from a sequence of octet values.

Template Parameters
InputIteratoriterator over inputs. InputIterator::value_type must be convertible to an unsigned 8-bit value without changing the value content.
Parameters
firstbeginning of the range over which CRCs will be calculated.
lastbeginning of the range over which CRCs will be calculated.
crcthe CRC value calculated over all previous message bits. Start with init, which is the defaulted value.
Returns
the unreflected CRC value over all message bits through this invocation.
See also
finalize()

◆ append() [2/2]

template<typename CRC >
constexpr fast_type pabigot::crc::Tabler< CRC >::append ( uint8_t  octet,
fast_type  crc = init 
) const
inlineconstexpr

Table-driven update of a CRC given a data octet.

Parameters
octetthe next octet of message bits.
crcthe CRC value calculated over all previous message bits. Start with init, which is the defaulted value.
Returns
the unreflected CRC value over all message bits through this invocation.
See also
finalize()

◆ finalize()

template<typename CRC >
constexpr least_type pabigot::crc::Tabler< CRC >::finalize ( fast_type  crc) const
inlineconstexpr

Perform necessary post-processing to get the final checksum.

Parameters
crcan unreflected unmodified CRC over input bits.
Returns
the reflected modified CRC.

◆ store()

template<typename CRC >
uint8_t* pabigot::crc::Tabler< CRC >::store ( least_type  crc,
uint8_t *  bp 
) const
inline

Store a finalized CRC into a buffer in a way that enables crc::residue().

Parameters
crcthe finalized CRC of a message.
bppointer to space of size bytes immediately following the message, into which the CRC can be stored.
Returns
pointer into the region identified by bp immediately following the stored CRC.

The documentation for this class was generated from the following file: