fsfw/serialize/SerializeElement.h

52 lines
1.2 KiB
C
Raw Normal View History

#ifndef SERIALIZEELEMENT_H_
#define SERIALIZEELEMENT_H_
2020-08-13 20:53:35 +02:00
#include "../container/SinglyLinkedList.h"
#include "SerializeAdapter.h"
#include <utility>
/**
* \ingroup serialize
*/
template<typename T>
class SerializeElement: public SerializeIF, public LinkedElement<SerializeIF> {
public:
template<typename ... Args>
SerializeElement(Args ... args) :
LinkedElement<SerializeIF>(this), entry(std::forward<Args>(args)...) {
}
SerializeElement() :
LinkedElement<SerializeIF>(this) {
}
T entry;
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override {
return SerializeAdapter::serialize(&entry, buffer, size, maxSize,
streamEndianness);
}
size_t getSerializedSize() const override {
return SerializeAdapter::getSerializedSize(&entry);
}
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override {
return SerializeAdapter::deSerialize(&entry, buffer, size,
streamEndianness);
}
operator T() {
return entry;
}
SerializeElement<T>& operator=(T newValue) {
entry = newValue;
return *this;
}
T* operator->() {
return &entry;
}
};
#endif /* SERIALIZEELEMENT_H_ */