2016-06-15 23:48:41 +02:00
|
|
|
#ifndef SERIALBUFFERADAPTER_H_
|
|
|
|
#define SERIALBUFFERADAPTER_H_
|
|
|
|
|
|
|
|
#include <framework/serialize/SerializeIF.h>
|
2018-07-12 16:29:32 +02:00
|
|
|
#include <framework/serialize/SerializeAdapter.h>
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2019-08-28 14:50:24 +02:00
|
|
|
/**
|
2019-11-02 23:30:12 +01:00
|
|
|
* This adapter provides an interface for SerializeIF to serialize or deserialize
|
|
|
|
* buffers with no length header but a known size.
|
|
|
|
*
|
|
|
|
* Additionally, the buffer length can be serialized too and will be put in front of the serialized buffer.
|
|
|
|
*
|
|
|
|
* Can be used with SerialLinkedListAdapter by declaring a SerializeElement with
|
|
|
|
* SerialElement<SerialBufferAdapter<T(will be uint8_t mostly)>> serialBufferElement
|
|
|
|
*
|
2019-08-28 14:50:24 +02:00
|
|
|
* \ingroup serialize
|
|
|
|
*/
|
2018-07-12 16:29:32 +02:00
|
|
|
template<typename T>
|
2016-06-15 23:48:41 +02:00
|
|
|
class SerialBufferAdapter: public SerializeIF {
|
|
|
|
public:
|
2018-07-12 16:29:32 +02:00
|
|
|
SerialBufferAdapter(const uint8_t * buffer, T bufferLength, bool serializeLenght = false);
|
|
|
|
SerialBufferAdapter(uint8_t* buffer, T bufferLength,
|
|
|
|
bool serializeLenght = false);
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
virtual ~SerialBufferAdapter();
|
|
|
|
|
|
|
|
virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size,
|
|
|
|
const uint32_t max_size, bool bigEndian) const;
|
|
|
|
|
|
|
|
virtual uint32_t getSerializedSize() const;
|
|
|
|
|
|
|
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,
|
|
|
|
bool bigEndian);
|
|
|
|
private:
|
2018-07-12 16:29:32 +02:00
|
|
|
bool serializeLength;
|
2016-06-15 23:48:41 +02:00
|
|
|
const uint8_t *constBuffer;
|
|
|
|
uint8_t *buffer;
|
2018-07-12 16:29:32 +02:00
|
|
|
T bufferLength;
|
2016-06-15 23:48:41 +02:00
|
|
|
};
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
|
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
#endif /* SERIALBUFFERADAPTER_H_ */
|