Array List swapper for SerialFixedArrayList

This commit is contained in:
Robin Müller 2020-01-18 18:01:37 +01:00
parent 6fe0f45c27
commit 5cb591a063
2 changed files with 20 additions and 0 deletions

View File

@ -78,6 +78,22 @@ public:
}
return result;
}
/**
* Swap the endianness of the Array list (not the length field !)
* Useful if the case the buffer type is large than uint8_t and the endianness
* is inconsistent with other SerializeElements.
* @param list
*/
static void swapArrayListEndianness(ArrayList<T, count_t>* list) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
count_t i = 0;
while ((result == HasReturnvaluesIF::RETURN_OK) && (i < list->size)) {
T newEntry = EndianSwapper::swap(list->entries[i]);
list->entries[i] = newEntry;
++i;
}
}
private:
ArrayList<T, count_t> *adaptee;
};

View File

@ -40,6 +40,10 @@ public:
bool bigEndian) {
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::deSerialize(this, buffer, size, bigEndian);
}
void swapArrayListEndianness() {
SerialArrayListAdapter<BUFFER_TYPE, count_t>::swapArrayListEndianness(this);
}
};