Pool Raw Access Helper serialization of vectors implemented
This commit is contained in:
parent
666341d03d
commit
2425685e44
@ -19,11 +19,12 @@ PoolRawAccessHelper::~PoolRawAccessHelper() {
|
||||
|
||||
ReturnValue_t PoolRawAccessHelper::serialize(uint8_t **buffer, uint32_t *size,
|
||||
const uint32_t max_size, bool bigEndian) {
|
||||
SerializationArgs serializationArgs = {buffer, size, max_size, bigEndian};
|
||||
ReturnValue_t result;
|
||||
int32_t remainingParametersSize = numberOfParameters * 4;
|
||||
for(uint8_t count=0; count < numberOfParameters; count++) {
|
||||
result = serializeCurrentPoolEntryIntoBuffer(buffer,
|
||||
&remainingParametersSize,size,max_size, bigEndian, false);
|
||||
result = serializeCurrentPoolEntryIntoBuffer(serializationArgs,
|
||||
&remainingParametersSize, false);
|
||||
if(result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
@ -35,16 +36,17 @@ ReturnValue_t PoolRawAccessHelper::serialize(uint8_t **buffer, uint32_t *size,
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t **buffer,
|
||||
uint32_t *size, const uint32_t max_size, bool bigEndian) {
|
||||
ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t ** buffer, uint32_t * size,
|
||||
const uint32_t max_size, bool bigEndian) {
|
||||
ReturnValue_t result;
|
||||
SerializationArgs argStruct = {buffer, size, max_size, bigEndian};
|
||||
int32_t remainingParametersSize = numberOfParameters * 4;
|
||||
uint8_t validityMaskSize = numberOfParameters/8;
|
||||
uint8_t validityMask[validityMaskSize];
|
||||
memset(validityMask,0, validityMaskSize);
|
||||
for(uint8_t count = 0; count < numberOfParameters; count++) {
|
||||
result = serializeCurrentPoolEntryIntoBuffer(buffer,
|
||||
&remainingParametersSize,size,max_size, bigEndian,true,validityMask);
|
||||
result = serializeCurrentPoolEntryIntoBuffer(argStruct,
|
||||
&remainingParametersSize,true,validityMask);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
@ -60,11 +62,9 @@ ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t **buffer,
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(uint8_t ** buffer,
|
||||
int32_t * remainingParameters, uint32_t * hkDataSize,
|
||||
const uint32_t max_size, bool bigEndian, bool withValidMask, uint8_t * validityMask) {
|
||||
ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(SerializationArgs argStruct,
|
||||
int32_t * remainingParameters, bool withValidMask, uint8_t * validityMask) {
|
||||
uint32_t currentPoolId;
|
||||
DataSet currentDataSet = DataSet();
|
||||
// Deserialize current pool ID from pool ID buffer
|
||||
ReturnValue_t result = AutoSerializeAdapter::deSerialize(¤tPoolId,
|
||||
&poolIdBuffer,remainingParameters,true);
|
||||
@ -72,36 +72,61 @@ ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(uint8_t *
|
||||
debug << std::hex << "Pool Raw Access Helper: Error deSeralizing pool IDs" << std::dec << std::endl;
|
||||
return result;
|
||||
}
|
||||
result = handlePoolEntrySerialization(currentPoolId, argStruct, withValidMask, validityMask);
|
||||
return result;
|
||||
}
|
||||
|
||||
// info << "Pool Raw Access Helper: Handling Pool ID: " << std::hex << currentPoolId << std::endl;
|
||||
PoolRawAccess currentPoolRawAccess(currentPoolId,0,¤tDataSet,PoolVariableIF::VAR_READ);
|
||||
|
||||
// set valid mask bit if necessary
|
||||
if(withValidMask) {
|
||||
if(currentPoolRawAccess.isValid()) {
|
||||
validityMask[validBufferIndex] =
|
||||
bitSetter(validityMask[validBufferIndex], validBufferIndexBit, true);
|
||||
validBufferIndexBit ++;
|
||||
if(validBufferIndexBit == 8) {
|
||||
validBufferIndex ++;
|
||||
validBufferIndexBit = 1;
|
||||
ReturnValue_t PoolRawAccessHelper::handlePoolEntrySerialization(uint32_t currentPoolId,SerializationArgs argStruct,
|
||||
bool withValidMask, uint8_t * validityMask) {
|
||||
ReturnValue_t result;
|
||||
uint8_t arrayPosition = 0;
|
||||
bool poolEntrySerialized = false;
|
||||
info << "Pool Raw Access Helper: Handling Pool ID: " << std::hex << currentPoolId << std::endl;
|
||||
while(not poolEntrySerialized) {
|
||||
DataSet currentDataSet = DataSet();
|
||||
PoolRawAccess currentPoolRawAccess(currentPoolId,arrayPosition,¤tDataSet,PoolVariableIF::VAR_READ);
|
||||
result = currentDataSet.read();
|
||||
if (result != RETURN_OK) {
|
||||
debug << std::hex << "Pool Raw Access Helper: Error reading raw dataset" << std::dec << std::endl;
|
||||
return result;
|
||||
}
|
||||
uint8_t remainingSize = currentPoolRawAccess.getSizeTillEnd() - currentPoolRawAccess.getSizeOfType();
|
||||
if(remainingSize == 0) {
|
||||
poolEntrySerialized = true;
|
||||
}
|
||||
else if(remainingSize > 0) {
|
||||
arrayPosition += currentPoolRawAccess.getSizeOfType() / 8;
|
||||
}
|
||||
else {
|
||||
error << "Pool Raw Access Helper: Configuration Error. Size till end smaller than 0" << std::endl;
|
||||
return result;
|
||||
}
|
||||
// set valid mask bit if necessary
|
||||
if(withValidMask) {
|
||||
if(currentPoolRawAccess.isValid()) {
|
||||
handleMaskModification(validityMask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = currentDataSet.read();
|
||||
if (result != RETURN_OK) {
|
||||
debug << std::hex << "Pool Raw Access Helper: Error read raw dataset" << std::dec << std::endl;
|
||||
return result;
|
||||
}
|
||||
result = currentDataSet.serialize(buffer, hkDataSize,
|
||||
max_size, bigEndian);
|
||||
if (result != RETURN_OK) {
|
||||
debug << "Pool Raw Access Helper: Error serializing pool data into send buffer" << std::endl;
|
||||
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 into send buffer" << std::endl;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void PoolRawAccessHelper::handleMaskModification(uint8_t * validityMask) {
|
||||
validityMask[validBufferIndex] =
|
||||
bitSetter(validityMask[validBufferIndex], validBufferIndexBit, true);
|
||||
validBufferIndexBit ++;
|
||||
if(validBufferIndexBit == 8) {
|
||||
validBufferIndex ++;
|
||||
validBufferIndexBit = 1;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -66,6 +66,12 @@ private:
|
||||
uint8_t validBufferIndex;
|
||||
uint8_t validBufferIndexBit;
|
||||
|
||||
struct SerializationArgs {
|
||||
uint8_t ** buffer;
|
||||
uint32_t * size;
|
||||
const uint32_t max_size;
|
||||
bool bigEndian;
|
||||
};
|
||||
/**
|
||||
* Helper function to serialize single pool entries
|
||||
* @param pPoolIdBuffer
|
||||
@ -78,10 +84,13 @@ private:
|
||||
* @param validityMask Can be supplied and will be set if @c withValidMask is set to true
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t serializeCurrentPoolEntryIntoBuffer(uint8_t ** buffer,
|
||||
int32_t * remainingParameters, uint32_t * hkDataSize,const uint32_t max_size,
|
||||
bool bigEndian, bool withValidMask = false, uint8_t * validityMask = NULL);
|
||||
ReturnValue_t serializeCurrentPoolEntryIntoBuffer(SerializationArgs argStruct,
|
||||
int32_t * remainingParameters, bool withValidMask = false, uint8_t * validityMask = NULL);
|
||||
|
||||
ReturnValue_t handlePoolEntrySerialization(uint32_t currentPoolId,SerializationArgs argStruct,
|
||||
bool withValidMask = false, uint8_t * validityMask = NULL);
|
||||
|
||||
void handleMaskModification(uint8_t * validityMask);
|
||||
/**
|
||||
* Sets specific bit of a byte
|
||||
* @param byte
|
||||
|
@ -9,7 +9,7 @@
|
||||
* buffers with a header containing the buffer length.
|
||||
* @details
|
||||
* Can be used by SerialLinkedListAdapter by using this type in
|
||||
* SerializeElement<>
|
||||
* SerializeElement<>.
|
||||
* Buffers with a size header inside that class can be declared with
|
||||
* SerialFixedArrayListAdapter<bufferType,MAX_BUFFER_LENGTH,typeOfMaxData>.
|
||||
* typeOfMaxData specifies the data type of the buffer header containing the buffer size that follows
|
||||
|
Loading…
Reference in New Issue
Block a user