Merge branch 'mueller/master' into mueller/project/distribDatapool
This commit is contained in:
commit
3aa6858c93
@ -20,40 +20,40 @@ template<typename count_t>
|
||||
SerialBufferAdapter<count_t>::~SerialBufferAdapter() {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ReturnValue_t SerialBufferAdapter<T>::serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
uint32_t serializedLength = bufferLength;
|
||||
template<typename count_t>
|
||||
ReturnValue_t SerialBufferAdapter<count_t>::serialize(uint8_t** buffer,
|
||||
size_t* size, size_t maxSize, Endianness streamEndianness) const {
|
||||
if (serializeLength) {
|
||||
serializedLength += SerializeAdapter::getSerializedSize(
|
||||
&bufferLength);
|
||||
ReturnValue_t result = SerializeAdapter::serialize(&bufferLength,
|
||||
buffer, size, maxSize, streamEndianness);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (*size + serializedLength > maxSize) {
|
||||
|
||||
if (*size + bufferLength > maxSize) {
|
||||
return BUFFER_TOO_SHORT;
|
||||
} else {
|
||||
if (serializeLength) {
|
||||
SerializeAdapter::serialize(&bufferLength, buffer, size,
|
||||
maxSize, streamEndianness);
|
||||
}
|
||||
if (constBuffer != nullptr) {
|
||||
memcpy(*buffer, this->constBuffer, bufferLength);
|
||||
}
|
||||
else if (buffer != nullptr) {
|
||||
// This will propably be never reached, constBuffer should always be
|
||||
// set if non-const buffer is set.
|
||||
memcpy(*buffer, this->buffer, bufferLength);
|
||||
}
|
||||
else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
*size += bufferLength;
|
||||
(*buffer) += bufferLength;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
if (this->constBuffer != nullptr) {
|
||||
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.
|
||||
std::memcpy(*buffer, this->buffer, bufferLength);
|
||||
}
|
||||
else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
*size += bufferLength;
|
||||
(*buffer) += bufferLength;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
size_t SerialBufferAdapter<T>::getSerializedSize() const {
|
||||
template<typename count_t>
|
||||
size_t SerialBufferAdapter<count_t>::getSerializedSize() const {
|
||||
if (serializeLength) {
|
||||
return bufferLength + SerializeAdapter::getSerializedSize(&bufferLength);
|
||||
} else {
|
||||
@ -61,35 +61,34 @@ size_t SerialBufferAdapter<T>::getSerializedSize() const {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ReturnValue_t SerialBufferAdapter<T>::deSerialize(const uint8_t** buffer,
|
||||
template<typename count_t>
|
||||
ReturnValue_t SerialBufferAdapter<count_t>::deSerialize(const uint8_t** buffer,
|
||||
size_t* size, Endianness streamEndianness) {
|
||||
//TODO Ignores Endian flag!
|
||||
if (buffer != NULL) {
|
||||
if(serializeLength){
|
||||
T serializedSize = SerializeAdapter::getSerializedSize(
|
||||
&bufferLength);
|
||||
if(bufferLength + serializedSize <= *size) {
|
||||
*buffer += serializedSize;
|
||||
*size -= serializedSize;
|
||||
}
|
||||
else {
|
||||
return STREAM_TOO_SHORT;
|
||||
}
|
||||
if (this->buffer == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
if(serializeLength){
|
||||
count_t lengthField = 0;
|
||||
ReturnValue_t result = SerializeAdapter::deSerialize(&lengthField,
|
||||
buffer, size, streamEndianness);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
//No Else If, go on with buffer
|
||||
if (bufferLength <= *size) {
|
||||
*size -= bufferLength;
|
||||
memcpy(this->buffer, *buffer, bufferLength);
|
||||
(*buffer) += bufferLength;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return STREAM_TOO_SHORT;
|
||||
if(lengthField > bufferLength) {
|
||||
return TOO_MANY_ELEMENTS;
|
||||
}
|
||||
bufferLength = lengthField;
|
||||
}
|
||||
|
||||
if (bufferLength <= *size) {
|
||||
*size -= bufferLength;
|
||||
std::memcpy(this->buffer, *buffer, bufferLength);
|
||||
(*buffer) += bufferLength;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
return STREAM_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,7 +105,8 @@ uint8_t * SerialBufferAdapter<count_t>::getBuffer() {
|
||||
template<typename count_t>
|
||||
const uint8_t * SerialBufferAdapter<count_t>::getConstBuffer() {
|
||||
if(constBuffer == nullptr) {
|
||||
sif::error << "SerialBufferAdapter: Buffers are unitialized!" << std::endl;
|
||||
sif::error << "SerialBufferAdapter::getConstBuffer:"
|
||||
" Buffers are unitialized!" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
return constBuffer;
|
||||
@ -125,4 +125,5 @@ void SerialBufferAdapter<count_t>::setBuffer(uint8_t* buffer,
|
||||
template class SerialBufferAdapter<uint8_t>;
|
||||
template class SerialBufferAdapter<uint16_t>;
|
||||
template class SerialBufferAdapter<uint32_t>;
|
||||
template class SerialBufferAdapter<uint64_t>;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user