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);
54 const U32 offsetMod4 = offset % 4;
55 if (offsetMod4 != 0) {
56 const U8 wordLength =
static_cast<U8>(
min(length, 4 - offsetMod4));
57 this->addWordUnaligned(&data[index], static_cast<U8>(offset + index), wordLength);
63 const U32 alignedEnd = index + (((length - index) / 4) * 4);
64 for (; index < alignedEnd; index += 4) {
65 addWordAligned(&data[index]);
70 const U8 wordLength =
static_cast<U8>(length - index);
71 this->addWordUnaligned(&data[index], static_cast<U8>(offset + index), wordLength);
75 void Checksum ::addWordAligned(
const U8*
const word) {
77 for (
U8 i = 0; i < 4; ++i) {
78 addByteAtOffset(word[i], i);
82 void Checksum ::addWordUnaligned(
const U8* word,
const U8 position,
const U8 length) {
85 U8 offset = position % 4;
86 for (
U8 i = 0; i < length; ++i) {
87 addByteAtOffset(word[i], offset);
95 void Checksum ::addByteAtOffset(
const U8 byte,
const U8 offset) {
97 const U32 addend =
static_cast<U32
>(byte) << (8 * (3 - offset));
98 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)