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