F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
HashBufferCommon.cpp
Go to the documentation of this file.
2 #include <cstring>
3 
4 #include <algorithm>
5 
7 
8 namespace Utils {
9 
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)) {
14  FW_ASSERT(Fw::FW_SERIALIZE_OK == stat, static_cast<FwAssertArgType>(stat));
15 }
16 
17 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 
25  if (this == &other) {
26  return *this;
27  }
28 
29  Fw::SerializeStatus stat = Fw::LinearBufferBase::setBuff(other.m_bufferData, other.getSize());
30  FW_ASSERT(Fw::FW_SERIALIZE_OK == stat, static_cast<FwAssertArgType>(stat));
31  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 
50  U32 result = 0;
51  const FwSizeType bufferSize = sizeof this->m_bufferData;
52  const FwSizeType numBytes = std::min(bufferSize, static_cast<FwSizeType>(sizeof(U32)));
53  for (FwSizeType i = 0; i < numBytes; i++) {
54  result <<= 8;
55  FW_ASSERT(i < bufferSize, static_cast<FwAssertArgType>(i), static_cast<FwAssertArgType>(bufferSize));
56  result += this->m_bufferData[i];
57  }
58  return result;
59 }
60 } // namespace Utils
Serialization/Deserialization operation was successful.
SerializeStatus setBuff(const U8 *src, Serializable::SizeType length) override
Set buffer contents from external source.
PlatformSizeType FwSizeType
Serializable::SizeType getSize() const override
Get current buffer size.
Serializable::SizeType getCapacity() const override
Get buffer capacity.
SerializeStatus
forward declaration for string
U8 * getBuffAddr()
Get buffer address for data filling (non-const version)
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
static U32 min(const U32 a, const U32 b)
Definition: Checksum.cpp:16
U32 asBigEndianU32() const
Convert bytes 0 through 3 of the hash data to a big-Endian U32 value.
A container class for holding a hash buffer.
Definition: HashBuffer.hpp:26
~HashBuffer() override
HashBuffer & operator=(const HashBuffer &other)
Implementation of malloc based allocator.
bool operator!=(const HashBuffer &other) const
#define FW_ASSERT(...)
Definition: Assert.hpp:14
bool operator==(const HashBuffer &other) const