compiling again
This commit is contained in:
@ -36,18 +36,18 @@ ReturnValue_t SerialBufferAdapter<T>::serialize(uint8_t** buffer, size_t* size,
|
||||
maxSize, streamEndianness);
|
||||
}
|
||||
if (constBuffer != nullptr) {
|
||||
memcpy(*buffer_, this->constBuffer, bufferLength);
|
||||
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);
|
||||
memcpy(*buffer, this->buffer, bufferLength);
|
||||
}
|
||||
else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
*size_ += bufferLength;
|
||||
(*buffer_) += bufferLength;
|
||||
*size += bufferLength;
|
||||
(*buffer) += bufferLength;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
}
|
||||
|
@ -39,30 +39,25 @@ public:
|
||||
*/
|
||||
template<typename... Args>
|
||||
SerialFixedArrayListAdapter(Args... args) :
|
||||
FixedArrayList<BUFFER_TYPE, MAX_SIZE, count_t>(std::forward<Args>(args)...)
|
||||
{}
|
||||
FixedArrayList<BUFFER_TYPE, MAX_SIZE, count_t>(
|
||||
std::forward<Args>(args)...){}
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t max_size, bool bigEndian) const override {
|
||||
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::serialize(this,
|
||||
buffer, size, max_size, bigEndian);
|
||||
}
|
||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::serialize(this,
|
||||
buffer, size, maxSize, streamEndianness);
|
||||
}
|
||||
|
||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
return SerialArrayListAdapter<T, count_t>::serialize(this, buffer, size, maxSize, streamEndianness);
|
||||
}
|
||||
size_t getSerializedSize() const {
|
||||
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::getSerializedSize(this);
|
||||
}
|
||||
|
||||
size_t getSerializedSize() const {
|
||||
return SerialArrayListAdapter<T, count_t>::getSerializedSize(this);
|
||||
}
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) {
|
||||
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::deSerialize(this,
|
||||
buffer, size, streamEndianness);
|
||||
}
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) {
|
||||
return SerialArrayListAdapter<T, count_t>::deSerialize(this, buffer, size, streamEndianness);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* SERIALFIXEDARRAYLISTADAPTER_H_ */
|
||||
|
@ -2,8 +2,9 @@
|
||||
#define SERIALIZEADAPTER_H_
|
||||
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/serialize/EndianSwapper.h>
|
||||
#include <framework/container/IsDerivedFrom.h>
|
||||
#include <framework/serialize/SerializeIF.h>
|
||||
#include <framework/serialize/SerializeAdapterInternal.h>
|
||||
#include <type_traits>
|
||||
|
||||
/**
|
||||
|
@ -1,118 +0,0 @@
|
||||
/**
|
||||
* @file SerializeAdapterInternal.h
|
||||
*
|
||||
* @date 13.04.2020
|
||||
* @author R. Mueller
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_SERIALIZE_SERIALIZEADAPTERINTERNAL_H_
|
||||
#define FRAMEWORK_SERIALIZE_SERIALIZEADAPTERINTERNAL_H_
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/container/IsDerivedFrom.h>
|
||||
#include <framework/serialize/EndianSwapper.h>
|
||||
|
||||
/**
|
||||
* This template specialization will be chosen for fundamental types or
|
||||
* anything else not implementing SerializeIF, based on partial
|
||||
* template specialization.
|
||||
* @tparam T
|
||||
* @tparam
|
||||
*/
|
||||
template<typename T, int>
|
||||
class SerializeAdapter_ {
|
||||
public:
|
||||
/**
|
||||
*
|
||||
* @param object
|
||||
* @param buffer
|
||||
* @param size
|
||||
* @param max_size
|
||||
* @param bigEndian
|
||||
* @return
|
||||
*/
|
||||
static ReturnValue_t serialize(const T* object, uint8_t** buffer,
|
||||
size_t* size, const size_t max_size, bool bigEndian) {
|
||||
// function eventuelly serializes structs here.
|
||||
// does this work on every architecture?
|
||||
// static_assert(std::is_fundamental<T>::value);
|
||||
size_t ignoredSize = 0;
|
||||
if (size == nullptr) {
|
||||
size = &ignoredSize;
|
||||
}
|
||||
if (sizeof(T) + *size <= max_size) {
|
||||
T tmp;
|
||||
if (bigEndian) {
|
||||
tmp = EndianSwapper::swap<T>(*object);
|
||||
} else {
|
||||
tmp = *object;
|
||||
}
|
||||
memcpy(*buffer, &tmp, sizeof(T));
|
||||
*size += sizeof(T);
|
||||
(*buffer) += sizeof(T);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::BUFFER_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize buffer into object
|
||||
* @param object [out] Object to be deserialized with buffer data
|
||||
* @param buffer contains the data. Non-Const pointer to non-const
|
||||
* pointer to const data.
|
||||
* @param size Size to deSerialize. wil be decremented by sizeof(T)
|
||||
* @param bigEndian Specify endianness
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t deSerialize(T* object, const uint8_t** buffer, size_t* size,
|
||||
bool bigEndian) {
|
||||
T tmp;
|
||||
if (*size >= sizeof(T)) {
|
||||
*size -= sizeof(T);
|
||||
memcpy(&tmp, *buffer, sizeof(T));
|
||||
if (bigEndian) {
|
||||
*object = EndianSwapper::swap<T>(tmp);
|
||||
} else {
|
||||
*object = tmp;
|
||||
}
|
||||
*buffer += sizeof(T);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
size_t getSerializedSize(const T * object) {
|
||||
return sizeof(T);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This template specialization will be chosen for class derived from
|
||||
* SerializeIF, based on partial template specialization.
|
||||
* @tparam T
|
||||
* @tparam
|
||||
*/
|
||||
template<typename T>
|
||||
class SerializeAdapter_<T, true> {
|
||||
public:
|
||||
ReturnValue_t serialize(const T* object, uint8_t** buffer, size_t* size,
|
||||
const size_t max_size, bool bigEndian) const {
|
||||
size_t ignoredSize = 0;
|
||||
if (size == NULL) {
|
||||
size = &ignoredSize;
|
||||
}
|
||||
return object->serialize(buffer, size, max_size, bigEndian);
|
||||
}
|
||||
|
||||
size_t getSerializedSize(const T* object) const {
|
||||
return object->getSerializedSize();
|
||||
}
|
||||
|
||||
ReturnValue_t deSerialize(T* object, const uint8_t** buffer, size_t* size,
|
||||
bool bigEndian) {
|
||||
return object->deSerialize(buffer, size, bigEndian);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_SERIALIZE_SERIALIZEADAPTERINTERNAL_H_ */
|
Reference in New Issue
Block a user