diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index 8a5bef4a..ab52262f 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -23,34 +23,33 @@ SerialBufferAdapter::~SerialBufferAdapter() { template ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const { - uint32_t serializedLength = bufferLength; if (serializeLength) { - serializedLength += SerializeAdapter::getSerializedSize( - &bufferLength); + ReturnValue_t result = SerializeAdapter::serialize(&bufferLength, + buffer, size, maxSize, streamEndianness); + if(result != HasReturnvaluesIF::RETURN_OK) { + return result; + } } - if (*size + serializedLength > maxSize) { + + if (*size + bufferLength > maxSize) { return BUFFER_TOO_SHORT; - } - else { - if (serializeLength) { - SerializeAdapter::serialize(&bufferLength, buffer, size, - maxSize, streamEndianness); - } - if (this->constBuffer != nullptr) { - memcpy(*buffer, this->constBuffer, bufferLength); - } - else if (this->buffer != nullptr) { - // This will propably be never reached, constBuffer should always be - // set if non-const buffer is set. - memcpy(*buffer, this->buffer, bufferLength); - } - else { - return HasReturnvaluesIF::RETURN_FAILED; - } - *size += bufferLength; - (*buffer) += bufferLength; - return HasReturnvaluesIF::RETURN_OK; } + + if (this->constBuffer != nullptr) { + std::memcpy(*buffer, this->constBuffer, bufferLength); + } + else if (this->buffer != nullptr) { + // This will propably be never reached, constBuffer should always be + // set if non-const buffer is set. + std::memcpy(*buffer, this->buffer, bufferLength); + } + else { + return HasReturnvaluesIF::RETURN_FAILED; + } + *size += bufferLength; + (*buffer) += bufferLength; + return HasReturnvaluesIF::RETURN_OK; + } template @@ -126,4 +125,6 @@ void SerialBufferAdapter::setBuffer(uint8_t* buffer, template class SerialBufferAdapter; template class SerialBufferAdapter; template class SerialBufferAdapter; +template class SerialBufferAdapter; +template class SerialBufferAdapter;