ssize_t in deSerialize replaced by size_t

This commit is contained in:
Robin Müller 2020-04-15 15:53:46 +02:00
parent af27a2441a
commit 906f941f32
47 changed files with 191 additions and 129 deletions

View File

@ -201,7 +201,7 @@ public:
return printSize;
}
virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
ReturnValue_t result = SerializeAdapter<uint32_t>::deSerialize(&this->_size,
buffer, size, bigEndian);

View File

@ -80,7 +80,7 @@ size_t DataPoolParameterWrapper::getSerializedSize() const {
}
ReturnValue_t DataPoolParameterWrapper::deSerialize(const uint8_t** buffer,
ssize_t* size, bool bigEndian) {
size_t* size, bool bigEndian) {
return HasReturnvaluesIF::RETURN_FAILED;
}

View File

@ -16,7 +16,7 @@ public:
virtual size_t getSerializedSize() const;
virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian);
ReturnValue_t copyFrom(const ParameterWrapper *from,

View File

@ -136,7 +136,7 @@ void DataSet::setValid(uint8_t valid) {
}
}
ReturnValue_t DataSet::deSerialize(const uint8_t** buffer, ssize_t* size,
ReturnValue_t DataSet::deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
ReturnValue_t result = RETURN_FAILED;
for (uint16_t count = 0; count < fill_count; count++) {

View File

@ -126,7 +126,7 @@ public:
virtual size_t getSerializedSize() const;
ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian);
private:

View File

@ -136,7 +136,7 @@ public:
return SerializeAdapter<T>::getSerializedSize(&value);
}
virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
return SerializeAdapter<T>::deSerialize(&value, buffer, size, bigEndian);
}

View File

