cgul_crc16_incr.h File Reference

incremental CRC-16 More...

#include "cgul_exception.h"
Include dependency graph for cgul_crc16_incr.h:
This graph shows which files directly or indirectly include this file:

Typedefs

typedef typedefCGUL_BEGIN_C struct cgul_crc16_incr * cgul_crc16_incr_t
 

Functions

CGUL_EXPORT cgul_crc16_incr_t cgul_crc16_incr__new (cgul_exception_t *cex, unsigned short g, unsigned short init, unsigned short final_xor, int reflected)
 
CGUL_EXPORT cgul_crc16_incr_t cgul_crc16_incr__new_appends_size (cgul_exception_t *cex, unsigned short g, unsigned short init, unsigned short final_xor, int reflected, size_t size_xor)
 
CGUL_EXPORT void cgul_crc16_incr__delete (cgul_crc16_incr_t crc)
 
CGUL_EXPORT void cgul_crc16_incr__assign (cgul_exception_t *cex, cgul_crc16_incr_t lhs, cgul_crc16_incr_t rhs)
 
CGUL_EXPORT unsigned long cgul_crc16_incr__crc (cgul_exception_t *cex, cgul_crc16_incr_t crc)
 
CGUL_EXPORT void cgul_crc16_incr__update_block (cgul_exception_t *cex, cgul_crc16_incr_t crc, const void *block, size_t length)
 
CGUL_EXPORT void cgul_crc16_incr__update_file (cgul_exception_t *cex, cgul_crc16_incr_t crc, FILE *f)
 
CGUL_EXPORT void cgul_crc16_incr__update_fname (cgul_exception_t *cex, cgul_crc16_incr_t crc, const char *fname)
 
CGUL_EXPORT void cgul_crc16_incr__reset (cgul_exception_t *cex, cgul_crc16_incr_t crc)
 

Detailed Description

This class is a wrapper around the cgul_crc16 class. It is designed so that CRC-16 values can be calculated incrementally. The problem is that cgul_crc16__crc() must be called to calculate the final CRC-16 value, but this operation destroys the previous state making it otherwise impossible to continue a CRC-16 calculation based on data already consumed. Without anything else, you would have to re-calculate the entire CRC-16 value from scratch. This class lets you incrementally calculate CRC-16 values by saving the intermediate state between calls to cgul_crc16__crc().

See also
cgul_crc16

Typedef Documentation

§ cgul_crc16_incr_t

typedef typedefCGUL_BEGIN_C struct cgul_crc16_incr* cgul_crc16_incr_t

Opaque pointer to a cgul_crc16_incr instance.

Function Documentation

§ cgul_crc16_incr__new()

CGUL_EXPORT cgul_crc16_incr_t cgul_crc16_incr__new ( cgul_exception_t cex,
unsigned short  g,
unsigned short  init,
unsigned short  final_xor,
int  reflected 
)

Create a new cgul_crc16_incr object. Objects created with this constructor do not append the size to the data stream that is CRCed. The client is responsible for calling cgul_crc16_incr__delete() on the object returned. If an error occurs, NULL is returned, and an exception is thrown.

Parameters
[in,out]cexc-style exception
[in]ggenerator polynomial
[in]initinitial value loaded into the accumulator
[in]final_xorvalue to xor with the calculated crc
[in]reflectedwhether to use the reflected algorithm
Returns
new cgul_crc16_incr instance
See also
cgul_crc16__new()

Referenced by cgul_crc16_incr_cxx::cgul_crc16_incr_cxx().

§ cgul_crc16_incr__new_appends_size()

CGUL_EXPORT cgul_crc16_incr_t cgul_crc16_incr__new_appends_size ( cgul_exception_t cex,
unsigned short  g,
unsigned short  init,
unsigned short  final_xor,
int  reflected,
size_t  size_xor 
)

Create a new cgul_crc16_incr object. Objects created with this constructor append the size to the data stream that is CRCed. The client is responsible for calling cgul_crc16_incr__delete() on the object returned. If an error occurs, NULL is returned, and an exception is thrown.

