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,28 +65,31 @@ size_t SerialBufferAdapter<count_t>::getSerializedSize() const {
template<typename count_t> template<typename count_t>
ReturnValue_t SerialBufferAdapter<count_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 (this->buffer != nullptr) { return HasReturnvaluesIF::RETURN_FAILED;
if(serializeLength){ }
ReturnValue_t result = SerializeAdapter::deSerialize(&bufferLength,
buffer, size, streamEndianness); if(serializeLength){
if(result != HasReturnvaluesIF::RETURN_OK) { count_t lengthField = 0;
return result; ReturnValue_t result = SerializeAdapter::deSerialize(&lengthField,
} buffer, size, streamEndianness);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
} }
//No Else If, go on with buffer if(lengthField > bufferLength) {
if (bufferLength <= *size) { return TOO_MANY_ELEMENTS;
*size -= bufferLength;
std::memcpy(this->buffer, *buffer, bufferLength);
(*buffer) += bufferLength;
return HasReturnvaluesIF::RETURN_OK;
}
else {
return STREAM_TOO_SHORT;
} }
bufferLength = lengthField;
}
if (bufferLength <= *size) {
*size -= bufferLength;
std::memcpy(this->buffer, *buffer, bufferLength);
(*buffer) += bufferLength;
return HasReturnvaluesIF::RETURN_OK;
} }
else { else {
return HasReturnvaluesIF::RETURN_FAILED; return STREAM_TOO_SHORT;
} }
} }