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 
11 
14  FW_ASSERT(Fw::FW_SERIALIZE_OK == stat, static_cast<FwAssertArgType>(stat));
15 }
16 
18 
20  Fw::SerializeStatus stat = Fw::SerializeBufferBase::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::SerializeBufferBase::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  (memcmp(this->getBuffAddr(), other.getBuffAddr(), static_cast<size_t>(this->getSize())) != 0)) {
37  return false;
38  }
39  return true;
40 }
41 
42 bool HashBuffer::operator!=(const HashBuffer& other) const {
43  return !(*this == other);
44 }
45 
46 const U8* HashBuffer::getBuffAddr() const {
47  return this->m_bufferData;
48 }
49 
51  return this->m_bufferData;
52 }
53 
55  return sizeof(this->m_bufferData);
56 }
57 
58 FwSizeType HashBuffer::getBuffCapacity() const {
59  return this->getCapacity();
60 }
61 
63  U32 result = 0;
64  const FwSizeType bufferSize = sizeof this->m_bufferData;
65  const FwSizeType numBytes = std::min(bufferSize, static_cast<FwSizeType>(sizeof(U32)));
66  for (FwSizeType i = 0; i < numBytes; i++) {
67  result <<= 8;
68  FW_ASSERT(i < bufferSize, static_cast<FwAssertArgType>(i), static_cast<FwAssertArgType>(bufferSize));
69  result += this->m_bufferData[i];
70  }
71  return result;
72 }
73 } // namespace Utils
Serialization/Deserialization operation was successful.
PlatformSizeType FwSizeType
LinearBufferBase SerializeBufferBase
forward declaration
Serializable::SizeType getSize() const override
Get current buffer size.
SerializeStatus
forward declaration for string
FwSizeType getCapacity() const
Get buffer capacity.
SerializeStatus setBuff(const U8 *src, Serializable::SizeType length) override
Set buffer contents from external source.
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
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 & 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