2016-06-15 23:48:41 +02:00
|
|
|
/**
|
|
|
|
* @file SerialLinkedListAdapter.h
|
|
|
|
* @brief This file defines the SerialLinkedListAdapter class.
|
|
|
|
* @date 22.07.2014
|
|
|
|
* @author baetz
|
|
|
|
*/
|
|
|
|
#ifndef SERIALLINKEDLISTADAPTER_H_
|
|
|
|
#define SERIALLINKEDLISTADAPTER_H_
|
|
|
|
|
|
|
|
#include <framework/container/SinglyLinkedList.h>
|
|
|
|
#include <framework/serialize/SerializeAdapter.h>
|
|
|
|
#include <framework/serialize/SerializeElement.h>
|
|
|
|
#include <framework/serialize/SerializeIF.h>
|
|
|
|
//This is where we need the SerializeAdapter!
|
2019-08-28 14:50:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \ingroup serialize
|
|
|
|
*/
|
2016-06-15 23:48:41 +02:00
|
|
|
template<typename T, typename count_t = uint8_t>
|
|
|
|
class SerialLinkedListAdapter: public SinglyLinkedList<T>, public SerializeIF {
|
|
|
|
public:
|
|
|
|
SerialLinkedListAdapter(typename LinkedElement<T>::Iterator start,
|
|
|
|
bool printCount = false) :
|
|
|
|
SinglyLinkedList<T>(start), printCount(printCount) {
|
|
|
|
}
|
|
|
|
SerialLinkedListAdapter(LinkedElement<T>* first, bool printCount = false) :
|
|
|
|
SinglyLinkedList<T>(first), printCount(printCount) {
|
|
|
|
|
|
|
|
}
|
|
|
|
SerialLinkedListAdapter(bool printCount = false) :
|
|
|
|
SinglyLinkedList<T>(), printCount(printCount) {
|
|
|
|
}
|
|
|
|
|
2020-04-21 21:34:03 +02:00
|
|
|
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
|
|
|
size_t maxSize, Endianness streamEndianness) const override {
|
2016-06-15 23:48:41 +02:00
|
|
|
if (printCount) {
|
|
|
|
count_t mySize = SinglyLinkedList<T>::getSize();
|
2020-04-21 21:34:03 +02:00
|
|
|
ReturnValue_t result = SerializeAdapter::serialize(&mySize,
|
|
|
|
buffer, size, maxSize, streamEndianness);
|
2016-06-15 23:48:41 +02:00
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2020-04-21 21:34:03 +02:00
|
|
|
return serialize(SinglyLinkedList<T>::start, buffer, size, maxSize,
|
|
|
|
streamEndianness);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ReturnValue_t serialize(const LinkedElement<T>* element,
|
2020-04-21 21:34:03 +02:00
|
|
|
uint8_t** buffer, size_t* size, size_t maxSize,
|
|
|
|
Endianness streamEndianness) {
|
2016-06-15 23:48:41 +02:00
|
|
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
|
|
|
while ((result == HasReturnvaluesIF::RETURN_OK) && (element != NULL)) {
|
2020-04-21 21:34:03 +02:00
|
|
|
result = element->value->serialize(buffer, size, maxSize,
|
|
|
|
streamEndianness);
|
2016-06-15 23:48:41 +02:00
|
|
|
element = element->getNext();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2020-04-21 21:34:03 +02:00
|
|
|
virtual size_t getSerializedSize() const override {
|
2016-06-15 23:48:41 +02:00
|
|
|
if (printCount) {
|
|
|
|
return SerialLinkedListAdapter<T>::getSerializedSize()
|
|
|
|
+ sizeof(count_t);
|
|
|
|
} else {
|
|
|
|
return getSerializedSize(SinglyLinkedList<T>::start);
|
|
|
|
}
|
|
|
|
}
|
2020-04-21 21:34:03 +02:00
|
|
|
static size_t getSerializedSize(const LinkedElement<T> *element) {
|
|
|
|
size_t size = 0;
|
2016-06-15 23:48:41 +02:00
|
|
|
while (element != NULL) {
|
|
|
|
size += element->value->getSerializedSize();
|
|
|
|
element = element->getNext();
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2020-04-21 21:34:03 +02:00
|
|
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
|
|
|
Endianness streamEndianness) override {
|
|
|
|
return deSerialize(SinglyLinkedList<T>::start, buffer, size, streamEndianness);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ReturnValue_t deSerialize(LinkedElement<T>* element,
|
2020-04-21 21:34:03 +02:00
|
|
|
const uint8_t** buffer, size_t* size, Endianness streamEndianness) {
|
2016-06-15 23:48:41 +02:00
|
|
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
|
|
|
while ((result == HasReturnvaluesIF::RETURN_OK) && (element != NULL)) {
|
2020-04-21 21:34:03 +02:00
|
|
|
result = element->value->deSerialize(buffer, size, streamEndianness);
|
2016-06-15 23:48:41 +02:00
|
|
|
element = element->getNext();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool printCount;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* SERIALLINKEDLISTADAPTER_H_ */
|