/workspaces/astro/sol3-sdk/cpp/sol3/core/size_delimited_log_writer.h Source File

Space-ng SDK: /workspaces/astro/sol3-sdk/cpp/sol3/core/size_delimited_log_writer.h Source File
Space-ng SDK
size_delimited_log_writer.h
Go to the documentation of this file.
1 // Copyright (c) Space-ng, inc. All rights reserved.
2 
3 #pragma once
4 
6 #include "sol3/cpp/filesystem.h" // IWYU pragma: keep
7 
8 #include <flatbuffers/flatbuffers.h>
9 
10 #include <cstddef>
11 #include <cstdint>
12 #include <fstream>
13 
14 namespace sol3::core {
35  public:
43  explicit SizeDelimitedLogWriter(cpp::fs::path log_path);
45 
47  void open(cpp::fs::path log_path);
49  void close();
50  bool isOpen() const;
51  cpp::fs::path const& logPath() const { return log_path_; }
52 
64  void writeSizePrefixed(flatbuffers::span<uint8_t const> frame);
65 
68  void commit(size_t message_count);
69 
71  void rollback();
72 
88  void writeNonSizePrefixedUnaligned(flatbuffers::span<uint8_t const> data);
89 
102  size_t offset, flatbuffers::span<uint8_t const> frame);
103 
105  size_t currentOffset() const;
106 
110  void write(char const* data, size_t size) override;
111 
112  private:
113  sol3::cpp::fs::path log_path_;
114  std::fstream file_;
115  size_t size_ = 0;
116 };
117 } // namespace sol3::core
Minimal append-only byte sink for streaming writes.
Definition: stream_writer.h:9
Definition: size_delimited_log_writer.h:34
void rewriteSizePrefixed(size_t offset, flatbuffers::span< uint8_t const > frame)
void open(cpp::fs::path log_path)
Opens or replaces the current log file for writing.
cpp::fs::path const & logPath() const
Definition: size_delimited_log_writer.h:51
void close()
Closes the log file and clears the path.
void commit(size_t message_count)
void write(char const *data, size_t size) override
SizeDelimitedLogWriter(cpp::fs::path log_path)
void rollback()
Roll back to currentOffset(), discarding uncommitted writes.
void writeSizePrefixed(flatbuffers::span< uint8_t const > frame)
size_t currentOffset() const
Returns the current write position in the file (always 8-byte aligned).
void writeNonSizePrefixedUnaligned(flatbuffers::span< uint8_t const > data)
Definition: any_message_input.h:15