CCSDSPack
C++ Library for CCSDS Space Packet manipulation. i.e. generation, extraction, analisys and more
Loading...
Searching...
No Matches
CCSDSSecondaryHeaderAbstract.h
Go to the documentation of this file.
1#ifndef CCSDS_SECONDARY_HEADER_ABSTRACT_H
2#define CCSDS_SECONDARY_HEADER_ABSTRACT_H
3
4#include <CCSDSResult.h>
5#include <vector>
6#include <cstdint>
7
8//exclude includes when building for MCU
9#ifndef CCSDS_MCU
10 #include "CCSDSConfig.h"
11#endif //CCSDS_MCU
12
13namespace CCSDS {
14 class DataField;
21 public:
22 virtual ~SecondaryHeaderAbstract() = default;
23
28 [[nodiscard]] virtual ResultBool deserialize(const std::vector<std::uint8_t> &data) = 0;
29
30
38 virtual void update(DataField* dataField) = 0;
39
44 [[nodiscard]] virtual std::uint16_t getSize() const = 0;
45
50 [[nodiscard]] virtual std::vector<std::uint8_t> serialize() const = 0; // Pure virtual method for polymorphism
51
56 [[nodiscard]] virtual std::string getType() const = 0; // Pure virtual method for polymorphism
57
58#ifndef CCSDS_MCU
59 virtual ResultBool loadFromConfig(const Config &config) = 0;
60#endif
61 void setVariableLength(const bool bEnable){ variableLength = bEnable;}
62 bool variableLength{false};
63 };
64
80 public:
81 BufferHeader() = default;
82
86 explicit BufferHeader(const std::vector<std::uint8_t>& data) : m_data(data) {
87 };
88
89 [[nodiscard]] ResultBool deserialize(const std::vector<std::uint8_t> &data) override {m_data = data; return true;};
90
91 [[nodiscard]] std::uint16_t getSize() const override { return m_data.size(); }
92 [[nodiscard]] std::string getType() const override { return m_type; }
93
94 [[nodiscard]] std::vector<std::uint8_t> serialize() const override {return m_data;};
95 void update(DataField* dataField) override {m_dataLength = m_data.size();}
96#ifndef CCSDS_MCU
97 ResultBool loadFromConfig(const Config &config) override{return true;};
98#endif
99
100 private:
101 std::vector<std::uint8_t> m_data;
102 std::uint16_t m_dataLength = 0;
103 const std::string m_type = "DataOnlyHeader";
104 };
105
106
107}
108
109
110
111
112#endif //CCSDS_SECONDARY_HEADER_ABSTRACT_H
Represents a fixed secondary header used as a data buffer.
std::vector< std::uint8_t > m_data
std::uint16_t getSize() const override
Gets the size of the header in bytes.
void update(DataField *dataField) override
Defines how the packet secondary header is updated using the data field as reference.
ResultBool deserialize(const std::vector< std::uint8_t > &data) override
takes a buffer if data (vector std::uint8) and creates the header
std::vector< std::uint8_t > serialize() const override
Retrieves the serialized representation of the header.
BufferHeader(const std::vector< std::uint8_t > &data)
Constructs a DataOnlyHeader object with all fields explicitly set.
std::string getType() const override
Retrieves the name of the packet.
ResultBool loadFromConfig(const Config &config) override
BufferHeader()=default
Represents the data field of a CCSDS packet.
Encapsulates a result that can hold either a value or an Error.
Definition CCSDSResult.h:82
Abstract base class for a (Packet Utilization Standard) header.
virtual std::vector< std::uint8_t > serialize() const =0
Retrieves the serialized representation of the header.
virtual std::string getType() const =0
Retrieves the name of the packet.
virtual ~SecondaryHeaderAbstract()=default
virtual void update(DataField *dataField)=0
Defines how the packet secondary header is updated using the data field as reference.
virtual ResultBool loadFromConfig(const Config &config)=0
virtual std::uint16_t getSize() const =0
Gets the size of the header in bytes.
virtual ResultBool deserialize(const std::vector< std::uint8_t > &data)=0
takes a buffer if data (vector std::uint8) and creates the header
Parses and stores config values from custom file format.
Definition CCSDSConfig.h:11
Contains definitions and classes for handling CCSDS headers.