2020-09-04 16:03:36 +02:00
|
|
|
#ifndef FSFW_SERIALIZE_SERIALIZEELEMENT_H_
|
|
|
|
#define FSFW_SERIALIZE_SERIALIZEELEMENT_H_
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "SerializeAdapter.h"
|
2020-09-04 16:03:36 +02:00
|
|
|
#include "../container/SinglyLinkedList.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
#include <utility>
|
|
|
|
|
2019-08-28 14:50:24 +02:00
|
|
|
/**
|
2020-09-04 16:03:36 +02:00
|
|
|
* @brief This class is used to mark datatypes for serialization with the
|
|
|
|
* SerialLinkedListAdapter
|
|
|
|
* @details
|
|
|
|
* Used by declaring any arbitrary datatype with SerializeElement<T> myVariable,
|
|
|
|
* inside a SerialLinkedListAdapter implementation and setting the sequence
|
|
|
|
* of objects with setNext() and setStart().
|
|
|
|
* Serialization and Deserialization is then performed automatically in
|
|
|
|
* specified sequence order.
|
|
|
|
* @ingroup serialize
|
2019-08-28 14:50:24 +02:00
|
|
|
*/
|
2016-06-15 23:48:41 +02:00
|
|
|
template<typename T>
|
2020-04-21 21:34:03 +02:00
|
|
|
class SerializeElement: public SerializeIF, public LinkedElement<SerializeIF> {
|
2016-06-15 23:48:41 +02:00
|
|
|
public:
|
2020-04-21 21:34:03 +02:00
|
|
|
template<typename ... Args>
|
|
|
|
SerializeElement(Args ... args) :
|
|
|
|
LinkedElement<SerializeIF>(this), entry(std::forward<Args>(args)...) {
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
}
|
2020-04-21 21:34:03 +02:00
|
|
|
SerializeElement() :
|
|
|
|
LinkedElement<SerializeIF>(this) {
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
2020-09-04 16:03:36 +02:00
|
|
|
|
2020-04-21 21:34:03 +02:00
|
|
|
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
|
|
|
Endianness streamEndianness) const override {
|
|
|
|
return SerializeAdapter::serialize(&entry, buffer, size, maxSize,
|
|
|
|
streamEndianness);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2020-04-21 22:28:43 +02:00
|
|
|
size_t getSerializedSize() const override {
|
2020-04-21 21:34:03 +02:00
|
|
|
return SerializeAdapter::getSerializedSize(&entry);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2020-04-21 21:34:03 +02:00
|
|
|
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
|
|
|
Endianness streamEndianness) override {
|
|
|
|
return SerializeAdapter::deSerialize(&entry, buffer, size,
|
|
|
|
streamEndianness);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
2020-09-04 16:03:36 +02:00
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
operator T() {
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2020-04-21 21:34:03 +02:00
|
|
|
SerializeElement<T>& operator=(T newValue) {
|
2016-06-15 23:48:41 +02:00
|
|
|
entry = newValue;
|
|
|
|
return *this;
|
|
|
|
}
|
2020-09-04 16:03:36 +02:00
|
|
|
|
2020-04-21 21:34:03 +02:00
|
|
|
T* operator->() {
|
2016-06-15 23:48:41 +02:00
|
|
|
return &entry;
|
|
|
|
}
|
2020-09-04 16:03:36 +02:00
|
|
|
|
|
|
|
T entry;
|
2016-06-15 23:48:41 +02:00
|
|
|
};
|
|
|
|
|
2020-09-04 16:03:36 +02:00
|
|
|
#endif /* FSFW_SERIALIZE_SERIALIZEELEMENT_H_ */
|