2022-08-09 14:39:03 +02:00
|
|
|
#ifndef FSFW_CFDP_PDU_VARLENFIELD_H_
|
|
|
|
#define FSFW_CFDP_PDU_VARLENFIELD_H_
|
2021-12-03 15:37:49 +01:00
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
2022-08-09 18:51:44 +02:00
|
|
|
#include <utility>
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-08-03 13:15:49 +02:00
|
|
|
#include "fsfw/cfdp/definitions.h"
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw/serialize/SerializeIF.h"
|
2022-08-03 13:15:49 +02:00
|
|
|
#include "fsfw/util/UnsignedByteField.h"
|
2022-08-09 14:39:03 +02:00
|
|
|
|
2021-12-03 15:37:49 +01:00
|
|
|
namespace cfdp {
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
class VarLenField : public SerializeIF {
|
|
|
|
public:
|
|
|
|
union LengthFieldLen {
|
|
|
|
uint8_t oneByte;
|
|
|
|
uint16_t twoBytes;
|
|
|
|
uint32_t fourBytes;
|
|
|
|
uint64_t eightBytes;
|
|
|
|
};
|
|
|
|
|
|
|
|
VarLenField();
|
2022-08-03 13:15:49 +02:00
|
|
|
template <typename T>
|
|
|
|
explicit VarLenField(UnsignedByteField<T> byteField);
|
2022-08-09 14:39:03 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
VarLenField(cfdp::WidthInBytes width, size_t value);
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-08-03 15:12:29 +02:00
|
|
|
bool operator==(const VarLenField &other) const;
|
|
|
|
bool operator<(const VarLenField &other) const;
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t setValue(cfdp::WidthInBytes, size_t value);
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
|
|
|
Endianness streamEndianness) const override;
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-08-03 13:15:49 +02:00
|
|
|
[[nodiscard]] size_t getSerializedSize() const override;
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t deSerialize(cfdp::WidthInBytes width, const uint8_t **buffer, size_t *size,
|
|
|
|
Endianness streamEndianness);
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-08-03 13:15:49 +02:00
|
|
|
[[nodiscard]] cfdp::WidthInBytes getWidth() const;
|
|
|
|
[[nodiscard]] size_t getValue() const;
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
private:
|
|
|
|
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
|
|
|
Endianness streamEndianness) override;
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
cfdp::WidthInBytes width;
|
2022-08-03 13:34:49 +02:00
|
|
|
LengthFieldLen value{};
|
2021-12-03 15:37:49 +01:00
|
|
|
};
|
|
|
|
|
2022-08-03 13:34:49 +02:00
|
|
|
template <typename T>
|
|
|
|
cfdp::VarLenField::VarLenField(UnsignedByteField<T> byteField)
|
2022-08-09 14:39:03 +02:00
|
|
|
: width(static_cast<cfdp::WidthInBytes>(sizeof(T))) {
|
2022-08-03 13:34:49 +02:00
|
|
|
static_assert((sizeof(T) % 2) == 0);
|
|
|
|
setValue(width, byteField.getValue());
|
|
|
|
}
|
|
|
|
|
2022-08-09 18:51:44 +02:00
|
|
|
struct EntityId : public VarLenField {
|
|
|
|
public:
|
|
|
|
EntityId() : VarLenField() {}
|
|
|
|
template <typename T>
|
|
|
|
explicit EntityId(UnsignedByteField<T> byteField) : VarLenField(byteField) {}
|
|
|
|
EntityId(cfdp::WidthInBytes width, size_t entityId) : VarLenField(width, entityId) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TransactionSeqNum : public VarLenField {
|
|
|
|
public:
|
|
|
|
TransactionSeqNum() : VarLenField() {}
|
|
|
|
template <typename T>
|
|
|
|
explicit TransactionSeqNum(UnsignedByteField<T> byteField) : VarLenField(byteField) {}
|
|
|
|
TransactionSeqNum(cfdp::WidthInBytes width, size_t seqNum) : VarLenField(width, seqNum) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TransactionId {
|
2022-08-23 20:30:41 +02:00
|
|
|
TransactionId() = default;
|
2022-08-09 18:51:44 +02:00
|
|
|
TransactionId(EntityId entityId, TransactionSeqNum seqNum)
|
|
|
|
: entityId(std::move(entityId)), seqNum(std::move(seqNum)) {}
|
|
|
|
|
2022-09-06 13:16:00 +02:00
|
|
|
bool operator==(const TransactionId &other) const {
|
2022-08-09 18:51:44 +02:00
|
|
|
return entityId == other.entityId and seqNum == other.seqNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityId entityId;
|
|
|
|
TransactionSeqNum seqNum;
|
|
|
|
};
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
} // namespace cfdp
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-08-09 14:39:03 +02:00
|
|
|
#endif /* FSFW_CFDP_PDU_VARLENFIELD_H_ */
|