fsfw/serialize/SerialArrayListAdapter.h
Robin Mueller d99ed47150 fixed map bugfix (fist instead of first), new access functions for fixed maP
(first(), second()), some documentation, raw pool access read() call public
because call is necessary before using public serialize function.
maybe integrate read() call into serialize function?
2019-12-08 19:04:53 +01:00

87 lines
2.4 KiB
C++

/**
* @file SerialArrayListAdapter.h
* @brief This file defines the SerialArrayListAdapter class.
* @date 22.07.2014
* @author baetz
*/
#ifndef SERIALARRAYLISTADAPTER_H_
#define SERIALARRAYLISTADAPTER_H_
#include <framework/container/ArrayList.h>
#include <framework/serialize/SerializeIF.h>
#include <utility>
/**
* \ingroup serialize
*/
template<typename T, typename count_t = uint8_t>
class SerialArrayListAdapter : public SerializeIF {
public:
SerialArrayListAdapter(ArrayList<T, count_t> *adaptee) : adaptee(adaptee) {
}
virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size,
const uint32_t max_size, bool bigEndian) const {
return serialize(adaptee, buffer, size, max_size, bigEndian);
}
static ReturnValue_t serialize(const ArrayList<T, count_t>* list, uint8_t** buffer, uint32_t* size,
const uint32_t max_size, bool bigEndian) {
// Serialize length field first
ReturnValue_t result = SerializeAdapter<count_t>::serialize(&list->size,
buffer, size, max_size, bigEndian);
count_t i = 0;
while ((result == HasReturnvaluesIF::RETURN_OK) && (i < list->size)) {
result = SerializeAdapter<T>::serialize(&list->entries[i], buffer, size,
max_size, bigEndian);
++i;
}
return result;
}
virtual uint32_t getSerializedSize() const {
return getSerializedSize(adaptee);
}
static uint32_t getSerializedSize(const ArrayList<T, count_t>* list) {
uint32_t printSize = sizeof(count_t);
count_t i = 0;
for (i = 0; i < list->size; ++i) {
printSize += SerializeAdapter<T>::getSerializedSize(&list->entries[i]);
}
return printSize;
}
virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,
bool bigEndian) {
return deSerialize(adaptee, buffer, size, bigEndian);
}
static ReturnValue_t deSerialize(ArrayList<T, count_t>* list, const uint8_t** buffer, int32_t* size,
bool bigEndian) {
count_t tempSize = 0;
ReturnValue_t result = SerializeAdapter<count_t>::deSerialize(&tempSize,
buffer, size, bigEndian);
if (tempSize > list->maxSize()) {
return SerializeIF::TOO_MANY_ELEMENTS;
}
list->size = tempSize;
count_t i = 0;
while ((result == HasReturnvaluesIF::RETURN_OK) && (i < list->size)) {
result = SerializeAdapter<T>::deSerialize(
&list->front()[i], buffer, size,
bigEndian);
++i;
}
return result;
}
private:
ArrayList<T, count_t> *adaptee;
};
#endif /* SERIALARRAYLISTADAPTER_H_ */