20#ifndef ORES_COMMS_MESSAGING_FRAME_HPP
21#define ORES_COMMS_MESSAGING_FRAME_HPP
29#include "ores.utility/log/make_logger.hpp"
30#include "ores.comms/messaging/message_types.hpp"
34constexpr size_t MAX_PAYLOAD_SIZE = 1'000'000;
60 std::uint16_t version_major;
61 std::uint16_t version_minor;
64 std::uint8_t compression_flags;
65 std::uint32_t payload_size;
66 std::uint32_t sequence;
68 std::uint32_t correlation_id;
69 std::array<std::uint8_t, 4> reserved2;
71 static constexpr size_t size = 32;
79 inline static std::string_view logger_name =
"ores.comms.messaging.frame";
83 static auto instance = make_logger(logger_name);
89 frame(message_type type, std::uint32_t sequence, std::vector<std::byte>
payload,
108 const std::vector<std::byte>&
payload()
const {
return payload_; }
129 std::vector<std::byte>
serialize()
const;
144 std::span<const std::byte> data,
bool skip_version_check =
false);
153 static std::expected<frame, error_code>
161 std::expected<void, error_code>
validate()
const;
165 std::vector<std::byte> payload_;
172 std::uint32_t calculate_crc()
const;
189std::ostream& operator<<(std::ostream& s,
const frame_header& v);
Contains messaging related infrastructure in the comms library.
Definition compression.hpp:29
compression_type
Compression algorithm used for payload compression.
Definition message_types.hpp:91
Implements logging for ORE Studio.
Definition lifecycle_manager.hpp:30
Frame header structure for the ORES protocol.
Definition frame.hpp:58
Complete frame with header and payload.
Definition frame.hpp:77
const frame_header & header() const
Get the frame header.
Definition frame.hpp:103
static std::expected< frame_header, error_code > deserialize_header(std::span< const std::byte > data, bool skip_version_check=false)
Deserialize and validate header from bytes.
Definition frame.cpp:204
std::vector< std::byte > serialize() const
Serialize frame to bytes.
Definition frame.cpp:187
std::uint32_t correlation_id() const
Get the correlation ID for request/response matching.
Definition frame.hpp:98
compression_type compression() const
Get the compression type used for the payload.
Definition frame.hpp:113
std::expected< std::vector< std::byte >, error_code > decompressed_payload() const
Decompress and return the payload.
Definition frame.cpp:360
const std::vector< std::byte > & payload() const
Get the raw payload (compressed if compression is enabled).
Definition frame.hpp:108
std::expected< void, error_code > validate() const
Validate frame integrity.
Definition frame.cpp:321
static std::expected< frame, error_code > deserialize(const frame_header &header, std::span< const std::byte > data)
Deserialize complete frame using a pre-parsed header.
Definition frame.cpp:289