serializhe improved

This commit is contained in:
Robin Müller 2020-08-25 13:32:17 +02:00
parent c8595c3442
commit 7d2c48fb33

View File

@ -28,21 +28,26 @@ ReturnValue_t SerialBufferAdapter<count_t>::serialize(uint8_t** buffer,
serializedLength += SerializeAdapter::getSerializedSize(
&bufferLength);
}
if (*size + serializedLength > maxSize) {
return BUFFER_TOO_SHORT;
}
else {
if (serializeLength) {
SerializeAdapter::serialize(&bufferLength, buffer, size,
maxSize, streamEndianness);
ReturnValue_t result = SerializeAdapter::serialize(&bufferLength,
buffer, size, maxSize, streamEndianness);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
}
if (this->constBuffer != nullptr) {
memcpy(*buffer, this->constBuffer, bufferLength);
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.
memcpy(*buffer, this->buffer, bufferLength);
std::memcpy(*buffer, this->buffer, bufferLength);
}
else {
return HasReturnvaluesIF::RETURN_FAILED;
@ -50,7 +55,7 @@ ReturnValue_t SerialBufferAdapter<count_t>::serialize(uint8_t** buffer,
*size += bufferLength;
(*buffer) += bufferLength;
return HasReturnvaluesIF::RETURN_OK;
}
}
template<typename count_t>