WIP: somethings wrong.. #19
@ -1,24 +1,27 @@
|
|||||||
#include <framework/serialize/SerialBufferAdapter.h>
|
#include <framework/serialize/SerialBufferAdapter.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SerialBufferAdapter<T>::SerialBufferAdapter(const uint8_t* buffer,
|
SerialBufferAdapter<T>::SerialBufferAdapter(const uint8_t* buffer,
|
||||||
T bufferLength, bool serializeLength) :
|
T bufferLength, bool serializeLength) :
|
||||||
serializeLength(serializeLength), constBuffer(buffer), buffer(NULL), bufferLength(
|
currentBufferType(bufferType::CONST), serializeLength(serializeLength),
|
||||||
bufferLength) {
|
constBuffer(buffer), buffer(NULL), bufferLength(bufferLength) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SerialBufferAdapter<T>::SerialBufferAdapter(uint8_t* buffer, T bufferLength,
|
SerialBufferAdapter<T>::SerialBufferAdapter(uint8_t* buffer, T bufferLength,
|
||||||
bool serializeLength) :
|
bool serializeLength) :
|
||||||
serializeLength(serializeLength), constBuffer(NULL), buffer(buffer), bufferLength(
|
currentBufferType(bufferType::NORMAL),serializeLength(serializeLength), constBuffer(NULL), buffer(buffer),
|
||||||
bufferLength) {
|
bufferLength(bufferLength) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SerialBufferAdapter<T>::SerialBufferAdapter(uint32_t* buffer,
|
SerialBufferAdapter<T>::SerialBufferAdapter(uint32_t* buffer,
|
||||||
T bufferLength, bool serializeLength) :
|
T bufferLength, bool serializeLength) :
|
||||||
serializeLength(serializeLength), constBuffer(NULL), buffer(reinterpret_cast<uint8_t *>(buffer)),
|
currentBufferType(bufferType::NORMAL),serializeLength(serializeLength),
|
||||||
|
constBuffer(NULL), buffer(reinterpret_cast<uint8_t *>(buffer)),
|
||||||
bufferLength(bufferLength*4) {
|
bufferLength(bufferLength*4) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,14 +96,28 @@ ReturnValue_t SerialBufferAdapter<T>::deSerialize(const uint8_t** buffer,
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
uint8_t * SerialBufferAdapter<T>::getBuffer() {
|
uint8_t * SerialBufferAdapter<T>::getBuffer() {
|
||||||
|
if(currentBufferType != NORMAL) {
|
||||||
|
warning << "Wrong access function for stored type ! Use getConstBuffer()" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
const uint8_t * SerialBufferAdapter<T>::getConstBuffer() {
|
||||||
|
if(currentBufferType != CONST) {
|
||||||
|
warning << "Wrong access function for stored type ! Use getBuffer()" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return constBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void SerialBufferAdapter<T>::setBuffer(uint8_t * buffer_) {
|
void SerialBufferAdapter<T>::setBuffer(uint8_t * buffer_) {
|
||||||
buffer = buffer_;
|
buffer = buffer_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//forward Template declaration for linker
|
//forward Template declaration for linker
|
||||||
template class SerialBufferAdapter<uint8_t>;
|
template class SerialBufferAdapter<uint8_t>;
|
||||||
template class SerialBufferAdapter<uint16_t>;
|
template class SerialBufferAdapter<uint16_t>;
|
||||||
|
@ -28,7 +28,7 @@ public:
|
|||||||
SerialBufferAdapter(const uint8_t * buffer, T bufferLength, bool serializeLength = false);
|
SerialBufferAdapter(const uint8_t * buffer, T bufferLength, bool serializeLength = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructoor for non-constant uint8_t buffer. Length field can be serialized optionally.
|
* Constructor for non-constant uint8_t buffer. Length field can be serialized optionally.
|
||||||
* Type of length can be supplied as template type.
|
* Type of length can be supplied as template type.
|
||||||
* @param buffer
|
* @param buffer
|
||||||
* @param bufferLength
|
* @param bufferLength
|
||||||
@ -56,8 +56,16 @@ public:
|
|||||||
bool bigEndian);
|
bool bigEndian);
|
||||||
|
|
||||||
uint8_t * getBuffer();
|
uint8_t * getBuffer();
|
||||||
|
const uint8_t * getConstBuffer();
|
||||||
void setBuffer(uint8_t * buffer_);
|
void setBuffer(uint8_t * buffer_);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
enum bufferType {
|
||||||
|
NORMAL,
|
||||||
|
CONST
|
||||||
|
};
|
||||||
|
bufferType currentBufferType;
|
||||||
|
|
||||||
bool serializeLength;
|
bool serializeLength;
|
||||||
const uint8_t *constBuffer;
|
const uint8_t *constBuffer;
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
|
Loading…
Reference in New Issue
Block a user