Parameters
[in,out]cexc-style exception
[in]gpolynomial
[in]initinitial value loaded into the accumulator
[in]final_xorvalue to xor with the calculated crc
[in]reflectedwhether to use the reflected algorithm
[in]size_xorvalue to xor with the size before appending
Returns
new cgul_crc16_incr instance
See also
cgul_crc16__new_appends_size()

Referenced by cgul_crc16_incr_cxx::cgul_crc16_incr_cxx().

§ cgul_crc16_incr__delete()

CGUL_EXPORT void cgul_crc16_incr__delete ( cgul_crc16_incr_t  crc)

This function frees all internally allocated resources associated with the crc instance. The client must not attempt to use crc after calling this method.

Parameters
[in]crccgul_crc16_incr instance

Referenced by cgul_crc16_incr_cxx::set_obj(), and cgul_crc16_incr_cxx::~cgul_crc16_incr_cxx().

§ cgul_crc16_incr__assign()

CGUL_EXPORT void cgul_crc16_incr__assign ( cgul_exception_t cex,
cgul_crc16_incr_t  lhs,
cgul_crc16_incr_t  rhs 
)

Assign the current state of of rhs to lhs. This operation probably only makes sense if lhs and rhs have been constructed identically. If an error occurs, an exception is thrown.

Parameters
[in,out]cexc-style exception
[in]lhsleft-hand side
[in]rhsright-hand side

Referenced by cgul_crc16_incr_cxx::assign().

§ cgul_crc16_incr__crc()

CGUL_EXPORT unsigned long cgul_crc16_incr__crc ( cgul_exception_t cex,
cgul_crc16_incr_t  crc 
)

This method completes the CRC calculation by performing the size XOR and the final XOR. Unlike cgul_crc16__crc(), this method does not reset the CRC-16 calculation. Instead, the current CRC-16 calculation can be continued with subsequent calls to cgul_crc16_incr__update_block(). The return value is the current value for the entire CRC-16 calculation. If an error occurs, an exception is thrown.

Parameters
[in,out]cexc-style exception
[in]crccgul_crc16_incr instance
Returns
final crc value

Referenced by cgul_crc16_incr_cxx::crc().

§ cgul_crc16_incr__update_block()

CGUL_EXPORT void cgul_crc16_incr__update_block ( cgul_exception_t cex,
cgul_crc16_incr_t  crc,
const void *  block,
size_t  length 
)

This method updates the CRC by adding all the bytes in block to the calculation.

Parameters
[in]cexc-style exception
[in]crccgul_crc16_incr instance
[in]blockblock of data to add to the crc
[in]lengthlength of block

Referenced by cgul_crc16_incr_cxx::update_block().

§ cgul_crc16_incr__update_file()

CGUL_EXPORT void cgul_crc16_incr__update_file ( cgul_exception_t cex,
cgul_crc16_incr_t  crc,
FILE *  f 
)

This method updates the CRC by adding all the bytes (starting at the current offset) in the file f to the calculation. If an error occurs, an exception is thrown.

Parameters
[in,out]cexc-style exception
[in]crccgul_crc16_incr instance
[in]finput file

Referenced by cgul_crc16_incr_cxx::update_file().

§ cgul_crc16_incr__update_fname()

CGUL_EXPORT void cgul_crc16_incr__update_fname ( cgul_exception_t cex,
cgul_crc16_incr_t  crc,
const char *  fname 
)

This method updates the CRC by adding all the bytes in the file with name fname to the calculation. If an error occurs, an exception is thrown.

Parameters
[in,out]cexc-style exception
[in]crccgul_crc16_incr instance
[in]fnameinput file name

Referenced by cgul_crc16_incr_cxx::update_fname().

§ cgul_crc16_incr__reset()

CGUL_EXPORT void cgul_crc16_incr__reset ( cgul_exception_t cex,
cgul_crc16_incr_t  crc 
)

Reset to the initial internal state.

Parameters
[in]cexc-style exception
[in]crccgul_crc16_incr instance

Referenced by cgul_crc16_incr_cxx::reset().