2016-06-15 23:48:41 +02:00
|
|
|
#ifndef SERIALIZEELEMENT_H_
|
|
|
|
#define SERIALIZEELEMENT_H_
|
|
|
|
|
|
|
|
#include <framework/container/SinglyLinkedList.h>
|
|
|
|
#include <framework/serialize/SerializeAdapter.h>
|
|
|
|
#include <utility>
|
|
|
|
|
2019-08-28 14:50:24 +02:00
|
|
|
/**
|
2019-12-08 22:57:03 +01: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().
|
|
|
|
* Serilization 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>
|
|
|
|
class SerializeElement : public SerializeIF, public LinkedElement<SerializeIF> {
|
|
|
|
public:
|
2020-01-22 14:24:48 +01:00
|
|
|
/**
|
|
|
|
* Arguments are forwarded to the element datatype constructor
|
|
|
|
* @param args
|
|
|
|
*/
|
2016-06-15 23:48:41 +02:00
|
|
|
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, uint32_t* size,
|
|
|
|
const uint32_t max_size, bool bigEndian) const {
|
|
|
|
return SerializeAdapter<T>::serialize(&entry, buffer, size, max_size, bigEndian);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t getSerializedSize() const {
|
|
|
|
return SerializeAdapter<T>::getSerializedSize(&entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,
|
|
|
|
bool bigEndian) {
|
|
|
|
return SerializeAdapter<T>::deSerialize(&entry, buffer, size, bigEndian);
|
|
|
|
}
|
|
|
|
operator T() {
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
SerializeElement<T> &operator=(T newValue) {
|
|
|
|
entry = newValue;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
T *operator->() {
|
|
|
|
return &entry;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* SERIALIZEELEMENT_H_ */
|