mirror of
https://github.com/nasa/fprime.git
synced 2025-12-11 13:54:34 -06:00
C++ assignment operators should not return const value to match behavior of primative types
67 lines
1.7 KiB
C++
67 lines
1.7 KiB
C++
#include <Autocoders/Python/test/interface1/UserSerializer.hpp>
|
|
#include <Fw/Types/Assert.hpp>
|
|
#include <cstdio>
|
|
|
|
namespace ANameSpace {
|
|
|
|
UserSerializer::UserSerializer(): Serializable() {
|
|
|
|
}
|
|
|
|
UserSerializer::UserSerializer(const SomeUserStruct& src) : Serializable() {
|
|
this->setVal(src);
|
|
}
|
|
|
|
UserSerializer::UserSerializer(const SomeUserStruct* src) : Serializable() {
|
|
FW_ASSERT(src);
|
|
this->setVal(*src);
|
|
}
|
|
|
|
UserSerializer::UserSerializer(SomeUserStruct val) : Serializable() {
|
|
this->setVal(val);
|
|
}
|
|
|
|
SomeUserStruct& UserSerializer::operator=(const SomeUserStruct& src) {
|
|
this->setVal(src);
|
|
return this->m_struct;
|
|
}
|
|
|
|
void UserSerializer::getVal(SomeUserStruct& arg) {
|
|
arg = this->m_struct;
|
|
}
|
|
|
|
void UserSerializer::setVal(const SomeUserStruct& val) {
|
|
this->m_struct = val;
|
|
}
|
|
|
|
Fw::SerializeStatus UserSerializer::serialize(Fw::SerializeBufferBase& buffer) const {
|
|
return buffer.serialize((U8*)&m_struct,sizeof(m_struct));
|
|
}
|
|
|
|
Fw::SerializeStatus UserSerializer::deserialize(Fw::SerializeBufferBase& buffer) {
|
|
NATIVE_UINT_TYPE serSize = sizeof(m_struct);
|
|
Fw::SerializeStatus stat = buffer.deserialize((U8*)&m_struct,serSize);
|
|
FW_ASSERT(serSize == sizeof(m_struct));
|
|
return stat;
|
|
}
|
|
|
|
|
|
|
|
#if FW_SERIALIZABLE_TO_STRING
|
|
|
|
void UserSerializer::toString(Fw::StringBase& text) const {
|
|
|
|
// declare strings to hold any serializable toString() arguments
|
|
|
|
char outputString[FW_SERIALIZABLE_TO_STRING_BUFFER_SIZE];
|
|
snprintf(outputString,FW_SERIALIZABLE_TO_STRING_BUFFER_SIZE,
|
|
"SomeUserStruct: %d %f %d",
|
|
this->m_struct.mem1,this->m_struct.mem2,this->m_struct.mem3);
|
|
outputString[FW_SERIALIZABLE_TO_STRING_BUFFER_SIZE-1] = 0; // NULL terminate
|
|
|
|
text = outputString;
|
|
}
|
|
|
|
#endif
|
|
}
|