took over serial array list adapter changes

This commit is contained in:
Robin Müller 2020-09-04 16:07:11 +02:00
parent 328c1b7195
commit 1a62158f33

View File

@ -1,13 +1,14 @@
#ifndef FRAMEWORK_SERIALIZE_SERIALARRAYLISTADAPTER_H_ #ifndef FSFW_SERIALIZE_SERIALARRAYLISTADAPTER_H_
#define FRAMEWORK_SERIALIZE_SERIALARRAYLISTADAPTER_H_ #define FSFW_SERIALIZE_SERIALARRAYLISTADAPTER_H_
#include "../container/ArrayList.h"
#include "SerializeIF.h" #include "SerializeIF.h"
#include "../container/ArrayList.h"
#include <utility> #include <utility>
/** /**
* Also serializes length field !
* @author baetz
* @ingroup serialize * @ingroup serialize
* @author baetz
*/ */
template<typename T, typename count_t = uint8_t> template<typename T, typename count_t = uint8_t>
class SerialArrayListAdapter : public SerializeIF { class SerialArrayListAdapter : public SerializeIF {
@ -21,14 +22,14 @@ public:
} }
static ReturnValue_t serialize(const ArrayList<T, count_t>* list, static ReturnValue_t serialize(const ArrayList<T, count_t>* list,
uint8_t** buffer, size_t* size, size_t maxSize, uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) { Endianness streamEndianness) {
ReturnValue_t result = SerializeAdapter::serialize(&list->size, ReturnValue_t result = SerializeAdapter::serialize(&list->size,
buffer, size, maxSize, streamEndianness); buffer, size, maxSize, streamEndianness);
count_t i = 0; count_t i = 0;
while ((result == HasReturnvaluesIF::RETURN_OK) && (i < list->size)) { while ((result == HasReturnvaluesIF::RETURN_OK) && (i < list->size)) {
result = SerializeAdapter::serialize(&list->entries[i], buffer, result = SerializeAdapter::serialize(&list->entries[i], buffer, size,
size, maxSize, streamEndianness); maxSize, streamEndianness);
++i; ++i;
} }
return result; return result;
@ -55,17 +56,18 @@ public:
} }
static ReturnValue_t deSerialize(ArrayList<T, count_t>* list, static ReturnValue_t deSerialize(ArrayList<T, count_t>* list,
const uint8_t** buffer, size_t* size, const uint8_t** buffer, size_t* size,
Endianness streamEndianness) { Endianness streamEndianness) {
count_t tempSize = 0; count_t tempSize = 0;
ReturnValue_t result = SerializeAdapter::deSerialize(&tempSize, ReturnValue_t result = SerializeAdapter::deSerialize(&tempSize,
buffer, size, streamEndianness); buffer, size, streamEndianness);
if(result != HasReturnvaluesIF::RETURN_OK) { if(result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
if (tempSize > list->maxSize()) { if (tempSize > list->maxSize()) {
return SerializeIF::TOO_MANY_ELEMENTS; return SerializeIF::TOO_MANY_ELEMENTS;
} }
list->size = tempSize; list->size = tempSize;
count_t i = 0; count_t i = 0;
while ((result == HasReturnvaluesIF::RETURN_OK) && (i < list->size)) { while ((result == HasReturnvaluesIF::RETURN_OK) && (i < list->size)) {
@ -76,10 +78,9 @@ public:
} }
return result; return result;
} }
private: private:
ArrayList<T, count_t> *adaptee; ArrayList<T, count_t> *adaptee;
}; };
#endif /* FSFW_SERIALIZE_SERIALARRAYLISTADAPTER_H_ */
#endif /* FRAMEWORK_SERIALIZE_SERIALARRAYLISTADAPTER_H_ */