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// Copyright 2025-2026 ExoSpaceLabs
2// SPDX-License-Identifier: Apache-2.0
3
4#ifndef CCSDS_SECONDARY_HEADER_ABSTRACT_H
5#define CCSDS_SECONDARY_HEADER_ABSTRACT_H
6
7#include <CCSDSResult.h>
8#include <vector>
9#include <cstdint>
10
11//exclude includes when building for MCU
12#ifndef CCSDS_MCU
13 #include "CCSDSConfig.h"
14#endif //CCSDS_MCU
15
16namespace CCSDS {
17 class DataField;
24 public:
25 virtual ~SecondaryHeaderAbstract() = default;
26
31 [[nodiscard]] virtual ResultBool deserialize(const std::vector<std::uint8_t> &data) = 0;
32
33
41 virtual void update(DataField* dataField) = 0;
42
47 [[nodiscard]] virtual std::uint16_t getSize() const = 0;
48
53 [[nodiscard]] virtual std::vector<std::uint8_t> serialize() const = 0; // Pure virtual method for polymorphism
54
59 [[nodiscard]] virtual std::string getType() const = 0; // Pure virtual method for polymorphism
60
61#ifndef CCSDS_MCU
62 virtual ResultBool loadFromConfig(const Config &config) = 0;
63#endif
64 void setVariableLength(const bool bEnable){ variableLength = bEnable;}
65 bool variableLength{false};
66 };
67
83 public:
84 BufferHeader() = default;
85
89 explicit BufferHeader(const std::vector<std::uint8_t>& data) : m_data(data) {
90 };
91
92 [[nodiscard]] ResultBool deserialize(const std::vector<std::uint8_t> &data) override {m_data = data; return true;};
93
94 [[nodiscard]] std::uint16_t getSize() const override { return m_data.size(); }
95 [[nodiscard]] std::string getType() const override { return m_type; }
96
97 [[nodiscard]] std::vector<std::uint8_t> serialize() const override {return m_data;};
98 void update(DataField* dataField) override {m_dataLength = m_data.size();}
99#ifndef CCSDS_MCU
100 ResultBool loadFromConfig(const Config &config) override{return true;};
101#endif
102
103 private:
104 std::vector<std::uint8_t> m_data;
105 std::uint16_t m_dataLength = 0;
106 const std::string m_type = "DataOnlyHeader";
107 };
108
109
110}
111
112
113
114
115#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:85
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:14
Contains definitions and classes for handling CCSDS headers.