From 05d89e17773319930c7659126c53d0e6b3de3d72 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 15 Apr 2020 21:10:04 +0200 Subject: [PATCH 01/16] serialize changes. 1. a lot of documentation 2. size_t introduced for both serialize and serialize 3. some features which could be useful 4. SerializeAdapter split up in interface file and internal file. 5. rest of size_t replacements (a lot of them..) will come in separate merge request --- container/FixedArrayList.h | 28 +++- serialize/SerialArrayListAdapter.h | 31 +++-- serialize/SerialBufferAdapter.cpp | 106 ++++++++++----- serialize/SerialBufferAdapter.h | 72 +++++++--- serialize/SerialFixedArrayListAdapter.h | 62 +++++++-- serialize/SerialLinkedListAdapter.h | 78 +++++++++-- serialize/SerializeAdapter.h | 166 +++++++++++------------- serialize/SerializeAdapterInternal.h | 118 +++++++++++++++++ serialize/SerializeElement.h | 38 ++++-- serialize/SerializeIF.h | 33 ++++- 10 files changed, 540 insertions(+), 192 deletions(-) create mode 100644 serialize/SerializeAdapterInternal.h diff --git a/container/FixedArrayList.h b/container/FixedArrayList.h index eeffcc870..5d93db90c 100644 --- a/container/FixedArrayList.h +++ b/container/FixedArrayList.h @@ -2,18 +2,44 @@ #define FIXEDARRAYLIST_H_ #include + /** - * \ingroup container + * @brief Array List with a fixed maximum size + * @ingroup container */ template class FixedArrayList: public ArrayList { private: T data[MAX_SIZE]; public: + /** + * (Robin) Maybe we should also implement move assignment and move ctor. + * Or at least delete them. + */ FixedArrayList() : ArrayList(data, MAX_SIZE) { } + // (Robin): We could create a constructor to initialize the fixed array list with data and the known size field + // so it can be used for serialization too (with SerialFixedArrrayListAdapter) + // is this feasible? + /** + * Initialize a fixed array list with data and number of data fields. + * Endianness of entries can be swapped optionally. + * @param data_ + * @param count + * @param swapArrayListEndianess + */ + FixedArrayList(T * data_, count_t count, + bool swapArrayListEndianess = false): + ArrayList(data, MAX_SIZE) { + memcpy(this->data, data_, count * sizeof(T)); + this->size = count; + if(swapArrayListEndianess) { + ArrayList::swapArrayListEndianness(); + } + } + FixedArrayList(const FixedArrayList& other) : ArrayList(data, MAX_SIZE) { memcpy(this->data, other.data, sizeof(this->data)); diff --git a/serialize/SerialArrayListAdapter.h b/serialize/SerialArrayListAdapter.h index 5ffbc3757..4f3b82e68 100644 --- a/serialize/SerialArrayListAdapter.h +++ b/serialize/SerialArrayListAdapter.h @@ -12,7 +12,8 @@ #include /** - * \ingroup serialize + * Also serializes length field ! + * @ingroup serialize */ template class SerialArrayListAdapter : public SerializeIF { @@ -20,13 +21,15 @@ public: SerialArrayListAdapter(ArrayList *adaptee) : adaptee(adaptee) { } - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const override { return serialize(adaptee, buffer, size, max_size, bigEndian); } - static ReturnValue_t serialize(const ArrayList* list, uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) { + static ReturnValue_t serialize(const ArrayList* list, + uint8_t** buffer, size_t* size, const size_t max_size, + bool bigEndian) { + // Serialize length field first ReturnValue_t result = SerializeAdapter::serialize(&list->size, buffer, size, max_size, bigEndian); count_t i = 0; @@ -38,7 +41,7 @@ public: return result; } - virtual uint32_t getSerializedSize() const { + virtual size_t getSerializedSize() const override { return getSerializedSize(adaptee); } @@ -53,16 +56,19 @@ public: return printSize; } - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, - bool bigEndian) { + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + bool bigEndian) override { return deSerialize(adaptee, buffer, size, bigEndian); } - static ReturnValue_t deSerialize(ArrayList* list, const uint8_t** buffer, int32_t* size, - bool bigEndian) { + static ReturnValue_t deSerialize(ArrayList* list, + const uint8_t** buffer, size_t* size, bool bigEndian) { count_t tempSize = 0; ReturnValue_t result = SerializeAdapter::deSerialize(&tempSize, buffer, size, bigEndian); + if(result != HasReturnvaluesIF::RETURN_OK) { + return result; + } if (tempSize > list->maxSize()) { return SerializeIF::TOO_MANY_ELEMENTS; } @@ -76,6 +82,11 @@ public: } return result; } + + + static void swapArrayListEndianness(ArrayList* list) { + list->swapArrayListEndianness(); + } private: ArrayList *adaptee; }; diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index 3ed083bf5..5fb5e3873 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -1,29 +1,33 @@ #include +#include #include +template +SerialBufferAdapter::SerialBufferAdapter(const void* buffer, + count_t bufferLength, bool serializeLength) : + serializeLength(serializeLength), + constBuffer(static_cast(buffer)), m_buffer(nullptr), + bufferLength(bufferLength) { - -template -SerialBufferAdapter::SerialBufferAdapter(const uint8_t* buffer, - T bufferLength, bool serializeLenght) : - serializeLength(serializeLenght), constBuffer(buffer), buffer(NULL), bufferLength( - bufferLength) { } -template -SerialBufferAdapter::SerialBufferAdapter(uint8_t* buffer, T bufferLength, - bool serializeLenght) : - serializeLength(serializeLenght), constBuffer(NULL), buffer(buffer), bufferLength( - bufferLength) { +template +SerialBufferAdapter::SerialBufferAdapter(void* buffer, + count_t bufferLength, bool serializeLength) : + serializeLength(serializeLength), bufferLength(bufferLength) { + uint8_t * member_buffer = static_cast(buffer); + m_buffer = member_buffer; + constBuffer = member_buffer; } -template -SerialBufferAdapter::~SerialBufferAdapter() { + +template +SerialBufferAdapter::~SerialBufferAdapter() { } -template -ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { +template +ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, + size_t* size, const size_t max_size, bool bigEndian) const { uint32_t serializedLength = bufferLength; if (serializeLength) { serializedLength += AutoSerializeAdapter::getSerializedSize( @@ -36,10 +40,10 @@ ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, uint32_t* size AutoSerializeAdapter::serialize(&bufferLength, buffer, size, max_size, bigEndian); } - if (this->constBuffer != NULL) { - memcpy(*buffer, this->constBuffer, bufferLength); - } else if (this->buffer != NULL) { - memcpy(*buffer, this->buffer, bufferLength); + if (constBuffer != nullptr) { + memcpy(*buffer, constBuffer, bufferLength); + } else if (m_buffer != nullptr) { + memcpy(*buffer, m_buffer, bufferLength); } else { return HasReturnvaluesIF::RETURN_FAILED; } @@ -49,43 +53,77 @@ ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, uint32_t* size } } -template -uint32_t SerialBufferAdapter::getSerializedSize() const { +template +size_t SerialBufferAdapter::getSerializedSize() const { if (serializeLength) { return bufferLength + AutoSerializeAdapter::getSerializedSize(&bufferLength); } else { return bufferLength; } } -template -ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, - int32_t* size, bool bigEndian) { + +template +ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, + size_t* size, bool bigEndian) { //TODO Ignores Endian flag! - if (buffer != NULL) { - if(serializeLength){ - T serializedSize = AutoSerializeAdapter::getSerializedSize( + // (Robin) the one of the buffer? wouldn't that be an issue for serialize + // as well? SerialFixedArrayListAdapter implements swapping of buffer + // fields (if buffer type is not uint8_t) + if (buffer != nullptr) { + if(serializeLength) { + count_t serializedSize = AutoSerializeAdapter::getSerializedSize( &bufferLength); - if((*size - bufferLength - serializedSize) >= 0){ + if(bufferLength + serializedSize >= *size) { *buffer += serializedSize; *size -= serializedSize; - }else{ + } + else { return STREAM_TOO_SHORT; } } //No Else If, go on with buffer - if (*size - bufferLength >= 0) { + if (bufferLength >= *size) { *size -= bufferLength; - memcpy(this->buffer, *buffer, bufferLength); + memcpy(m_buffer, *buffer, bufferLength); (*buffer) += bufferLength; return HasReturnvaluesIF::RETURN_OK; - } else { + } + else { return STREAM_TOO_SHORT; } - } else { + } + else { return HasReturnvaluesIF::RETURN_FAILED; } } +template +uint8_t * SerialBufferAdapter::getBuffer() { + if(m_buffer == nullptr) { + error << "Wrong access function for stored type !" + " Use getConstBuffer()" << std::endl; + return nullptr; + } + return m_buffer; +} + +template +const uint8_t * SerialBufferAdapter::getConstBuffer() { + if(constBuffer == nullptr) { + error << "Wrong access function for stored type !" + " Use getBuffer()" << std::endl; + return nullptr; + } + return constBuffer; +} + +template +void SerialBufferAdapter::setBuffer(void * buffer, + count_t buffer_length) { + m_buffer = static_cast(buffer); + bufferLength = buffer_length; +} + //forward Template declaration for linker template class SerialBufferAdapter; diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index 7cd75d556..d414573cb 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -5,31 +5,73 @@ #include /** + * 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>. + * Right now, the SerialBufferAdapter must always + * be initialized with the buffer and size ! + * * \ingroup serialize */ -template +template class SerialBufferAdapter: public SerializeIF { public: - SerialBufferAdapter(const uint8_t * buffer, T bufferLength, bool serializeLenght = false); - SerialBufferAdapter(uint8_t* buffer, T bufferLength, - bool serializeLenght = 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 void* 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(void* buffer, count_t bufferLength, bool serializeLength = false); virtual ~SerialBufferAdapter(); - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const override; - virtual uint32_t getSerializedSize() const; + virtual size_t getSerializedSize() const; - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, - bool bigEndian); + /** + * @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, + bool bigEndian) override; + + uint8_t * getBuffer(); + const uint8_t * getConstBuffer(); + void setBuffer(void* buffer_, count_t bufferLength_); private: - bool serializeLength; - const uint8_t *constBuffer; - uint8_t *buffer; - T bufferLength; + bool serializeLength = false; + const uint8_t *constBuffer = nullptr; + uint8_t *m_buffer = nullptr; + count_t bufferLength = 0; }; - - #endif /* SERIALBUFFERADAPTER_H_ */ diff --git a/serialize/SerialFixedArrayListAdapter.h b/serialize/SerialFixedArrayListAdapter.h index 16919b623..6e13ff6f4 100644 --- a/serialize/SerialFixedArrayListAdapter.h +++ b/serialize/SerialFixedArrayListAdapter.h @@ -5,24 +5,62 @@ #include /** - * \ingroup serialize + * @brief This adapter provides an interface for SerializeIF to serialize and + * deserialize buffers with a header containing the buffer length. + * @details + * Can be used by SerialLinkedListAdapter by declaring + * as a linked element with SerializeElement>. + * The sequence of objects is defined in the constructor by + * using the setStart and setNext functions. + * + * 1. Buffers with a size header inside that class can be declared with + * @code + * SerialFixedArrayListAdapter mySerialFixedArrayList(...). + * @endcode + * 2. MAX_BUFFER_LENGTH specifies the maximum allowed number of elements + * in FixedArrayList. + * 3. LENGTH_FIELD_TYPE specifies the data type of the buffer header + * containing the buffer size (defaults to 1 byte length field) + * that follows. + * + * @ingroup serialize */ -template -class SerialFixedArrayListAdapter : public FixedArrayList, public SerializeIF { +template +class SerialFixedArrayListAdapter : + public FixedArrayList, + public SerializeIF { public: + /** + * Constructor Arguments are forwarded to FixedArrayList constructor. + * Refer to the fixed array list constructors for different options. + * @param args + */ template - SerialFixedArrayListAdapter(Args... args) : FixedArrayList(std::forward(args)...) { + SerialFixedArrayListAdapter(Args... args) : + FixedArrayList(std::forward(args)...) + {} + + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const override { + return SerialArrayListAdapter::serialize(this, + buffer, size, max_size, bigEndian); } - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { - return SerialArrayListAdapter::serialize(this, buffer, size, max_size, bigEndian); + + size_t getSerializedSize() const { + return SerialArrayListAdapter:: + getSerializedSize(this); } - uint32_t getSerializedSize() const { - return SerialArrayListAdapter::getSerializedSize(this); + + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + bool bigEndian) override { + return SerialArrayListAdapter::deSerialize(this, + buffer, size, bigEndian); } - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, - bool bigEndian) { - return SerialArrayListAdapter::deSerialize(this, buffer, size, bigEndian); + + void swapArrayListEndianness() { + SerialArrayListAdapter:: + swapArrayListEndianness(this); } }; diff --git a/serialize/SerialLinkedListAdapter.h b/serialize/SerialLinkedListAdapter.h index 29952c4a3..8cb9afc8b 100644 --- a/serialize/SerialLinkedListAdapter.h +++ b/serialize/SerialLinkedListAdapter.h @@ -13,26 +13,73 @@ #include //This is where we need the SerializeAdapter! -/** - * \ingroup serialize + /** + * @brief Implement the conversion of object data to data streams + * or vice-versa, using linked lists. + * @details + * An alternative to the AutoSerializeAdapter functions + * - All object members with a datatype are declared as + * SerializeElement members inside the class + * implementing this adapter. + * - The element type can also be a SerialBufferAdapter to + * de-/serialize buffers with a known size + * - The element type can also be a SerialFixedArrayListAdapter to + * de-/serialize buffers with a size header, which is scanned automatically. + * + * The sequence of objects is defined in the constructor by using + * the setStart and setNext functions. + * + * 1. The serialization process is done by instantiating the class and + * calling serialize after all SerializeElement entries have been set by + * using the constructor or setter functions. An additional size variable + * can be supplied which is calculated/incremented automatically. + * 2. The deserialization process is done by instantiating the class and + * supplying a buffer with the data which is converted into an object. + * The size of data to serialize can be supplied and is + * decremented in the function. Range checking is done internally. + * + * @ingroup serialize */ template class SerialLinkedListAdapter: public SinglyLinkedList, public SerializeIF { public: + /** + * 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; + SerialLinkedListAdapter(typename LinkedElement::Iterator start, bool printCount = false) : SinglyLinkedList(start), printCount(printCount) { } + SerialLinkedListAdapter(LinkedElement* first, bool printCount = false) : SinglyLinkedList(first), printCount(printCount) { } + SerialLinkedListAdapter(bool printCount = false) : SinglyLinkedList(), printCount(printCount) { } - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + /** + * Serialize object implementing this adapter into the supplied buffer + * and calculate the serialized size + * @param buffer [out] Object is serialized into this buffer. + * Note that the buffer pointer *buffer is incremented automatically + * inside the respective serialize functions + * @param size [out] Calculated serialized size. Don't forget to set to 0. + * @param max_size + * @param bigEndian Specify endianness + * @return + */ + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const override{ if (printCount) { count_t mySize = SinglyLinkedList::getSize(); ReturnValue_t result = SerializeAdapter::serialize(&mySize, @@ -46,7 +93,7 @@ public: } static ReturnValue_t serialize(const LinkedElement* element, - uint8_t** buffer, uint32_t* size, const uint32_t max_size, + uint8_t** buffer, size_t* size, const size_t max_size, bool bigEndian) { ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; while ((result == HasReturnvaluesIF::RETURN_OK) && (element != NULL)) { @@ -56,7 +103,9 @@ public: } return result; } - virtual uint32_t getSerializedSize() const { + + + virtual size_t getSerializedSize() const override { if (printCount) { return SerialLinkedListAdapter::getSerializedSize() + sizeof(count_t); @@ -64,6 +113,7 @@ public: return getSerializedSize(SinglyLinkedList::start); } } + static uint32_t getSerializedSize(const LinkedElement *element) { uint32_t size = 0; while (element != NULL) { @@ -73,13 +123,22 @@ public: return size; } - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, - bool bigEndian) { + + /** + * Deserialize supplied buffer with supplied size into object + * implementing this adapter. + * @param buffer + * @param size Decremented in respective deSerialize functions automatically + * @param bigEndian Specify endianness + * @return + */ + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + bool bigEndian) override { return deSerialize(SinglyLinkedList::start, buffer, size, bigEndian); } static ReturnValue_t deSerialize(LinkedElement* element, - const uint8_t** buffer, int32_t* size, bool bigEndian) { + const uint8_t** buffer, size_t* size, bool bigEndian) { ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; while ((result == HasReturnvaluesIF::RETURN_OK) && (element != NULL)) { result = element->value->deSerialize(buffer, size, bigEndian); @@ -89,7 +148,6 @@ public: } bool printCount; - }; #endif /* SERIALLINKEDLISTADAPTER_H_ */ diff --git a/serialize/SerializeAdapter.h b/serialize/SerializeAdapter.h index fd9e1b6af..87e4457ae 100644 --- a/serialize/SerializeAdapter.h +++ b/serialize/SerializeAdapter.h @@ -1,82 +1,86 @@ #ifndef SERIALIZEADAPTER_H_ #define SERIALIZEADAPTER_H_ -#include #include -#include #include -#include +#include +#include -/** - * \ingroup serialize + /** + * @brief These adapters provides an interface to use the SerializeIF functions + * with arbitrary template objects to facilitate and simplify the + * serialization of classes with different multiple different data types + * into buffers and vice-versa. + * @details + * + * A report class is converted into a TM buffer. The report class implements a + * serialize functions and calls the AutoSerializeAdapter::serialize function + * repeatedly on all object data fields. The getSerializedSize function is + * implemented by calling the AutoSerializeAdapter::getSerializedSize function + * repeatedly on all data fields. + * + * The AutoSerializeAdapter functions can also be used as an alternative to + * memcpy to retrieve data out of a buffer directly into a class variable + * with data type T while being able to specify endianness. The boolean + * bigEndian specifies whether an endian swap is performed on the data before + * serialization or deserialization. + * + * There are three ways to retrieve data out of a buffer to be used in the FSFW + * to use regular aligned (big endian) data. Examples: + * + * 1. Use the AutoSerializeAdapter::deSerialize function + * The pointer *buffer will be incremented automatically by the typeSize + * of the object, so this function can be called on &buffer repeatedly + * without adjusting pointer position. Set bigEndian parameter to true + * to perform endian swapping, if necessary + * @code + * uint16_t data; + * int32_t dataLen = sizeof(data); + * ReturnValue_t result = + * AutoSerializeAdapter::deSerialize(&data,&buffer,&dataLen,true); + * @endcode + * + * 2. Perform a bitshift operation. Watch for for endianness: + * @code + * uint16_t data; + * data = buffer[targetByte1] << 8 | buffer[targetByte2]; + * data = EndianSwapper::swap(data); //optional, or swap order above + * @endcode + * + * 3. memcpy or std::copy can also be used, but watch out if system + * endianness is different from required data endianness. + * Perform endian-swapping if necessary. + * @code + * uint16_t data; + * memcpy(&data,buffer + positionOfTargetByte1,sizeof(data)); + * data = EndianSwapper::swap(data); //optional + * @endcode + * + * When serializing for downlink, the packets are generally serialized assuming + * big endian data format like seen in TmPacketStored.cpp for example. + * + * @ingroup serialize */ -template -class SerializeAdapter_ { + +// No type specification necessary here. +class AutoSerializeAdapter { public: + template static ReturnValue_t serialize(const T* object, uint8_t** buffer, - uint32_t* size, const uint32_t max_size, bool bigEndian) { - uint32_t ignoredSize = 0; - if (size == NULL) { - size = &ignoredSize; - } - if (sizeof(T) + *size <= max_size) { - T tmp; - if (bigEndian) { - tmp = EndianSwapper::swap(*object); - } else { - tmp = *object; - } - memcpy(*buffer, &tmp, sizeof(T)); - *size += sizeof(T); - (*buffer) += sizeof(T); - return HasReturnvaluesIF::RETURN_OK; - } else { - return SerializeIF::BUFFER_TOO_SHORT; - } + size_t* size, const size_t max_size, bool bigEndian) { + SerializeAdapter_::Is> adapter; + return adapter.serialize(object, buffer, size, max_size, bigEndian); } - - ReturnValue_t deSerialize(T* object, const uint8_t** buffer, int32_t* size, - bool bigEndian) { - T tmp; - *size -= sizeof(T); - if (*size >= 0) { - memcpy(&tmp, *buffer, sizeof(T)); - if (bigEndian) { - *object = EndianSwapper::swap(tmp); - } else { - *object = tmp; - } - *buffer += sizeof(T); - return HasReturnvaluesIF::RETURN_OK; - } else { - return SerializeIF::STREAM_TOO_SHORT; - } + template + static size_t getSerializedSize(const T* object) { + SerializeAdapter_::Is> adapter; + return adapter.getSerializedSize(object); } - - uint32_t getSerializedSize(const T * object) { - return sizeof(T); - } - -}; - -template -class SerializeAdapter_ { -public: - ReturnValue_t serialize(const T* object, uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { - uint32_t ignoredSize = 0; - if (size == NULL) { - size = &ignoredSize; - } - return object->serialize(buffer, size, max_size, bigEndian); - } - uint32_t getSerializedSize(const T* object) const { - return object->getSerializedSize(); - } - - ReturnValue_t deSerialize(T* object, const uint8_t** buffer, int32_t* size, - bool bigEndian) { - return object->deSerialize(buffer, size, bigEndian); + template + static ReturnValue_t deSerialize(T* object, const uint8_t** buffer, + size_t* size, bool bigEndian) { + SerializeAdapter_::Is> adapter; + return adapter.deSerialize(object, buffer, size, bigEndian); } }; @@ -84,7 +88,7 @@ template class SerializeAdapter { public: static ReturnValue_t serialize(const T* object, uint8_t** buffer, - uint32_t* size, const uint32_t max_size, bool bigEndian) { + size_t* size, const size_t max_size, bool bigEndian) { SerializeAdapter_::Is> adapter; return adapter.serialize(object, buffer, size, max_size, bigEndian); } @@ -94,29 +98,7 @@ public: } static ReturnValue_t deSerialize(T* object, const uint8_t** buffer, - int32_t* size, bool bigEndian) { - SerializeAdapter_::Is> adapter; - return adapter.deSerialize(object, buffer, size, bigEndian); - } -}; - - -class AutoSerializeAdapter { -public: - template - static ReturnValue_t serialize(const T* object, uint8_t** buffer, - uint32_t* size, const uint32_t max_size, bool bigEndian) { - SerializeAdapter_::Is> adapter; - return adapter.serialize(object, buffer, size, max_size, bigEndian); - } - template - static uint32_t getSerializedSize(const T* object) { - SerializeAdapter_::Is> adapter; - return adapter.getSerializedSize(object); - } - template - static ReturnValue_t deSerialize(T* object, const uint8_t** buffer, - int32_t* size, bool bigEndian) { + size_t* size, bool bigEndian) { SerializeAdapter_::Is> adapter; return adapter.deSerialize(object, buffer, size, bigEndian); } diff --git a/serialize/SerializeAdapterInternal.h b/serialize/SerializeAdapterInternal.h new file mode 100644 index 000000000..c57af0c95 --- /dev/null +++ b/serialize/SerializeAdapterInternal.h @@ -0,0 +1,118 @@ +/** + * @file SerializeAdapterInternal.h + * + * @date 13.04.2020 + * @author R. Mueller + */ + +#ifndef FRAMEWORK_SERIALIZE_SERIALIZEADAPTERINTERNAL_H_ +#define FRAMEWORK_SERIALIZE_SERIALIZEADAPTERINTERNAL_H_ +#include +#include +#include + +/** + * This template specialization will be chosen for fundamental types or + * anything else not implementing SerializeIF, based on partial + * template specialization. + * @tparam T + * @tparam + */ +template +class SerializeAdapter_ { +public: + /** + * + * @param object + * @param buffer + * @param size + * @param max_size + * @param bigEndian + * @return + */ + static ReturnValue_t serialize(const T* object, uint8_t** buffer, + size_t* size, const size_t max_size, bool bigEndian) { + // function eventuelly serializes structs here. + // does this work on every architecture? + // static_assert(std::is_fundamental::value); + size_t ignoredSize = 0; + if (size == nullptr) { + size = &ignoredSize; + } + if (sizeof(T) + *size <= max_size) { + T tmp; + if (bigEndian) { + tmp = EndianSwapper::swap(*object); + } else { + tmp = *object; + } + memcpy(*buffer, &tmp, sizeof(T)); + *size += sizeof(T); + (*buffer) += sizeof(T); + return HasReturnvaluesIF::RETURN_OK; + } else { + return SerializeIF::BUFFER_TOO_SHORT; + } + } + + /** + * Deserialize buffer into object + * @param object [out] Object to be deserialized with buffer data + * @param buffer contains the data. Non-Const pointer to non-const + * pointer to const data. + * @param size Size to deSerialize. wil be decremented by sizeof(T) + * @param bigEndian Specify endianness + * @return + */ + ReturnValue_t deSerialize(T* object, const uint8_t** buffer, size_t* size, + bool bigEndian) { + T tmp; + if (*size >= sizeof(T)) { + *size -= sizeof(T); + memcpy(&tmp, *buffer, sizeof(T)); + if (bigEndian) { + *object = EndianSwapper::swap(tmp); + } else { + *object = tmp; + } + *buffer += sizeof(T); + return HasReturnvaluesIF::RETURN_OK; + } else { + return SerializeIF::STREAM_TOO_SHORT; + } + } + + size_t getSerializedSize(const T * object) { + return sizeof(T); + } +}; + +/** + * This template specialization will be chosen for class derived from + * SerializeIF, based on partial template specialization. + * @tparam T + * @tparam + */ +template +class SerializeAdapter_ { +public: + ReturnValue_t serialize(const T* object, uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { + size_t ignoredSize = 0; + if (size == NULL) { + size = &ignoredSize; + } + return object->serialize(buffer, size, max_size, bigEndian); + } + + size_t getSerializedSize(const T* object) const { + return object->getSerializedSize(); + } + + ReturnValue_t deSerialize(T* object, const uint8_t** buffer, size_t* size, + bool bigEndian) { + return object->deSerialize(buffer, size, bigEndian); + } +}; + +#endif /* FRAMEWORK_SERIALIZE_SERIALIZEADAPTERINTERNAL_H_ */ diff --git a/serialize/SerializeElement.h b/serialize/SerializeElement.h index db7db20a9..4717ae17f 100644 --- a/serialize/SerializeElement.h +++ b/serialize/SerializeElement.h @@ -6,31 +6,47 @@ #include /** - * \ingroup serialize + * @brief This class is used to mark datatypes for serialization with the + * SerialLinkedListAdapter + * @details + * Used by declaring any arbitrary datatype with SerializeElement myVariable, + * inside a SerialLinkedListAdapter implementation and setting the sequence + * of objects with setNext() and setStart(). + * Serilization and Deserialization is then performed automatically in + * specified sequence order. + * @ingroup serialize */ template class SerializeElement : public SerializeIF, public LinkedElement { public: + /** + * Arguments are forwarded to the element datatype constructor + * @param args + */ template - SerializeElement(Args... args) : LinkedElement(this), entry(std::forward(args)...) { + SerializeElement(Args... args): + LinkedElement(this), + entry(std::forward(args)...) {} + + SerializeElement() : LinkedElement(this) {} - } - SerializeElement() : LinkedElement(this) { - } T entry; - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { - return SerializeAdapter::serialize(&entry, buffer, size, max_size, bigEndian); + + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const override { + return SerializeAdapter::serialize(&entry, buffer, size, + max_size, bigEndian); } - uint32_t getSerializedSize() const { + size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&entry); } - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, - bool bigEndian) { + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + bool bigEndian) override { return SerializeAdapter::deSerialize(&entry, buffer, size, bigEndian); } + operator T() { return entry; } diff --git a/serialize/SerializeIF.h b/serialize/SerializeIF.h index 701fbf563..5f8102c86 100644 --- a/serialize/SerializeIF.h +++ b/serialize/SerializeIF.h @@ -2,15 +2,34 @@ #define SERIALIZEIF_H_ #include +#include /** - * \defgroup serialize Serialization + * @defgroup serialize Serialization * Contains serialisation services. */ /** - * Translation of objects into data streams. - * \ingroup serialize + * @brief An interface for alle classes which require + * translation of objects data into data streams and vice-versa. + * @details + * If the target architecture is little endian (e.g. ARM), any data types + * created might have the wrong endianess if they are to be used for the FSFW. + * Depending on the system architecture, endian correctness must be assured, + * This is important for incoming and outgoing data. The internal handling + * of data should be performed in the native system endianness. + * There are three ways to copy data (with different options to ensure + * endian correctness): + * + * 1. Use the @c AutoSerializeAdapter::deSerialize function (with + * the endian flag) + * 2. Perform a bitshift operation (with correct order) + * 3. @c memcpy (with @c EndianSwapper if necessary) + * + * When serializing for downlink, the packets are generally serialized + * assuming big endian data format like seen in TmPacketStored.cpp for example. + * + * @ingroup serialize */ class SerializeIF { public: @@ -22,12 +41,12 @@ public: virtual ~SerializeIF() { } - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const = 0; + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const = 0; - virtual uint32_t getSerializedSize() const = 0; + virtual size_t getSerializedSize() const = 0; - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) = 0; }; -- 2.34.1 From ca3dbc7ca0f9ce52160e159766223073ab7a141d Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 4 May 2020 18:33:06 +0200 Subject: [PATCH 02/16] reverted fixed array list container changes --- container/FixedArrayList.h | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/container/FixedArrayList.h b/container/FixedArrayList.h index 5d93db90c..eeffcc870 100644 --- a/container/FixedArrayList.h +++ b/container/FixedArrayList.h @@ -2,44 +2,18 @@ #define FIXEDARRAYLIST_H_ #include - /** - * @brief Array List with a fixed maximum size - * @ingroup container + * \ingroup container */ template class FixedArrayList: public ArrayList { private: T data[MAX_SIZE]; public: - /** - * (Robin) Maybe we should also implement move assignment and move ctor. - * Or at least delete them. - */ FixedArrayList() : ArrayList(data, MAX_SIZE) { } - // (Robin): We could create a constructor to initialize the fixed array list with data and the known size field - // so it can be used for serialization too (with SerialFixedArrrayListAdapter) - // is this feasible? - /** - * Initialize a fixed array list with data and number of data fields. - * Endianness of entries can be swapped optionally. - * @param data_ - * @param count - * @param swapArrayListEndianess - */ - FixedArrayList(T * data_, count_t count, - bool swapArrayListEndianess = false): - ArrayList(data, MAX_SIZE) { - memcpy(this->data, data_, count * sizeof(T)); - this->size = count; - if(swapArrayListEndianess) { - ArrayList::swapArrayListEndianness(); - } - } - FixedArrayList(const FixedArrayList& other) : ArrayList(data, MAX_SIZE) { memcpy(this->data, other.data, sizeof(this->data)); -- 2.34.1 From 050b837fb636a3e313f6986a14939c1c837e5ecc Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 4 May 2020 18:35:27 +0200 Subject: [PATCH 03/16] removed swapper --- serialize/SerialArrayListAdapter.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/serialize/SerialArrayListAdapter.h b/serialize/SerialArrayListAdapter.h index 4f3b82e68..68d5cf621 100644 --- a/serialize/SerialArrayListAdapter.h +++ b/serialize/SerialArrayListAdapter.h @@ -45,8 +45,8 @@ public: return getSerializedSize(adaptee); } - static uint32_t getSerializedSize(const ArrayList* list) { - uint32_t printSize = sizeof(count_t); + static size_t getSerializedSize(const ArrayList* list) { + size_t printSize = sizeof(count_t); count_t i = 0; for (i = 0; i < list->size; ++i) { @@ -83,10 +83,6 @@ public: return result; } - - static void swapArrayListEndianness(ArrayList* list) { - list->swapArrayListEndianness(); - } private: ArrayList *adaptee; }; -- 2.34.1 From 059f05ee480d454013ae683e2e91a4c5101f9073 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 4 May 2020 18:38:18 +0200 Subject: [PATCH 04/16] reverted serial buffer adapter changes is going to be refactored anyway --- container/FixedMap.h | 6 +- serialize/SerialBufferAdapter.cpp | 104 ++++++++++-------------------- serialize/SerialBufferAdapter.h | 67 ++++--------------- 3 files changed, 49 insertions(+), 128 deletions(-) diff --git a/container/FixedMap.h b/container/FixedMap.h index 0b84bf4ea..36ff07f9f 100644 --- a/container/FixedMap.h +++ b/container/FixedMap.h @@ -148,7 +148,7 @@ public: return theMap.maxSize(); } - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, const uint32_t max_size, bool bigEndian) const { ReturnValue_t result = SerializeAdapter::serialize(&this->_size, buffer, size, max_size, bigEndian); @@ -163,7 +163,7 @@ public: return result; } - virtual uint32_t getSerializedSize() const { + virtual size_t getSerializedSize() const { uint32_t printSize = sizeof(_size); uint32_t i = 0; @@ -176,7 +176,7 @@ public: return printSize; } - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) { ReturnValue_t result = SerializeAdapter::deSerialize(&this->_size, buffer, size, bigEndian); diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index 5fb5e3873..8cec25631 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -1,33 +1,29 @@ #include -#include #include -template -SerialBufferAdapter::SerialBufferAdapter(const void* buffer, - count_t bufferLength, bool serializeLength) : - serializeLength(serializeLength), - constBuffer(static_cast(buffer)), m_buffer(nullptr), - bufferLength(bufferLength) { + +template +SerialBufferAdapter::SerialBufferAdapter(const uint8_t* buffer, + T bufferLength, bool serializeLenght) : + serializeLength(serializeLenght), constBuffer(buffer), buffer(NULL), bufferLength( + bufferLength) { } -template -SerialBufferAdapter::SerialBufferAdapter(void* buffer, - count_t bufferLength, bool serializeLength) : - serializeLength(serializeLength), bufferLength(bufferLength) { - uint8_t * member_buffer = static_cast(buffer); - m_buffer = member_buffer; - constBuffer = member_buffer; +template +SerialBufferAdapter::SerialBufferAdapter(uint8_t* buffer, T bufferLength, + bool serializeLenght) : + serializeLength(serializeLenght), constBuffer(NULL), buffer(buffer), bufferLength( + bufferLength) { } - -template -SerialBufferAdapter::~SerialBufferAdapter() { +template +SerialBufferAdapter::~SerialBufferAdapter() { } -template -ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, - size_t* size, const size_t max_size, bool bigEndian) const { +template +ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, size_t* size, + const uint32_t max_size, bool bigEndian) const { uint32_t serializedLength = bufferLength; if (serializeLength) { serializedLength += AutoSerializeAdapter::getSerializedSize( @@ -40,10 +36,10 @@ ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, AutoSerializeAdapter::serialize(&bufferLength, buffer, size, max_size, bigEndian); } - if (constBuffer != nullptr) { - memcpy(*buffer, constBuffer, bufferLength); - } else if (m_buffer != nullptr) { - memcpy(*buffer, m_buffer, bufferLength); + if (this->constBuffer != NULL) { + memcpy(*buffer, this->constBuffer, bufferLength); + } else if (this->buffer != NULL) { + memcpy(*buffer, this->buffer, bufferLength); } else { return HasReturnvaluesIF::RETURN_FAILED; } @@ -53,77 +49,43 @@ ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, } } -template -size_t SerialBufferAdapter::getSerializedSize() const { +template +size_t SerialBufferAdapter::getSerializedSize() const { if (serializeLength) { return bufferLength + AutoSerializeAdapter::getSerializedSize(&bufferLength); } else { return bufferLength; } } - -template -ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, +template +ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) { //TODO Ignores Endian flag! - // (Robin) the one of the buffer? wouldn't that be an issue for serialize - // as well? SerialFixedArrayListAdapter implements swapping of buffer - // fields (if buffer type is not uint8_t) - if (buffer != nullptr) { - if(serializeLength) { - count_t serializedSize = AutoSerializeAdapter::getSerializedSize( + if (buffer != NULL) { + if(serializeLength){ + T serializedSize = AutoSerializeAdapter::getSerializedSize( &bufferLength); - if(bufferLength + serializedSize >= *size) { + if((*size - bufferLength - serializedSize) >= 0){ *buffer += serializedSize; *size -= serializedSize; - } - else { + }else{ return STREAM_TOO_SHORT; } } //No Else If, go on with buffer - if (bufferLength >= *size) { + if (*size - bufferLength >= 0) { *size -= bufferLength; - memcpy(m_buffer, *buffer, bufferLength); + memcpy(this->buffer, *buffer, bufferLength); (*buffer) += bufferLength; return HasReturnvaluesIF::RETURN_OK; - } - else { + } else { return STREAM_TOO_SHORT; } - } - else { + } else { return HasReturnvaluesIF::RETURN_FAILED; } } -template -uint8_t * SerialBufferAdapter::getBuffer() { - if(m_buffer == nullptr) { - error << "Wrong access function for stored type !" - " Use getConstBuffer()" << std::endl; - return nullptr; - } - return m_buffer; -} - -template -const uint8_t * SerialBufferAdapter::getConstBuffer() { - if(constBuffer == nullptr) { - error << "Wrong access function for stored type !" - " Use getBuffer()" << std::endl; - return nullptr; - } - return constBuffer; -} - -template -void SerialBufferAdapter::setBuffer(void * buffer, - count_t buffer_length) { - m_buffer = static_cast(buffer); - bufferLength = buffer_length; -} - //forward Template declaration for linker template class SerialBufferAdapter; diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index d414573cb..6b813c3e0 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -5,73 +5,32 @@ #include /** - * 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>. - * Right now, the SerialBufferAdapter must always - * be initialized with the buffer and size ! - * * \ingroup serialize */ -template +template 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 void* 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(void* buffer, count_t bufferLength, bool serializeLength = false); + SerialBufferAdapter(const uint8_t * buffer, T bufferLength, + bool serializeLenght = false); + SerialBufferAdapter(uint8_t* buffer, T bufferLength, + bool serializeLenght = false); virtual ~SerialBufferAdapter(); virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, - const size_t max_size, bool bigEndian) const override; + const uint32_t max_size, bool bigEndian) const; virtual size_t getSerializedSize() const; - /** - * @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, - bool bigEndian) override; - - uint8_t * getBuffer(); - const uint8_t * getConstBuffer(); - void setBuffer(void* buffer_, count_t bufferLength_); + bool bigEndian); private: - bool serializeLength = false; - const uint8_t *constBuffer = nullptr; - uint8_t *m_buffer = nullptr; - count_t bufferLength = 0; + bool serializeLength; + const uint8_t *constBuffer; + uint8_t *buffer; + T bufferLength; }; + + #endif /* SERIALBUFFERADAPTER_H_ */ -- 2.34.1 From a88a73a9be5ff0c5abb133c284231cec0ef0745a Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 4 May 2020 18:40:11 +0200 Subject: [PATCH 05/16] removed swapper --- serialize/SerialFixedArrayListAdapter.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/serialize/SerialFixedArrayListAdapter.h b/serialize/SerialFixedArrayListAdapter.h index 6e13ff6f4..c2616bd22 100644 --- a/serialize/SerialFixedArrayListAdapter.h +++ b/serialize/SerialFixedArrayListAdapter.h @@ -7,6 +7,7 @@ /** * @brief This adapter provides an interface for SerializeIF to serialize and * deserialize buffers with a header containing the buffer length. + * Parses the length field automatically. * @details * Can be used by SerialLinkedListAdapter by declaring * as a linked element with SerializeElement>. @@ -47,7 +48,7 @@ public: buffer, size, max_size, bigEndian); } - size_t getSerializedSize() const { + size_t getSerializedSize() const override{ return SerialArrayListAdapter:: getSerializedSize(this); } @@ -58,10 +59,6 @@ public: buffer, size, bigEndian); } - void swapArrayListEndianness() { - SerialArrayListAdapter:: - swapArrayListEndianness(this); - } }; -- 2.34.1 From d71a4ab654f2171082b889aaf13e29e70d9a3df3 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 4 May 2020 18:46:41 +0200 Subject: [PATCH 06/16] removed internal file. reverted most changes is going to be refactored anyway. --- serialize/SerializeAdapter.h | 162 +++++++++++++++------------ serialize/SerializeAdapterInternal.h | 118 ------------------- 2 files changed, 92 insertions(+), 188 deletions(-) delete mode 100644 serialize/SerializeAdapterInternal.h diff --git a/serialize/SerializeAdapter.h b/serialize/SerializeAdapter.h index 87e4457ae..64c585c04 100644 --- a/serialize/SerializeAdapter.h +++ b/serialize/SerializeAdapter.h @@ -1,10 +1,11 @@ #ifndef SERIALIZEADAPTER_H_ #define SERIALIZEADAPTER_H_ +#include #include +#include #include -#include -#include +#include /** * @brief These adapters provides an interface to use the SerializeIF functions @@ -12,57 +13,98 @@ * serialization of classes with different multiple different data types * into buffers and vice-versa. * @details - * - * A report class is converted into a TM buffer. The report class implements a - * serialize functions and calls the AutoSerializeAdapter::serialize function - * repeatedly on all object data fields. The getSerializedSize function is - * implemented by calling the AutoSerializeAdapter::getSerializedSize function - * repeatedly on all data fields. - * - * The AutoSerializeAdapter functions can also be used as an alternative to - * memcpy to retrieve data out of a buffer directly into a class variable - * with data type T while being able to specify endianness. The boolean - * bigEndian specifies whether an endian swap is performed on the data before - * serialization or deserialization. - * - * There are three ways to retrieve data out of a buffer to be used in the FSFW - * to use regular aligned (big endian) data. Examples: - * - * 1. Use the AutoSerializeAdapter::deSerialize function - * The pointer *buffer will be incremented automatically by the typeSize - * of the object, so this function can be called on &buffer repeatedly - * without adjusting pointer position. Set bigEndian parameter to true - * to perform endian swapping, if necessary - * @code - * uint16_t data; - * int32_t dataLen = sizeof(data); - * ReturnValue_t result = - * AutoSerializeAdapter::deSerialize(&data,&buffer,&dataLen,true); - * @endcode - * - * 2. Perform a bitshift operation. Watch for for endianness: - * @code - * uint16_t data; - * data = buffer[targetByte1] << 8 | buffer[targetByte2]; - * data = EndianSwapper::swap(data); //optional, or swap order above - * @endcode - * - * 3. memcpy or std::copy can also be used, but watch out if system - * endianness is different from required data endianness. - * Perform endian-swapping if necessary. - * @code - * uint16_t data; - * memcpy(&data,buffer + positionOfTargetByte1,sizeof(data)); - * data = EndianSwapper::swap(data); //optional - * @endcode - * - * When serializing for downlink, the packets are generally serialized assuming - * big endian data format like seen in TmPacketStored.cpp for example. - * * @ingroup serialize */ +template +class SerializeAdapter_ { +public: + static ReturnValue_t serialize(const T* object, uint8_t** buffer, + size_t* size, const size_t max_size, bool bigEndian) { + size_t ignoredSize = 0; + if (size == nullptr) { + size = &ignoredSize; + } + if (sizeof(T) + *size <= max_size) { + T tmp; + if (bigEndian) { + tmp = EndianSwapper::swap(*object); + } else { + tmp = *object; + } + 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, + bool bigEndian) { + T tmp; + if (*size >= sizeof(T)) { + memcpy(&tmp, *buffer, sizeof(T)); + if (bigEndian) { + *object = EndianSwapper::swap(tmp); + } else { + *object = tmp; + } + *buffer += sizeof(T); + return HasReturnvaluesIF::RETURN_OK; + } else { + return SerializeIF::STREAM_TOO_SHORT; + } + } + + size_t getSerializedSize(const T * object) { + return sizeof(T); + } + +}; + +template +class SerializeAdapter_ { +public: + ReturnValue_t serialize(const T* object, uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { + size_t ignoredSize = 0; + if (size == nullptr) { + size = &ignoredSize; + } + return object->serialize(buffer, size, max_size, bigEndian); + } + size_t getSerializedSize(const T* object) const { + return object->getSerializedSize(); + } + + ReturnValue_t deSerialize(T* object, const uint8_t** buffer, size_t* size, + bool bigEndian) { + return object->deSerialize(buffer, size, bigEndian); + } +}; + +template +class SerializeAdapter { +public: + static ReturnValue_t serialize(const T* object, uint8_t** buffer, + size_t* size, const size_t max_size, bool bigEndian) { + SerializeAdapter_::Is> adapter; + return adapter.serialize(object, buffer, size, max_size, bigEndian); + } + static size_t getSerializedSize(const T* object) { + SerializeAdapter_::Is> adapter; + return adapter.getSerializedSize(object); + } + + static ReturnValue_t deSerialize(T* object, const uint8_t** buffer, + size_t* size, bool bigEndian) { + SerializeAdapter_::Is> adapter; + return adapter.deSerialize(object, buffer, size, bigEndian); + } +}; + -// No type specification necessary here. class AutoSerializeAdapter { public: template @@ -84,24 +126,4 @@ public: } }; -template -class SerializeAdapter { -public: - static ReturnValue_t serialize(const T* object, uint8_t** buffer, - size_t* size, const size_t max_size, bool bigEndian) { - SerializeAdapter_::Is> adapter; - return adapter.serialize(object, buffer, size, max_size, bigEndian); - } - static uint32_t getSerializedSize(const T* object) { - SerializeAdapter_::Is> adapter; - return adapter.getSerializedSize(object); - } - - static ReturnValue_t deSerialize(T* object, const uint8_t** buffer, - size_t* size, bool bigEndian) { - SerializeAdapter_::Is> adapter; - return adapter.deSerialize(object, buffer, size, bigEndian); - } -}; - #endif /* SERIALIZEADAPTER_H_ */ diff --git a/serialize/SerializeAdapterInternal.h b/serialize/SerializeAdapterInternal.h deleted file mode 100644 index c57af0c95..000000000 --- a/serialize/SerializeAdapterInternal.h +++ /dev/null @@ -1,118 +0,0 @@ -/** - * @file SerializeAdapterInternal.h - * - * @date 13.04.2020 - * @author R. Mueller - */ - -#ifndef FRAMEWORK_SERIALIZE_SERIALIZEADAPTERINTERNAL_H_ -#define FRAMEWORK_SERIALIZE_SERIALIZEADAPTERINTERNAL_H_ -#include -#include -#include - -/** - * This template specialization will be chosen for fundamental types or - * anything else not implementing SerializeIF, based on partial - * template specialization. - * @tparam T - * @tparam - */ -template -class SerializeAdapter_ { -public: - /** - * - * @param object - * @param buffer - * @param size - * @param max_size - * @param bigEndian - * @return - */ - static ReturnValue_t serialize(const T* object, uint8_t** buffer, - size_t* size, const size_t max_size, bool bigEndian) { - // function eventuelly serializes structs here. - // does this work on every architecture? - // static_assert(std::is_fundamental::value); - size_t ignoredSize = 0; - if (size == nullptr) { - size = &ignoredSize; - } - if (sizeof(T) + *size <= max_size) { - T tmp; - if (bigEndian) { - tmp = EndianSwapper::swap(*object); - } else { - tmp = *object; - } - memcpy(*buffer, &tmp, sizeof(T)); - *size += sizeof(T); - (*buffer) += sizeof(T); - return HasReturnvaluesIF::RETURN_OK; - } else { - return SerializeIF::BUFFER_TOO_SHORT; - } - } - - /** - * Deserialize buffer into object - * @param object [out] Object to be deserialized with buffer data - * @param buffer contains the data. Non-Const pointer to non-const - * pointer to const data. - * @param size Size to deSerialize. wil be decremented by sizeof(T) - * @param bigEndian Specify endianness - * @return - */ - ReturnValue_t deSerialize(T* object, const uint8_t** buffer, size_t* size, - bool bigEndian) { - T tmp; - if (*size >= sizeof(T)) { - *size -= sizeof(T); - memcpy(&tmp, *buffer, sizeof(T)); - if (bigEndian) { - *object = EndianSwapper::swap(tmp); - } else { - *object = tmp; - } - *buffer += sizeof(T); - return HasReturnvaluesIF::RETURN_OK; - } else { - return SerializeIF::STREAM_TOO_SHORT; - } - } - - size_t getSerializedSize(const T * object) { - return sizeof(T); - } -}; - -/** - * This template specialization will be chosen for class derived from - * SerializeIF, based on partial template specialization. - * @tparam T - * @tparam - */ -template -class SerializeAdapter_ { -public: - ReturnValue_t serialize(const T* object, uint8_t** buffer, size_t* size, - const size_t max_size, bool bigEndian) const { - size_t ignoredSize = 0; - if (size == NULL) { - size = &ignoredSize; - } - return object->serialize(buffer, size, max_size, bigEndian); - } - - size_t getSerializedSize(const T* object) const { - return object->getSerializedSize(); - } - - ReturnValue_t deSerialize(T* object, const uint8_t** buffer, size_t* size, - bool bigEndian) { - return object->deSerialize(buffer, size, bigEndian); - } -}; - -#endif /* FRAMEWORK_SERIALIZE_SERIALIZEADAPTERINTERNAL_H_ */ -- 2.34.1 From e0079c4468458579095afe78cb6561741ce5316b Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 4 May 2020 18:48:52 +0200 Subject: [PATCH 07/16] removed doc, will be refacoted anyway --- serialize/SerializeIF.h | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/serialize/SerializeIF.h b/serialize/SerializeIF.h index 5f8102c86..e96b7172e 100644 --- a/serialize/SerializeIF.h +++ b/serialize/SerializeIF.h @@ -13,22 +13,6 @@ * @brief An interface for alle classes which require * translation of objects data into data streams and vice-versa. * @details - * If the target architecture is little endian (e.g. ARM), any data types - * created might have the wrong endianess if they are to be used for the FSFW. - * Depending on the system architecture, endian correctness must be assured, - * This is important for incoming and outgoing data. The internal handling - * of data should be performed in the native system endianness. - * There are three ways to copy data (with different options to ensure - * endian correctness): - * - * 1. Use the @c AutoSerializeAdapter::deSerialize function (with - * the endian flag) - * 2. Perform a bitshift operation (with correct order) - * 3. @c memcpy (with @c EndianSwapper if necessary) - * - * When serializing for downlink, the packets are generally serialized - * assuming big endian data format like seen in TmPacketStored.cpp for example. - * * @ingroup serialize */ class SerializeIF { -- 2.34.1 From 12c3f9f168d923c0b994284b1b0a8158b02a675f Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 4 May 2020 18:49:24 +0200 Subject: [PATCH 08/16] typos --- serialize/SerializeIF.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/serialize/SerializeIF.h b/serialize/SerializeIF.h index e96b7172e..9d5a3d4c8 100644 --- a/serialize/SerializeIF.h +++ b/serialize/SerializeIF.h @@ -6,11 +6,11 @@ /** * @defgroup serialize Serialization - * Contains serialisation services. + * Contains serialization services. */ /** - * @brief An interface for alle classes which require + * @brief An interface for all classes which require * translation of objects data into data streams and vice-versa. * @details * @ingroup serialize -- 2.34.1 From 190c9ab0ef0384912026563395905cf95de26e0d Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 4 May 2020 19:00:46 +0200 Subject: [PATCH 09/16] adding all replacements --- action/ActionHelper.cpp | 4 ++-- action/CommandActionHelper.cpp | 4 ++-- container/FixedMap.h | 6 +++--- datapool/DataPoolAdmin.cpp | 2 +- datapool/DataPoolParameterWrapper.cpp | 6 +++--- datapool/DataPoolParameterWrapper.h | 8 ++++---- datapool/DataSet.cpp | 10 +++++----- datapool/DataSet.h | 8 ++++---- datapool/PIDReader.h | 8 ++++---- datapool/PoolRawAccess.cpp | 11 +++++------ datapool/PoolRawAccess.h | 8 ++++---- datapool/PoolVariable.h | 8 ++++---- events/eventmatching/EventRangeMatcherBase.h | 6 +++--- globalfunctions/Type.h | 8 ++++---- globalfunctions/matching/MatchTree.h | 8 ++++---- globalfunctions/matching/RangeMatcher.h | 8 ++++---- parameters/ParameterWrapper.cpp | 18 +++++++++--------- parameters/ParameterWrapper.h | 18 +++++++++--------- subsystem/modes/ModeDefinitions.h | 8 ++++---- 19 files changed, 78 insertions(+), 79 deletions(-) diff --git a/action/ActionHelper.cpp b/action/ActionHelper.cpp index 9c1475f12..09841d73e 100644 --- a/action/ActionHelper.cpp +++ b/action/ActionHelper.cpp @@ -71,12 +71,12 @@ ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo, ActionId_t rep CommandMessage reply; store_address_t storeAddress; uint8_t *dataPtr; - uint32_t maxSize = data->getSerializedSize(); + size_t maxSize = data->getSerializedSize(); if (maxSize == 0) { //No error, there's simply nothing to report. return HasReturnvaluesIF::RETURN_OK; } - uint32_t size = 0; + size_t size = 0; ReturnValue_t result = ipcStore->getFreeElement(&storeAddress, maxSize, &dataPtr); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/action/CommandActionHelper.cpp b/action/CommandActionHelper.cpp index 05eb93461..0cbb0ae22 100644 --- a/action/CommandActionHelper.cpp +++ b/action/CommandActionHelper.cpp @@ -20,13 +20,13 @@ ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo, } store_address_t storeId; uint8_t* storePointer; - uint32_t maxSize = data->getSerializedSize(); + size_t maxSize = data->getSerializedSize(); ReturnValue_t result = ipcStore->getFreeElement(&storeId, maxSize, &storePointer); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - uint32_t size = 0; + size_t size = 0; result = data->serialize(&storePointer, &size, maxSize, true); if (result != HasReturnvaluesIF::RETURN_OK) { return result; diff --git a/container/FixedMap.h b/container/FixedMap.h index 36ff07f9f..39ca1a280 100644 --- a/container/FixedMap.h +++ b/container/FixedMap.h @@ -149,7 +149,7 @@ public: } virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, - const uint32_t max_size, bool bigEndian) const { + const size_t max_size, bool bigEndian) const override { ReturnValue_t result = SerializeAdapter::serialize(&this->_size, buffer, size, max_size, bigEndian); uint32_t i = 0; @@ -163,7 +163,7 @@ public: return result; } - virtual size_t getSerializedSize() const { + virtual size_t getSerializedSize() const override { uint32_t printSize = sizeof(_size); uint32_t i = 0; @@ -177,7 +177,7 @@ public: } virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, - bool bigEndian) { + bool bigEndian) override { ReturnValue_t result = SerializeAdapter::deSerialize(&this->_size, buffer, size, bigEndian); if (this->_size > theMap.maxSize()) { diff --git a/datapool/DataPoolAdmin.cpp b/datapool/DataPoolAdmin.cpp index fe6b92152..a906feebe 100644 --- a/datapool/DataPoolAdmin.cpp +++ b/datapool/DataPoolAdmin.cpp @@ -272,7 +272,7 @@ ReturnValue_t DataPoolAdmin::sendParameter(MessageQueueId_t to, uint32_t id, return result; } - uint32_t storeElementSize = 0; + size_t storeElementSize = 0; result = wrapper->serialize(&storeElement, &storeElementSize, serializedSize, true); diff --git a/datapool/DataPoolParameterWrapper.cpp b/datapool/DataPoolParameterWrapper.cpp index 0ff2121d6..11399fb6e 100644 --- a/datapool/DataPoolParameterWrapper.cpp +++ b/datapool/DataPoolParameterWrapper.cpp @@ -36,7 +36,7 @@ ReturnValue_t DataPoolParameterWrapper::set(uint8_t domainId, } ReturnValue_t DataPoolParameterWrapper::serialize(uint8_t** buffer, - uint32_t* size, const uint32_t max_size, bool bigEndian) const { + size_t* size, const size_t max_size, bool bigEndian) const { ReturnValue_t result; result = SerializeAdapter::serialize(&type, buffer, size, max_size, @@ -69,7 +69,7 @@ ReturnValue_t DataPoolParameterWrapper::serialize(uint8_t** buffer, } //same as ParameterWrapper -uint32_t DataPoolParameterWrapper::getSerializedSize() const { +size_t DataPoolParameterWrapper::getSerializedSize() const { uint32_t serializedSize = 0; serializedSize += type.getSerializedSize(); serializedSize += sizeof(rows); @@ -80,7 +80,7 @@ uint32_t DataPoolParameterWrapper::getSerializedSize() const { } ReturnValue_t DataPoolParameterWrapper::deSerialize(const uint8_t** buffer, - int32_t* size, bool bigEndian) { + size_t* size, bool bigEndian) { return HasReturnvaluesIF::RETURN_FAILED; } diff --git a/datapool/DataPoolParameterWrapper.h b/datapool/DataPoolParameterWrapper.h index faadf6599..99593310e 100644 --- a/datapool/DataPoolParameterWrapper.h +++ b/datapool/DataPoolParameterWrapper.h @@ -11,12 +11,12 @@ public: ReturnValue_t set(uint8_t domainId, uint16_t parameterId); - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const; - virtual uint32_t getSerializedSize() const; + virtual size_t getSerializedSize() const; - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian); ReturnValue_t copyFrom(const ParameterWrapper *from, diff --git a/datapool/DataSet.cpp b/datapool/DataSet.cpp index b4725c735..28cc45009 100644 --- a/datapool/DataSet.cpp +++ b/datapool/DataSet.cpp @@ -106,8 +106,8 @@ uint8_t DataSet::lockDataPool() { return ::dataPool.lockDataPool(); } -ReturnValue_t DataSet::serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { +ReturnValue_t DataSet::serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { ReturnValue_t result = RETURN_FAILED; for (uint16_t count = 0; count < fill_count; count++) { result = registeredVariables[count]->serialize(buffer, size, max_size, @@ -119,8 +119,8 @@ ReturnValue_t DataSet::serialize(uint8_t** buffer, uint32_t* size, return result; } -uint32_t DataSet::getSerializedSize() const { - uint32_t size = 0; +size_t DataSet::getSerializedSize() const { + size_t size = 0; for (uint16_t count = 0; count < fill_count; count++) { size += registeredVariables[count]->getSerializedSize(); } @@ -136,7 +136,7 @@ void DataSet::setValid(uint8_t valid) { } } -ReturnValue_t DataSet::deSerialize(const uint8_t** buffer, int32_t* size, +ReturnValue_t DataSet::deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) { ReturnValue_t result = RETURN_FAILED; for (uint16_t count = 0; count < fill_count; count++) { diff --git a/datapool/DataSet.h b/datapool/DataSet.h index 982be6928..fa2103506 100644 --- a/datapool/DataSet.h +++ b/datapool/DataSet.h @@ -146,12 +146,12 @@ public: */ void setValid(uint8_t valid); - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const; - uint32_t getSerializedSize() const; + size_t getSerializedSize() const; - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian); }; diff --git a/datapool/PIDReader.h b/datapool/PIDReader.h index 299cc2fe6..7572cd2c8 100644 --- a/datapool/PIDReader.h +++ b/datapool/PIDReader.h @@ -126,17 +126,17 @@ public: return *this; } - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { return SerializeAdapter::serialize(&value, buffer, size, max_size, bigEndian); } - virtual uint32_t getSerializedSize() const { + virtual size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&value); } - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) { return SerializeAdapter::deSerialize(&value, buffer, size, bigEndian); } diff --git a/datapool/PoolRawAccess.cpp b/datapool/PoolRawAccess.cpp index 555896bb2..d98ba2be4 100644 --- a/datapool/PoolRawAccess.cpp +++ b/datapool/PoolRawAccess.cpp @@ -145,8 +145,8 @@ uint16_t PoolRawAccess::getSizeTillEnd() const { return sizeTillEnd; } -ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { +ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { if (typeSize + *size <= max_size) { if (bigEndian) { #ifndef BYTE_ORDER_SYSTEM @@ -169,14 +169,13 @@ ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, uint32_t* size, } } -uint32_t PoolRawAccess::getSerializedSize() const { +size_t PoolRawAccess::getSerializedSize() const { return typeSize; } -ReturnValue_t PoolRawAccess::deSerialize(const uint8_t** buffer, int32_t* size, +ReturnValue_t PoolRawAccess::deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) { - *size -= typeSize; - if (*size >= 0) { + if (*size >= typeSize) { if (bigEndian) { #ifndef BYTE_ORDER_SYSTEM diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index 3e2bd7ae3..f5f3a58d3 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -140,12 +140,12 @@ public: */ uint16_t getSizeTillEnd() const; - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const; - uint32_t getSerializedSize() const; + size_t getSerializedSize() const; - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian); }; diff --git a/datapool/PoolVariable.h b/datapool/PoolVariable.h index 25345c0ac..1d501c097 100644 --- a/datapool/PoolVariable.h +++ b/datapool/PoolVariable.h @@ -194,17 +194,17 @@ public: return *this; } - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { return SerializeAdapter::serialize(&value, buffer, size, max_size, bigEndian); } - virtual uint32_t getSerializedSize() const { + virtual size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&value); } - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) { return SerializeAdapter::deSerialize(&value, buffer, size, bigEndian); } diff --git a/events/eventmatching/EventRangeMatcherBase.h b/events/eventmatching/EventRangeMatcherBase.h index 921a5d6a1..277cfefaf 100644 --- a/events/eventmatching/EventRangeMatcherBase.h +++ b/events/eventmatching/EventRangeMatcherBase.h @@ -11,14 +11,14 @@ class EventRangeMatcherBase: public SerializeableMatcherIF { public: EventRangeMatcherBase(T from, T till, bool inverted) : rangeMatcher(from, till, inverted) { } virtual ~EventRangeMatcherBase() { } - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, + ReturnValue_t serialize(uint8_t** buffer, size_t* size, const uint32_t max_size, bool bigEndian) const { return rangeMatcher.serialize(buffer, size, max_size, bigEndian); } - uint32_t getSerializedSize() const { + size_t getSerializedSize() const { return rangeMatcher.getSerializedSize(); } - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) { return rangeMatcher.deSerialize(buffer, size, bigEndian); } diff --git a/globalfunctions/Type.h b/globalfunctions/Type.h index 88df07b6f..f4146f4ea 100644 --- a/globalfunctions/Type.h +++ b/globalfunctions/Type.h @@ -39,12 +39,12 @@ public: static ActualType_t getActualType(uint8_t ptc, uint8_t pfc); - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const; - virtual uint32_t getSerializedSize() const; + virtual size_t getSerializedSize() const; - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian); private: diff --git a/globalfunctions/matching/MatchTree.h b/globalfunctions/matching/MatchTree.h index 398cf3f0b..5a897f407 100644 --- a/globalfunctions/matching/MatchTree.h +++ b/globalfunctions/matching/MatchTree.h @@ -45,8 +45,8 @@ public: return matchSubtree(iter, number); } - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { iterator iter = this->begin(); uint8_t count = this->countRight(iter); ReturnValue_t result = SerializeAdapter::serialize(&count, @@ -86,7 +86,7 @@ public: return result; } - uint32_t getSerializedSize() const { + size_t getSerializedSize() const { //Analogous to serialize! uint32_t size = 1; //One for count iterator iter = this->begin(); @@ -115,7 +115,7 @@ public: return size; } - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) { return HasReturnvaluesIF::RETURN_OK; } diff --git a/globalfunctions/matching/RangeMatcher.h b/globalfunctions/matching/RangeMatcher.h index 10e07173b..fecb4a071 100644 --- a/globalfunctions/matching/RangeMatcher.h +++ b/globalfunctions/matching/RangeMatcher.h @@ -27,8 +27,8 @@ public: } } - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { ReturnValue_t result = SerializeAdapter::serialize(&lowerBound, buffer, size, max_size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { return result; @@ -40,11 +40,11 @@ public: return SerializeAdapter::serialize(&inverted, buffer, size, max_size, bigEndian); } - uint32_t getSerializedSize() const { + size_t getSerializedSize() const { return sizeof(lowerBound) + sizeof(upperBound) + sizeof(bool); } - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) { ReturnValue_t result = SerializeAdapter::deSerialize(&lowerBound, buffer, size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/parameters/ParameterWrapper.cpp b/parameters/ParameterWrapper.cpp index 8f661bb32..85b240b8e 100644 --- a/parameters/ParameterWrapper.cpp +++ b/parameters/ParameterWrapper.cpp @@ -20,8 +20,8 @@ ParameterWrapper::ParameterWrapper(Type type, uint8_t rows, uint8_t columns, ParameterWrapper::~ParameterWrapper() { } -ReturnValue_t ParameterWrapper::serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { +ReturnValue_t ParameterWrapper::serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { ReturnValue_t result; result = SerializeAdapter::serialize(&type, buffer, size, max_size, @@ -88,8 +88,8 @@ uint32_t ParameterWrapper::getSerializedSize() const { } template -ReturnValue_t ParameterWrapper::serializeData(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { +ReturnValue_t ParameterWrapper::serializeData(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { const T *element = (const T*) readonlyData; ReturnValue_t result; uint16_t dataSize = columns * rows; @@ -137,12 +137,12 @@ ReturnValue_t ParameterWrapper::deSerializeData(uint8_t startingRow, } ReturnValue_t ParameterWrapper::deSerialize(const uint8_t** buffer, - int32_t* size, bool bigEndian) { + size_t* size, bool bigEndian) { return deSerialize(buffer, size, bigEndian, 0); } ReturnValue_t ParameterWrapper::deSerialize(const uint8_t** buffer, - int32_t* size, bool bigEndian, uint16_t startWritingAtIndex) { + size_t* size, bool bigEndian, uint16_t startWritingAtIndex) { ParameterWrapper streamDescription; ReturnValue_t result = streamDescription.set(*buffer, *size, buffer, size); @@ -153,8 +153,8 @@ ReturnValue_t ParameterWrapper::deSerialize(const uint8_t** buffer, return copyFrom(&streamDescription, startWritingAtIndex); } -ReturnValue_t ParameterWrapper::set(const uint8_t* stream, int32_t streamSize, - const uint8_t **remainingStream, int32_t *remainingSize) { +ReturnValue_t ParameterWrapper::set(const uint8_t* stream, size_t streamSize, + const uint8_t **remainingStream, size_t *remainingSize) { ReturnValue_t result = SerializeAdapter::deSerialize(&type, &stream, &streamSize, true); if (result != HasReturnvaluesIF::RETURN_OK) { @@ -172,7 +172,7 @@ ReturnValue_t ParameterWrapper::set(const uint8_t* stream, int32_t streamSize, return result; } - int32_t dataSize = type.getSize() * rows * columns; + size_t dataSize = type.getSize() * rows * columns; if (streamSize < dataSize) { return SerializeIF::STREAM_TOO_SHORT; diff --git a/parameters/ParameterWrapper.h b/parameters/ParameterWrapper.h index f61786b8a..ef54fe6d7 100644 --- a/parameters/ParameterWrapper.h +++ b/parameters/ParameterWrapper.h @@ -25,15 +25,15 @@ public: const void *data); virtual ~ParameterWrapper(); - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const; - virtual uint32_t getSerializedSize() const; + virtual size_t getSerializedSize() const; - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian); - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian, uint16_t startWritingAtIndex = 0); template @@ -111,8 +111,8 @@ public: void setMatrix(const T& member) { this->set(member[0], sizeof(member)/sizeof(member[0]), sizeof(member[0])/sizeof(member[0][0])); } - ReturnValue_t set(const uint8_t *stream, int32_t streamSize, - const uint8_t **remainingStream = NULL, int32_t *remainingSize = + ReturnValue_t set(const uint8_t *stream, size_t streamSize, + const uint8_t **remainingStream = NULL, size_t *remainingSize = NULL); ReturnValue_t copyFrom(const ParameterWrapper *from, @@ -128,8 +128,8 @@ private: const void *readonlyData; template - ReturnValue_t serializeData(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + ReturnValue_t serializeData(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const; template ReturnValue_t deSerializeData(uint8_t startingRow, uint8_t startingColumn, diff --git a/subsystem/modes/ModeDefinitions.h b/subsystem/modes/ModeDefinitions.h index 8e7531f3d..5e5631b2c 100644 --- a/subsystem/modes/ModeDefinitions.h +++ b/subsystem/modes/ModeDefinitions.h @@ -18,8 +18,8 @@ public: uint8_t value3; uint8_t value4; - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { ReturnValue_t result; @@ -49,11 +49,11 @@ public: } - virtual uint32_t getSerializedSize() const { + virtual size_t getSerializedSize() const { return sizeof(value1) + sizeof(value2) + sizeof(value3) + sizeof(value4); } - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) { ReturnValue_t result; -- 2.34.1 From 2da1dfd1ffc224eed9a2f874b6a63fa6d28368bf Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 4 May 2020 19:06:53 +0200 Subject: [PATCH 10/16] some more size_t replacements --- devicehandlers/DeviceTmReportingWrapper.h | 8 ++++---- serialize/SerialBufferAdapter.h | 6 +++--- serialize/SerializeElement.h | 2 +- subsystem/Subsystem.cpp | 6 +++--- tmstorage/TmStorePackets.h | 22 +++++++++++----------- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/devicehandlers/DeviceTmReportingWrapper.h b/devicehandlers/DeviceTmReportingWrapper.h index 1cd9470d8..e2fa43164 100644 --- a/devicehandlers/DeviceTmReportingWrapper.h +++ b/devicehandlers/DeviceTmReportingWrapper.h @@ -11,12 +11,12 @@ public: SerializeIF *data); virtual ~DeviceTmReportingWrapper(); - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const; - virtual uint32_t getSerializedSize() const; + virtual size_t getSerializedSize() const; - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian); private: object_id_t objectId; diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index 6b813c3e0..4b380d9ea 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -18,12 +18,12 @@ public: virtual ~SerialBufferAdapter(); virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, - const uint32_t max_size, bool bigEndian) const; + const size_t max_size, bool bigEndian) const override; - virtual size_t getSerializedSize() const; + virtual size_t getSerializedSize() const override; virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, - bool bigEndian); + bool bigEndian) override; private: bool serializeLength; const uint8_t *constBuffer; diff --git a/serialize/SerializeElement.h b/serialize/SerializeElement.h index 4717ae17f..5582e02c9 100644 --- a/serialize/SerializeElement.h +++ b/serialize/SerializeElement.h @@ -38,7 +38,7 @@ public: max_size, bigEndian); } - size_t getSerializedSize() const { + size_t getSerializedSize() const override { return SerializeAdapter::getSerializedSize(&entry); } diff --git a/subsystem/Subsystem.cpp b/subsystem/Subsystem.cpp index e1ec544b0..114fa44ba 100644 --- a/subsystem/Subsystem.cpp +++ b/subsystem/Subsystem.cpp @@ -168,7 +168,7 @@ ReturnValue_t Subsystem::handleCommandMessage(CommandMessage* message) { &sizeRead); if (result == RETURN_OK) { Mode_t fallbackId; - int32_t size = sizeRead; + size_t size = sizeRead; result = SerializeAdapter::deSerialize(&fallbackId, &pointer, &size, true); if (result == RETURN_OK) { @@ -193,7 +193,7 @@ ReturnValue_t Subsystem::handleCommandMessage(CommandMessage* message) { ModeSequenceMessage::getStoreAddress(message), &pointer, &sizeRead); if (result == RETURN_OK) { - int32_t size = sizeRead; + size_t size = sizeRead; result = SerialArrayListAdapter::deSerialize(&table, &pointer, &size, true); if (result == RETURN_OK) { @@ -607,7 +607,7 @@ void Subsystem::sendSerializablesAsCommandMessage(Command_t command, } uint8_t *storeBuffer; store_address_t address; - uint32_t size = 0; + size_t size = 0; result = IPCStore->getFreeElement(&address, maxSize, &storeBuffer); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/tmstorage/TmStorePackets.h b/tmstorage/TmStorePackets.h index 6eea6f586..d408d4cfa 100644 --- a/tmstorage/TmStorePackets.h +++ b/tmstorage/TmStorePackets.h @@ -32,8 +32,8 @@ public: } uint16_t apid; uint16_t ssc; - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const override { ReturnValue_t result = SerializeAdapter::serialize(&apid, buffer, size, max_size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { @@ -44,12 +44,12 @@ public: } - uint32_t getSerializedSize() const { + size_t getSerializedSize() const override{ return sizeof(apid) + sizeof(ssc); } - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, - bool bigEndian) { + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + bool bigEndian) override { ReturnValue_t result = SerializeAdapter::deSerialize(&apid, buffer, size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { @@ -218,8 +218,8 @@ public: } - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const override { ReturnValue_t result = AutoSerializeAdapter::serialize(&apid,buffer,size,max_size,bigEndian); if(result!=HasReturnvaluesIF::RETURN_OK){ return result; @@ -244,8 +244,8 @@ public: return adapter.serialize(buffer,size,max_size,bigEndian); } - uint32_t getSerializedSize() const { - uint32_t size = 0; + size_t getSerializedSize() const override { + size_t size = 0; size += AutoSerializeAdapter::getSerializedSize(&apid); size += AutoSerializeAdapter::getSerializedSize(&sourceSequenceCount); size += AutoSerializeAdapter::getSerializedSize(&serviceType); @@ -257,8 +257,8 @@ public: }; - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, - bool bigEndian) { + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + bool bigEndian) override { ReturnValue_t result = AutoSerializeAdapter::deSerialize(&apid, buffer, size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { -- 2.34.1 From 83080cd4e37b938f8abd615798bb52326c199cfd Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 4 May 2020 19:31:40 +0200 Subject: [PATCH 11/16] yay compiling again --- devicehandlers/DeviceTmReportingWrapper.cpp | 6 +++--- events/eventmatching/EventRangeMatcherBase.h | 7 ++++--- globalfunctions/Type.cpp | 8 ++++---- health/HealthTable.cpp | 4 ++-- health/HealthTable.h | 2 +- health/HealthTableIF.h | 2 +- monitoring/LimitViolationReporter.cpp | 2 +- parameters/ParameterHelper.cpp | 2 +- parameters/ParameterWrapper.cpp | 6 +++--- power/Fuse.cpp | 8 ++++---- power/Fuse.h | 15 +++++++++------ power/PowerComponent.cpp | 8 ++++---- power/PowerComponent.h | 10 +++++----- serialize/SerialBufferAdapter.cpp | 2 +- thermal/ThermalComponent.cpp | 11 +++++------ thermal/ThermalComponent.h | 2 +- tmtcpacket/packetmatcher/ApidMatcher.h | 16 +++++++++------- tmtcpacket/packetmatcher/ServiceMatcher.h | 14 ++++++++------ tmtcpacket/packetmatcher/SubserviceMatcher.h | 14 ++++++++------ tmtcpacket/pus/TmPacketStored.cpp | 2 +- tmtcservices/CommandingServiceBase.cpp | 2 +- tmtcservices/PusVerificationReport.h | 4 ++-- 22 files changed, 78 insertions(+), 69 deletions(-) diff --git a/devicehandlers/DeviceTmReportingWrapper.cpp b/devicehandlers/DeviceTmReportingWrapper.cpp index 2c9e820fe..adddf4f3f 100644 --- a/devicehandlers/DeviceTmReportingWrapper.cpp +++ b/devicehandlers/DeviceTmReportingWrapper.cpp @@ -12,7 +12,7 @@ DeviceTmReportingWrapper::~DeviceTmReportingWrapper() { } ReturnValue_t DeviceTmReportingWrapper::serialize(uint8_t** buffer, - uint32_t* size, const uint32_t max_size, bool bigEndian) const { + size_t* size, const size_t max_size, bool bigEndian) const { ReturnValue_t result = SerializeAdapter::serialize(&objectId, buffer, size, max_size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { @@ -26,12 +26,12 @@ ReturnValue_t DeviceTmReportingWrapper::serialize(uint8_t** buffer, return data->serialize(buffer, size, max_size, bigEndian); } -uint32_t DeviceTmReportingWrapper::getSerializedSize() const { +size_t DeviceTmReportingWrapper::getSerializedSize() const { return sizeof(objectId) + sizeof(ActionId_t) + data->getSerializedSize(); } ReturnValue_t DeviceTmReportingWrapper::deSerialize(const uint8_t** buffer, - int32_t* size, bool bigEndian) { + size_t* size, bool bigEndian) { ReturnValue_t result = SerializeAdapter::deSerialize(&objectId, buffer, size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/events/eventmatching/EventRangeMatcherBase.h b/events/eventmatching/EventRangeMatcherBase.h index 277cfefaf..80bd88f90 100644 --- a/events/eventmatching/EventRangeMatcherBase.h +++ b/events/eventmatching/EventRangeMatcherBase.h @@ -11,15 +11,16 @@ class EventRangeMatcherBase: public SerializeableMatcherIF { public: EventRangeMatcherBase(T from, T till, bool inverted) : rangeMatcher(from, till, inverted) { } virtual ~EventRangeMatcherBase() { } + ReturnValue_t serialize(uint8_t** buffer, size_t* size, - const uint32_t max_size, bool bigEndian) const { + const size_t max_size, bool bigEndian) const override { return rangeMatcher.serialize(buffer, size, max_size, bigEndian); } - size_t getSerializedSize() const { + size_t getSerializedSize() const override { return rangeMatcher.getSerializedSize(); } ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, - bool bigEndian) { + bool bigEndian) override { return rangeMatcher.deSerialize(buffer, size, bigEndian); } protected: diff --git a/globalfunctions/Type.cpp b/globalfunctions/Type.cpp index 814d26f4e..0da886223 100644 --- a/globalfunctions/Type.cpp +++ b/globalfunctions/Type.cpp @@ -59,8 +59,8 @@ uint8_t Type::getSize() const { } } -ReturnValue_t Type::serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { +ReturnValue_t Type::serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { uint8_t ptc; uint8_t pfc; ReturnValue_t result = getPtcPfc(&ptc, &pfc); @@ -81,12 +81,12 @@ ReturnValue_t Type::serialize(uint8_t** buffer, uint32_t* size, } -uint32_t Type::getSerializedSize() const { +size_t Type::getSerializedSize() const { uint8_t dontcare = 0; return 2 * SerializeAdapter::getSerializedSize(&dontcare); } -ReturnValue_t Type::deSerialize(const uint8_t** buffer, int32_t* size, +ReturnValue_t Type::deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) { uint8_t ptc; uint8_t pfc; diff --git a/health/HealthTable.cpp b/health/HealthTable.cpp index a575b2828..7223cf15a 100644 --- a/health/HealthTable.cpp +++ b/health/HealthTable.cpp @@ -63,9 +63,9 @@ bool HealthTable::hasHealth(object_id_t object) { return exits; } -void HealthTable::printAll(uint8_t* pointer, uint32_t maxSize) { +void HealthTable::printAll(uint8_t* pointer, size_t maxSize) { mutex->lockMutex(MutexIF::NO_TIMEOUT); - uint32_t size = 0; + size_t size = 0; uint16_t count = healthMap.size(); ReturnValue_t result = SerializeAdapter::serialize(&count, &pointer, &size, maxSize, true); diff --git a/health/HealthTable.h b/health/HealthTable.h index 32a7eee2f..2c74bda44 100644 --- a/health/HealthTable.h +++ b/health/HealthTable.h @@ -21,7 +21,7 @@ public: virtual HasHealthIF::HealthState getHealth(object_id_t); virtual uint32_t getPrintSize(); - virtual void printAll(uint8_t *pointer, uint32_t maxSize); + virtual void printAll(uint8_t *pointer, size_t maxSize); protected: MutexIF* mutex; diff --git a/health/HealthTableIF.h b/health/HealthTableIF.h index 6fdfc2c04..a850a8048 100644 --- a/health/HealthTableIF.h +++ b/health/HealthTableIF.h @@ -17,7 +17,7 @@ public: HasHealthIF::HealthState initilialState = HasHealthIF::HEALTHY) = 0; virtual uint32_t getPrintSize() = 0; - virtual void printAll(uint8_t *pointer, uint32_t maxSize) = 0; + virtual void printAll(uint8_t *pointer, size_t maxSize) = 0; protected: virtual ReturnValue_t iterate(std::pair *value, bool reset = false) = 0; diff --git a/monitoring/LimitViolationReporter.cpp b/monitoring/LimitViolationReporter.cpp index 760e8b93d..77c3dad13 100644 --- a/monitoring/LimitViolationReporter.cpp +++ b/monitoring/LimitViolationReporter.cpp @@ -26,7 +26,7 @@ ReturnValue_t LimitViolationReporter::sendLimitViolationReport(const SerializeIF if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - uint32_t size = 0; + size_t size = 0; result = data->serialize(&dataTarget, &size, maxSize, true); if (result != HasReturnvaluesIF::RETURN_OK) { return result; diff --git a/parameters/ParameterHelper.cpp b/parameters/ParameterHelper.cpp index 75b71a7e9..0c501ae72 100644 --- a/parameters/ParameterHelper.cpp +++ b/parameters/ParameterHelper.cpp @@ -94,7 +94,7 @@ ReturnValue_t ParameterHelper::sendParameter(MessageQueueId_t to, uint32_t id, return result; } - uint32_t storeElementSize = 0; + size_t storeElementSize = 0; result = description->serialize(&storeElement, &storeElementSize, serializedSize, true); diff --git a/parameters/ParameterWrapper.cpp b/parameters/ParameterWrapper.cpp index 85b240b8e..a2b0bc886 100644 --- a/parameters/ParameterWrapper.cpp +++ b/parameters/ParameterWrapper.cpp @@ -77,8 +77,8 @@ ReturnValue_t ParameterWrapper::serialize(uint8_t** buffer, size_t* size, return result; } -uint32_t ParameterWrapper::getSerializedSize() const { - uint32_t serializedSize = 0; +size_t ParameterWrapper::getSerializedSize() const { + size_t serializedSize = 0; serializedSize += type.getSerializedSize(); serializedSize += sizeof(rows); serializedSize += sizeof(columns); @@ -112,7 +112,7 @@ ReturnValue_t ParameterWrapper::deSerializeData(uint8_t startingRow, //treat from as a continuous Stream as we copy all of it const uint8_t *fromAsStream = (const uint8_t *) from; - int32_t streamSize = fromRows * fromColumns * sizeof(T); + size_t streamSize = fromRows * fromColumns * sizeof(T); ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; diff --git a/power/Fuse.cpp b/power/Fuse.cpp index dd5d3e3f4..a41aba494 100644 --- a/power/Fuse.cpp +++ b/power/Fuse.cpp @@ -86,8 +86,8 @@ ReturnValue_t Fuse::check() { return result; } -ReturnValue_t Fuse::serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { +ReturnValue_t Fuse::serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { ReturnValue_t result = RETURN_FAILED; for (DeviceList::const_iterator iter = devices.begin(); iter != devices.end(); iter++) { @@ -99,7 +99,7 @@ ReturnValue_t Fuse::serialize(uint8_t** buffer, uint32_t* size, return RETURN_OK; } -uint32_t Fuse::getSerializedSize() const { +size_t Fuse::getSerializedSize() const { uint32_t size = 0; for (DeviceList::const_iterator iter = devices.begin(); iter != devices.end(); iter++) { @@ -108,7 +108,7 @@ uint32_t Fuse::getSerializedSize() const { return size; } -ReturnValue_t Fuse::deSerialize(const uint8_t** buffer, int32_t* size, +ReturnValue_t Fuse::deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) { ReturnValue_t result = RETURN_FAILED; for (DeviceList::iterator iter = devices.begin(); iter != devices.end(); diff --git a/power/Fuse.h b/power/Fuse.h index 6da241788..d972e135a 100644 --- a/power/Fuse.h +++ b/power/Fuse.h @@ -18,7 +18,8 @@ void setStaticFrameworkObjectIds(); class Fuse: public SystemObject, public HasHealthIF, public HasReturnvaluesIF, - public ReceivesParameterMessagesIF { + public ReceivesParameterMessagesIF, + public SerializeIF { friend void (Factory::setStaticFrameworkObjectIds)(); private: static constexpr float RESIDUAL_POWER = 0.005 * 28.5; //!< This is the upper limit of residual power lost by fuses and switches. Worst case is Fuse and one of two switches on. See PCDU ICD 1.9 p29 bottom @@ -49,11 +50,13 @@ public: uint8_t getFuseId() const; ReturnValue_t initialize(); DeviceList devices; - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; - uint32_t getSerializedSize() const; - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, - bool bigEndian); + + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const override; + size_t getSerializedSize() const override; + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + bool bigEndian) override; + void setAllMonitorsToUnchecked(); ReturnValue_t performOperation(uint8_t opCode); MessageQueueId_t getCommandQueue() const; diff --git a/power/PowerComponent.cpp b/power/PowerComponent.cpp index 6a87d88b8..a8d54ee8f 100644 --- a/power/PowerComponent.cpp +++ b/power/PowerComponent.cpp @@ -17,8 +17,8 @@ PowerComponent::PowerComponent(object_id_t setId, uint8_t moduleId, float min, f twoSwitches), min(min), max(max), moduleId(moduleId) { } -ReturnValue_t PowerComponent::serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { +ReturnValue_t PowerComponent::serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { ReturnValue_t result = SerializeAdapter::serialize(&min, buffer, size, max_size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { @@ -28,7 +28,7 @@ ReturnValue_t PowerComponent::serialize(uint8_t** buffer, uint32_t* size, bigEndian); } -uint32_t PowerComponent::getSerializedSize() const { +size_t PowerComponent::getSerializedSize() const { return sizeof(min) + sizeof(max); } @@ -56,7 +56,7 @@ float PowerComponent::getMax() { return max; } -ReturnValue_t PowerComponent::deSerialize(const uint8_t** buffer, int32_t* size, +ReturnValue_t PowerComponent::deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) { ReturnValue_t result = SerializeAdapter::deSerialize(&min, buffer, size, bigEndian); diff --git a/power/PowerComponent.h b/power/PowerComponent.h index a82fe1d7f..c21596707 100644 --- a/power/PowerComponent.h +++ b/power/PowerComponent.h @@ -19,13 +19,13 @@ public: float getMin(); float getMax(); - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const override; - uint32_t getSerializedSize() const; + size_t getSerializedSize() const override; - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, - bool bigEndian); + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + bool bigEndian) override; ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, ParameterWrapper *parameterWrapper, diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index 8cec25631..994f29d90 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -23,7 +23,7 @@ SerialBufferAdapter::~SerialBufferAdapter() { template ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, size_t* size, - const uint32_t max_size, bool bigEndian) const { + const size_t max_size, bool bigEndian) const { uint32_t serializedLength = bufferLength; if (serializeLength) { serializedLength += AutoSerializeAdapter::getSerializedSize( diff --git a/thermal/ThermalComponent.cpp b/thermal/ThermalComponent.cpp index bf6f73986..d7e043bc1 100644 --- a/thermal/ThermalComponent.cpp +++ b/thermal/ThermalComponent.cpp @@ -42,19 +42,18 @@ ReturnValue_t ThermalComponent::setTargetState(int8_t newState) { } } -ReturnValue_t ThermalComponent::setLimits(const uint8_t* data, uint32_t size) { +ReturnValue_t ThermalComponent::setLimits(const uint8_t* data, size_t size) { if (size != 4 * sizeof(parameters.lowerOpLimit)) { return MonitoringIF::INVALID_SIZE; } - int32_t readSize = size; SerializeAdapter::deSerialize(&nopParameters.lowerNopLimit, &data, - &readSize, true); + &size, true); SerializeAdapter::deSerialize(¶meters.lowerOpLimit, &data, - &readSize, true); + &size, true); SerializeAdapter::deSerialize(¶meters.upperOpLimit, &data, - &readSize, true); + &size, true); SerializeAdapter::deSerialize(&nopParameters.upperNopLimit, &data, - &readSize, true); + &size, true); return HasReturnvaluesIF::RETURN_OK; } diff --git a/thermal/ThermalComponent.h b/thermal/ThermalComponent.h index 932438684..0372eaf73 100644 --- a/thermal/ThermalComponent.h +++ b/thermal/ThermalComponent.h @@ -29,7 +29,7 @@ public: ReturnValue_t setTargetState(int8_t newState); - virtual ReturnValue_t setLimits( const uint8_t* data, uint32_t size); + virtual ReturnValue_t setLimits( const uint8_t* data, size_t size); virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, ParameterWrapper *parameterWrapper, diff --git a/tmtcpacket/packetmatcher/ApidMatcher.h b/tmtcpacket/packetmatcher/ApidMatcher.h index 1f1949682..a11d35feb 100644 --- a/tmtcpacket/packetmatcher/ApidMatcher.h +++ b/tmtcpacket/packetmatcher/ApidMatcher.h @@ -22,16 +22,18 @@ public: return false; } } - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { - return SerializeAdapter::serialize(&apid, buffer, size, max_size, bigEndian); + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const override { + return SerializeAdapter::serialize(&apid, buffer, size, + max_size, bigEndian); } - uint32_t getSerializedSize() const { + size_t getSerializedSize() const override { return SerializeAdapter::getSerializedSize(&apid); } - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, - bool bigEndian) { - return SerializeAdapter::deSerialize(&apid, buffer, size, bigEndian); + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + bool bigEndian) override { + return SerializeAdapter::deSerialize(&apid, buffer, + size, bigEndian); } }; diff --git a/tmtcpacket/packetmatcher/ServiceMatcher.h b/tmtcpacket/packetmatcher/ServiceMatcher.h index 1a6781b40..8e61b8db7 100644 --- a/tmtcpacket/packetmatcher/ServiceMatcher.h +++ b/tmtcpacket/packetmatcher/ServiceMatcher.h @@ -22,16 +22,18 @@ public: return false; } } - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { - return SerializeAdapter::serialize(&service, buffer, size, max_size, bigEndian); + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { + return SerializeAdapter::serialize(&service, buffer, size, + max_size, bigEndian); } - uint32_t getSerializedSize() const { + size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&service); } - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) { - return SerializeAdapter::deSerialize(&service, buffer, size, bigEndian); + return SerializeAdapter::deSerialize(&service, buffer, + size, bigEndian); } }; diff --git a/tmtcpacket/packetmatcher/SubserviceMatcher.h b/tmtcpacket/packetmatcher/SubserviceMatcher.h index 1b589b201..7d0558f6d 100644 --- a/tmtcpacket/packetmatcher/SubserviceMatcher.h +++ b/tmtcpacket/packetmatcher/SubserviceMatcher.h @@ -20,16 +20,18 @@ public: return false; } } - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { - return SerializeAdapter::serialize(&subService, buffer, size, max_size, bigEndian); + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { + return SerializeAdapter::serialize(&subService, buffer, + size, max_size, bigEndian); } - uint32_t getSerializedSize() const { + size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&subService); } - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) { - return SerializeAdapter::deSerialize(&subService, buffer, size, bigEndian); + return SerializeAdapter::deSerialize(&subService, buffer, + size, bigEndian); } private: uint8_t subService; diff --git a/tmtcpacket/pus/TmPacketStored.cpp b/tmtcpacket/pus/TmPacketStored.cpp index f2c1eb28a..cad97cc1f 100644 --- a/tmtcpacket/pus/TmPacketStored.cpp +++ b/tmtcpacket/pus/TmPacketStored.cpp @@ -57,7 +57,7 @@ TmPacketStored::TmPacketStored(uint16_t apid, uint8_t service, setData(p_data); initializeTmPacket(apid, service, subservice, packetSubcounter); uint8_t* putDataHere = getSourceData(); - uint32_t size = 0; + size_t size = 0; if (header != NULL) { header->serialize(&putDataHere, &size, sourceDataSize, true); } diff --git a/tmtcservices/CommandingServiceBase.cpp b/tmtcservices/CommandingServiceBase.cpp index d70b90428..a9ed569eb 100644 --- a/tmtcservices/CommandingServiceBase.cpp +++ b/tmtcservices/CommandingServiceBase.cpp @@ -235,7 +235,7 @@ void CommandingServiceBase::sendTmPacket(uint8_t subservice, object_id_t objectId, const uint8_t *data, uint32_t dataLen) { uint8_t buffer[sizeof(object_id_t)]; uint8_t* pBuffer = buffer; - uint32_t size = 0; + size_t size = 0; SerializeAdapter::serialize(&objectId, &pBuffer, &size, sizeof(object_id_t), true); TmPacketStored tmPacketStored(this->apid, this->service, subservice, diff --git a/tmtcservices/PusVerificationReport.h b/tmtcservices/PusVerificationReport.h index 7a173be9f..f8913627f 100644 --- a/tmtcservices/PusVerificationReport.h +++ b/tmtcservices/PusVerificationReport.h @@ -49,7 +49,7 @@ class PusSuccessReport { private: static const uint16_t MAX_SIZE = 7; uint8_t reportBuffer[MAX_SIZE]; - uint32_t reportSize; + size_t reportSize; uint8_t * pBuffer; public: PusSuccessReport(uint16_t setPacketId, uint16_t setSequenceControl, @@ -63,7 +63,7 @@ class PusFailureReport { private: static const uint16_t MAX_SIZE = 16; uint8_t reportBuffer[MAX_SIZE]; - uint32_t reportSize; + size_t reportSize; uint8_t * pBuffer; public: PusFailureReport(uint16_t setPacketId, uint16_t setSequenceControl, -- 2.34.1 From 9349b393bb1f36ccde3838989b414f6656d93a4d Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 4 May 2020 19:45:12 +0200 Subject: [PATCH 12/16] sizet replacement for pool vector --- datapool/PoolVector.h | 10 +++++----- serialize/SerialBufferAdapter.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/datapool/PoolVector.h b/datapool/PoolVector.h index d3617d17a..2f0501a33 100644 --- a/datapool/PoolVector.h +++ b/datapool/PoolVector.h @@ -197,8 +197,8 @@ public: return *this; } - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const override { uint16_t i; ReturnValue_t result; for (i = 0; i < vector_size; i++) { @@ -211,12 +211,12 @@ public: return result; } - virtual uint32_t getSerializedSize() const { + virtual size_t getSerializedSize() const override { return vector_size * SerializeAdapter::getSerializedSize(value); } - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, - bool bigEndian) { + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + bool bigEndian) override { uint16_t i; ReturnValue_t result; for (i = 0; i < vector_size; i++) { diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index 994f29d90..2a6e20482 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -91,4 +91,4 @@ ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, template class SerialBufferAdapter; template class SerialBufferAdapter; template class SerialBufferAdapter; - +template class SerialBufferAdapter; -- 2.34.1 From 1131aa54d8b8ce8dc20f318a8b3188c983a373c2 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 4 May 2020 19:58:07 +0200 Subject: [PATCH 13/16] added fix so that unit test runs --- storagemanager/LocalPool.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storagemanager/LocalPool.h b/storagemanager/LocalPool.h index 08cb017fc..03985bde6 100644 --- a/storagemanager/LocalPool.h +++ b/storagemanager/LocalPool.h @@ -263,7 +263,7 @@ inline ReturnValue_t LocalPool::reserveSpace( size_list[address->pool_index][address->packet_index] = size; } else { - if (!ignoreFault) { + if (!ignoreFault and internalErrorReporter != nullptr) { internalErrorReporter->storeFull(); } // error << "LocalPool( " << std::hex << getObjectId() << std::dec -- 2.34.1 From 52eeda87db9bfe6f507bce64155f05e1472280ba Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 5 Jun 2020 18:19:25 +0200 Subject: [PATCH 14/16] important bugfix for serial buffer adapter --- serialize/SerialBufferAdapter.cpp | 103 +++++++++++++++++++----------- serialize/SerialBufferAdapter.h | 66 +++++++++++++++---- 2 files changed, 120 insertions(+), 49 deletions(-) diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index 2a6e20482..db91a93fd 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -1,29 +1,28 @@ #include +#include #include +template +SerialBufferAdapter::SerialBufferAdapter(const uint8_t* buffer, + count_t bufferLength, bool serializeLength) : + serializeLength(serializeLength), + constBuffer(buffer), buffer(nullptr), + bufferLength(bufferLength) {} + +template +SerialBufferAdapter::SerialBufferAdapter(uint8_t* buffer, + count_t bufferLength, bool serializeLength) : + serializeLength(serializeLength), buffer(buffer), constBuffer(buffer), + bufferLength(bufferLength) {} -template -SerialBufferAdapter::SerialBufferAdapter(const uint8_t* buffer, - T bufferLength, bool serializeLenght) : - serializeLength(serializeLenght), constBuffer(buffer), buffer(NULL), bufferLength( - bufferLength) { +template +SerialBufferAdapter::~SerialBufferAdapter() { } -template -SerialBufferAdapter::SerialBufferAdapter(uint8_t* buffer, T bufferLength, - bool serializeLenght) : - serializeLength(serializeLenght), constBuffer(NULL), buffer(buffer), bufferLength( - bufferLength) { -} - -template -SerialBufferAdapter::~SerialBufferAdapter() { -} - -template -ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, size_t* size, - const size_t max_size, bool bigEndian) const { +template +ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, + size_t* size, const size_t max_size, bool bigEndian) const { uint32_t serializedLength = bufferLength; if (serializeLength) { serializedLength += AutoSerializeAdapter::getSerializedSize( @@ -36,10 +35,10 @@ ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, size_t* size, AutoSerializeAdapter::serialize(&bufferLength, buffer, size, max_size, bigEndian); } - if (this->constBuffer != NULL) { - memcpy(*buffer, this->constBuffer, bufferLength); - } else if (this->buffer != NULL) { - memcpy(*buffer, this->buffer, bufferLength); + if (constBuffer != nullptr) { + memcpy(*buffer, constBuffer, bufferLength); + } else if (buffer != nullptr) { + memcpy(*buffer, buffer, bufferLength); } else { return HasReturnvaluesIF::RETURN_FAILED; } @@ -49,46 +48,76 @@ ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, size_t* size, } } -template -size_t SerialBufferAdapter::getSerializedSize() const { +template +size_t SerialBufferAdapter::getSerializedSize() const { if (serializeLength) { return bufferLength + AutoSerializeAdapter::getSerializedSize(&bufferLength); } else { return bufferLength; } } -template -ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, + +template +ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) { //TODO Ignores Endian flag! - if (buffer != NULL) { - if(serializeLength){ - T serializedSize = AutoSerializeAdapter::getSerializedSize( + if (buffer != nullptr) { + if(serializeLength) { + count_t serializedSize = AutoSerializeAdapter::getSerializedSize( &bufferLength); - if((*size - bufferLength - serializedSize) >= 0){ + if(bufferLength + serializedSize <= *size) { *buffer += serializedSize; *size -= serializedSize; - }else{ + } + else { return STREAM_TOO_SHORT; } } //No Else If, go on with buffer - if (*size - bufferLength >= 0) { + if (bufferLength <= *size) { *size -= bufferLength; - memcpy(this->buffer, *buffer, bufferLength); + memcpy(buffer, *buffer, bufferLength); (*buffer) += bufferLength; return HasReturnvaluesIF::RETURN_OK; - } else { + } + else { return STREAM_TOO_SHORT; } - } else { + } + else { return HasReturnvaluesIF::RETURN_FAILED; } } +template +uint8_t * SerialBufferAdapter::getBuffer() { + if(buffer == nullptr) { + sif::error << "Wrong access function for stored type !" + " Use getConstBuffer()" << std::endl; + return nullptr; + } + return buffer; +} + +template +const uint8_t * SerialBufferAdapter::getConstBuffer() { + if(constBuffer == nullptr) { + sif::error << "SerialBufferAdapter: Buffers are unitialized!" << std::endl; + return nullptr; + } + return constBuffer; +} + +template +void SerialBufferAdapter::setBuffer(uint8_t* buffer, + count_t buffer_length) { + this->buffer = buffer; + bufferLength = buffer_length; +} + //forward Template declaration for linker template class SerialBufferAdapter; template class SerialBufferAdapter; template class SerialBufferAdapter; -template class SerialBufferAdapter; + diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index 4b380d9ea..cb799be5e 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -5,32 +5,74 @@ #include /** + * 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>. + * Right now, the SerialBufferAdapter must always + * be initialized with the buffer and size ! + * * \ingroup serialize */ -template +template class SerialBufferAdapter: public SerializeIF { public: - SerialBufferAdapter(const uint8_t * buffer, T bufferLength, - bool serializeLenght = false); - SerialBufferAdapter(uint8_t* buffer, T bufferLength, - bool serializeLenght = 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); virtual ~SerialBufferAdapter(); virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, const size_t max_size, bool bigEndian) const override; - virtual size_t getSerializedSize() const override; + virtual size_t getSerializedSize() const; + /** + * @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, bool bigEndian) override; + + uint8_t * getBuffer(); + const uint8_t * getConstBuffer(); + void setBuffer(uint8_t* buffer_, count_t bufferLength_); private: - bool serializeLength; - const uint8_t *constBuffer; - uint8_t *buffer; - T bufferLength; + bool serializeLength = false; + const uint8_t *constBuffer = nullptr; + uint8_t *buffer = nullptr; + count_t bufferLength = 0; }; - - #endif /* SERIALBUFFERADAPTER_H_ */ -- 2.34.1 From 58a9d795ff45f0edb1c56edb1d97f27bae37e701 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 5 Jun 2020 18:36:54 +0200 Subject: [PATCH 15/16] small important bugfix --- serialize/SerialBufferAdapter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index db91a93fd..ad4ec358b 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -76,7 +76,7 @@ ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, //No Else If, go on with buffer if (bufferLength <= *size) { *size -= bufferLength; - memcpy(buffer, *buffer, bufferLength); + memcpy(this->buffer, *buffer, bufferLength); (*buffer) += bufferLength; return HasReturnvaluesIF::RETURN_OK; } -- 2.34.1 From d8f45d7b676e1d2cce8a7ab4bc481c02737ada2b Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 11 Jun 2020 16:47:35 +0200 Subject: [PATCH 16/16] critical bugfixes --- serialize/SerialBufferAdapter.cpp | 33 ++++++++++++++++++------------- serialize/SerialBufferAdapter.h | 4 ++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index ad4ec358b..5e834fe26 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -12,7 +12,7 @@ SerialBufferAdapter::SerialBufferAdapter(const uint8_t* buffer, template SerialBufferAdapter::SerialBufferAdapter(uint8_t* buffer, count_t bufferLength, bool serializeLength) : - serializeLength(serializeLength), buffer(buffer), constBuffer(buffer), + serializeLength(serializeLength), constBuffer(buffer), buffer(buffer), bufferLength(bufferLength) {} @@ -21,29 +21,33 @@ SerialBufferAdapter::~SerialBufferAdapter() { } template -ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, - size_t* size, const size_t max_size, bool bigEndian) const { +ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer_, + size_t* size_, const size_t max_size, bool bigEndian) const { uint32_t serializedLength = bufferLength; if (serializeLength) { serializedLength += AutoSerializeAdapter::getSerializedSize( &bufferLength); } - if (*size + serializedLength > max_size) { + if (*size_ + serializedLength > max_size) { return BUFFER_TOO_SHORT; } else { if (serializeLength) { - AutoSerializeAdapter::serialize(&bufferLength, buffer, size, + AutoSerializeAdapter::serialize(&bufferLength, buffer_, size_, max_size, bigEndian); } if (constBuffer != nullptr) { - memcpy(*buffer, constBuffer, bufferLength); - } else if (buffer != nullptr) { - memcpy(*buffer, buffer, bufferLength); - } else { + memcpy(*buffer_, this->constBuffer, bufferLength); + } + else if (buffer != nullptr) { + // This will propably be never reached, constBuffer should always be + // set if non-const buffer is set. + memcpy(*buffer_, this->buffer, bufferLength); + } + else { return HasReturnvaluesIF::RETURN_FAILED; } - *size += bufferLength; - (*buffer) += bufferLength; + *size_ += bufferLength; + (*buffer_) += bufferLength; return HasReturnvaluesIF::RETURN_OK; } } @@ -93,7 +97,7 @@ template uint8_t * SerialBufferAdapter::getBuffer() { if(buffer == nullptr) { sif::error << "Wrong access function for stored type !" - " Use getConstBuffer()" << std::endl; + " Use getConstBuffer()." << std::endl; return nullptr; } return buffer; @@ -110,9 +114,10 @@ const uint8_t * SerialBufferAdapter::getConstBuffer() { template void SerialBufferAdapter::setBuffer(uint8_t* buffer, - count_t buffer_length) { + count_t bufferLength) { this->buffer = buffer; - bufferLength = buffer_length; + this->constBuffer = buffer; + this->bufferLength = bufferLength; } diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index cb799be5e..a30451a1a 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -45,7 +45,7 @@ public: virtual ~SerialBufferAdapter(); - virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + virtual ReturnValue_t serialize(uint8_t** buffer_, size_t* size, const size_t max_size, bool bigEndian) const override; virtual size_t getSerializedSize() const; @@ -67,7 +67,7 @@ public: uint8_t * getBuffer(); const uint8_t * getConstBuffer(); - void setBuffer(uint8_t* buffer_, count_t bufferLength_); + void setBuffer(uint8_t* buffer, count_t bufferLength); private: bool serializeLength = false; const uint8_t *constBuffer = nullptr; -- 2.34.1