GCC Code Coverage Report


Directory: Utils/Hash/
File: HashBufferCommon.cpp
Date: 2026-09-03 21:18:39
Exec Total Coverage
Lines: 16 33 48.5%
Functions: 4 9 44.4%
Branches: 3 13 23.1%

Line Branch Exec Source
1 #include <Utils/Hash/HashBuffer.hpp>
2 #include <cstring>
3
4 #include <algorithm>
5
6 #include "Fw/Types/Serializable.hpp"
7
8 namespace Utils {
9
10 10 HashBuffer::HashBuffer() : Fw::LinearBufferBase(m_bufferData, sizeof(m_bufferData)) {}
11
12 HashBuffer::HashBuffer(const U8* args, FwSizeType size) : Fw::LinearBufferBase(m_bufferData, sizeof(m_bufferData)) {
13 Fw::SerializeStatus stat = Fw::LinearBufferBase::setBuff(args, size);
14 FW_ASSERT(Fw::FW_SERIALIZE_OK == stat, static_cast<FwAssertArgType>(stat));
15 }
16
17 20 HashBuffer::~HashBuffer() = default;
18
19 HashBuffer::HashBuffer(const HashBuffer& other) : Fw::LinearBufferBase(m_bufferData, sizeof(m_bufferData)) {
20 Fw::SerializeStatus stat = Fw::LinearBufferBase::setBuff(other.m_bufferData, other.getSize());
21 FW_ASSERT(Fw::FW_SERIALIZE_OK == stat, static_cast<FwAssertArgType>(stat));
22 }
23
24 5 HashBuffer& HashBuffer::operator=(const HashBuffer& other) {
25
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (this == &other) {
26 return *this;
27 }
28
29 5 Fw::SerializeStatus stat = Fw::LinearBufferBase::setBuff(other.m_bufferData, other.getSize());
30 5 FW_ASSERT(Fw::FW_SERIALIZE_OK == stat, static_cast<FwAssertArgType>(stat));
31 5 return *this;
32 }
33
34 bool HashBuffer::operator==(const HashBuffer& other) const {
35 if (this->getSize() != other.getSize()) {
36 return false;
37 }
38 return memcmp(this->getBuffAddr(), other.getBuffAddr(), static_cast<size_t>(this->getSize())) == 0;
39 }
40
41 bool HashBuffer::operator!=(const HashBuffer& other) const {
42 return !(*this == other);
43 }
44
45 FwSizeType HashBuffer::getBuffCapacity() const {
46 return this->getCapacity();
47 }
48
49 5 U32 HashBuffer::asBigEndianU32() const {
50 5 U32 result = 0;
51 5 const FwSizeType bufferSize = sizeof this->m_bufferData;
52 5 const FwSizeType numBytes = std::min(bufferSize, static_cast<FwSizeType>(sizeof(U32)));
53
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 5 times.
25 for (FwSizeType i = 0; i < numBytes; i++) {
54 20 result <<= 8;
55 20 FW_ASSERT(i < bufferSize, static_cast<FwAssertArgType>(i), static_cast<FwAssertArgType>(bufferSize));
56 20 result += this->m_bufferData[i];
57 }
58 5 return result;
59 }
60 } // namespace Utils
61