16 static U32
min(
const U32 a,
const U32 b) {
17 return (a < b) ? a : b;
33 this->m_value = checksum.m_value;
38 return this->m_value == checksum.m_value;
42 return not(*
this == checksum);
53 const U32 offsetMod4 = offset % 4;
54 if (offsetMod4 != 0) {
55 const U8 wordLength =
static_cast<U8>(
min(length, 4 - offsetMod4));
56 this->addWordUnaligned(&data[index], static_cast<U8>(offset + index), wordLength);
61 for (; index + 4 <= length; index += 4) {
62 addWordAligned(&data[index]);
67 const U8 wordLength =
static_cast<U8>(length - index);
68 this->addWordUnaligned(&data[index], static_cast<U8>(offset + index), wordLength);
72 void Checksum ::addWordAligned(
const U8*
const word) {
73 for (
U8 i = 0; i < 4; ++i) {
74 addByteAtOffset(word[i], i);
78 void Checksum ::addWordUnaligned(
const U8* word,
const U8 position,
const U8 length) {
80 U8 offset = position % 4;
81 for (
U8 i = 0; i < length; ++i) {
82 addByteAtOffset(word[i], offset);
90 void Checksum ::addByteAtOffset(
const U8 byte,
const U8 offset) {
92 const U32 addend =
static_cast<U32
>(byte) << (8 * (3 - offset));
93 this->m_value += addend;
Checksum & operator=(const Checksum &checksum)
Assign checksum to this.
Checksum()
Construct a fresh Checksum object.
bool operator!=(const Checksum &checksum) const
Compare checksum and this for inequality.
Class representing a 32-bit checksum as mandated by the CCSDS File Delivery Protocol.
~Checksum()
Destroy a Checksum object.
void update(const U8 *const data, const U32 offset, const U32 length)
U32 getValue() const
Get the checksum value.
bool operator==(const Checksum &checksum) const
Compare checksum and this for equality.
uint8_t U8
8-bit unsigned integer
static U32 min(const U32 a, const U32 b)