incremental CRC-16 More...
#include "cgul_exception.h"
Typedefs | |
typedef typedefCGUL_BEGIN_C struct cgul_crc16_incr * | cgul_crc16_incr_t |
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()
.
typedef typedefCGUL_BEGIN_C struct cgul_crc16_incr* cgul_crc16_incr_t |
Opaque pointer to a cgul_crc16_incr
instance.
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.
[in,out] | cex | c-style exception |
[in] | g | generator polynomial |
[in] | init | initial value loaded into the accumulator |
[in] | final_xor | value to xor with the calculated crc |
[in] | reflected | whether to use the reflected algorithm |
cgul_crc16_incr
instance Referenced by cgul_crc16_incr_cxx::cgul_crc16_incr_cxx().
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.
[in,out] | cex | c-style exception |
[in] | g | polynomial |
[in] | init | initial value loaded into the accumulator |
[in] | final_xor | value to xor with the calculated crc |
[in] | reflected | whether to use the reflected algorithm |
[in] | size_xor | value to xor with the size before appending |
cgul_crc16_incr
instance Referenced by cgul_crc16_incr_cxx::cgul_crc16_incr_cxx().
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.
[in] | crc | cgul_crc16_incr instance |
Referenced by cgul_crc16_incr_cxx::set_obj(), and cgul_crc16_incr_cxx::~cgul_crc16_incr_cxx().
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.
[in,out] | cex | c-style exception |
[in] | lhs | left-hand side |
[in] | rhs | right-hand side |
Referenced by cgul_crc16_incr_cxx::assign().
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.
[in,out] | cex | c-style exception |
[in] | crc | cgul_crc16_incr instance |
Referenced by cgul_crc16_incr_cxx::crc().
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.
[in] | cex | c-style exception |
[in] | crc | cgul_crc16_incr instance |
[in] | block | block of data to add to the crc |
[in] | length | length of block |
Referenced by cgul_crc16_incr_cxx::update_block().
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.
[in,out] | cex | c-style exception |
[in] | crc | cgul_crc16_incr instance |
[in] | f | input file |
Referenced by cgul_crc16_incr_cxx::update_file().
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.
[in,out] | cex | c-style exception |
[in] | crc | cgul_crc16_incr instance |
[in] | fname | input file name |
Referenced by cgul_crc16_incr_cxx::update_fname().
CGUL_EXPORT void cgul_crc16_incr__reset | ( | cgul_exception_t * | cex, |
cgul_crc16_incr_t | crc | ||
) |
Reset to the initial internal state.
[in] | cex | c-style exception |
[in] | crc | cgul_crc16_incr instance |
Referenced by cgul_crc16_incr_cxx::reset().