reapply clang format
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
#ifndef FSFW_SERIALIZE_ENDIANCONVERTER_H_
|
||||
#define FSFW_SERIALIZE_ENDIANCONVERTER_H_
|
||||
|
||||
#include "../osal/Endiness.h"
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
#include "../osal/Endiness.h"
|
||||
|
||||
/**
|
||||
* Helper class to convert variables or bitstreams between machine
|
||||
@ -34,91 +35,90 @@
|
||||
* Thus, there is only one function supplied to do the conversion.
|
||||
*/
|
||||
class EndianConverter {
|
||||
private:
|
||||
EndianConverter() {};
|
||||
public:
|
||||
/**
|
||||
* Convert a typed variable between big endian and machine endian.
|
||||
* Intended for plain old datatypes.
|
||||
*/
|
||||
template<typename T>
|
||||
static T convertBigEndian(T in) {
|
||||
private:
|
||||
EndianConverter(){};
|
||||
|
||||
public:
|
||||
/**
|
||||
* Convert a typed variable between big endian and machine endian.
|
||||
* Intended for plain old datatypes.
|
||||
*/
|
||||
template <typename T>
|
||||
static T convertBigEndian(T in) {
|
||||
#ifndef BYTE_ORDER_SYSTEM
|
||||
#error BYTE_ORDER_SYSTEM not defined
|
||||
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
|
||||
T tmp;
|
||||
uint8_t *pointerOut = (uint8_t*) &tmp;
|
||||
uint8_t *pointerIn = (uint8_t*) ∈
|
||||
for (size_t count = 0; count < sizeof(T); count++) {
|
||||
pointerOut[sizeof(T) - count - 1] = pointerIn[count];
|
||||
}
|
||||
return tmp;
|
||||
T tmp;
|
||||
uint8_t *pointerOut = (uint8_t *)&tmp;
|
||||
uint8_t *pointerIn = (uint8_t *)∈
|
||||
for (size_t count = 0; count < sizeof(T); count++) {
|
||||
pointerOut[sizeof(T) - count - 1] = pointerIn[count];
|
||||
}
|
||||
return tmp;
|
||||
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
|
||||
return in;
|
||||
return in;
|
||||
#else
|
||||
#error Unknown Byte Order
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a bytestream representing a single variable between big endian
|
||||
* and machine endian.
|
||||
*/
|
||||
static void convertBigEndian(uint8_t *out, const uint8_t *in,
|
||||
size_t size) {
|
||||
/**
|
||||
* convert a bytestream representing a single variable between big endian
|
||||
* and machine endian.
|
||||
*/
|
||||
static void convertBigEndian(uint8_t *out, const uint8_t *in, size_t size) {
|
||||
#ifndef BYTE_ORDER_SYSTEM
|
||||
#error BYTE_ORDER_SYSTEM not defined
|
||||
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
|
||||
for (size_t count = 0; count < size; count++) {
|
||||
out[size - count - 1] = in[count];
|
||||
}
|
||||
return;
|
||||
for (size_t count = 0; count < size; count++) {
|
||||
out[size - count - 1] = in[count];
|
||||
}
|
||||
return;
|
||||
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
|
||||
memcpy(out, in, size);
|
||||
return;
|
||||
memcpy(out, in, size);
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a typed variable between little endian and machine endian.
|
||||
* Intended for plain old datatypes.
|
||||
*/
|
||||
template<typename T>
|
||||
static T convertLittleEndian(T in) {
|
||||
/**
|
||||
* Convert a typed variable between little endian and machine endian.
|
||||
* Intended for plain old datatypes.
|
||||
*/
|
||||
template <typename T>
|
||||
static T convertLittleEndian(T in) {
|
||||
#ifndef BYTE_ORDER_SYSTEM
|
||||
#error BYTE_ORDER_SYSTEM not defined
|
||||
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
|
||||
T tmp;
|
||||
uint8_t *pointerOut = (uint8_t *) &tmp;
|
||||
uint8_t *pointerIn = (uint8_t *) ∈
|
||||
for (size_t count = 0; count < sizeof(T); count++) {
|
||||
pointerOut[sizeof(T) - count - 1] = pointerIn[count];
|
||||
}
|
||||
return tmp;
|
||||
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
|
||||
return in;
|
||||
#error BYTE_ORDER_SYSTEM not defined
|
||||
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
|
||||
T tmp;
|
||||
uint8_t *pointerOut = (uint8_t *)&tmp;
|
||||
uint8_t *pointerIn = (uint8_t *)∈
|
||||
for (size_t count = 0; count < sizeof(T); count++) {
|
||||
pointerOut[sizeof(T) - count - 1] = pointerIn[count];
|
||||
}
|
||||
return tmp;
|
||||
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
|
||||
return in;
|
||||
#else
|
||||
#error Unknown Byte Order
|
||||
#endif
|
||||
}
|
||||
/**
|
||||
* convert a bytestream representing a single variable between little endian
|
||||
* and machine endian.
|
||||
*/
|
||||
static void convertLittleEndian(uint8_t *out, const uint8_t *in,
|
||||
size_t size) {
|
||||
#ifndef BYTE_ORDER_SYSTEM
|
||||
#error BYTE_ORDER_SYSTEM not defined
|
||||
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
|
||||
for (size_t count = 0; count < size; count++) {
|
||||
out[size - count - 1] = in[count];
|
||||
}
|
||||
return;
|
||||
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
|
||||
memcpy(out, in, size);
|
||||
return;
|
||||
#error Unknown Byte Order
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/**
|
||||
* convert a bytestream representing a single variable between little endian
|
||||
* and machine endian.
|
||||
*/
|
||||
static void convertLittleEndian(uint8_t *out, const uint8_t *in, size_t size) {
|
||||
#ifndef BYTE_ORDER_SYSTEM
|
||||
#error BYTE_ORDER_SYSTEM not defined
|
||||
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
|
||||
for (size_t count = 0; count < size; count++) {
|
||||
out[size - count - 1] = in[count];
|
||||
}
|
||||
return;
|
||||
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
|
||||
memcpy(out, in, size);
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* FSFW_SERIALIZE_ENDIANCONVERTER_H_ */
|
||||
|
@ -1,86 +1,79 @@
|
||||
#ifndef FSFW_SERIALIZE_SERIALARRAYLISTADAPTER_H_
|
||||
#define FSFW_SERIALIZE_SERIALARRAYLISTADAPTER_H_
|
||||
|
||||
#include "SerializeIF.h"
|
||||
#include "../container/ArrayList.h"
|
||||
#include <utility>
|
||||
|
||||
#include "../container/ArrayList.h"
|
||||
#include "SerializeIF.h"
|
||||
|
||||
/**
|
||||
* Also serializes length field !
|
||||
* @author baetz
|
||||
* @ingroup serialize
|
||||
*/
|
||||
template<typename T, typename count_t = uint8_t>
|
||||
template <typename T, typename count_t = uint8_t>
|
||||
class SerialArrayListAdapter : public SerializeIF {
|
||||
public:
|
||||
SerialArrayListAdapter(ArrayList<T, count_t> *adaptee) : adaptee(adaptee) {
|
||||
}
|
||||
public:
|
||||
SerialArrayListAdapter(ArrayList<T, count_t>* adaptee) : adaptee(adaptee) {}
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
return serialize(adaptee, buffer, size, maxSize, streamEndianness);
|
||||
}
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
|
||||
Endianness streamEndianness) const {
|
||||
return serialize(adaptee, buffer, size, maxSize, streamEndianness);
|
||||
}
|
||||
|
||||
static ReturnValue_t serialize(const ArrayList<T, count_t>* list,
|
||||
uint8_t** buffer, size_t* size, size_t maxSize,
|
||||
Endianness streamEndianness) {
|
||||
ReturnValue_t result = SerializeAdapter::serialize(&list->size,
|
||||
buffer, size, maxSize, streamEndianness);
|
||||
count_t i = 0;
|
||||
while ((result == HasReturnvaluesIF::RETURN_OK) && (i < list->size)) {
|
||||
result = SerializeAdapter::serialize(&list->entries[i], buffer, size,
|
||||
maxSize, streamEndianness);
|
||||
++i;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
static ReturnValue_t serialize(const ArrayList<T, count_t>* list, uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) {
|
||||
ReturnValue_t result =
|
||||
SerializeAdapter::serialize(&list->size, buffer, size, maxSize, streamEndianness);
|
||||
count_t i = 0;
|
||||
while ((result == HasReturnvaluesIF::RETURN_OK) && (i < list->size)) {
|
||||
result =
|
||||
SerializeAdapter::serialize(&list->entries[i], buffer, size, maxSize, streamEndianness);
|
||||
++i;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual size_t getSerializedSize() const {
|
||||
return getSerializedSize(adaptee);
|
||||
}
|
||||
virtual size_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;
|
||||
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::getSerializedSize(&list->entries[i]);
|
||||
}
|
||||
for (i = 0; i < list->size; ++i) {
|
||||
printSize += SerializeAdapter::getSerializedSize(&list->entries[i]);
|
||||
}
|
||||
|
||||
return printSize;
|
||||
}
|
||||
return printSize;
|
||||
}
|
||||
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) {
|
||||
return deSerialize(adaptee, buffer, size, streamEndianness);
|
||||
}
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) {
|
||||
return deSerialize(adaptee, buffer, size, streamEndianness);
|
||||
}
|
||||
|
||||
static ReturnValue_t deSerialize(ArrayList<T, count_t>* list,
|
||||
const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) {
|
||||
count_t tempSize = 0;
|
||||
ReturnValue_t result = SerializeAdapter::deSerialize(&tempSize,
|
||||
buffer, size, streamEndianness);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
if (tempSize > list->maxSize()) {
|
||||
return SerializeIF::TOO_MANY_ELEMENTS;
|
||||
}
|
||||
static ReturnValue_t deSerialize(ArrayList<T, count_t>* list, const uint8_t** buffer,
|
||||
size_t* size, Endianness streamEndianness) {
|
||||
count_t tempSize = 0;
|
||||
ReturnValue_t result = SerializeAdapter::deSerialize(&tempSize, buffer, size, streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
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::deSerialize(
|
||||
&list->front()[i], buffer, size,
|
||||
streamEndianness);
|
||||
++i;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
list->size = tempSize;
|
||||
count_t i = 0;
|
||||
while ((result == HasReturnvaluesIF::RETURN_OK) && (i < list->size)) {
|
||||
result = SerializeAdapter::deSerialize(&list->front()[i], buffer, size, streamEndianness);
|
||||
++i;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
ArrayList<T, count_t> *adaptee;
|
||||
private:
|
||||
ArrayList<T, count_t>* adaptee;
|
||||
};
|
||||
|
||||
#endif /* FSFW_SERIALIZE_SERIALARRAYLISTADAPTER_H_ */
|
||||
|
@ -1,133 +1,132 @@
|
||||
#include "fsfw/serialize/SerialBufferAdapter.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
template<typename count_t>
|
||||
SerialBufferAdapter<count_t>::SerialBufferAdapter(const uint8_t* buffer,
|
||||
count_t bufferLength, bool serializeLength) :
|
||||
serializeLength(serializeLength),
|
||||
constBuffer(buffer), buffer(nullptr),
|
||||
bufferLength(bufferLength) {}
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
|
||||
template<typename count_t>
|
||||
SerialBufferAdapter<count_t>::SerialBufferAdapter(uint8_t* buffer,
|
||||
count_t bufferLength, bool serializeLength) :
|
||||
serializeLength(serializeLength), constBuffer(buffer), buffer(buffer),
|
||||
bufferLength(bufferLength) {}
|
||||
template <typename count_t>
|
||||
SerialBufferAdapter<count_t>::SerialBufferAdapter(const uint8_t* buffer, count_t bufferLength,
|
||||
bool serializeLength)
|
||||
: serializeLength(serializeLength),
|
||||
constBuffer(buffer),
|
||||
buffer(nullptr),
|
||||
bufferLength(bufferLength) {}
|
||||
|
||||
template <typename count_t>
|
||||
SerialBufferAdapter<count_t>::SerialBufferAdapter(uint8_t* buffer, count_t bufferLength,
|
||||
bool serializeLength)
|
||||
: serializeLength(serializeLength),
|
||||
constBuffer(buffer),
|
||||
buffer(buffer),
|
||||
bufferLength(bufferLength) {}
|
||||
|
||||
template<typename count_t>
|
||||
SerialBufferAdapter<count_t>::~SerialBufferAdapter() {
|
||||
template <typename count_t>
|
||||
SerialBufferAdapter<count_t>::~SerialBufferAdapter() {}
|
||||
|
||||
template <typename count_t>
|
||||
ReturnValue_t SerialBufferAdapter<count_t>::serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize,
|
||||
Endianness streamEndianness) const {
|
||||
if (serializeLength) {
|
||||
ReturnValue_t result =
|
||||
SerializeAdapter::serialize(&bufferLength, buffer, size, maxSize, streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (*size + bufferLength > maxSize) {
|
||||
return BUFFER_TOO_SHORT;
|
||||
}
|
||||
|
||||
if (this->constBuffer != nullptr) {
|
||||
std::memcpy(*buffer, this->constBuffer, bufferLength);
|
||||
} else if (this->buffer != nullptr) {
|
||||
// This will propably be never reached, constBuffer should always be
|
||||
// set if non-const buffer is set.
|
||||
std::memcpy(*buffer, this->buffer, bufferLength);
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
*size += bufferLength;
|
||||
(*buffer) += bufferLength;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
template<typename count_t>
|
||||
ReturnValue_t SerialBufferAdapter<count_t>::serialize(uint8_t** buffer,
|
||||
size_t* size, size_t maxSize, Endianness streamEndianness) const {
|
||||
if (serializeLength) {
|
||||
ReturnValue_t result = SerializeAdapter::serialize(&bufferLength,
|
||||
buffer, size, maxSize, streamEndianness);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (*size + bufferLength > maxSize) {
|
||||
return BUFFER_TOO_SHORT;
|
||||
}
|
||||
|
||||
if (this->constBuffer != nullptr) {
|
||||
std::memcpy(*buffer, this->constBuffer, bufferLength);
|
||||
}
|
||||
else if (this->buffer != nullptr) {
|
||||
// This will propably be never reached, constBuffer should always be
|
||||
// set if non-const buffer is set.
|
||||
std::memcpy(*buffer, this->buffer, bufferLength);
|
||||
}
|
||||
else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
*size += bufferLength;
|
||||
(*buffer) += bufferLength;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
|
||||
}
|
||||
|
||||
template<typename count_t>
|
||||
template <typename count_t>
|
||||
size_t SerialBufferAdapter<count_t>::getSerializedSize() const {
|
||||
if (serializeLength) {
|
||||
return bufferLength + SerializeAdapter::getSerializedSize(&bufferLength);
|
||||
} else {
|
||||
return bufferLength;
|
||||
}
|
||||
if (serializeLength) {
|
||||
return bufferLength + SerializeAdapter::getSerializedSize(&bufferLength);
|
||||
} else {
|
||||
return bufferLength;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename count_t>
|
||||
ReturnValue_t SerialBufferAdapter<count_t>::deSerialize(const uint8_t** buffer,
|
||||
size_t* size, Endianness streamEndianness) {
|
||||
if (this->buffer == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
template <typename count_t>
|
||||
ReturnValue_t SerialBufferAdapter<count_t>::deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) {
|
||||
if (this->buffer == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
if(serializeLength){
|
||||
count_t lengthField = 0;
|
||||
ReturnValue_t result = SerializeAdapter::deSerialize(&lengthField,
|
||||
buffer, size, streamEndianness);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
if(lengthField > bufferLength) {
|
||||
return TOO_MANY_ELEMENTS;
|
||||
}
|
||||
bufferLength = lengthField;
|
||||
}
|
||||
if (serializeLength) {
|
||||
count_t lengthField = 0;
|
||||
ReturnValue_t result =
|
||||
SerializeAdapter::deSerialize(&lengthField, buffer, size, streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
if (lengthField > bufferLength) {
|
||||
return TOO_MANY_ELEMENTS;
|
||||
}
|
||||
bufferLength = lengthField;
|
||||
}
|
||||
|
||||
if (bufferLength <= *size) {
|
||||
*size -= bufferLength;
|
||||
std::memcpy(this->buffer, *buffer, bufferLength);
|
||||
(*buffer) += bufferLength;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return STREAM_TOO_SHORT;
|
||||
}
|
||||
if (bufferLength <= *size) {
|
||||
*size -= bufferLength;
|
||||
std::memcpy(this->buffer, *buffer, bufferLength);
|
||||
(*buffer) += bufferLength;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return STREAM_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename count_t>
|
||||
uint8_t * SerialBufferAdapter<count_t>::getBuffer() {
|
||||
if(buffer == nullptr) {
|
||||
template <typename count_t>
|
||||
uint8_t* SerialBufferAdapter<count_t>::getBuffer() {
|
||||
if (buffer == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "Wrong access function for stored type !"
|
||||
" Use getConstBuffer()." << std::endl;
|
||||
sif::error << "Wrong access function for stored type !"
|
||||
" Use getConstBuffer()."
|
||||
<< std::endl;
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
return buffer;
|
||||
return nullptr;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
template<typename count_t>
|
||||
const uint8_t * SerialBufferAdapter<count_t>::getConstBuffer() const {
|
||||
if(constBuffer == nullptr) {
|
||||
template <typename count_t>
|
||||
const uint8_t* SerialBufferAdapter<count_t>::getConstBuffer() const {
|
||||
if (constBuffer == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "SerialBufferAdapter::getConstBuffer:"
|
||||
" Buffers are unitialized!" << std::endl;
|
||||
sif::error << "SerialBufferAdapter::getConstBuffer:"
|
||||
" Buffers are unitialized!"
|
||||
<< std::endl;
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
return constBuffer;
|
||||
return nullptr;
|
||||
}
|
||||
return constBuffer;
|
||||
}
|
||||
|
||||
template<typename count_t>
|
||||
void SerialBufferAdapter<count_t>::setBuffer(uint8_t* buffer,
|
||||
count_t bufferLength) {
|
||||
this->buffer = buffer;
|
||||
this->constBuffer = buffer;
|
||||
this->bufferLength = bufferLength;
|
||||
template <typename count_t>
|
||||
void SerialBufferAdapter<count_t>::setBuffer(uint8_t* buffer, count_t bufferLength) {
|
||||
this->buffer = buffer;
|
||||
this->constBuffer = buffer;
|
||||
this->bufferLength = bufferLength;
|
||||
}
|
||||
|
||||
|
||||
//forward Template declaration for linker
|
||||
// forward Template declaration for linker
|
||||
template class SerialBufferAdapter<uint8_t>;
|
||||
template class SerialBufferAdapter<uint16_t>;
|
||||
template class SerialBufferAdapter<uint32_t>;
|
||||
template class SerialBufferAdapter<uint64_t>;
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
#ifndef SERIALBUFFERADAPTER_H_
|
||||
#define SERIALBUFFERADAPTER_H_
|
||||
|
||||
#include "fsfw/serialize/SerializeIF.h"
|
||||
#include "fsfw/serialize/SerializeAdapter.h"
|
||||
#include "fsfw/serialize/SerializeIF.h"
|
||||
|
||||
/**
|
||||
* This adapter provides an interface for SerializeIF to serialize or deserialize
|
||||
@ -18,61 +18,59 @@
|
||||
*
|
||||
* \ingroup serialize
|
||||
*/
|
||||
template<typename count_t>
|
||||
class SerialBufferAdapter: public SerializeIF {
|
||||
public:
|
||||
template <typename count_t>
|
||||
class SerialBufferAdapter : public SerializeIF {
|
||||
public:
|
||||
/**
|
||||
* Constructor for constant uint8_t buffer. Length field can be serialized optionally.
|
||||
* Type of length can be supplied as template type.
|
||||
* @param buffer
|
||||
* @param bufferLength
|
||||
* @param serializeLength
|
||||
*/
|
||||
SerialBufferAdapter(const uint8_t* buffer, count_t bufferLength, bool serializeLength = false);
|
||||
|
||||
/**
|
||||
* Constructor for constant uint8_t buffer. Length field can be serialized optionally.
|
||||
* Type of length can be supplied as template type.
|
||||
* @param buffer
|
||||
* @param bufferLength
|
||||
* @param serializeLength
|
||||
*/
|
||||
SerialBufferAdapter(const uint8_t* buffer, count_t bufferLength,
|
||||
bool serializeLength = false);
|
||||
/**
|
||||
* Constructor for non-constant uint8_t buffer.
|
||||
* Length field can be serialized optionally.
|
||||
* Type of length can be supplied as template type.
|
||||
* @param buffer
|
||||
* @param bufferLength
|
||||
* @param serializeLength Length field will be serialized with size count_t
|
||||
*/
|
||||
SerialBufferAdapter(uint8_t* buffer, count_t bufferLength, bool serializeLength = false);
|
||||
|
||||
/**
|
||||
* Constructor for non-constant uint8_t buffer.
|
||||
* Length field can be serialized optionally.
|
||||
* Type of length can be supplied as template type.
|
||||
* @param buffer
|
||||
* @param bufferLength
|
||||
* @param serializeLength Length field will be serialized with size count_t
|
||||
*/
|
||||
SerialBufferAdapter(uint8_t* buffer, count_t bufferLength,
|
||||
bool serializeLength = false);
|
||||
virtual ~SerialBufferAdapter();
|
||||
|
||||
virtual ~SerialBufferAdapter();
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
|
||||
Endianness streamEndianness) const override;
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const override;
|
||||
virtual size_t getSerializedSize() const override;
|
||||
|
||||
virtual size_t getSerializedSize() const override;
|
||||
/**
|
||||
* @brief This function deserializes a buffer into the member buffer.
|
||||
* @details
|
||||
* If a length field is present, it is ignored, as the size should have
|
||||
* been set in the constructor. If the size is not known beforehand,
|
||||
* consider using SerialFixedArrayListAdapter instead.
|
||||
* @param buffer [out] Resulting buffer
|
||||
* @param size remaining size to deserialize, should be larger than buffer
|
||||
* + size field size
|
||||
* @param bigEndian
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) override;
|
||||
|
||||
/**
|
||||
* @brief This function deserializes a buffer into the member buffer.
|
||||
* @details
|
||||
* If a length field is present, it is ignored, as the size should have
|
||||
* been set in the constructor. If the size is not known beforehand,
|
||||
* consider using SerialFixedArrayListAdapter instead.
|
||||
* @param buffer [out] Resulting buffer
|
||||
* @param size remaining size to deserialize, should be larger than buffer
|
||||
* + size field size
|
||||
* @param bigEndian
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) override;
|
||||
uint8_t* getBuffer();
|
||||
const uint8_t* getConstBuffer() const;
|
||||
void setBuffer(uint8_t* buffer, count_t bufferLength);
|
||||
|
||||
uint8_t * getBuffer();
|
||||
const uint8_t * getConstBuffer() const;
|
||||
void setBuffer(uint8_t* buffer, count_t bufferLength);
|
||||
private:
|
||||
bool serializeLength = false;
|
||||
const uint8_t *constBuffer = nullptr;
|
||||
uint8_t *buffer = nullptr;
|
||||
count_t bufferLength = 0;
|
||||
private:
|
||||
bool serializeLength = false;
|
||||
const uint8_t* constBuffer = nullptr;
|
||||
uint8_t* buffer = nullptr;
|
||||
count_t bufferLength = 0;
|
||||
};
|
||||
|
||||
#endif /* SERIALBUFFERADAPTER_H_ */
|
||||
|
@ -1,8 +1,8 @@
|
||||
#ifndef FSFW_SERIALIZE_SERIALFIXEDARRAYLISTADAPTER_H_
|
||||
#define FSFW_SERIALIZE_SERIALFIXEDARRAYLISTADAPTER_H_
|
||||
|
||||
#include "SerialArrayListAdapter.h"
|
||||
#include "../container/FixedArrayList.h"
|
||||
#include "SerialArrayListAdapter.h"
|
||||
|
||||
/**
|
||||
* @brief This adapter provides an interface for SerializeIF to serialize and
|
||||
@ -20,38 +20,33 @@
|
||||
* to one byte.
|
||||
* @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:
|
||||
/**
|
||||
* Constructor arguments are forwarded to FixedArrayList constructor.
|
||||
* Refer to the fixed array list constructors for different options.
|
||||
* @param args
|
||||
*/
|
||||
template<typename... Args>
|
||||
SerialFixedArrayListAdapter(Args... args) :
|
||||
FixedArrayList<BUFFER_TYPE, MAX_SIZE, count_t>(
|
||||
std::forward<Args>(args)...){}
|
||||
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:
|
||||
/**
|
||||
* Constructor arguments are forwarded to FixedArrayList constructor.
|
||||
* Refer to the fixed array list constructors for different options.
|
||||
* @param args
|
||||
*/
|
||||
template <typename... Args>
|
||||
SerialFixedArrayListAdapter(Args... args)
|
||||
: FixedArrayList<BUFFER_TYPE, MAX_SIZE, count_t>(std::forward<Args>(args)...) {}
|
||||
|
||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::serialize(this,
|
||||
buffer, size, maxSize, streamEndianness);
|
||||
}
|
||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
|
||||
Endianness streamEndianness) const {
|
||||
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::serialize(this, buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
}
|
||||
|
||||
size_t getSerializedSize() const {
|
||||
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::
|
||||
getSerializedSize(this);
|
||||
}
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) {
|
||||
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::deSerialize(this,
|
||||
buffer, size, streamEndianness);
|
||||
}
|
||||
size_t getSerializedSize() const {
|
||||
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::getSerializedSize(this);
|
||||
}
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, Endianness streamEndianness) {
|
||||
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::deSerialize(this, buffer, size,
|
||||
streamEndianness);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* FSFW_SERIALIZE_SERIALFIXEDARRAYLISTADAPTER_H_ */
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "SerializeElement.h"
|
||||
#include "SerializeIF.h"
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Implement the conversion of object data to data streams
|
||||
* or vice-versa, using linked lists.
|
||||
* @details
|
||||
@ -33,96 +33,84 @@
|
||||
* @author baetz
|
||||
* @ingroup serialize
|
||||
*/
|
||||
template<typename T, typename count_t = uint8_t>
|
||||
class SerialLinkedListAdapter: public SinglyLinkedList<T>, public SerializeIF {
|
||||
public:
|
||||
template <typename T, typename count_t = uint8_t>
|
||||
class SerialLinkedListAdapter : public SinglyLinkedList<T>, public SerializeIF {
|
||||
public:
|
||||
SerialLinkedListAdapter(typename LinkedElement<T>::Iterator start, bool printCount = false)
|
||||
: SinglyLinkedList<T>(start), printCount(printCount) {}
|
||||
|
||||
SerialLinkedListAdapter(typename LinkedElement<T>::Iterator start,
|
||||
bool printCount = false) :
|
||||
SinglyLinkedList<T>(start), printCount(printCount) {
|
||||
}
|
||||
SerialLinkedListAdapter(LinkedElement<T>* first, bool printCount = false)
|
||||
: SinglyLinkedList<T>(first), printCount(printCount) {}
|
||||
|
||||
SerialLinkedListAdapter(LinkedElement<T>* first, bool printCount = false) :
|
||||
SinglyLinkedList<T>(first), printCount(printCount) {
|
||||
SerialLinkedListAdapter(bool printCount = false)
|
||||
: SinglyLinkedList<T>(), printCount(printCount) {}
|
||||
|
||||
}
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
|
||||
Endianness streamEndianness) const override {
|
||||
if (printCount) {
|
||||
count_t mySize = SinglyLinkedList<T>::getSize();
|
||||
ReturnValue_t result =
|
||||
SerializeAdapter::serialize(&mySize, buffer, size, maxSize, streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return serialize(SinglyLinkedList<T>::start, buffer, size, maxSize, streamEndianness);
|
||||
}
|
||||
|
||||
SerialLinkedListAdapter(bool printCount = false) :
|
||||
SinglyLinkedList<T>(), printCount(printCount) {
|
||||
}
|
||||
static ReturnValue_t serialize(const LinkedElement<T>* element, uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
while ((result == HasReturnvaluesIF::RETURN_OK) and (element != nullptr)) {
|
||||
result = element->value->serialize(buffer, size, maxSize, streamEndianness);
|
||||
element = element->getNext();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const override {
|
||||
if (printCount) {
|
||||
count_t mySize = SinglyLinkedList<T>::getSize();
|
||||
ReturnValue_t result = SerializeAdapter::serialize(&mySize,
|
||||
buffer, size, maxSize, streamEndianness);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return serialize(SinglyLinkedList<T>::start, buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
}
|
||||
virtual size_t getSerializedSize() const override {
|
||||
if (printCount) {
|
||||
return SerialLinkedListAdapter<T>::getSerializedSize() + sizeof(count_t);
|
||||
} else {
|
||||
return getSerializedSize(SinglyLinkedList<T>::start);
|
||||
}
|
||||
}
|
||||
|
||||
static ReturnValue_t serialize(const LinkedElement<T>* element,
|
||||
uint8_t** buffer, size_t* size, size_t maxSize,
|
||||
Endianness streamEndianness) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
while ((result == HasReturnvaluesIF::RETURN_OK) and (element != nullptr)) {
|
||||
result = element->value->serialize(buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
element = element->getNext();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
static size_t getSerializedSize(const LinkedElement<T>* element) {
|
||||
size_t size = 0;
|
||||
while (element != nullptr) {
|
||||
size += element->value->getSerializedSize();
|
||||
element = element->getNext();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
virtual size_t getSerializedSize() const override {
|
||||
if (printCount) {
|
||||
return SerialLinkedListAdapter<T>::getSerializedSize()
|
||||
+ sizeof(count_t);
|
||||
} else {
|
||||
return getSerializedSize(SinglyLinkedList<T>::start);
|
||||
}
|
||||
}
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) override {
|
||||
return deSerialize(SinglyLinkedList<T>::start, buffer, size, streamEndianness);
|
||||
}
|
||||
|
||||
static size_t getSerializedSize(const LinkedElement<T> *element) {
|
||||
size_t size = 0;
|
||||
while (element != nullptr) {
|
||||
size += element->value->getSerializedSize();
|
||||
element = element->getNext();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
static ReturnValue_t deSerialize(LinkedElement<T>* element, const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
while ((result == HasReturnvaluesIF::RETURN_OK) and (element != nullptr)) {
|
||||
result = element->value->deSerialize(buffer, size, streamEndianness);
|
||||
element = element->getNext();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copying is forbidden by deleting the copy constructor and the copy
|
||||
* assignment operator because of the pointers to the linked list members.
|
||||
* Unless the child class implements an own copy constructor or
|
||||
* copy assignment operator, these operation will throw a compiler error.
|
||||
* @param
|
||||
*/
|
||||
SerialLinkedListAdapter(const SerialLinkedListAdapter&) = delete;
|
||||
SerialLinkedListAdapter& operator=(const SerialLinkedListAdapter&) = delete;
|
||||
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) override {
|
||||
return deSerialize(SinglyLinkedList<T>::start, buffer, size,
|
||||
streamEndianness);
|
||||
}
|
||||
|
||||
static ReturnValue_t deSerialize(LinkedElement<T>* element,
|
||||
const uint8_t** buffer, size_t* size, Endianness streamEndianness) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
while ((result == HasReturnvaluesIF::RETURN_OK) and (element != nullptr)) {
|
||||
result = element->value->deSerialize(buffer, size, streamEndianness);
|
||||
element = element->getNext();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copying is forbidden by deleting the copy constructor and the copy
|
||||
* assignment operator because of the pointers to the linked list members.
|
||||
* Unless the child class implements an own copy constructor or
|
||||
* copy assignment operator, these operation will throw a compiler error.
|
||||
* @param
|
||||
*/
|
||||
SerialLinkedListAdapter(const SerialLinkedListAdapter &) = delete;
|
||||
SerialLinkedListAdapter& operator=(const SerialLinkedListAdapter&) = delete;
|
||||
|
||||
bool printCount;
|
||||
bool printCount;
|
||||
};
|
||||
|
||||
#endif /* FSFW_SERIALIZE_SERIALLINKEDLISTADAPTER_H_ */
|
||||
|
@ -1,11 +1,12 @@
|
||||
#ifndef _FSFW_SERIALIZE_SERIALIZEADAPTER_H_
|
||||
#define _FSFW_SERIALIZE_SERIALIZEADAPTER_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "EndianConverter.h"
|
||||
#include "SerializeIF.h"
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
|
||||
/**
|
||||
* @brief These adapters provides an interface to use the SerializeIF functions
|
||||
@ -19,251 +20,244 @@
|
||||
* @ingroup serialize
|
||||
*/
|
||||
class SerializeAdapter {
|
||||
public:
|
||||
/***
|
||||
* @brief Serialize a trivial copy-able type or a child of SerializeIF.
|
||||
* @details
|
||||
* The right template to be called is determined in the function itself.
|
||||
* For objects of non trivial copy-able type this function is almost never
|
||||
* called by the user directly. Instead helpers for specific types like
|
||||
* SerialArrayListAdapter or SerialLinkedListAdapter are the right choice here.
|
||||
*
|
||||
* @param[in] object: Object to serialize, the used type is deduced from this pointer
|
||||
* @param[in/out] buffer: Pointer to the buffer to serialize into. Buffer position will be
|
||||
* incremented by the function.
|
||||
* @param[in/out] size: Pointer to size of current written buffer.
|
||||
* SIze will be incremented by the function.
|
||||
* @param[in] maxSize: Max size of Buffer
|
||||
* @param[in] streamEndianness: Endianness of serialized element as in according to
|
||||
* SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c BUFFER_TOO_SHORT The given buffer in is too short
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful serialization
|
||||
*/
|
||||
template<typename T>
|
||||
static ReturnValue_t serialize(const T *object, uint8_t **buffer,
|
||||
size_t *size, size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.serialize(object, buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
public:
|
||||
/***
|
||||
* @brief Serialize a trivial copy-able type or a child of SerializeIF.
|
||||
* @details
|
||||
* The right template to be called is determined in the function itself.
|
||||
* For objects of non trivial copy-able type this function is almost never
|
||||
* called by the user directly. Instead helpers for specific types like
|
||||
* SerialArrayListAdapter or SerialLinkedListAdapter are the right choice here.
|
||||
*
|
||||
* @param[in] object: Object to serialize, the used type is deduced from this pointer
|
||||
* @param[in/out] buffer: Pointer to the buffer to serialize into. Buffer position will be
|
||||
* incremented by the function.
|
||||
* @param[in/out] size: Pointer to size of current written buffer.
|
||||
* SIze will be incremented by the function.
|
||||
* @param[in] maxSize: Max size of Buffer
|
||||
* @param[in] streamEndianness: Endianness of serialized element as in according to
|
||||
* SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c BUFFER_TOO_SHORT The given buffer in is too short
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful serialization
|
||||
*/
|
||||
template <typename T>
|
||||
static ReturnValue_t serialize(const T *object, uint8_t **buffer, size_t *size, size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.serialize(object, buffer, size, maxSize, streamEndianness);
|
||||
}
|
||||
|
||||
/***
|
||||
* This function can be used to serialize a trivial copy-able type or a child of SerializeIF.
|
||||
* The right template to be called is determined in the function itself.
|
||||
* For objects of non trivial copy-able type this function is almost never
|
||||
* called by the user directly. Instead helpers for specific types like
|
||||
* SerialArrayListAdapter or SerialLinkedListAdapter are the right choice here.
|
||||
*
|
||||
* @param[in] object: Object to serialize, the used type is deduced from this pointer
|
||||
* @param[in/out] buffer: Buffer to serialize into.
|
||||
* @param[out] serSize: Serialized size
|
||||
* @param[in] maxSize: Max size of buffer
|
||||
* @param[in] streamEndianness: Endianness of serialized element as in according to
|
||||
* SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c BUFFER_TOO_SHORT The given buffer in is too short
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful serialization
|
||||
*/
|
||||
template <typename T>
|
||||
static ReturnValue_t serialize(const T *object, uint8_t *const buffer, size_t *serSize,
|
||||
size_t maxSize, SerializeIF::Endianness streamEndianness) {
|
||||
if (object == nullptr or buffer == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
uint8_t **tempPtr = const_cast<uint8_t **>(&buffer);
|
||||
size_t tmpSize = 0;
|
||||
ReturnValue_t result = adapter.serialize(object, tempPtr, &tmpSize, maxSize, streamEndianness);
|
||||
if (serSize != nullptr) {
|
||||
*serSize = tmpSize;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function to return the serialized size of the object in the pointer.
|
||||
* @details
|
||||
* May be a trivially copy-able object or a child of SerializeIF.
|
||||
*
|
||||
* @param object Pointer to Object
|
||||
* @return Serialized size of object
|
||||
*/
|
||||
template <typename T>
|
||||
static size_t getSerializedSize(const T *object) {
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.getSerializedSize(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deserializes a object from a given buffer of given size.
|
||||
*
|
||||
* @details
|
||||
* Object Must be trivially copy-able or a child of SerializeIF.
|
||||
* Buffer will be moved to the current read location. Size will be decreased by the function.
|
||||
*
|
||||
* @param[in] object: Pointer to object to deserialize
|
||||
* @param[in/out] buffer: Pointer to the buffer to deSerialize from. Buffer position will be
|
||||
* incremented by the function
|
||||
* @param[in/out] size: Pointer to remaining size of the buffer to read from.
|
||||
* Will be decreased by function.
|
||||
* @param[in] streamEndianness: Endianness as in according to SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c STREAM_TOO_SHORT The input stream is too short to deSerialize the object
|
||||
* - @c TOO_MANY_ELEMENTS The buffer has more inputs than expected
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful deserialization
|
||||
*/
|
||||
template <typename T>
|
||||
static ReturnValue_t deSerialize(T *object, const uint8_t **buffer, size_t *size,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.deSerialize(object, buffer, size, streamEndianness);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deserializes a object from a given buffer of given size.
|
||||
*
|
||||
* @details
|
||||
* Object Must be trivially copy-able or a child of SerializeIF.
|
||||
*
|
||||
* @param[in] object: Pointer to object to deserialize
|
||||
* @param[in] buffer: Buffer to deSerialize from
|
||||
* @param[out] deserSize: Deserialized length
|
||||
* @param[in] streamEndianness: Endianness as in according to SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c STREAM_TOO_SHORT The input stream is too short to deSerialize the object
|
||||
* - @c TOO_MANY_ELEMENTS The buffer has more inputs than expected
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful deserialization
|
||||
*/
|
||||
template <typename T>
|
||||
static ReturnValue_t deSerialize(T *object, const uint8_t *buffer, size_t *deserSize,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
if (object == nullptr or buffer == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
const uint8_t **tempPtr = &buffer;
|
||||
size_t maxVal = -1;
|
||||
ReturnValue_t result = adapter.deSerialize(object, tempPtr, &maxVal, streamEndianness);
|
||||
if (deserSize != nullptr) {
|
||||
*deserSize = -1 - maxVal;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Internal template to deduce the right function calls at compile time
|
||||
*/
|
||||
template <typename T, bool>
|
||||
class InternalSerializeAdapter;
|
||||
|
||||
/**
|
||||
* Template to be used if T is not a child of SerializeIF
|
||||
*
|
||||
* @tparam T T must be trivially_copyable
|
||||
*/
|
||||
template <typename T>
|
||||
class InternalSerializeAdapter<T, false> {
|
||||
static_assert(std::is_trivially_copyable<T>::value,
|
||||
"If a type needs to be serialized it must be a child of "
|
||||
"SerializeIF or trivially copy-able");
|
||||
|
||||
public:
|
||||
static ReturnValue_t serialize(const T *object, uint8_t **buffer, size_t *size, size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
size_t ignoredSize = 0;
|
||||
if (size == nullptr) {
|
||||
size = &ignoredSize;
|
||||
}
|
||||
// Check remaining size is large enough and check integer
|
||||
// overflow of *size
|
||||
size_t newSize = sizeof(T) + *size;
|
||||
if ((newSize <= max_size) and (newSize > *size)) {
|
||||
T tmp;
|
||||
switch (streamEndianness) {
|
||||
case SerializeIF::Endianness::BIG:
|
||||
tmp = EndianConverter::convertBigEndian<T>(*object);
|
||||
break;
|
||||
case SerializeIF::Endianness::LITTLE:
|
||||
tmp = EndianConverter::convertLittleEndian<T>(*object);
|
||||
break;
|
||||
default:
|
||||
case SerializeIF::Endianness::MACHINE:
|
||||
tmp = *object;
|
||||
break;
|
||||
}
|
||||
std::memcpy(*buffer, &tmp, sizeof(T));
|
||||
*size += sizeof(T);
|
||||
(*buffer) += sizeof(T);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::BUFFER_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* This function can be used to serialize a trivial copy-able type or a child of SerializeIF.
|
||||
* The right template to be called is determined in the function itself.
|
||||
* For objects of non trivial copy-able type this function is almost never
|
||||
* called by the user directly. Instead helpers for specific types like
|
||||
* SerialArrayListAdapter or SerialLinkedListAdapter are the right choice here.
|
||||
*
|
||||
* @param[in] object: Object to serialize, the used type is deduced from this pointer
|
||||
* @param[in/out] buffer: Buffer to serialize into.
|
||||
* @param[out] serSize: Serialized size
|
||||
* @param[in] maxSize: Max size of buffer
|
||||
* @param[in] streamEndianness: Endianness of serialized element as in according to
|
||||
* SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c BUFFER_TOO_SHORT The given buffer in is too short
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful serialization
|
||||
*/
|
||||
template<typename T>
|
||||
static ReturnValue_t serialize(const T *object, uint8_t* const buffer, size_t* serSize,
|
||||
size_t maxSize, SerializeIF::Endianness streamEndianness) {
|
||||
if(object == nullptr or buffer == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
ReturnValue_t deSerialize(T *object, const uint8_t **buffer, size_t *size,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
T tmp;
|
||||
if (*size >= sizeof(T)) {
|
||||
*size -= sizeof(T);
|
||||
std::memcpy(&tmp, *buffer, sizeof(T));
|
||||
switch (streamEndianness) {
|
||||
case SerializeIF::Endianness::BIG:
|
||||
*object = EndianConverter::convertBigEndian<T>(tmp);
|
||||
break;
|
||||
case SerializeIF::Endianness::LITTLE:
|
||||
*object = EndianConverter::convertLittleEndian<T>(tmp);
|
||||
break;
|
||||
default:
|
||||
case SerializeIF::Endianness::MACHINE:
|
||||
*object = tmp;
|
||||
break;
|
||||
}
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
uint8_t** tempPtr = const_cast<uint8_t**>(&buffer);
|
||||
size_t tmpSize = 0;
|
||||
ReturnValue_t result = adapter.serialize(object, tempPtr, &tmpSize, maxSize,
|
||||
streamEndianness);
|
||||
if(serSize != nullptr) {
|
||||
*serSize = tmpSize;
|
||||
}
|
||||
return result;
|
||||
|
||||
*buffer += sizeof(T);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function to return the serialized size of the object in the pointer.
|
||||
* @details
|
||||
* May be a trivially copy-able object or a child of SerializeIF.
|
||||
*
|
||||
* @param object Pointer to Object
|
||||
* @return Serialized size of object
|
||||
*/
|
||||
template<typename T>
|
||||
static size_t getSerializedSize(const T *object){
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.getSerializedSize(object);
|
||||
uint32_t getSerializedSize(const T *object) { return sizeof(T); }
|
||||
};
|
||||
|
||||
/**
|
||||
* Template for objects that inherit from SerializeIF
|
||||
*
|
||||
* @tparam T A child of SerializeIF
|
||||
*/
|
||||
template <typename T>
|
||||
class InternalSerializeAdapter<T, true> {
|
||||
public:
|
||||
ReturnValue_t serialize(const T *object, uint8_t **buffer, size_t *size, size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) const {
|
||||
size_t ignoredSize = 0;
|
||||
if (size == nullptr) {
|
||||
size = &ignoredSize;
|
||||
}
|
||||
return object->serialize(buffer, size, max_size, streamEndianness);
|
||||
}
|
||||
size_t getSerializedSize(const T *object) const { return object->getSerializedSize(); }
|
||||
|
||||
/**
|
||||
* @brief Deserializes a object from a given buffer of given size.
|
||||
*
|
||||
* @details
|
||||
* Object Must be trivially copy-able or a child of SerializeIF.
|
||||
* Buffer will be moved to the current read location. Size will be decreased by the function.
|
||||
*
|
||||
* @param[in] object: Pointer to object to deserialize
|
||||
* @param[in/out] buffer: Pointer to the buffer to deSerialize from. Buffer position will be
|
||||
* incremented by the function
|
||||
* @param[in/out] size: Pointer to remaining size of the buffer to read from.
|
||||
* Will be decreased by function.
|
||||
* @param[in] streamEndianness: Endianness as in according to SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c STREAM_TOO_SHORT The input stream is too short to deSerialize the object
|
||||
* - @c TOO_MANY_ELEMENTS The buffer has more inputs than expected
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful deserialization
|
||||
*/
|
||||
template<typename T>
|
||||
static ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.deSerialize(object, buffer, size, streamEndianness);
|
||||
ReturnValue_t deSerialize(T *object, const uint8_t **buffer, size_t *size,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
return object->deSerialize(buffer, size, streamEndianness);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deserializes a object from a given buffer of given size.
|
||||
*
|
||||
* @details
|
||||
* Object Must be trivially copy-able or a child of SerializeIF.
|
||||
*
|
||||
* @param[in] object: Pointer to object to deserialize
|
||||
* @param[in] buffer: Buffer to deSerialize from
|
||||
* @param[out] deserSize: Deserialized length
|
||||
* @param[in] streamEndianness: Endianness as in according to SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c STREAM_TOO_SHORT The input stream is too short to deSerialize the object
|
||||
* - @c TOO_MANY_ELEMENTS The buffer has more inputs than expected
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful deserialization
|
||||
*/
|
||||
template<typename T>
|
||||
static ReturnValue_t deSerialize(T *object, const uint8_t* buffer,
|
||||
size_t* deserSize, SerializeIF::Endianness streamEndianness) {
|
||||
if(object == nullptr or buffer == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
const uint8_t** tempPtr = &buffer;
|
||||
size_t maxVal = -1;
|
||||
ReturnValue_t result = adapter.deSerialize(object, tempPtr, &maxVal, streamEndianness);
|
||||
if(deserSize != nullptr) {
|
||||
*deserSize = -1 - maxVal;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Internal template to deduce the right function calls at compile time
|
||||
*/
|
||||
template<typename T, bool> class InternalSerializeAdapter;
|
||||
|
||||
/**
|
||||
* Template to be used if T is not a child of SerializeIF
|
||||
*
|
||||
* @tparam T T must be trivially_copyable
|
||||
*/
|
||||
template<typename T>
|
||||
class InternalSerializeAdapter<T, false> {
|
||||
static_assert (std::is_trivially_copyable<T>::value,
|
||||
"If a type needs to be serialized it must be a child of "
|
||||
"SerializeIF or trivially copy-able");
|
||||
public:
|
||||
static ReturnValue_t serialize(const T *object, uint8_t **buffer,
|
||||
size_t *size, size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
size_t ignoredSize = 0;
|
||||
if (size == nullptr) {
|
||||
size = &ignoredSize;
|
||||
}
|
||||
// Check remaining size is large enough and check integer
|
||||
// overflow of *size
|
||||
size_t newSize = sizeof(T) + *size;
|
||||
if ((newSize <= max_size) and (newSize > *size)) {
|
||||
T tmp;
|
||||
switch (streamEndianness) {
|
||||
case SerializeIF::Endianness::BIG:
|
||||
tmp = EndianConverter::convertBigEndian<T>(*object);
|
||||
break;
|
||||
case SerializeIF::Endianness::LITTLE:
|
||||
tmp = EndianConverter::convertLittleEndian<T>(*object);
|
||||
break;
|
||||
default:
|
||||
case SerializeIF::Endianness::MACHINE:
|
||||
tmp = *object;
|
||||
break;
|
||||
}
|
||||
std::memcpy(*buffer, &tmp, sizeof(T));
|
||||
*size += sizeof(T);
|
||||
(*buffer) += sizeof(T);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::BUFFER_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||
T tmp;
|
||||
if (*size >= sizeof(T)) {
|
||||
*size -= sizeof(T);
|
||||
std::memcpy(&tmp, *buffer, sizeof(T));
|
||||
switch (streamEndianness) {
|
||||
case SerializeIF::Endianness::BIG:
|
||||
*object = EndianConverter::convertBigEndian<T>(tmp);
|
||||
break;
|
||||
case SerializeIF::Endianness::LITTLE:
|
||||
*object = EndianConverter::convertLittleEndian<T>(tmp);
|
||||
break;
|
||||
default:
|
||||
case SerializeIF::Endianness::MACHINE:
|
||||
*object = tmp;
|
||||
break;
|
||||
}
|
||||
|
||||
*buffer += sizeof(T);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t getSerializedSize(const T *object) {
|
||||
return sizeof(T);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Template for objects that inherit from SerializeIF
|
||||
*
|
||||
* @tparam T A child of SerializeIF
|
||||
*/
|
||||
template<typename T>
|
||||
class InternalSerializeAdapter<T, true> {
|
||||
public:
|
||||
ReturnValue_t serialize(const T *object, uint8_t **buffer, size_t *size,
|
||||
size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) const {
|
||||
size_t ignoredSize = 0;
|
||||
if (size == nullptr) {
|
||||
size = &ignoredSize;
|
||||
}
|
||||
return object->serialize(buffer, size, max_size, streamEndianness);
|
||||
}
|
||||
size_t getSerializedSize(const T *object) const {
|
||||
return object->getSerializedSize();
|
||||
}
|
||||
|
||||
ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||
return object->deSerialize(buffer, size, streamEndianness);
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* _FSFW_SERIALIZE_SERIALIZEADAPTER_H_ */
|
||||
|
@ -1,10 +1,11 @@
|
||||
#ifndef FSFW_SERIALIZE_SERIALIZEELEMENT_H_
|
||||
#define FSFW_SERIALIZE_SERIALIZEELEMENT_H_
|
||||
|
||||
#include "SerializeAdapter.h"
|
||||
#include "../container/SinglyLinkedList.h"
|
||||
#include <utility>
|
||||
|
||||
#include "../container/SinglyLinkedList.h"
|
||||
#include "SerializeAdapter.h"
|
||||
|
||||
/**
|
||||
* @brief This class is used to mark datatypes for serialization with the
|
||||
* SerialLinkedListAdapter
|
||||
@ -16,48 +17,36 @@
|
||||
* specified sequence order.
|
||||
* @ingroup serialize
|
||||
*/
|
||||
template<typename T>
|
||||
class SerializeElement: public SerializeIF, public LinkedElement<SerializeIF> {
|
||||
public:
|
||||
template<typename ... Args>
|
||||
SerializeElement(Args ... args) :
|
||||
LinkedElement<SerializeIF>(this), entry(std::forward<Args>(args)...) {
|
||||
template <typename T>
|
||||
class SerializeElement : public SerializeIF, public LinkedElement<SerializeIF> {
|
||||
public:
|
||||
template <typename... Args>
|
||||
SerializeElement(Args... args)
|
||||
: LinkedElement<SerializeIF>(this), entry(std::forward<Args>(args)...) {}
|
||||
SerializeElement() : LinkedElement<SerializeIF>(this), entry() {}
|
||||
|
||||
}
|
||||
SerializeElement() :
|
||||
LinkedElement<SerializeIF>(this), entry() {
|
||||
}
|
||||
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
||||
Endianness streamEndianness) const override {
|
||||
return SerializeAdapter::serialize(&entry, buffer, size, maxSize, streamEndianness);
|
||||
}
|
||||
|
||||
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
||||
Endianness streamEndianness) const override {
|
||||
return SerializeAdapter::serialize(&entry, buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
}
|
||||
size_t getSerializedSize() const override { return SerializeAdapter::getSerializedSize(&entry); }
|
||||
|
||||
size_t getSerializedSize() const override {
|
||||
return SerializeAdapter::getSerializedSize(&entry);
|
||||
}
|
||||
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) override {
|
||||
return SerializeAdapter::deSerialize(&entry, buffer, size, streamEndianness);
|
||||
}
|
||||
|
||||
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) override {
|
||||
return SerializeAdapter::deSerialize(&entry, buffer, size,
|
||||
streamEndianness);
|
||||
}
|
||||
operator T() { return entry; }
|
||||
|
||||
operator T() {
|
||||
return entry;
|
||||
}
|
||||
SerializeElement<T> &operator=(T newValue) {
|
||||
entry = newValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
SerializeElement<T>& operator=(T newValue) {
|
||||
entry = newValue;
|
||||
return *this;
|
||||
}
|
||||
T *operator->() { return &entry; }
|
||||
|
||||
T* operator->() {
|
||||
return &entry;
|
||||
}
|
||||
|
||||
T entry;
|
||||
T entry;
|
||||
};
|
||||
|
||||
#endif /* FSFW_SERIALIZE_SERIALIZEELEMENT_H_ */
|
||||
|
@ -1,9 +1,10 @@
|
||||
#ifndef FSFW_SERIALIZE_SERIALIZEIF_H_
|
||||
#define FSFW_SERIALIZE_SERIALIZEIF_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include <cstddef>
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
/**
|
||||
* @defgroup serialize Serialization
|
||||
* Contains serialization services.
|
||||
@ -17,74 +18,78 @@
|
||||
* @ingroup serialize
|
||||
*/
|
||||
class SerializeIF {
|
||||
public:
|
||||
enum class Endianness : uint8_t {
|
||||
BIG,
|
||||
LITTLE,
|
||||
MACHINE,
|
||||
NETWORK = BIG // Added for convenience like htons on sockets
|
||||
};
|
||||
public:
|
||||
enum class Endianness : uint8_t {
|
||||
BIG,
|
||||
LITTLE,
|
||||
MACHINE,
|
||||
NETWORK = BIG // Added for convenience like htons on sockets
|
||||
};
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::SERIALIZE_IF;
|
||||
static const ReturnValue_t BUFFER_TOO_SHORT = MAKE_RETURN_CODE(1); // !< The given buffer in serialize is too short
|
||||
static const ReturnValue_t STREAM_TOO_SHORT = MAKE_RETURN_CODE(2); // !< The input stream in deserialize is too short
|
||||
static const ReturnValue_t TOO_MANY_ELEMENTS = MAKE_RETURN_CODE(3);// !< There are too many elements to be deserialized
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::SERIALIZE_IF;
|
||||
static const ReturnValue_t BUFFER_TOO_SHORT =
|
||||
MAKE_RETURN_CODE(1); // !< The given buffer in serialize is too short
|
||||
static const ReturnValue_t STREAM_TOO_SHORT =
|
||||
MAKE_RETURN_CODE(2); // !< The input stream in deserialize is too short
|
||||
static const ReturnValue_t TOO_MANY_ELEMENTS =
|
||||
MAKE_RETURN_CODE(3); // !< There are too many elements to be deserialized
|
||||
|
||||
virtual ~SerializeIF() {
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* Function to serialize the object into a buffer with maxSize. Size represents the written amount.
|
||||
* If a part of the buffer has been used already, size must be set to the used amount of bytes.
|
||||
*
|
||||
* @details
|
||||
* Implementations of this function must increase the size variable and move the buffer pointer.
|
||||
* MaxSize must be checked by implementations of this function
|
||||
* and BUFFER_TOO_SHORT has to be returned if size would be larger than maxSize.
|
||||
*
|
||||
* Custom implementations might use additional return values.
|
||||
*
|
||||
* @param[in/out] buffer Buffer to serialize into, will be set to the current write location
|
||||
* @param[in/out] size Size that has been used in the buffer already, will be increased by the function
|
||||
* @param[in] maxSize The size of the buffer that is allowed to be used for serialize.
|
||||
* @param[in] streamEndianness Endianness of the serialized data according to SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c BUFFER_TOO_SHORT The given buffer in is too short
|
||||
* - @c RETURN_FAILED Generic error
|
||||
* - @c RETURN_OK Successful serialization
|
||||
*/
|
||||
virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size,
|
||||
size_t maxSize, Endianness streamEndianness) const = 0;
|
||||
virtual ~SerializeIF() {}
|
||||
/**
|
||||
* @brief
|
||||
* Function to serialize the object into a buffer with maxSize. Size represents the written
|
||||
* amount. If a part of the buffer has been used already, size must be set to the used amount of
|
||||
* bytes.
|
||||
*
|
||||
* @details
|
||||
* Implementations of this function must increase the size variable and move the buffer pointer.
|
||||
* MaxSize must be checked by implementations of this function
|
||||
* and BUFFER_TOO_SHORT has to be returned if size would be larger than maxSize.
|
||||
*
|
||||
* Custom implementations might use additional return values.
|
||||
*
|
||||
* @param[in/out] buffer Buffer to serialize into, will be set to the current write location
|
||||
* @param[in/out] size Size that has been used in the buffer already, will be increased by the
|
||||
* function
|
||||
* @param[in] maxSize The size of the buffer that is allowed to be used for serialize.
|
||||
* @param[in] streamEndianness Endianness of the serialized data according to
|
||||
* SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c BUFFER_TOO_SHORT The given buffer in is too short
|
||||
* - @c RETURN_FAILED Generic error
|
||||
* - @c RETURN_OK Successful serialization
|
||||
*/
|
||||
virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
||||
Endianness streamEndianness) const = 0;
|
||||
|
||||
/**
|
||||
* Gets the size of a object if it would be serialized in a buffer
|
||||
* @return Size of serialized object
|
||||
*/
|
||||
virtual size_t getSerializedSize() const = 0;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Deserializes a object from a given buffer of given size.
|
||||
*
|
||||
* @details
|
||||
* Buffer must be moved to the current read location by the implementation
|
||||
* of this function. Size must be decreased by the implementation.
|
||||
* Implementations are not allowed to alter the buffer as indicated by const pointer.
|
||||
*
|
||||
* Custom implementations might use additional return values.
|
||||
*
|
||||
* @param[in/out] buffer Buffer to deSerialize from. Will be moved by the function.
|
||||
* @param[in/out] size Remaining size of the buffer to read from. Will be decreased by function.
|
||||
* @param[in] streamEndianness Endianness as in according to SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c STREAM_TOO_SHORT The input stream is too short to deSerialize the object
|
||||
* - @c TOO_MANY_ELEMENTS The buffer has more inputs than expected
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful deserialization
|
||||
*/
|
||||
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) = 0;
|
||||
/**
|
||||
* Gets the size of a object if it would be serialized in a buffer
|
||||
* @return Size of serialized object
|
||||
*/
|
||||
virtual size_t getSerializedSize() const = 0;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Deserializes a object from a given buffer of given size.
|
||||
*
|
||||
* @details
|
||||
* Buffer must be moved to the current read location by the implementation
|
||||
* of this function. Size must be decreased by the implementation.
|
||||
* Implementations are not allowed to alter the buffer as indicated by const pointer.
|
||||
*
|
||||
* Custom implementations might use additional return values.
|
||||
*
|
||||
* @param[in/out] buffer Buffer to deSerialize from. Will be moved by the function.
|
||||
* @param[in/out] size Remaining size of the buffer to read from. Will be decreased by function.
|
||||
* @param[in] streamEndianness Endianness as in according to SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c STREAM_TOO_SHORT The input stream is too short to deSerialize the object
|
||||
* - @c TOO_MANY_ELEMENTS The buffer has more inputs than expected
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful deserialization
|
||||
*/
|
||||
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) = 0;
|
||||
};
|
||||
|
||||
#endif /* FSFW_SERIALIZE_SERIALIZEIF_H_ */
|
||||
|
Reference in New Issue
Block a user