pabigot  0.1.1
C++ support classes
Public Types | Static Public Member Functions | Static Public Attributes | Protected Types | Static Protected Member Functions
pabigot::crc::details::base_crc< W, Rin > Class Template Reference

CRC core framework using Rocksoft^tm Model characteristics. More...

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

Inheritance diagram for pabigot::crc::details::base_crc< W, Rin >:
pabigot::crc::crc< W, Poly, Rin, Rout, Init, XorOut >

Public Types

using uint_traits = typename support_traits::uint_traits
 
using fast_type = typename support_traits::fast_type
 A fast native unsigned integral type capable of holding width-bit CRC values. More...
 
using least_type = typename support_traits::least_type
 A small native unsigned integral type capable of holding width-bit CRC values. More...
 

Static Public Member Functions

static constexpr fast_type reflect (const fast_type &v)
 Delegate to support_traits::reflect.
 
static constexpr uint8_t * store (fast_type crc, uint8_t *bp)
 Store a finalized CRC into a buffer in a way that enables crc::residue(). More...
 

Static Public Attributes

static constexpr unsigned int width = W
 The width of the CRC in bits.
 
static constexpr unsigned int size = (7 + width) / 8
 The width of the CRC in bytes.
 
static constexpr fast_type mask = support_traits::mask
 The mask that discards bits of a fast_type that would be outside the width limit.
 
static constexpr bool refin = Rin
 true iff the input message bit stream is reflected. More...
 

Protected Types

using support_traits = details::uint_support< width >
 Traits class providing native integral types and parameter-independent values supporting width-bit operations.
 

Static Protected Member Functions

static constexpr least_type lookup_for_byte (const fast_type &poly, std::uint_fast8_t byte)
 Calculate a single lookup table entry using the given polynomial. More...
 
static constexpr fast_type crc_apply (const fast_type &poly, const fast_type &crc, fast_type msg, unsigned int n)
 Apply message bits into a CRC. More...
 

Detailed Description

template<unsigned int W, bool Rin = false>
class pabigot::crc::details::base_crc< W, Rin >

CRC core framework using Rocksoft^tm Model characteristics.

This class supports the basic operations that are common when parameterized by polynomial and output processing.

Template Parameters
Winitializes width.
Rininitializes refin.

Member Typedef Documentation

◆ fast_type

template<unsigned int W, bool Rin = false>
using pabigot::crc::details::base_crc< W, Rin >::fast_type = typename support_traits::fast_type

A fast native unsigned integral type capable of holding width-bit CRC values.

Warning
This value may have more octets or bits than are required to store the CRC.

◆ least_type

template<unsigned int W, bool Rin = false>
using pabigot::crc::details::base_crc< W, Rin >::least_type = typename support_traits::least_type

A small native unsigned integral type capable of holding width-bit CRC values.

Warning
This value may have more octets or bits than are required to store the CRC.

Member Function Documentation

◆ crc_apply()

template<unsigned int W, bool Rin = false>
static constexpr fast_type pabigot::crc::details::base_crc< W, Rin >::crc_apply ( const fast_type poly,
const fast_type crc,
fast_type  msg,
unsigned int  n 
)
inlinestaticconstexprprotected

Apply message bits into a CRC.

Parameters
polythe normal-form polynomial for the CRC.
crcthe remainder polynomial for the previously encountered message bits.
msgbits of message, already reflected.
nthe number of bits in msg that carry message bits.
Returns
the CRC after incorporating msg using poly.

◆ lookup_for_byte()

template<unsigned int W, bool Rin = false>
static constexpr least_type pabigot::crc::details::base_crc< W, Rin >::lookup_for_byte ( const fast_type poly,
std::uint_fast8_t  byte 
)
inlinestaticconstexprprotected

Calculate a single lookup table entry using the given polynomial.

Parameters
indexthe table index for which the precomputed CRC adjustment is desired.
polythe polynomial for which the table is being generated.
Returns
the effective CRC adjustment using poly when the next 8 bits to shift out of the CRC are index.

◆ store()

template<unsigned int W, bool Rin = false>
static constexpr uint8_t* pabigot::crc::details::base_crc< W, Rin >::store ( fast_type  crc,
uint8_t *  bp 
)
inlinestaticconstexpr

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

Warning
If the CRC width is not a multiple of 8 the stored value will not be correct, as this namespace provides no API to operate on messages that are not an integral number of octets.
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.

Field Documentation

◆ refin

template<unsigned int W, bool Rin = false>
constexpr bool pabigot::crc::details::base_crc< W, Rin >::refin = Rin
staticconstexpr

true iff the input message bit stream is reflected.

The CRC is a linear shift register; it is necessary to know which bit in a byte should be fed in first:

  • When refin is false the most significant bit of the byte is consumed first. This is the "big-endian" configuration.
  • When refin is true the least significant bit of the byte is consumed first. This is the "little-endian" configuration.

This parameter also affects crc::store() in that CRCs with width greater than 8 must use the byte order that matches the bit order when catenated to the end of a message to ensure that the aggregate CRC matches the crc::residual().


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