Merge branch 'mueller/master' into mueller/project/distribDatapool

This commit is contained in:
Robin Müller 2020-08-25 13:04:20 +02:00
commit 3aa6858c93

View File

@ -20,28 +20,28 @@ template<typename count_t>
SerialBufferAdapter<count_t>::~SerialBufferAdapter() { SerialBufferAdapter<count_t>::~SerialBufferAdapter() {
} }
template<typename T> template<typename count_t>
ReturnValue_t SerialBufferAdapter<T>::serialize(uint8_t** buffer, size_t* size, ReturnValue_t SerialBufferAdapter<count_t>::serialize(uint8_t** buffer,
size_t maxSize, Endianness streamEndianness) const { size_t* size, size_t maxSize, Endianness streamEndianness) const {
uint32_t serializedLength = bufferLength;
if (serializeLength) { if (serializeLength) {
serializedLength += SerializeAdapter::getSerializedSize( ReturnValue_t result = SerializeAdapter::serialize(&bufferLength,
&bufferLength); buffer, size, maxSize, streamEndianness);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
} }
if (*size + serializedLength > maxSize) { }
if (*size + bufferLength > maxSize) {
return BUFFER_TOO_SHORT; return BUFFER_TOO_SHORT;
} else {
if (serializeLength) {
SerializeAdapter::serialize(&bufferLength, buffer, size,
maxSize, streamEndianness);
} }
if (constBuffer != nullptr) {
memcpy(*buffer, this->constBuffer, bufferLength); if (this->constBuffer != nullptr) {
std::memcpy(*buffer, this->constBuffer, bufferLength);
} }
else if (buffer != nullptr) { else if (this->buffer != nullptr) {
// This will propably be never reached, constBuffer should always be // This will propably be never reached, constBuffer should always be
// set if non-const buffer is set. // set if non-const buffer is set.
memcpy(*buffer, this->buffer, bufferLength); std::memcpy(*buffer, this->buffer, bufferLength);
} }
else { else {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
@ -49,11 +49,11 @@ ReturnValue_t SerialBufferAdapter<T>::serialize(uint8_t** buffer, size_t* size,
*size += bufferLength; *size += bufferLength;
(*buffer) += bufferLength; (*buffer) += bufferLength;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
}
} }
template<typename T> template<typename count_t>
size_t SerialBufferAdapter<T>::getSerializedSize() const { size_t SerialBufferAdapter<count_t>::getSerializedSize() const {
if (serializeLength) { if (serializeLength) {
return bufferLength + SerializeAdapter::getSerializedSize(&bufferLength); return bufferLength + SerializeAdapter::getSerializedSize(&bufferLength);
} else { } else {
@ -61,36 +61,35 @@ size_t SerialBufferAdapter<T>::getSerializedSize() const {
} }
} }
template<typename T> template<typename count_t>
ReturnValue_t SerialBufferAdapter<T>::deSerialize(const uint8_t** buffer, ReturnValue_t SerialBufferAdapter<count_t>::deSerialize(const uint8_t** buffer,
size_t* size, Endianness streamEndianness) { size_t* size, Endianness streamEndianness) {
//TODO Ignores Endian flag! if (this->buffer == nullptr) {
if (buffer != NULL) { return HasReturnvaluesIF::RETURN_FAILED;
}
if(serializeLength){ if(serializeLength){
T serializedSize = SerializeAdapter::getSerializedSize( count_t lengthField = 0;
&bufferLength); ReturnValue_t result = SerializeAdapter::deSerialize(&lengthField,
if(bufferLength + serializedSize <= *size) { buffer, size, streamEndianness);
*buffer += serializedSize; if(result != HasReturnvaluesIF::RETURN_OK) {
*size -= serializedSize; return result;
} }
else { if(lengthField > bufferLength) {
return STREAM_TOO_SHORT; return TOO_MANY_ELEMENTS;
} }
bufferLength = lengthField;
} }
//No Else If, go on with buffer
if (bufferLength <= *size) { if (bufferLength <= *size) {
*size -= bufferLength; *size -= bufferLength;
memcpy(this->buffer, *buffer, bufferLength); std::memcpy(this->buffer, *buffer, bufferLength);
(*buffer) += bufferLength; (*buffer) += bufferLength;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
else { else {
return STREAM_TOO_SHORT; return STREAM_TOO_SHORT;
} }
}
else {
return HasReturnvaluesIF::RETURN_FAILED;
}
} }
template<typename count_t> template<typename count_t>
@ -106,7 +105,8 @@ uint8_t * SerialBufferAdapter<count_t>::getBuffer() {
template<typename count_t> template<typename count_t>
const uint8_t * SerialBufferAdapter<count_t>::getConstBuffer() { const uint8_t * SerialBufferAdapter<count_t>::getConstBuffer() {
if(constBuffer == nullptr) { if(constBuffer == nullptr) {
sif::error << "SerialBufferAdapter: Buffers are unitialized!" << std::endl; sif::error << "SerialBufferAdapter::getConstBuffer:"
" Buffers are unitialized!" << std::endl;
return nullptr; return nullptr;
} }
return constBuffer; return constBuffer;
@ -125,4 +125,5 @@ void SerialBufferAdapter<count_t>::setBuffer(uint8_t* buffer,
template class SerialBufferAdapter<uint8_t>; template class SerialBufferAdapter<uint8_t>;
template class SerialBufferAdapter<uint16_t>; template class SerialBufferAdapter<uint16_t>;
template class SerialBufferAdapter<uint32_t>; template class SerialBufferAdapter<uint32_t>;
template class SerialBufferAdapter<uint64_t>;