diff --git a/datapool/PoolRawAccess.cpp b/datapool/PoolRawAccess.cpp index 555896bb..6e9b3d08 100644 --- a/datapool/PoolRawAccess.cpp +++ b/datapool/PoolRawAccess.cpp @@ -31,7 +31,10 @@ ReturnValue_t PoolRawAccess::read() { sizeTillEnd = read_out->getByteSize() - arrayPosition; uint8_t* ptr = &((uint8_t*) read_out->getRawData())[arrayPosition]; - memcpy(value, ptr, typeSize); + for(uint8_t arrayCount = 0; arrayCount < arraySize; arrayCount++) { + memcpy(value + typeSize * arrayCount, ptr + typeSize * arrayCount, typeSize); + } + return HasReturnvaluesIF::RETURN_OK; } else { //Error value type too large. @@ -152,17 +155,20 @@ ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, uint32_t* size, #ifndef BYTE_ORDER_SYSTEM #error BYTE_ORDER_SYSTEM not defined #elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN - for (uint8_t count = 0; count < typeSize; count++) { - (*buffer)[count] = value[typeSize - count - 1]; + for(uint8_t arrayCount = 0; arrayCount < arraySize; arrayCount++) { + for (uint8_t count = 0; count < typeSize; count++) { + (*buffer)[typeSize * (arrayCount + 1) - count - 1] = + value[typeSize * arrayCount + count]; + } } #elif BYTE_ORDER_SYSTEM == BIG_ENDIAN - memcpy(*buffer, value, typeSize); + memcpy(*buffer, value, typeSize * arraySize); #endif } else { - memcpy(*buffer, value, typeSize); + memcpy(*buffer, value, typeSize * arraySize); } - *size += typeSize; - (*buffer) += typeSize; + *size += typeSize * arraySize; + (*buffer) += typeSize * arraySize; return HasReturnvaluesIF::RETURN_OK; } else { return SerializeIF::BUFFER_TOO_SHORT; diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index 8b81894a..2a634fa8 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -48,7 +48,6 @@ private: ReadWriteMode_t readWriteMode; static const uint8_t RAW_MAX_SIZE = sizeof(double); protected: - /** * \brief The commit call writes back the variable's value to the data pool. * \details It checks type and size, as well as if the variable is writable. If so, @@ -80,6 +79,20 @@ public: * The operation does NOT provide any mutual exclusive protection by itself. */ ReturnValue_t read(); + + /** + * @brief Serialize raw pool entry into provided buffer directly + * @details Should be called after read() call. Endianness can be specified too + * @param buffer Provided buffer. Raw pool data will be copied here + * @param size [out] Increment provided size value by serialized size + * @param max_size Maximum allowed serialization size + * @param bigEndian Specify endianess + * @return - @c RETURN_OK if serialization was successfull + * - @c SerializeIF::BUFFER_TOO_SHORT if range check failed + */ + ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, + const uint32_t max_size, bool bigEndian) const; + /** * \brief This operation returns a pointer to the entry fetched. * \details Return pointer to the buffer containing the raw data @@ -142,9 +155,6 @@ public: */ uint16_t getSizeTillEnd() const; - 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, diff --git a/serialize/EndianSwapper.h b/serialize/EndianSwapper.h index dfd93484..db170c0b 100644 --- a/serialize/EndianSwapper.h +++ b/serialize/EndianSwapper.h @@ -44,6 +44,27 @@ public: #elif BYTE_ORDER_SYSTEM == BIG_ENDIAN memcpy(out, in, size); return; +#endif + } + + template + static void swap(T * out, const T * in, uint32_t size) { +#ifndef BYTE_ORDER_SYSTEM +#error BYTE_ORDER_SYSTEM not defined +#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN + const uint8_t * in_buffer = reinterpret_cast(in); + uint8_t * out_buffer = reinterpret_cast(out); + for (uint8_t count = 0; count < size; count++) { + for(uint8_t i = 0; i < sizeof(T);i++) { + out_buffer[sizeof(T)* (count + 1) - i - 1] = in_buffer[count * sizeof(T) + i]; + } + + } + + return; +#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN + memcpy(out, in, size*sizeof(T)); + return; #endif } }; diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index 9a8e6f06..d7ab0d88 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -96,6 +96,11 @@ uint8_t * SerialBufferAdapter::getBuffer() { return buffer; } +//template +//void SerialBufferAdapter::setBuffer(uint8_t * buffer_) { +// buffer = buffer_; +//} + //forward Template declaration for linker template class SerialBufferAdapter; template class SerialBufferAdapter; diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index 7496c137..0438f884 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -56,6 +56,7 @@ public: bool bigEndian); uint8_t * getBuffer(); + //void setBuffer(uint8_t * buffer_); private: bool serializeLength; const uint8_t *constBuffer; diff --git a/serialize/SerializeAdapter.h b/serialize/SerializeAdapter.h index 385f40d3..933d933d 100644 --- a/serialize/SerializeAdapter.h +++ b/serialize/SerializeAdapter.h @@ -76,6 +76,14 @@ public: } } + /** + * Deserialize buffer into object + * @param object [out] Object to be deserialized with buffer data + * @param buffer buffer containing the data + * @param size int32_t type to allow value to be values smaller than 0, needed for range/size checking + * @param bigEndian Specify endianness + * @return + */ ReturnValue_t deSerialize(T* object, const uint8_t** buffer, int32_t* size, bool bigEndian) { T tmp;