ORE Studio 0.0.4
Loading...
Searching...
No Matches
session_file.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_COMMS_RECORDING_SESSION_FILE_HPP
21#define ORES_COMMS_RECORDING_SESSION_FILE_HPP
22
23#include <array>
24#include <chrono>
25#include <cstdint>
26#include <expected>
27#include <string>
28#include <boost/uuid/uuid.hpp>
29#include "ores.comms/messaging/message_types.hpp"
30
31namespace ores::comms::recording {
32
38constexpr std::array<std::uint8_t, 8> SESSION_FILE_MAGIC = {
39 0x4F, 0x52, 0x45, 0x53, 0x2D, 0x52, 0x45, 0x43
40};
41
45constexpr std::uint16_t SESSION_FILE_VERSION = 1;
46
50enum class frame_direction : std::uint8_t {
51 sent = 0x00,
52 received = 0x01
53};
54
74struct session_file_header final {
75 std::array<std::uint8_t, 8> magic;
76 std::uint16_t version;
77 std::uint16_t reserved1;
78 std::uint16_t protocol_version_major;
79 std::uint16_t protocol_version_minor;
80 boost::uuids::uuid session_id;
81 std::int64_t start_timestamp_us;
82 std::uint16_t server_address_length;
84 std::array<std::uint8_t, 21> reserved2;
85
86 static constexpr size_t size = 64;
87};
88
89static_assert(sizeof(session_file_header) == session_file_header::size,
90 "session_file_header must be exactly 64 bytes");
91
105 std::int64_t timestamp_offset_us;
106 std::uint32_t frame_size;
107 frame_direction direction;
108 std::array<std::uint8_t, 3> reserved;
109
110 static constexpr size_t size = 16;
111};
112
113static_assert(sizeof(frame_record_header) == frame_record_header::size,
114 "frame_record_header must be exactly 16 bytes");
115
120 none = 0,
121 file_open_failed,
122 file_write_failed,
123 file_read_failed,
124 invalid_magic,
125 unsupported_version,
126 corrupt_file,
129};
130
140std::string generate_session_filename(
141 const boost::uuids::uuid& session_id,
142 std::chrono::system_clock::time_point start_time);
143
144}
145
146#endif
compression_type
Compression algorithm used for payload compression.
Definition message_types.hpp:259
Session recording infrastructure for debugging and analysis.
Definition ores.comms.recording.hpp:28
session_file_error
Error codes for session file operations.
Definition session_file.hpp:119
@ unexpected_eof
Truncated file in middle of read.
@ end_of_file
Clean end of file at frame boundary.
constexpr std::uint16_t SESSION_FILE_VERSION
Current version of the session file format.
Definition session_file.hpp:45
std::string generate_session_filename(const boost::uuids::uuid &session_id, std::chrono::system_clock::time_point start_time)
Generate a session filename with timestamp and UUID.
Definition session_file.cpp:28
constexpr std::array< std::uint8_t, 8 > SESSION_FILE_MAGIC
Magic bytes identifying an ORES session recording file.
Definition session_file.hpp:38
frame_direction
Direction of a recorded frame.
Definition session_file.hpp:50
@ sent
Frame was sent by the client.
@ received
Frame was received by the client.
File header for session recording files.
Definition session_file.hpp:74
Header for each recorded frame in the session file.
Definition session_file.hpp:104