mirror of
https://github.com/nasa/fprime.git
synced 2025-12-10 00:44:37 -06:00
* Pull in framework changes from data-products branch * Pull in changes to DpManager from data-products branch * Pull in DpWriter from data-products branch * Fix spelling * Revise FileNameString * Fix warnings in CI * Fix static analysis warnings * Fix static analysis warnings * Revise formatting and comments * Revise banner comments * Revise FileNameString per PR comment * Revise path names in config headers If a header H.hpp exists in the F Prime source base, then is dangerous. Because [project root] and [fprime root] are both in the list of include paths, it's not clear whether this means "include [project root]/config/H.hpp" or "include [fprime root]/config/H.hpp." On the other hand, or has no such ambiguity, because only one of [project root]/config and [fprime root]/config is in the list of include paths. * Revise path names in config headers If a header H.hpp exists in the F Prime source base, then `#include "config/H.hpp"` is dangerous. Because [project root] and [fprime root] are both in the list of include paths, it's not clear whether this means "include [project root]/config/H.hpp" or "include [fprime root]/config/H.hpp." On the other hand, include <config/H.hpp> or `#include "config/H.hpp"` has no such ambiguity, because only one of [project root]/config and [fprime root]/config is in the list of include paths.
70 lines
2.1 KiB
C++
70 lines
2.1 KiB
C++
#include <Utils/Hash/HashBuffer.hpp>
|
|
#include <cstring>
|
|
|
|
#include <algorithm>
|
|
|
|
#include "Fw/Types/Serializable.hpp"
|
|
|
|
namespace Utils {
|
|
|
|
HashBuffer::HashBuffer() {}
|
|
|
|
HashBuffer::HashBuffer(const U8* args, NATIVE_UINT_TYPE size) : Fw::SerializeBufferBase() {
|
|
Fw::SerializeStatus stat = Fw::SerializeBufferBase::setBuff(args, size);
|
|
FW_ASSERT(Fw::FW_SERIALIZE_OK == stat, static_cast<NATIVE_INT_TYPE>(stat));
|
|
}
|
|
|
|
HashBuffer::~HashBuffer() {}
|
|
|
|
HashBuffer::HashBuffer(const HashBuffer& other) : Fw::SerializeBufferBase() {
|
|
Fw::SerializeStatus stat = Fw::SerializeBufferBase::setBuff(other.m_bufferData, other.getBuffLength());
|
|
FW_ASSERT(Fw::FW_SERIALIZE_OK == stat, static_cast<NATIVE_INT_TYPE>(stat));
|
|
}
|
|
|
|
HashBuffer& HashBuffer::operator=(const HashBuffer& other) {
|
|
if (this == &other) {
|
|
return *this;
|
|
}
|
|
|
|
Fw::SerializeStatus stat = Fw::SerializeBufferBase::setBuff(other.m_bufferData, other.getBuffLength());
|
|
FW_ASSERT(Fw::FW_SERIALIZE_OK == stat, static_cast<NATIVE_INT_TYPE>(stat));
|
|
return *this;
|
|
}
|
|
|
|
bool HashBuffer::operator==(const HashBuffer& other) const {
|
|
if ((this->getBuffLength() == other.getBuffLength()) &&
|
|
(memcmp(this->getBuffAddr(), other.getBuffAddr(), this->getBuffLength()) != 0)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool HashBuffer::operator!=(const HashBuffer& other) const {
|
|
return !(*this == other);
|
|
}
|
|
|
|
const U8* HashBuffer::getBuffAddr() const {
|
|
return this->m_bufferData;
|
|
}
|
|
|
|
U8* HashBuffer::getBuffAddr() {
|
|
return this->m_bufferData;
|
|
}
|
|
|
|
NATIVE_UINT_TYPE HashBuffer::getBuffCapacity() const {
|
|
return sizeof(this->m_bufferData);
|
|
}
|
|
|
|
U32 HashBuffer::asBigEndianU32() const {
|
|
U32 result = 0;
|
|
const FwSizeType bufferSize = sizeof this->m_bufferData;
|
|
const FwSizeType numBytes = std::min(bufferSize, static_cast<FwSizeType>(sizeof(U32)));
|
|
for (FwSizeType i = 0; i < numBytes; i++) {
|
|
result <<= 8;
|
|
FW_ASSERT(i < bufferSize, static_cast<FwAssertArgType>(i), static_cast<FwAssertArgType>(bufferSize));
|
|
result += this->m_bufferData[i];
|
|
}
|
|
return result;
|
|
}
|
|
} // namespace Utils
|