SerialBufferAdapter refactoring #677

Merged
mohr merged 1 commits from mueller/refactor-serial-buffer-adapter into development 2022-09-12 14:30:53 +02:00
8 changed files with 25 additions and 25 deletions

View File

@ -360,7 +360,8 @@ if(NOT FSFW_CONFIG_PATH)
if(NOT FSFW_BUILD_DOCS)
message(
WARNING
"${MSG_PREFIX} Flight Software Framework configuration path FSFW_CONFIG_PATH not set")
"${MSG_PREFIX} Flight Software Framework configuration path FSFW_CONFIG_PATH not set"
)
message(
WARNING
"${MSG_PREFIX} Setting default configuration from ${DEF_CONF_PATH} ..")

View File

@ -21,7 +21,7 @@ cfdp::Lv& cfdp::Lv::operator=(const Lv& other) {
if (value == nullptr or otherSize == 0) {
this->zeroLen = true;
}
this->value.setBuffer(value, otherSize);
this->value.setConstBuffer(value, otherSize);
return *this;
}
@ -70,7 +70,7 @@ ReturnValue_t cfdp::Lv::deSerialize(const uint8_t** buffer, size_t* size,
}
zeroLen = false;
// Zero-copy implementation
value.setBuffer(const_cast<uint8_t*>(*buffer + 1), lengthField);
value.setConstBuffer(*buffer + 1, lengthField);
*buffer += 1 + lengthField;
*size -= 1 + lengthField;
return returnvalue::OK;

View File

@ -75,7 +75,7 @@ ReturnValue_t cfdp::Tlv::deSerialize(const uint8_t **buffer, size_t *size,
}
zeroLen = false;
// Zero-copy implementation
value.setBuffer(const_cast<uint8_t *>(*buffer + 1), lengthField);
value.setConstBuffer(*buffer + 1, lengthField);
*buffer += 1 + lengthField;
*size -= 1 + lengthField;
return returnvalue::OK;
@ -96,7 +96,7 @@ void cfdp::Tlv::setValue(uint8_t *value, size_t len) {
if (len > 0) {
zeroLen = false;
}
this->value.setBuffer(value, len);
this->value.setConstBuffer(value, len);
}
uint8_t cfdp::Tlv::getLengthField() const { return this->value.getSerializedSize() - 1; }

View File

@ -571,7 +571,7 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::getMapFilterFr
if (result != returnvalue::OK) {
return result;
}
if(fromTimestamp > toTimestamp) {
if (fromTimestamp > toTimestamp) {
return INVALID_TIME_WINDOW;
}
itBegin = telecommandMap.begin();
@ -580,7 +580,7 @@ inline ReturnValue_t Service11TelecommandScheduling<MAX_NUM_TCS>::getMapFilterFr
itBegin++;
}
//start looking for end beginning at begin
// start looking for end beginning at begin
itEnd = itBegin;
while (itEnd->first <= toTimestamp && itEnd != telecommandMap.end()) {
itEnd++;

View File

@ -21,7 +21,7 @@ SerialBufferAdapter<count_t>::SerialBufferAdapter(uint8_t* buffer, count_t buffe
bufferLength(bufferLength) {}
template <typename count_t>
SerialBufferAdapter<count_t>::~SerialBufferAdapter() {}
SerialBufferAdapter<count_t>::~SerialBufferAdapter() = default;
template <typename count_t>
ReturnValue_t SerialBufferAdapter<count_t>::serialize(uint8_t** buffer, size_t* size,
@ -119,10 +119,10 @@ const uint8_t* SerialBufferAdapter<count_t>::getConstBuffer() const {
}
template <typename count_t>
void SerialBufferAdapter<count_t>::setBuffer(uint8_t* buffer, count_t bufferLength) {
this->buffer = buffer;
this->constBuffer = buffer;
this->bufferLength = bufferLength;
void SerialBufferAdapter<count_t>::setConstBuffer(const uint8_t* buf, count_t bufLen) {
this->buffer = nullptr;
this->bufferLength = bufLen;
this->constBuffer = buf;
}
// forward Template declaration for linker

View File

@ -21,6 +21,7 @@
template <typename count_t>
class SerialBufferAdapter : public SerializeIF {
public:
SerialBufferAdapter() = default;
/**
* Constructor for constant uint8_t buffer. Length field can be serialized optionally.
* Type of length can be supplied as template type.
@ -40,12 +41,12 @@ class SerialBufferAdapter : public SerializeIF {
*/
SerialBufferAdapter(uint8_t* buffer, count_t bufferLength, bool serializeLength = false);
virtual ~SerialBufferAdapter();
~SerialBufferAdapter() override;
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override;
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override;
virtual size_t getSerializedSize() const override;
[[nodiscard]] size_t getSerializedSize() const override;
/**
* @brief This function deserializes a buffer into the member buffer.
@ -59,12 +60,12 @@ class SerialBufferAdapter : public SerializeIF {
* @param bigEndian
* @return
*/
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) override;
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) override;
uint8_t* getBuffer();
const uint8_t* getConstBuffer() const;
void setBuffer(uint8_t* buffer, count_t bufferLength);
[[nodiscard]] const uint8_t* getConstBuffer() const;
void setConstBuffer(const uint8_t* buf, count_t bufLen);
private:
bool serializeLength = false;

View File

@ -17,7 +17,6 @@
*/
class SpacePacketParser {
public:
struct FoundPacketInfo {
size_t startIdx = 0;
size_t sizeFound = 0;
@ -51,9 +50,7 @@ class SpacePacketParser {
ReturnValue_t parseSpacePackets(const uint8_t** buffer, const size_t maxSize,
FoundPacketInfo& packetInfo);
size_t getAmountRead() {
return amountRead;
}
size_t getAmountRead() { return amountRead; }
void reset() {
nextStartIdx = 0;

View File

@ -64,7 +64,8 @@ TEST_CASE("Serial Buffer Adapter", "[single-file]") {
SECTION("Test set buffer function") {
SerialBufferAdapter<uint8_t> tv_serial_buffer_adapter_loc =
SerialBufferAdapter<uint8_t>((uint8_t*)nullptr, 0, true);
tv_serial_buffer_adapter_loc.setBuffer(test_serial_buffer.data(), test_serial_buffer.size());
tv_serial_buffer_adapter_loc.setConstBuffer(test_serial_buffer.data(),
test_serial_buffer.size());
serialized_size = 0;
arrayPtr = testArray.data();
SerializeAdapter::serialize(&test_value_bool, &arrayPtr, &serialized_size, testArray.size(),