2016-06-15 23:48:41 +02:00
|
|
|
#ifndef SERIALFIXEDARRAYLISTADAPTER_H_
|
|
|
|
#define SERIALFIXEDARRAYLISTADAPTER_H_
|
|
|
|
|
|
|
|
#include <framework/container/FixedArrayList.h>
|
|
|
|
#include <framework/serialize/SerialArrayListAdapter.h>
|
|
|
|
|
2019-08-28 14:50:24 +02:00
|
|
|
/**
|
2020-04-15 20:53:03 +02:00
|
|
|
* @brief This adapter provides an interface for SerializeIF to serialize and
|
|
|
|
* deserialize buffers with a header containing the buffer length.
|
2019-12-08 22:57:03 +01:00
|
|
|
* @details
|
2020-01-16 19:07:53 +01:00
|
|
|
* Can be used by SerialLinkedListAdapter by declaring
|
|
|
|
* as a linked element with SerializeElement<SerialFixedArrayListAdapter<...>>.
|
2020-04-15 20:53:03 +02:00
|
|
|
* The sequence of objects is defined in the constructor by
|
|
|
|
* using the setStart and setNext functions.
|
2019-11-02 23:30:12 +01:00
|
|
|
*
|
2020-04-18 17:12:26 +02:00
|
|
|
* - Buffers with a size header inside that class can be declared with
|
|
|
|
* @code
|
|
|
|
* SerialFixedArrayListAdapter<BUFFER_TYPE,
|
|
|
|
* MAX_SIZE, count_t> mySerialFixedArrayList(...).
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* - MAX_SIZE: specifies the maximum allowed number of elements
|
|
|
|
* in FixedArrayList.
|
|
|
|
* - BUFFER_TYPE: specifies the data type of the buffer
|
|
|
|
* - count_t: specifies the type/size of the length field
|
|
|
|
* which defaults to one byte.
|
2020-01-16 19:07:53 +01:00
|
|
|
*
|
2019-12-08 22:57:03 +01:00
|
|
|
* @ingroup serialize
|
2019-08-28 14:50:24 +02:00
|
|
|
*/
|
2020-01-15 17:30:23 +01:00
|
|
|
template<typename BUFFER_TYPE, uint32_t MAX_SIZE, typename count_t = uint8_t>
|
2020-04-15 15:53:46 +02:00
|
|
|
class SerialFixedArrayListAdapter :
|
|
|
|
public FixedArrayList<BUFFER_TYPE, MAX_SIZE, count_t>,
|
|
|
|
public SerializeIF {
|
2016-06-15 23:48:41 +02:00
|
|
|
public:
|
2020-01-22 14:24:48 +01:00
|
|
|
/**
|
2020-04-15 20:53:03 +02:00
|
|
|
* Constructor Arguments are forwarded to FixedArrayList constructor.
|
|
|
|
* Refer to the fixed array list constructors for different options.
|
2020-01-22 14:24:48 +01:00
|
|
|
* @param args
|
|
|
|
*/
|
2016-06-15 23:48:41 +02:00
|
|
|
template<typename... Args>
|
2020-04-15 15:53:46 +02:00
|
|
|
SerialFixedArrayListAdapter(Args... args) :
|
|
|
|
FixedArrayList<BUFFER_TYPE, MAX_SIZE, count_t>(std::forward<Args>(args)...)
|
|
|
|
{}
|
2019-12-08 19:04:53 +01:00
|
|
|
|
2020-04-15 20:53:03 +02:00
|
|
|
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
|
|
|
const size_t max_size, bool bigEndian) const override {
|
2020-04-15 15:53:46 +02:00
|
|
|
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::serialize(this,
|
|
|
|
buffer, size, max_size, bigEndian);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
2019-12-08 19:04:53 +01:00
|
|
|
|
2020-04-05 21:54:11 +02:00
|
|
|
size_t getSerializedSize() const {
|
2020-04-15 15:53:46 +02:00
|
|
|
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::
|
|
|
|
getSerializedSize(this);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
2020-04-15 20:53:03 +02:00
|
|
|
|
|
|
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
|
|
|
bool bigEndian) override {
|
2020-04-05 22:42:48 +02:00
|
|
|
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::deSerialize(this,
|
|
|
|
buffer, size, bigEndian);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
2020-01-18 18:01:37 +01:00
|
|
|
|
|
|
|
void swapArrayListEndianness() {
|
2020-04-15 15:53:46 +02:00
|
|
|
SerialArrayListAdapter<BUFFER_TYPE, count_t>::
|
|
|
|
swapArrayListEndianness(this);
|
2020-01-18 18:01:37 +01:00
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* SERIALFIXEDARRAYLISTADAPTER_H_ */
|