23 bool open(
const std::string& dir, std::string_view venue, std::string_view channel) {
25 const std::string path = dir +
"/" + std::string(venue) +
"-" + std::string(channel) +
".jsonl";
26 file_ = std::fopen(path.c_str(),
"a");
27 return file_ !=
nullptr;
29 void close() noexcept {
30 if (file_ !=
nullptr) {
35 [[nodiscard]]
bool enabled() const noexcept {
return file_ !=
nullptr; }
37 void record(std::int64_t rx_ns, std::string_view frame)
noexcept {
38 if (file_ ==
nullptr)
return;
39 std::fprintf(file_,
"%lld\t",
static_cast<long long>(rx_ns));
40 std::fwrite(frame.data(), 1, frame.size(), file_);
41 std::fputc(
'\n', file_);
45 void record_hex(std::int64_t rx_ns, std::span<const std::byte> frame)
noexcept {
46 if (file_ ==
nullptr)
return;
47 static constexpr char kHex[] =
"0123456789abcdef";
48 std::fprintf(file_,
"%lld\t",
static_cast<long long>(rx_ns));
49 for (
const std::byte b : frame) {
50 const auto v =
static_cast<unsigned>(b);
51 std::fputc(kHex[v >> 4], file_);
52 std::fputc(kHex[v & 15U], file_);
54 std::fputc(
'\n', file_);
57 void flush() noexcept {
58 if (file_ !=
nullptr) std::fflush(file_);
60 [[nodiscard]] std::uint64_t
frames() const noexcept {
return frames_; }
63 std::FILE* file_ =
nullptr;
64 std::uint64_t frames_ = 0;
Definition raw_recorder.hpp:18
bool enabled() const noexcept
Definition raw_recorder.hpp:37
void record(std::int64_t rx_ns, std::string_view frame) noexcept
Definition raw_recorder.hpp:39
void close() noexcept
Definition raw_recorder.hpp:31
std::uint64_t frames() const noexcept
Definition raw_recorder.hpp:62
void flush() noexcept
Definition raw_recorder.hpp:59
~RawRecorder()
Definition raw_recorder.hpp:21
bool open(const std::string &dir, std::string_view venue, std::string_view channel)
Definition raw_recorder.hpp:25
RawRecorder & operator=(const RawRecorder &)=delete
void record_hex(std::int64_t rx_ns, std::span< const std::byte > frame) noexcept
Binary frame (SBE market data) as lowercase hex on one line, same timestamp prefix.
Definition raw_recorder.hpp:47