F´ Flight Software - C/C++ Documentation  devel
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 
12 HashBuffer::HashBuffer(const U8* args, NATIVE_UINT_TYPE size) : Fw::SerializeBufferBase() {
14  FW_ASSERT(Fw::FW_SERIALIZE_OK == stat, static_cast<NATIVE_INT_TYPE>(stat));
15 }
16 
18 
19 HashBuffer::HashBuffer(const HashBuffer& other) : Fw::SerializeBufferBase() {
20  Fw::SerializeStatus stat = Fw::SerializeBufferBase::setBuff(other.m_bufferData, other.getBuffLength());
21  FW_ASSERT(Fw::FW_SERIALIZE_OK == stat, static_cast<NATIVE_INT_TYPE>(stat));
22 }
23 
25  if (this == &other) {
26  return *this;
27  }
28 
29  Fw::SerializeStatus stat = Fw::SerializeBufferBase::setBuff(other.m_bufferData, other.getBuffLength());
30  FW_ASSERT(Fw::FW_SERIALIZE_OK == stat, static_cast<NATIVE_INT_TYPE>(stat));
31  return *this;
32 }
33 
34 bool HashBuffer::operator==(const HashBuffer& other) const {
35  if ((this->getBuffLength() == other.getBuffLength()) &&
36  (memcmp(this->getBuffAddr(), other.getBuffAddr(), this->getBuffLength()) != 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 
59  U32 result = 0;
60  const FwSizeType bufferSize = sizeof this->m_bufferData;
61  const FwSizeType numBytes = std::min(bufferSize, static_cast<FwSizeType>(sizeof(U32)));
62  for (FwSizeType i = 0; i < numBytes; i++) {
63  result <<= 8;
64  FW_ASSERT(i < bufferSize, static_cast<FwAssertArgType>(i), static_cast<FwAssertArgType>(bufferSize));
65  result += this->m_bufferData[i];
66  }
67  return result;
68 }
69 } // namespace Utils
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:55
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:30
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:56
static U32 min(const U32 a, const U32 b)
Definition: Checksum.cpp:16
PlatformAssertArgType FwAssertArgType
Definition: FpConfig.h:39
PlatformSizeType FwSizeType
Definition: FpConfig.h:35
Serializable::SizeType getBuffLength() const
returns current buffer size
SerializeStatus setBuff(const U8 *src, Serializable::SizeType length)
sets buffer contents and size
A container class for holding a hash buffer.
Definition: HashBuffer.hpp:26
HashBuffer & operator=(const HashBuffer &other)
NATIVE_UINT_TYPE getBuffCapacity() const
U32 asBigEndianU32() const
Convert bytes 0 through 3 of the hash data to a big-Endian U32 value.
bool operator==(const HashBuffer &other) const
bool operator!=(const HashBuffer &other) const
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.