@ -197,11 +197,11 @@ size_t PoolRawAccess::getSerializedSize() const {
return typeSize;
}
ReturnValue_t PoolRawAccess::deSerialize(const uint8_t** buffer, ssize_t* size,
ReturnValue_t PoolRawAccess::deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
*size -= typeSize;
if (*size >= 0) {
// TODO: Needs to be tested!!!
if (*size >= typeSize) {
*size -= typeSize;
if (bigEndian) {
#ifndef BYTE_ORDER_SYSTEM
#error BYTE_ORDER_SYSTEM not defined
@ -212,12 +212,14 @@ ReturnValue_t PoolRawAccess::deSerialize(const uint8_t** buffer, ssize_t* size,
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
memcpy(value, *buffer, typeSize);
#endif
} else {
}
else {
memcpy(value, *buffer, typeSize);
}
*buffer += typeSize;
return HasReturnvaluesIF::RETURN_OK;
} else {
}
else {
return SerializeIF::STREAM_TOO_SHORT;
}
}

View File

@ -127,7 +127,7 @@ public:
size_t getSerializedSize() const;
ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian);
protected:

View File

@ -25,7 +25,7 @@ ReturnValue_t PoolRawAccessHelper::serialize(uint8_t **buffer, size_t *size,
const size_t max_size, bool bigEndian) {
SerializationArgs serializationArgs = {buffer, size, max_size, bigEndian};
ReturnValue_t result;
ssize_t remainingParametersSize = numberOfParameters * 4;
size_t remainingParametersSize = numberOfParameters * 4;
for(uint8_t count=0; count < numberOfParameters; count++) {
result = serializeCurrentPoolEntryIntoBuffer(serializationArgs,
&remainingParametersSize, false);
@ -44,7 +44,7 @@ ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t ** buffer,
size_t * size, const size_t max_size, bool bigEndian) {
ReturnValue_t result;
SerializationArgs argStruct = {buffer, size, max_size, bigEndian};
ssize_t remainingParametersSize = numberOfParameters * 4;
size_t remainingParametersSize = numberOfParameters * 4;
uint8_t validityMaskSize = ceil((float)numberOfParameters/8.0);
uint8_t validityMask[validityMaskSize];
memset(validityMask,0, validityMaskSize);
@ -67,49 +67,60 @@ ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t ** buffer,
return result;
}
ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(SerializationArgs argStruct,
ssize_t * remainingParameters, bool withValidMask, uint8_t * validityMask) {
ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(
SerializationArgs argStruct, size_t * remainingParameters,
bool withValidMask, uint8_t * validityMask) {
uint32_t currentPoolId;
// Deserialize current pool ID from pool ID buffer
ReturnValue_t result = AutoSerializeAdapter::deSerialize(&currentPoolId,
&poolIdBuffer,remainingParameters,true);
if(result != RETURN_OK) {
debug << std::hex << "Pool Raw Access Helper: Error deSeralizing pool IDs" << std::dec << std::endl;
debug << std::hex << "Pool Raw Access Helper: Error deSeralizing "
"pool IDs" << std::dec << std::endl;
return result;
}
result = handlePoolEntrySerialization(currentPoolId, argStruct, withValidMask, validityMask);
result = handlePoolEntrySerialization(currentPoolId, argStruct,
withValidMask, validityMask);
return result;
}
ReturnValue_t PoolRawAccessHelper::handlePoolEntrySerialization(uint32_t currentPoolId,SerializationArgs argStruct,
bool withValidMask, uint8_t * validityMask) {
ReturnValue_t PoolRawAccessHelper::handlePoolEntrySerialization(
uint32_t currentPoolId,SerializationArgs argStruct, bool withValidMask,
uint8_t * validityMask) {
ReturnValue_t result = RETURN_FAILED;
uint8_t arrayPosition = 0;
uint8_t counter = 0;
bool poolEntrySerialized = false;
//debug << "Pool Raw Access Helper: Handling Pool ID: " << std::hex << currentPoolId << std::endl;
//debug << "Pool Raw Access Helper: Handling Pool ID: "
// << std::hex << currentPoolId << std::endl;
while(not poolEntrySerialized) {
if(counter > DataSet::DATA_SET_MAX_SIZE) {
error << "Pool Raw Access Helper: Config error, max. number of possible data set variables exceeded" << std::endl;
error << "Pool Raw Access Helper: Config error, "
"max. number of possible data set variables exceeded"
<< std::endl;
return result;
}
counter ++;
DataSet currentDataSet = DataSet();
//debug << "Current array position: " << (int)arrayPosition << std::endl;
PoolRawAccess currentPoolRawAccess(currentPoolId,arrayPosition,&currentDataSet,PoolVariableIF::VAR_READ);
PoolRawAccess currentPoolRawAccess(currentPoolId,arrayPosition,
&currentDataSet,PoolVariableIF::VAR_READ);
result = currentDataSet.read();
if (result != RETURN_OK) {
debug << std::hex << "Pool Raw Access Helper: Error reading raw dataset with returncode 0x"
debug << std::hex << "Pool Raw Access Helper: Error reading raw "
"dataset with returncode 0x"
<< result << std::dec << std::endl;
return result;
}
result = checkRemainingSize(&currentPoolRawAccess, &poolEntrySerialized, &arrayPosition);
result = checkRemainingSize(&currentPoolRawAccess, &poolEntrySerialized,
&arrayPosition);
if(result != RETURN_OK) {
error << "Pool Raw Access Helper: Configuration Error at pool ID " << std::hex << currentPoolId
error << "Pool Raw Access Helper: Configuration Error at pool ID "
<< std::hex << currentPoolId
<< ". Size till end smaller than 0" << std::dec << std::endl;
return result;
}
@ -125,8 +136,9 @@ ReturnValue_t PoolRawAccessHelper::handlePoolEntrySerialization(uint32_t current
result = currentDataSet.serialize(argStruct.buffer, argStruct.size,
argStruct.max_size, argStruct.bigEndian);
if (result != RETURN_OK) {
debug << "Pool Raw Access Helper: Error serializing pool data with ID 0x" << std::hex <<
currentPoolId << " into send buffer with return code " << result << std::dec << std::endl;
debug << "Pool Raw Access Helper: Error serializing pool data with "
"ID 0x" << std::hex << currentPoolId << " into send buffer "
"with return code " << result << std::dec << std::endl;
return result;
}
@ -134,9 +146,10 @@ ReturnValue_t PoolRawAccessHelper::handlePoolEntrySerialization(uint32_t current
return result;
}
ReturnValue_t PoolRawAccessHelper::checkRemainingSize(PoolRawAccess * currentPoolRawAccess,
bool * isSerialized, uint8_t * arrayPosition) {
int8_t remainingSize = currentPoolRawAccess->getSizeTillEnd() - currentPoolRawAccess->getSizeOfType();
ReturnValue_t PoolRawAccessHelper::checkRemainingSize(PoolRawAccess*
currentPoolRawAccess, bool * isSerialized, uint8_t * arrayPosition) {
int8_t remainingSize = currentPoolRawAccess->getSizeTillEnd() -
currentPoolRawAccess->getSizeOfType();
if(remainingSize == 0) {
*isSerialized = true;
}
@ -158,7 +171,8 @@ void PoolRawAccessHelper::handleMaskModification(uint8_t * validityMask) {
}
}
uint8_t PoolRawAccessHelper::bitSetter(uint8_t byte, uint8_t position, bool value) {
uint8_t PoolRawAccessHelper::bitSetter(uint8_t byte, uint8_t position,
bool value) {
if(position < 1 or position > 8) {
debug << "Pool Raw Access: Bit setting invalid position" << std::endl;
return byte;

View File

@ -80,13 +80,15 @@ private:
* @param hkDataSize
* @param max_size
* @param bigEndian
* @param withValidMask Can be set optionally to set a provided validity mask
* @param validityMask Can be supplied and will be set if @c withValidMask is set to true
* @param withValidMask Can be set optionally to set a
* provided validity mask
* @param validityMask Can be supplied and will be set if
* @c withValidMask is set to true
* @return
*/
ReturnValue_t serializeCurrentPoolEntryIntoBuffer(SerializationArgs argStruct,
ssize_t * remainingParameters, bool withValidMask = false,
uint8_t * validityMask = nullptr);
ReturnValue_t serializeCurrentPoolEntryIntoBuffer(
SerializationArgs argStruct, size_t * remainingParameters,
bool withValidMask = false, uint8_t * validityMask = nullptr);
ReturnValue_t handlePoolEntrySerialization(uint32_t currentPoolId,
SerializationArgs argStruct, bool withValidMask = false,

View File

@ -203,7 +203,7 @@ public:
return SerializeAdapter<T>::getSerializedSize(&value);
}
virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
return SerializeAdapter<T>::deSerialize(&value, buffer, size, bigEndian);
}

View File

@ -215,7 +215,7 @@ public:
return vector_size * SerializeAdapter<T>::getSerializedSize(value);
}
virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
uint16_t i;
ReturnValue_t result;

View File

@ -31,7 +31,7 @@ size_t DeviceTmReportingWrapper::getSerializedSize() const {
}
ReturnValue_t DeviceTmReportingWrapper::deSerialize(const uint8_t** buffer,
ssize_t* size, bool bigEndian) {
size_t* size, bool bigEndian) {
ReturnValue_t result = SerializeAdapter<object_id_t>::deSerialize(&objectId,
buffer, size, bigEndian);
if (result != HasReturnvaluesIF::RETURN_OK) {

View File

@ -16,7 +16,7 @@ public:
virtual size_t getSerializedSize() const;
virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian);
private:
object_id_t objectId;

View File

@ -18,7 +18,7 @@ public:
size_t getSerializedSize() const {
return rangeMatcher.getSerializedSize();
}
ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
return rangeMatcher.deSerialize(buffer, size, bigEndian);
}

View File

@ -85,7 +85,7 @@ size_t Type::getSerializedSize() const {
return 2 * SerializeAdapter<uint8_t>::getSerializedSize(&dontcare);
}
ReturnValue_t Type::deSerialize(const uint8_t** buffer, ssize_t* size,
ReturnValue_t Type::deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
uint8_t ptc;
uint8_t pfc;

View File

@ -44,7 +44,7 @@ public:
virtual size_t getSerializedSize() const;
virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian);
private:

View File

@ -115,7 +115,7 @@ public:
return size;
}
ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -29,32 +29,38 @@ public:
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
const size_t max_size, bool bigEndian) const {
ReturnValue_t result = SerializeAdapter<T>::serialize(&lowerBound, buffer, size, max_size, bigEndian);
ReturnValue_t result = SerializeAdapter<T>::serialize(&lowerBound,
buffer, size, max_size, bigEndian);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = SerializeAdapter<T>::serialize(&upperBound, buffer, size, max_size, bigEndian);
result = SerializeAdapter<T>::serialize(&upperBound, buffer, size,
max_size, bigEndian);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return SerializeAdapter<bool>::serialize(&inverted, buffer, size, max_size, bigEndian);
return SerializeAdapter<bool>::serialize(&inverted, buffer, size,
max_size, bigEndian);
}
size_t getSerializedSize() const {
return sizeof(lowerBound) + sizeof(upperBound) + sizeof(bool);
}
ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
ReturnValue_t result = SerializeAdapter<T>::deSerialize(&lowerBound, buffer, size, bigEndian);
ReturnValue_t result = SerializeAdapter<T>::deSerialize(&lowerBound,
buffer, size, bigEndian);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = SerializeAdapter<T>::deSerialize(&upperBound, buffer, size, bigEndian);
result = SerializeAdapter<T>::deSerialize(&upperBound, buffer,
size, bigEndian);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return SerializeAdapter<bool>::deSerialize(&inverted, buffer, size, bigEndian);
return SerializeAdapter<bool>::deSerialize(&inverted, buffer,
size, bigEndian);
}
protected:
bool doMatch(T input) {

View File

@ -112,7 +112,7 @@ ReturnValue_t ParameterWrapper::deSerializeData(uint8_t startingRow,
//treat from as a continuous Stream as we copy all of it
const uint8_t *fromAsStream = (const uint8_t *) from;
ssize_t streamSize = fromRows * fromColumns * sizeof(T);
size_t streamSize = fromRows * fromColumns * sizeof(T);
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
@ -137,12 +137,12 @@ ReturnValue_t ParameterWrapper::deSerializeData(uint8_t startingRow,
}
ReturnValue_t ParameterWrapper::deSerialize(const uint8_t** buffer,
ssize_t* size, bool bigEndian) {
size_t* size, bool bigEndian) {
return deSerialize(buffer, size, bigEndian, 0);
}
ReturnValue_t ParameterWrapper::deSerialize(const uint8_t** buffer,
ssize_t* size, bool bigEndian, uint16_t startWritingAtIndex) {
size_t* size, bool bigEndian, uint16_t startWritingAtIndex) {
ParameterWrapper streamDescription;
ReturnValue_t result = streamDescription.set(*buffer, *size, buffer, size);
@ -153,8 +153,10 @@ ReturnValue_t ParameterWrapper::deSerialize(const uint8_t** buffer,
return copyFrom(&streamDescription, startWritingAtIndex);
}
ReturnValue_t ParameterWrapper::set(const uint8_t* stream, ssize_t streamSize,
const uint8_t **remainingStream, ssize_t *remainingSize) {
ReturnValue_t ParameterWrapper::set(const uint8_t* stream, size_t streamSize,
const uint8_t **remainingStream, size_t *remainingSize) {
// TODO: Replaced ssize_t for remainingSize and streamSize
// is the logic here correct?
ReturnValue_t result = SerializeAdapter<Type>::deSerialize(&type, &stream,
&streamSize, true);
if (result != HasReturnvaluesIF::RETURN_OK) {
@ -172,22 +174,22 @@ ReturnValue_t ParameterWrapper::set(const uint8_t* stream, ssize_t streamSize,
return result;
}
int32_t dataSize = type.getSize() * rows * columns;
size_t dataSize = type.getSize() * rows * columns;
if (streamSize < dataSize) {
return SerializeIF::STREAM_TOO_SHORT;
}
data = NULL;
data = nullptr;
readonlyData = stream;
pointsToStream = true;
stream += dataSize;
if (remainingStream != NULL) {
if (remainingStream != nullptr) {
*remainingStream = stream;
}
streamSize -= dataSize;
if (remainingSize != NULL) {
if (remainingSize != nullptr) {
*remainingSize = streamSize;
}

View File

@ -30,10 +30,10 @@ public:
virtual size_t getSerializedSize() const;
virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian);
virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian, uint16_t startWritingAtIndex = 0);
template<typename T>
@ -111,8 +111,8 @@ public:
void setMatrix(const T& member) {
this->set(member[0], sizeof(member)/sizeof(member[0]), sizeof(member[0])/sizeof(member[0][0]));
}
ReturnValue_t set(const uint8_t *stream, ssize_t streamSize,
const uint8_t **remainingStream = NULL, ssize_t *remainingSize =
ReturnValue_t set(const uint8_t *stream, size_t streamSize,
const uint8_t **remainingStream = NULL, size_t *remainingSize =
NULL);
ReturnValue_t copyFrom(const ParameterWrapper *from,

View File

@ -108,7 +108,7 @@ uint32_t Fuse::getSerializedSize() const {
return size;
}
ReturnValue_t Fuse::deSerialize(const uint8_t** buffer, ssize_t* size,
ReturnValue_t Fuse::deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
ReturnValue_t result = RETURN_FAILED;
for (DeviceList::iterator iter = devices.begin(); iter != devices.end();

View File

@ -52,7 +52,7 @@ public:
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
const size_t max_size, bool bigEndian) const;
uint32_t getSerializedSize() const;
ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian);
void setAllMonitorsToUnchecked();
ReturnValue_t performOperation(uint8_t opCode);

View File

@ -56,7 +56,7 @@ float PowerComponent::getMax() {
return max;
}
ReturnValue_t PowerComponent::deSerialize(const uint8_t** buffer, ssize_t* size,
ReturnValue_t PowerComponent::deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
ReturnValue_t result = SerializeAdapter<float>::deSerialize(&min, buffer,
size, bigEndian);

View File

@ -24,7 +24,7 @@ public:
size_t getSerializedSize() const;
ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian);
ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,

View File

@ -56,16 +56,19 @@ public:
return printSize;
}
virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
return deSerialize(adaptee, buffer, size, bigEndian);
}
static ReturnValue_t deSerialize(ArrayList<T, count_t>* list,
const uint8_t** buffer, ssize_t* size, bool bigEndian) {
const uint8_t** buffer, size_t* size, bool bigEndian) {
count_t tempSize = 0;
ReturnValue_t result = SerializeAdapter<count_t>::deSerialize(&tempSize,
buffer, size, bigEndian);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if (tempSize > list->maxSize()) {
return SerializeIF::TOO_MANY_ELEMENTS;
}

View File

@ -61,36 +61,38 @@ size_t SerialBufferAdapter<count_t>::getSerializedSize() const {
return bufferLength;
}
}
template<typename count_t>
ReturnValue_t SerialBufferAdapter<count_t>::deSerialize(const uint8_t** buffer,
ssize_t* size, bool bigEndian) {
size_t* size, bool bigEndian) {
//TODO Ignores Endian flag!
if (buffer != NULL) {
if(serializeLength){
// Suggestion (would require removing rest of the block inside this if clause !):
//ReturnValue_t result = AutoSerializeAdapter::deSerialize(&bufferLength,buffer,size,bigEndian);
//if (result != HasReturnvaluesIF::RETURN_OK) {
// return result;
//}
// (Robin) the one of the buffer? wouldn't that be an issue for serialize
// as well? SerialFixedArrayListAdapter implements swapping of buffer
// fields (if buffer type is not uint8_t)
if (buffer != nullptr) {
if(serializeLength) {
count_t serializedSize = AutoSerializeAdapter::getSerializedSize(
&bufferLength);
if((*size - bufferLength - serializedSize) >= 0){
if(bufferLength + serializedSize >= *size) {
*buffer += serializedSize;
*size -= serializedSize;
}else{
}
else {
return STREAM_TOO_SHORT;
}
}
//No Else If, go on with buffer
if (*size - bufferLength >= 0) {
if (bufferLength >= *size) {
*size -= bufferLength;
memcpy(m_buffer, *buffer, bufferLength);
(*buffer) += bufferLength;
return HasReturnvaluesIF::RETURN_OK;
} else {
}
else {
return STREAM_TOO_SHORT;
}
} else {
}
else {
return HasReturnvaluesIF::RETURN_FAILED;
}
}

View File

@ -49,7 +49,19 @@ public:
virtual size_t getSerializedSize() const;
virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
/**
* @brief This function deserializes a buffer into the member buffer.
* @details
* If a length field is present, it is ignored, as the size should have
* been set in the constructor. If the size is not known beforehand,
* consider using SerialFixedArrayListAdapter instead.
* @param buffer [out] Resulting buffer
* @param size remaining size to deserialize, should be larger than buffer
* + size field size
* @param bigEndian
* @return
*/
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian);
uint8_t * getBuffer();

View File

@ -22,32 +22,38 @@
* @ingroup serialize
*/
template<typename BUFFER_TYPE, uint32_t MAX_SIZE, typename count_t = uint8_t>
class SerialFixedArrayListAdapter : public FixedArrayList<BUFFER_TYPE, MAX_SIZE, count_t>, public SerializeIF {
class SerialFixedArrayListAdapter :
public FixedArrayList<BUFFER_TYPE, MAX_SIZE, count_t>,
public SerializeIF {
public:
/**
* Constructor Arguments are forwarded to FixedArrayList constructor
* @param args
*/
template<typename... Args>
SerialFixedArrayListAdapter(Args... args) : FixedArrayList<BUFFER_TYPE, MAX_SIZE, count_t>(std::forward<Args>(args)...) {
}
SerialFixedArrayListAdapter(Args... args) :
FixedArrayList<BUFFER_TYPE, MAX_SIZE, count_t>(std::forward<Args>(args)...)
{}
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
const size_t max_size, bool bigEndian) const {
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::serialize(this, buffer, size, max_size, bigEndian);
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::serialize(this,
buffer, size, max_size, bigEndian);
}
size_t getSerializedSize() const {
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::getSerializedSize(this);
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::
getSerializedSize(this);
}
ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::deSerialize(this,
buffer, size, bigEndian);
}
void swapArrayListEndianness() {
SerialArrayListAdapter<BUFFER_TYPE, count_t>::swapArrayListEndianness(this);
SerialArrayListAdapter<BUFFER_TYPE, count_t>::
swapArrayListEndianness(this);
}
};

View File

@ -122,13 +122,13 @@ public:
* @param bigEndian Specify endianness
* @return
*/
virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
return deSerialize(SinglyLinkedList<T>::start, buffer, size, bigEndian);
}
static ReturnValue_t deSerialize(LinkedElement<T>* element,
const uint8_t** buffer, ssize_t* size, bool bigEndian) {
const uint8_t** buffer, size_t* size, bool bigEndian) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
while ((result == HasReturnvaluesIF::RETURN_OK) && (element != NULL)) {
result = element->value->deSerialize(buffer, size, bigEndian);

View File

@ -78,7 +78,7 @@ public:
}
template<typename T>
static ReturnValue_t deSerialize(T* object, const uint8_t** buffer,
ssize_t* size, bool bigEndian) {
size_t* size, bool bigEndian) {
SerializeAdapter_<T, IsDerivedFrom<T, SerializeIF>::Is> adapter;
return adapter.deSerialize(object, buffer, size, bigEndian);
}
@ -98,7 +98,7 @@ public:
}
static ReturnValue_t deSerialize(T* object, const uint8_t** buffer,
ssize_t* size, bool bigEndian) {
size_t* size, bool bigEndian) {
SerializeAdapter_<T, IsDerivedFrom<T, SerializeIF>::Is> adapter;
return adapter.deSerialize(object, buffer, size, bigEndian);
}

View File

@ -33,7 +33,7 @@ public:
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);
// static_assert(std::is_fundamental<T>::value);
size_t ignoredSize = 0;
if (size == nullptr) {
size = &ignoredSize;
@ -57,18 +57,17 @@ public:
/**
* Deserialize buffer into object
* @param object [out] Object to be deserialized with buffer data
* @param buffer buffer containing the data. Non-Const pointer to non-const
* pointer to const buffer.
* @param size int32_t type to allow value to be values smaller than 0,
* needed for range/size checking
* @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, ssize_t* size,
ReturnValue_t deSerialize(T* object, const uint8_t** buffer, size_t* size,
bool bigEndian) {
T tmp;
*size -= sizeof(T);
if (*size >= 0) {
if (*size >= sizeof(T)) {
*size -= sizeof(T);
memcpy(&tmp, *buffer, sizeof(T));
if (bigEndian) {
*object = EndianSwapper::swap<T>(tmp);
@ -109,7 +108,7 @@ public:
return object->getSerializedSize();
}
ReturnValue_t deSerialize(T* object, const uint8_t** buffer, ssize_t* size,
ReturnValue_t deSerialize(T* object, const uint8_t** buffer, size_t* size,
bool bigEndian) {
return object->deSerialize(buffer, size, bigEndian);
}

View File

@ -41,7 +41,7 @@ public:
return SerializeAdapter<T>::getSerializedSize(&entry);
}
virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
return SerializeAdapter<T>::deSerialize(&entry, buffer, size, bigEndian);
}

View File

@ -47,7 +47,7 @@ public:
virtual size_t getSerializedSize() const = 0;
virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) = 0;
};

View File

@ -144,7 +144,8 @@ public:
* @li RETURN_FAILED if data could not be added.
* storageId is unchanged then.
*/
virtual ReturnValue_t getFreeElement(store_address_t* storageId, const uint32_t size, uint8_t** p_data, bool ignoreFault = false ) = 0;
virtual ReturnValue_t getFreeElement(store_address_t* storageId,
const uint32_t size, uint8_t** p_data, bool ignoreFault = false ) = 0;
/**
* Clears the whole store.
* Use with care!

View File

@ -168,7 +168,7 @@ ReturnValue_t Subsystem::handleCommandMessage(CommandMessage* message) {
&sizeRead);
if (result == RETURN_OK) {
Mode_t fallbackId;
ssize_t size = sizeRead;
size_t size = sizeRead;
result = SerializeAdapter<Mode_t>::deSerialize(&fallbackId,
&pointer, &size, true);
if (result == RETURN_OK) {
@ -193,7 +193,7 @@ ReturnValue_t Subsystem::handleCommandMessage(CommandMessage* message) {
ModeSequenceMessage::getStoreAddress(message), &pointer,
&sizeRead);
if (result == RETURN_OK) {
ssize_t size = sizeRead;
size_t size = sizeRead;
result = SerialArrayListAdapter<ModeListEntry>::deSerialize(&table,
&pointer, &size, true);
if (result == RETURN_OK) {

View File

@ -53,7 +53,7 @@ public:
return sizeof(value1) + sizeof(value2) + sizeof(value3) + sizeof(value4);
}
virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
ReturnValue_t result;

View File

@ -157,7 +157,7 @@ ReturnValue_t UnitTestClass::test_autoserialization() {
// Unit Test AutoSerializeAdapter serialize
current_id = TestIds::AUTO_SERIALIZATION_DESERIALIZE;
p_array = test_array.data();
ssize_t remaining_size = serialized_size;
size_t remaining_size = serialized_size;
AutoSerializeAdapter::deSerialize(&test_value_bool,
const_cast<const uint8_t**>(&p_array), &remaining_size, false);
AutoSerializeAdapter::deSerialize(&tv_uint8,
@ -197,6 +197,8 @@ ReturnValue_t UnitTestClass::test_autoserialization() {
abs(tv_sdouble - (-2.2421e19)) > 0.01) {
return put_error(current_id);
}
// Check overflow
return RETURN_OK;
}
@ -285,9 +287,16 @@ ReturnValue_t UnitTestClass::test_serial_buffer_adapter() {
return RETURN_OK;
}
ReturnValue_t UnitTestClass::put_error(TestIds current_id) {
ReturnValue_t UnitTestClass::put_error(TestIds currentId) {
auto errorIter = testResultMap.find(currentId);
if(errorIter != testResultMap.end()) {
testResultMap.emplace(currentId, 1);
}
else {
errorIter->second ++;
}
error << "Unit Tester failed at test ID "
<< static_cast<uint32_t>(current_id) << "\r\n" << std::flush;
<< static_cast<uint32_t>(currentId) << "\r\n" << std::flush;
return RETURN_FAILED;
}

View File

@ -56,7 +56,8 @@ private:
TestIds current_id = TestIds::MISC;
std::array<uint8_t, 512> test_array;
using TestResultMap = std::map<uint32_t, ReturnValue_t>;
using error_count_t = uint8_t;
using TestResultMap = std::map<TestIds, error_count_t>;
using TestBuffer = std::vector<uint8_t>;
TestResultMap testResultMap;

View File

@ -40,11 +40,11 @@ ReturnValue_t ThermalComponent::setTargetState(int8_t newState) {
}
}
ReturnValue_t ThermalComponent::setLimits(const uint8_t* data, ssize_t size) {
ReturnValue_t ThermalComponent::setLimits(const uint8_t* data, size_t size) {
if (size != 4 * sizeof(parameters.lowerOpLimit)) {
return MonitoringIF::INVALID_SIZE;
}
ssize_t readSize = size;
size_t readSize = size;
SerializeAdapter<float>::deSerialize(&nopParameters.lowerNopLimit, &data,
&readSize, true);
SerializeAdapter<float>::deSerialize(&parameters.lowerOpLimit, &data,

View File

@ -53,7 +53,7 @@ public:
ReturnValue_t setTargetState(int8_t newState);
virtual ReturnValue_t setLimits( const uint8_t* data, ssize_t size);
virtual ReturnValue_t setLimits( const uint8_t* data, size_t size);
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
ParameterWrapper *parameterWrapper,

View File

@ -48,7 +48,7 @@ public:
return sizeof(apid) + sizeof(ssc);
}
ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
ReturnValue_t result = SerializeAdapter<uint16_t>::deSerialize(&apid,
buffer, size, bigEndian);
@ -257,7 +257,7 @@ public:
};
ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
ReturnValue_t result = AutoSerializeAdapter::deSerialize(&apid, buffer,
size, bigEndian);

View File

@ -30,9 +30,10 @@ public:
size_t getSerializedSize() const {
return SerializeAdapter<uint16_t>::getSerializedSize(&apid);
}
ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
return SerializeAdapter<uint16_t>::deSerialize(&apid, buffer, size, bigEndian);
return SerializeAdapter<uint16_t>::deSerialize(&apid, buffer,
size, bigEndian);
}
};

View File

@ -30,9 +30,10 @@ public:
size_t getSerializedSize() const {
return SerializeAdapter<uint8_t>::getSerializedSize(&service);
}
ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
return SerializeAdapter<uint8_t>::deSerialize(&service, buffer, size, bigEndian);
return SerializeAdapter<uint8_t>::deSerialize(&service, buffer,
size, bigEndian);
}
};

View File

@ -28,9 +28,10 @@ public:
size_t getSerializedSize() const {
return SerializeAdapter<uint8_t>::getSerializedSize(&subService);
}
ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size,
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
bool bigEndian) {
return SerializeAdapter<uint8_t>::deSerialize(&subService, buffer, size, bigEndian);
return SerializeAdapter<uint8_t>::deSerialize(&subService, buffer,
size, bigEndian);
}
private:
uint8_t subService;

View File

@ -28,7 +28,7 @@ const uint8_t* TcPacketBase::getApplicationData() const {
return &tcData->data;
}
uint16_t TcPacketBase::getApplicationDataSize() {
size_t TcPacketBase::getApplicationDataSize() {
return getPacketDataLength() - sizeof(tcData->data_field) - CRC_SIZE + 1;
}

View File

@ -151,7 +151,7 @@ public:
* @return The size of the PUS Application Data (without Error Control
* field)
*/
uint16_t getApplicationDataSize();
size_t getApplicationDataSize();
/**
* This getter returns the Error Control Field of the packet.
*