deSerialize fixed/improved

This commit is contained in:
Robin Müller 2020-08-25 13:29:36 +02:00
parent 857d61ea13
commit c8595c3442

View File

@ -65,16 +65,23 @@ size_t SerialBufferAdapter<count_t>::getSerializedSize() const {
template<typename count_t>
ReturnValue_t SerialBufferAdapter<count_t>::deSerialize(const uint8_t** buffer,
size_t* size, Endianness streamEndianness) {
//TODO Ignores Endian flag!
if (this->buffer != nullptr) {
if (this->buffer == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
if(serializeLength){
ReturnValue_t result = SerializeAdapter::deSerialize(&bufferLength,
count_t lengthField = 0;
ReturnValue_t result = SerializeAdapter::deSerialize(&lengthField,
buffer, size, streamEndianness);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if(lengthField > bufferLength) {
return TOO_MANY_ELEMENTS;
}
//No Else If, go on with buffer
bufferLength = lengthField;
}
if (bufferLength <= *size) {
*size -= bufferLength;
std::memcpy(this->buffer, *buffer, bufferLength);
@ -84,10 +91,6 @@ ReturnValue_t SerialBufferAdapter<count_t>::deSerialize(const uint8_t** buffer,
else {
return STREAM_TOO_SHORT;
}
}
else {
return HasReturnvaluesIF::RETURN_FAILED;
}
}
template<typename count_t>