integrated pool raw access serialize changes

This commit is contained in:
Robin Müller 2020-07-05 00:28:06 +02:00
parent 24240b6c7d
commit 1a177d2efa
2 changed files with 34 additions and 56 deletions

View File

@ -1,7 +1,7 @@
#include <framework/datapoolglob/GlobalDataPool.h> #include <framework/datapoolglob/GlobalDataPool.h>
#include <framework/datapoolglob/PoolRawAccess.h> #include <framework/datapoolglob/PoolRawAccess.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <framework/osal/Endiness.h> #include <framework/serialize/EndianConverter.h>
#include <cstring> #include <cstring>
@ -130,15 +130,7 @@ ReturnValue_t PoolRawAccess::getEntryEndianSafe(uint8_t* buffer,
return DATA_POOL_ACCESS_FAILED; return DATA_POOL_ACCESS_FAILED;
if (typeSize > max_size) if (typeSize > max_size)
return INCORRECT_SIZE; return INCORRECT_SIZE;
#ifndef BYTE_ORDER_SYSTEM EndianConverter::convertBigEndian(buffer, data_ptr, typeSize);
#error BYTE_ORDER_SYSTEM not defined
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
for (uint8_t count = 0; count < typeSize; count++) {
buffer[count] = data_ptr[typeSize - count - 1];
}
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
memcpy(buffer, data_ptr, typeSize);
#endif
*writtenBytes = typeSize; *writtenBytes = typeSize;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
@ -146,21 +138,18 @@ ReturnValue_t PoolRawAccess::getEntryEndianSafe(uint8_t* buffer,
ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, size_t* size, ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, size_t* size,
size_t maxSize, Endianness streamEndianness) const { size_t maxSize, Endianness streamEndianness) const {
//TODO integer overflow
if (typeSize + *size <= maxSize) { if (typeSize + *size <= maxSize) {
#warning use endian swapper switch(streamEndianness) {
if (1) { case(Endianness::BIG):
#ifndef BYTE_ORDER_SYSTEM EndianConverter::convertBigEndian(*buffer, value, typeSize);
#error BYTE_ORDER_SYSTEM not defined break;
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN case(Endianness::LITTLE):
for (uint8_t count = 0; count < typeSize; count++) { EndianConverter::convertLittleEndian(*buffer, value, typeSize);
(*buffer)[count] = value[typeSize - count - 1]; break;
} case(Endianness::MACHINE):
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN default:
memcpy(*buffer, value, typeSize);
#endif
} else {
memcpy(*buffer, value, typeSize); memcpy(*buffer, value, typeSize);
break;
} }
*size += typeSize; *size += typeSize;
(*buffer) += typeSize; (*buffer) += typeSize;
@ -175,11 +164,11 @@ Type PoolRawAccess::getType() {
return type; return type;
} }
uint8_t PoolRawAccess::getSizeOfType() { size_t PoolRawAccess::getSizeOfType() {
return typeSize; return typeSize;
} }
uint8_t PoolRawAccess::getArraySize(){ size_t PoolRawAccess::getArraySize(){
return arraySize; return arraySize;
} }
@ -191,22 +180,14 @@ PoolVariableIF::ReadWriteMode_t PoolRawAccess::getReadWriteMode() const {
return readWriteMode; return readWriteMode;
} }
ReturnValue_t PoolRawAccess::setEntryFromBigEndian(const uint8_t* buffer, ReturnValue_t PoolRawAccess::setEntryFromBigEndian(const uint8_t *buffer,
uint32_t setSize) { size_t setSize) {
if (typeSize == setSize) { if (typeSize == setSize) {
#ifndef BYTE_ORDER_SYSTEM EndianConverter::convertBigEndian(value, buffer, typeSize);
#error BYTE_ORDER_SYSTEM not defined
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
for (uint8_t count = 0; count < typeSize; count++) {
value[count] = buffer[typeSize - count - 1];
}
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
memcpy(value, buffer, typeSize);
#endif
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} else { } else {
sif::error << "PoolRawAccess::setEntryFromBigEndian: Illegal sizes: Internal" sif::error << "PoolRawAccess::setEntryFromBigEndian: Illegal sizes: "
<< (uint32_t) typeSize << ", Requested: " << setSize "Internal" << (uint32_t) typeSize << ", Requested: " << setSize
<< std::endl; << std::endl;
return INCORRECT_SIZE; return INCORRECT_SIZE;
} }
@ -232,27 +213,24 @@ size_t PoolRawAccess::getSerializedSize() const {
return typeSize; return typeSize;
} }
ReturnValue_t PoolRawAccess::deSerialize(const uint8_t** buffer, size_t* size, ReturnValue_t PoolRawAccess::deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) { Endianness streamEndianness) {
if (*size >= typeSize) { if (*size >= typeSize) {
*size -= typeSize; switch(streamEndianness) {
if (1) { case(Endianness::BIG):
#ifndef BYTE_ORDER_SYSTEM EndianConverter::convertBigEndian(value, *buffer, typeSize);
#error BYTE_ORDER_SYSTEM not defined break;
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN case(Endianness::LITTLE):
for (uint8_t count = 0; count < typeSize; count++) { EndianConverter::convertLittleEndian(value, *buffer, typeSize);
value[count] = (*buffer)[typeSize - count - 1]; break;
} case(Endianness::MACHINE):
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN default:
memcpy(value, *buffer, typeSize);
#endif
} else {
memcpy(value, *buffer, typeSize); memcpy(value, *buffer, typeSize);
break;
} }
*size -= typeSize;
*buffer += typeSize; *buffer += typeSize;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} else {
return SerializeIF::STREAM_TOO_SHORT;
} }
} }

View File

@ -85,7 +85,7 @@ public:
* - @c RETURN_FAILED on failure * - @c RETURN_FAILED on failure
*/ */
ReturnValue_t setEntryFromBigEndian(const uint8_t* buffer, ReturnValue_t setEntryFromBigEndian(const uint8_t* buffer,
uint32_t setSize); size_t setSize);
/** /**
* @brief This operation returns the type of the entry currently stored. * @brief This operation returns the type of the entry currently stored.
*/ */
@ -93,12 +93,12 @@ public:
/** /**
* @brief This operation returns the size of the entry currently stored. * @brief This operation returns the size of the entry currently stored.
*/ */
uint8_t getSizeOfType(); size_t getSizeOfType();
/** /**
* *
* @return the size of the datapool array * @return the size of the datapool array
*/ */
uint8_t getArraySize(); size_t getArraySize();
/** /**
* @brief This operation returns the data pool id of the variable. * @brief This operation returns the data pool id of the variable.
*/ */