cgul_crc32_incr.h File Reference

incremental CRC-32 More...

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

Typedefs

typedef typedefCGUL_BEGIN_C struct cgul_crc32_incr * cgul_crc32_incr_t
 

Functions

CGUL_EXPORT cgul_crc32_incr_t cgul_crc32_incr__new (cgul_exception_t *cex, unsigned long g, unsigned long init, unsigned long final_xor, int reflected)
 
CGUL_EXPORT cgul_crc32_incr_t cgul_crc32_incr__new_appends_size (cgul_exception_t *cex, unsigned long g, unsigned long init, unsigned long final_xor, int reflected, size_t size_xor)
 
CGUL_EXPORT void cgul_crc32_incr__delete (cgul_crc32_incr_t crc)
 
CGUL_EXPORT void cgul_crc32_incr__assign (cgul_exception_t *cex, cgul_crc32_incr_t lhs, cgul_crc32_incr_t rhs)
 
CGUL_EXPORT unsigned long cgul_crc32_incr__crc (cgul_exception_t *cex, cgul_crc32_incr_t crc)
 
CGUL_EXPORT void cgul_crc32_incr__update_block (cgul_exception_t *cex, cgul_crc32_incr_t crc, const void *block, size_t length)
 
CGUL_EXPORT void cgul_crc32_incr__update_file (cgul_exception_t *cex, cgul_crc32_incr_t crc, FILE *f)
 
CGUL_EXPORT void cgul_crc32_incr__update_fname (cgul_exception_t *cex, cgul_crc32_incr_t crc, const char *fname)
 
CGUL_EXPORT void cgul_crc32_incr__reset (cgul_exception_t *cex, cgul_crc32_incr_t crc)
 

Detailed Description

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

See also
cgul_crc32

Typedef Documentation

§ cgul_crc32_incr_t

typedef typedefCGUL_BEGIN_C struct cgul_crc32_incr* cgul_crc32_incr_t

Opaque pointer to a cgul_crc32_incr instance.

Function Documentation

§ cgul_crc32_incr__new()

CGUL_EXPORT cgul_crc32_incr_t cgul_crc32_incr__new ( cgul_exception_t cex,
unsigned long  g,
unsigned long  init,
unsigned long  final_xor,
int  reflected 
)

Create a new cgul_crc32_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_crc32_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_crc32_incr instance
See also
cgul_crc32__new()

Referenced by cgul_crc32_incr_cxx::cgul_crc32_incr_cxx().

§ cgul_crc32_incr__new_appends_size()

CGUL_EXPORT cgul_crc32_incr_t cgul_crc32_incr__new_appends_size ( cgul_exception_t cex,
unsigned long  g,
unsigned long  init,
unsigned long  final_xor,
int  reflected,
size_t  size_xor 
)

Create a new cgul_crc32_incr object. Objects created with this constructor append the size to the data stream that is CRCed. The client is responsible for calling cgul_crc32_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_crc32_incr instance
See also
cgul_crc32__new_appends_size()

Referenced by cgul_crc32_incr_cxx::cgul_crc32_incr_cxx().

§ cgul_crc32_incr__delete()

CGUL_EXPORT void cgul_crc32_incr__delete ( cgul_crc32_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_crc32_incr instance

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

§ cgul_crc32_incr__assign()

CGUL_EXPORT void cgul_crc32_incr__assign ( cgul_exception_t cex,
cgul_crc32_incr_t  lhs,
cgul_crc32_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_crc32_incr_cxx::assign().

§ cgul_crc32_incr__crc()

CGUL_EXPORT unsigned long cgul_crc32_incr__crc ( cgul_exception_t cex,
cgul_crc32_incr_t  crc 
)

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

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

Referenced by cgul_crc32_incr_cxx::crc().

§ cgul_crc32_incr__update_block()

CGUL_EXPORT void cgul_crc32_incr__update_block ( cgul_exception_t cex,
cgul_crc32_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_crc32_incr instance
[in]blockblock of data to add to the crc
[in]lengthlength of block

Referenced by cgul_crc32_incr_cxx::update_block().

§ cgul_crc32_incr__update_file()

CGUL_EXPORT void cgul_crc32_incr__update_file ( cgul_exception_t cex,
cgul_crc32_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_crc32_incr instance
[in]finput file

Referenced by cgul_crc32_incr_cxx::update_file().

§ cgul_crc32_incr__update_fname()

CGUL_EXPORT void cgul_crc32_incr__update_fname ( cgul_exception_t cex,
cgul_crc32_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_crc32_incr instance
[in]fnameinput file name

Referenced by cgul_crc32_incr_cxx::update_fname().

§ cgul_crc32_incr__reset()

CGUL_EXPORT void cgul_crc32_incr__reset ( cgul_exception_t cex,
cgul_crc32_incr_t  crc 
)

Reset to the initial internal state.

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

Referenced by cgul_crc32_incr_cxx::reset().