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
8namespace CCSDS {
15 public:
16 virtual ~SecondaryHeaderAbstract() = default;
17
22 virtual void setDataLength(uint16_t dataLength) = 0;
23
24
29 [[nodiscard]] virtual ResultBool deserialize(const std::vector<uint8_t> &data) = 0;
30
35 [[nodiscard]] virtual uint16_t getDataLength() const = 0;
36
41 [[nodiscard]] virtual uint16_t getSize() const = 0;
42
47 [[nodiscard]] virtual std::vector<uint8_t> serialize() const = 0; // Pure virtual method for polymorphism
48
53 [[nodiscard]] virtual std::string getType() const = 0; // Pure virtual method for polymorphism
54 };
55
71 public:
72 BufferHeader() = default;
73
77 explicit BufferHeader(const std::vector<uint8_t>& data) : m_data(data) {
78 };
79
80 void setDataLength(const uint16_t dataLength) override { m_dataLength = dataLength; }
81
82 [[nodiscard]] ResultBool deserialize(const std::vector<uint8_t> &data) override {m_data = data; return true;};
83
84 [[nodiscard]] uint16_t getDataLength() const override { return m_dataLength; }
85 [[nodiscard]] uint16_t getSize() const override { return m_data.size(); }
86 [[nodiscard]] std::string getType() const override { return m_type; }
87
88 [[nodiscard]] std::vector<uint8_t> serialize() const override {return m_data;};
89
90 private:
91 std::vector<uint8_t> m_data;
92 uint16_t m_dataLength = 0;
93 const std::string m_type = "DataOnlyHeader";
94 };
95
96
97}
98
99
100
101
102#endif //CCSDS_SECONDARY_HEADER_ABSTRACT_H
Represents a fixed secondary header used as a data buffer.
ResultBool deserialize(const std::vector< uint8_t > &data) override
takes a buffer if data (vector uint8) and creates the header
std::vector< uint8_t > serialize() const override
Retrieves the serialized representation of the header.
BufferHeader(const std::vector< uint8_t > &data)
Constructs a DataOnlyHeader object with all fields explicitly set.
void setDataLength(const uint16_t dataLength) override
Sets the length of the data associated with the packet.
std::string getType() const override
Retrieves the name of the packet.
BufferHeader()=default
std::vector< uint8_t > m_data
uint16_t getDataLength() const override
Gets the length of the data associated with the packet if applicable.
uint16_t getSize() const override
Gets the size of the header in bytes.
Encapsulates a result that can hold either a value or an Error.
Definition CCSDSResult.h:81
Abstract base class for a (Packet Utilization Standard) header.
virtual std::string getType() const =0
Retrieves the name of the packet.
virtual ~SecondaryHeaderAbstract()=default
virtual uint16_t getSize() const =0
Gets the size of the header in bytes.
virtual uint16_t getDataLength() const =0
Gets the length of the data associated with the packet if applicable.
virtual ResultBool deserialize(const std::vector< uint8_t > &data)=0
takes a buffer if data (vector uint8) and creates the header
virtual std::vector< uint8_t > serialize() const =0
Retrieves the serialized representation of the header.
virtual void setDataLength(uint16_t dataLength)=0
Sets the length of the data associated with the packet.
Contains definitions and classes for handling CCSDS headers.