serial buffer adapter
This commit is contained in:
parent
8e7f167a66
commit
c8ba486538
@ -20,9 +20,9 @@ template<typename count_t>
|
|||||||
SerialBufferAdapter<count_t>::~SerialBufferAdapter() {
|
SerialBufferAdapter<count_t>::~SerialBufferAdapter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename count_t>
|
||||||
ReturnValue_t SerialBufferAdapter<T>::serialize(uint8_t** buffer, size_t* size,
|
ReturnValue_t SerialBufferAdapter<count_t>::serialize(uint8_t** buffer,
|
||||||
size_t maxSize, Endianness streamEndianness) const {
|
size_t* size, size_t maxSize, Endianness streamEndianness) const {
|
||||||
uint32_t serializedLength = bufferLength;
|
uint32_t serializedLength = bufferLength;
|
||||||
if (serializeLength) {
|
if (serializeLength) {
|
||||||
serializedLength += SerializeAdapter::getSerializedSize(
|
serializedLength += SerializeAdapter::getSerializedSize(
|
||||||
@ -53,8 +53,8 @@ ReturnValue_t SerialBufferAdapter<T>::serialize(uint8_t** buffer, size_t* size,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename count_t>
|
||||||
size_t SerialBufferAdapter<T>::getSerializedSize() const {
|
size_t SerialBufferAdapter<count_t>::getSerializedSize() const {
|
||||||
if (serializeLength) {
|
if (serializeLength) {
|
||||||
return bufferLength + SerializeAdapter::getSerializedSize(&bufferLength);
|
return bufferLength + SerializeAdapter::getSerializedSize(&bufferLength);
|
||||||
} else {
|
} else {
|
||||||
@ -62,26 +62,22 @@ size_t SerialBufferAdapter<T>::getSerializedSize() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename count_t>
|
||||||
ReturnValue_t SerialBufferAdapter<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!
|
//TODO Ignores Endian flag!
|
||||||
if (buffer != NULL) {
|
if (this->buffer != nullptr) {
|
||||||
if(serializeLength){
|
if(serializeLength){
|
||||||
T serializedSize = SerializeAdapter::getSerializedSize(
|
ReturnValue_t result = SerializeAdapter::deSerialize(&bufferLength,
|
||||||
&bufferLength);
|
buffer, size, streamEndianness);
|
||||||
if(bufferLength + serializedSize <= *size) {
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
*buffer += serializedSize;
|
return result;
|
||||||
*size -= serializedSize;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return STREAM_TOO_SHORT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//No Else If, go on with buffer
|
//No Else If, go on with buffer
|
||||||
if (bufferLength <= *size) {
|
if (bufferLength <= *size) {
|
||||||
*size -= bufferLength;
|
*size -= bufferLength;
|
||||||
memcpy(this->buffer, *buffer, bufferLength);
|
std::memcpy(this->buffer, *buffer, bufferLength);
|
||||||
(*buffer) += bufferLength;
|
(*buffer) += bufferLength;
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
@ -107,7 +103,8 @@ uint8_t * SerialBufferAdapter<count_t>::getBuffer() {
|
|||||||
template<typename count_t>
|
template<typename count_t>
|
||||||
const uint8_t * SerialBufferAdapter<count_t>::getConstBuffer() {
|
const uint8_t * SerialBufferAdapter<count_t>::getConstBuffer() {
|
||||||
if(constBuffer == nullptr) {
|
if(constBuffer == nullptr) {
|
||||||
sif::error << "SerialBufferAdapter: Buffers are unitialized!" << std::endl;
|
sif::error << "SerialBufferAdapter::getConstBuffer:"
|
||||||
|
" Buffers are unitialized!" << std::endl;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return constBuffer;
|
return constBuffer;
|
||||||
|
Loading…
Reference in New Issue
Block a user