Switch Controller
Loading...
Searching...
No Matches
Action.h
Go to the documentation of this file.
1#pragma once
2
3#include "pch.h"
4#include <boost/endian/conversion.hpp>
5
6struct Action {
7 uint64_t time;
8 std::array<uint8_t, 8> data;
9};
10
11void saveActionVector(const std::string &filename,
12 const std::vector<Action> &record) {
13 std::ofstream outfile(filename, std::ios::binary);
14 if (!outfile.is_open()) {
15 spdlog::error("Could not open file: {}", filename);
16 return;
17 }
18 for (auto action : record) {
19 boost::endian::native_to_little_inplace(action.time);
20 outfile.write(reinterpret_cast<char *>(&action), sizeof(action));
21 }
22}
23std::vector<Action> loadActionVector(const std::string &filename) {
24 std::vector<Action> res;
25 std::ifstream infile(filename, std::ios::binary);
26 if (!infile.is_open()) {
27 spdlog::error("Could not open file: {}", filename);
28 return {};
29 }
30 Action action;
31 while (infile.readsome(reinterpret_cast<char *>(&action), sizeof(action)) ==
32 sizeof(action)) {
33 boost::endian::little_to_native_inplace(action.time);
34 res.push_back(action);
35 }
36 return res;
37}
void saveActionVector(const std::string &filename, const std::vector< Action > &record)
Definition: Action.h:11
std::vector< Action > loadActionVector(const std::string &filename)
Definition: Action.h:23
Definition: Action.h:6
std::array< uint8_t, 8 > data
Definition: Action.h:8
uint64_t time
Definition: Action.h:7