fsfw/serialize/SerialFixedArrayListAdapter.h

52 lines
2.0 KiB
C
Raw Normal View History

#ifndef SERIALFIXEDARRAYLISTADAPTER_H_
#define SERIALFIXEDARRAYLISTADAPTER_H_
#include <framework/container/FixedArrayList.h>
#include <framework/serialize/SerialArrayListAdapter.h>
/**
2019-12-08 22:57:03 +01:00
* @brief This adapter provides an interface for SerializeIF to serialize and deserialize
* buffers with a header containing the buffer length.
* @details
*
2020-01-16 19:07:53 +01:00
* Can be used by SerialLinkedListAdapter by declaring
* as a linked element with SerializeElement<SerialFixedArrayListAdapter<...>>.
2019-11-02 23:30:12 +01:00
* The sequence of objects is defined in the constructor by using the setStart and setNext functions.
*
2020-01-16 19:07:53 +01:00
* 1. Buffers with a size header inside that class can be declared with
* SerialFixedArrayListAdapter<BUFFER_TYPE, MAX_BUFFER_LENGTH, LENGTH_FIELD_TYPE>.
* 2. MAX_BUFFER_LENGTH specifies the maximum allowed number of elements in FixedArrayList
2020-01-16 19:07:53 +01:00
* 3. LENGTH_FIELD_TYPE specifies the data type of the buffer header containing the buffer size
* (defaults to 1 byte length field) that follows
*
2019-12-08 22:57:03 +01:00
* @ingroup serialize
*/
template<typename BUFFER_TYPE, uint32_t MAX_SIZE, typename count_t = uint8_t>
class SerialFixedArrayListAdapter : public FixedArrayList<BUFFER_TYPE, MAX_SIZE, count_t>, public SerializeIF {
public:
template<typename... Args>
SerialFixedArrayListAdapter(Args... args) : FixedArrayList<BUFFER_TYPE, MAX_SIZE, count_t>(std::forward<Args>(args)...) {
}
ReturnValue_t serialize(uint8_t** buffer, uint32_t* size,
const uint32_t max_size, bool bigEndian) const {
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::serialize(this, buffer, size, max_size, bigEndian);
}
uint32_t getSerializedSize() const {
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::getSerializedSize(this);
}
ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,
bool bigEndian) {
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::deSerialize(this, buffer, size, bigEndian);
}
void swapArrayListEndianness() {
SerialArrayListAdapter<BUFFER_TYPE, count_t>::swapArrayListEndianness(this);
}
};
#endif /* SERIALFIXEDARRAYLISTADAPTER_H_ */