deserialize improved

This commit is contained in:
Robin Müller 2020-08-25 13:29:10 +02:00
parent c8ba486538
commit b97128c12e

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;
} }
} }