#include #include #include template SerialBufferAdapter::SerialBufferAdapter(const uint8_t* buffer, count_t bufferLength, bool serializeLength) : serializeLength(serializeLength), constBuffer(buffer), buffer(nullptr), bufferLength(bufferLength) {} template SerialBufferAdapter::SerialBufferAdapter(uint8_t* buffer, count_t bufferLength, bool serializeLength) : serializeLength(serializeLength), constBuffer(buffer), buffer(buffer), bufferLength(bufferLength) {} template SerialBufferAdapter::~SerialBufferAdapter() { } template ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer_, size_t* size_, const size_t max_size, bool bigEndian) const { uint32_t serializedLength = bufferLength; if (serializeLength) { serializedLength += AutoSerializeAdapter::getSerializedSize( &bufferLength); } if (*size_ + serializedLength > max_size) { return BUFFER_TOO_SHORT; } else { if (serializeLength) { AutoSerializeAdapter::serialize(&bufferLength, buffer_, size_, max_size, bigEndian); } if (constBuffer != nullptr) { memcpy(*buffer_, this->constBuffer, bufferLength); } else if (buffer != nullptr) { memcpy(*buffer_, this->buffer, bufferLength); } else { return HasReturnvaluesIF::RETURN_FAILED; } *size_ += bufferLength; (*buffer_) += bufferLength; return HasReturnvaluesIF::RETURN_OK; } } template size_t SerialBufferAdapter::getSerializedSize() const { if (serializeLength) { return bufferLength + AutoSerializeAdapter::getSerializedSize(&bufferLength); } else { return bufferLength; } } template ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, size_t* size, bool bigEndian) { //TODO Ignores Endian flag! if (buffer != nullptr) { if(serializeLength) { count_t serializedSize = AutoSerializeAdapter::getSerializedSize( &bufferLength); if(bufferLength + serializedSize <= *size) { *buffer += serializedSize; *size -= serializedSize; } else { return STREAM_TOO_SHORT; } } //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; } } else { return HasReturnvaluesIF::RETURN_FAILED; } } template uint8_t * SerialBufferAdapter::getBuffer() { if(buffer == nullptr) { sif::error << "Wrong access function for stored type !" " Use getConstBuffer()" << std::endl; return nullptr; } return buffer; } template const uint8_t * SerialBufferAdapter::getConstBuffer() { if(constBuffer == nullptr) { sif::error << "SerialBufferAdapter: Buffers are unitialized!" << std::endl; return nullptr; } return constBuffer; } template void SerialBufferAdapter::setBuffer(uint8_t* buffer, count_t buffer_length) { this->buffer = buffer; bufferLength = buffer_length; } //forward Template declaration for linker template class SerialBufferAdapter; template class SerialBufferAdapter; template class SerialBufferAdapter;