pyxcp 0.23.8__cp313-cp313-macosx_11_0_arm64.whl → 0.25.7__cp313-cp313-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. pyxcp/__init__.py +1 -1
  2. pyxcp/cmdline.py +14 -29
  3. pyxcp/config/__init__.py +1257 -1258
  4. pyxcp/cpp_ext/aligned_buffer.hpp +168 -0
  5. pyxcp/cpp_ext/bin.hpp +7 -6
  6. pyxcp/cpp_ext/cpp_ext.cpython-310-darwin.so +0 -0
  7. pyxcp/cpp_ext/cpp_ext.cpython-311-darwin.so +0 -0
  8. pyxcp/cpp_ext/cpp_ext.cpython-312-darwin.so +0 -0
  9. pyxcp/cpp_ext/cpp_ext.cpython-313-darwin.so +0 -0
  10. pyxcp/cpp_ext/daqlist.hpp +241 -73
  11. pyxcp/cpp_ext/extension_wrapper.cpp +123 -15
  12. pyxcp/cpp_ext/framing.hpp +360 -0
  13. pyxcp/cpp_ext/helper.hpp +280 -280
  14. pyxcp/cpp_ext/mcobject.hpp +248 -246
  15. pyxcp/cpp_ext/sxi_framing.hpp +332 -0
  16. pyxcp/daq_stim/__init__.py +145 -67
  17. pyxcp/daq_stim/optimize/binpacking.py +2 -2
  18. pyxcp/daq_stim/scheduler.cpp +8 -8
  19. pyxcp/errormatrix.py +2 -2
  20. pyxcp/examples/run_daq.py +5 -4
  21. pyxcp/examples/xcp_policy.py +6 -6
  22. pyxcp/examples/xcp_read_benchmark.py +2 -2
  23. pyxcp/examples/xcp_skel.py +1 -2
  24. pyxcp/examples/xcp_unlock.py +10 -12
  25. pyxcp/examples/xcp_user_supplied_driver.py +1 -2
  26. pyxcp/examples/xcphello.py +2 -15
  27. pyxcp/examples/xcphello_recorder.py +2 -2
  28. pyxcp/master/__init__.py +1 -0
  29. pyxcp/master/errorhandler.py +134 -4
  30. pyxcp/master/master.py +823 -252
  31. pyxcp/recorder/.idea/.gitignore +8 -0
  32. pyxcp/recorder/.idea/misc.xml +4 -0
  33. pyxcp/recorder/.idea/modules.xml +8 -0
  34. pyxcp/recorder/.idea/recorder.iml +6 -0
  35. pyxcp/recorder/.idea/sonarlint/issuestore/3/8/3808afc69ac1edb9d760000a2f137335b1b99728 +7 -0
  36. pyxcp/recorder/.idea/sonarlint/issuestore/9/a/9a2aa4db38d3115ed60da621e012c0efc0172aae +0 -0
  37. pyxcp/recorder/.idea/sonarlint/issuestore/b/4/b49006702b459496a8e8c94ebe60947108361b91 +0 -0
  38. pyxcp/recorder/.idea/sonarlint/issuestore/index.pb +7 -0
  39. pyxcp/recorder/.idea/sonarlint/securityhotspotstore/3/8/3808afc69ac1edb9d760000a2f137335b1b99728 +0 -0
  40. pyxcp/recorder/.idea/sonarlint/securityhotspotstore/9/a/9a2aa4db38d3115ed60da621e012c0efc0172aae +0 -0
  41. pyxcp/recorder/.idea/sonarlint/securityhotspotstore/b/4/b49006702b459496a8e8c94ebe60947108361b91 +0 -0
  42. pyxcp/recorder/.idea/sonarlint/securityhotspotstore/index.pb +7 -0
  43. pyxcp/recorder/.idea/vcs.xml +10 -0
  44. pyxcp/recorder/__init__.py +96 -98
  45. pyxcp/recorder/converter/__init__.py +4 -10
  46. pyxcp/recorder/reader.hpp +138 -139
  47. pyxcp/recorder/reco.py +1 -0
  48. pyxcp/recorder/rekorder.cpython-310-darwin.so +0 -0
  49. pyxcp/recorder/rekorder.cpython-311-darwin.so +0 -0
  50. pyxcp/recorder/rekorder.cpython-312-darwin.so +0 -0
  51. pyxcp/recorder/rekorder.cpython-313-darwin.so +0 -0
  52. pyxcp/recorder/rekorder.hpp +274 -274
  53. pyxcp/recorder/unfolder.hpp +1354 -1319
  54. pyxcp/recorder/wrap.cpp +184 -183
  55. pyxcp/recorder/writer.hpp +302 -302
  56. pyxcp/scripts/xcp_daq_recorder.py +54 -0
  57. pyxcp/scripts/xcp_fetch_a2l.py +2 -2
  58. pyxcp/scripts/xcp_id_scanner.py +1 -2
  59. pyxcp/scripts/xcp_info.py +66 -51
  60. pyxcp/scripts/xcp_profile.py +1 -2
  61. pyxcp/tests/test_daq.py +1 -1
  62. pyxcp/tests/test_framing.py +262 -0
  63. pyxcp/tests/test_master.py +210 -100
  64. pyxcp/tests/test_transport.py +138 -42
  65. pyxcp/timing.py +1 -1
  66. pyxcp/transport/__init__.py +8 -5
  67. pyxcp/transport/base.py +70 -180
  68. pyxcp/transport/can.py +58 -7
  69. pyxcp/transport/eth.py +32 -15
  70. pyxcp/transport/hdf5_policy.py +167 -0
  71. pyxcp/transport/sxi.py +126 -52
  72. pyxcp/transport/transport_ext.cpython-310-darwin.so +0 -0
  73. pyxcp/transport/transport_ext.cpython-311-darwin.so +0 -0
  74. pyxcp/transport/transport_ext.cpython-312-darwin.so +0 -0
  75. pyxcp/transport/transport_ext.cpython-313-darwin.so +0 -0
  76. pyxcp/transport/transport_ext.hpp +214 -0
  77. pyxcp/transport/transport_wrapper.cpp +249 -0
  78. pyxcp/transport/usb_transport.py +47 -31
  79. pyxcp/types.py +0 -13
  80. pyxcp/{utils.py → utils/__init__.py} +1 -2
  81. pyxcp/utils/cli.py +78 -0
  82. {pyxcp-0.23.8.dist-info → pyxcp-0.25.7.dist-info}/METADATA +4 -2
  83. pyxcp-0.25.7.dist-info/RECORD +158 -0
  84. {pyxcp-0.23.8.dist-info → pyxcp-0.25.7.dist-info}/WHEEL +1 -1
  85. pyxcp/examples/conf_sxi.json +0 -9
  86. pyxcp/examples/conf_sxi.toml +0 -7
  87. pyxcp-0.23.8.dist-info/RECORD +0 -135
  88. {pyxcp-0.23.8.dist-info → pyxcp-0.25.7.dist-info}/entry_points.txt +0 -0
  89. {pyxcp-0.23.8.dist-info → pyxcp-0.25.7.dist-info/licenses}/LICENSE +0 -0
@@ -1,274 +1,274 @@
1
-
2
- #if !defined(__REKORDER_HPP)
3
- #define __REKORDER_HPP
4
-
5
- #if !defined(STANDALONE_REKORDER)
6
- #define STANDALONE_REKORDER 0
7
- #endif /* STANDALONE_REKORDER */
8
-
9
- #include <array>
10
- #include <atomic>
11
- #include <bit>
12
- #include <bitset>
13
- #include <cctype>
14
- #include <cerrno>
15
- #include <chrono>
16
- #include <cstdint>
17
- #include <cstdio>
18
- #include <cstdlib>
19
- #include <cstring>
20
- #include <ctime>
21
- #include <exception>
22
- #include <filesystem>
23
- #include <functional>
24
- #include <optional>
25
- #include <sstream>
26
- #include <stdexcept>
27
- #include <string>
28
- #include <thread>
29
- #include <utility>
30
- #include <variant>
31
- #include <vector>
32
-
33
- #include "blockmem.hpp"
34
- #include "event.hpp"
35
- #include "tsqueue.hpp"
36
-
37
- #if defined(_WIN32)
38
- #include <Windows.h>
39
- #include <fcntl.h>
40
- #include <io.h>
41
- #endif /* _WIN32 */
42
-
43
- #include "lz4hc.h"
44
- #include "mio.hpp"
45
-
46
- #if STANDALONE_REKORDER == 0
47
- #include <pybind11/numpy.h>
48
- #include <pybind11/pybind11.h>
49
- #include <pybind11/stl.h>
50
-
51
- namespace py = pybind11;
52
- using namespace pybind11::literals;
53
- #endif /* STANDALONE_REKORDER */
54
-
55
- #if !defined(__BIGGEST_ALIGNMENT__)
56
- #define __BIGGEST_ALIGNMENT__ (8)
57
- #endif
58
-
59
- #define __ALIGNMENT_REQUIREMENT __BIGGEST_ALIGNMENT__
60
- #define __ALIGN alignas(__ALIGNMENT_REQUIREMENT)
61
-
62
- constexpr auto kilobytes(std::uint32_t value) -> std::uint32_t {
63
- return value * 1024;
64
- }
65
-
66
- constexpr auto megabytes(std::uint32_t value) -> std::uint32_t {
67
- return kilobytes(value) * 1024;
68
- }
69
-
70
- constexpr std::uint16_t XCP_PAYLOAD_MAX = 0xFFFFUL;
71
-
72
- constexpr std::uint16_t XMRAW_RELATIVE_TIMESTAMPS = 0x0002UL;
73
- constexpr std::uint16_t XMRAW_HAS_METADATA = 0x0004UL;
74
-
75
- /*
76
- byte-order is, where applicable little ending (LSB first).
77
- */
78
- #pragma pack(push)
79
- #pragma pack(1)
80
-
81
- struct FileHeaderType {
82
- std::uint16_t hdr_size;
83
- std::uint16_t version;
84
- std::uint16_t options;
85
- std::uint64_t num_containers;
86
- std::uint64_t record_count;
87
- std::uint64_t size_compressed;
88
- std::uint64_t size_uncompressed;
89
- };
90
-
91
- using HeaderTuple = std::tuple<std::uint16_t, std::uint16_t, std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t, double>;
92
-
93
- static_assert(sizeof(FileHeaderType) == 38);
94
-
95
- struct ContainerHeaderType {
96
- std::uint32_t record_count;
97
- std::uint32_t size_compressed;
98
- std::uint32_t size_uncompressed;
99
- };
100
-
101
- using blob_t = unsigned char;
102
- using blob_string = std::basic_string<blob_t>;
103
-
104
- #if STANDALONE_REKORDER == 1
105
- using payload_t = std::shared_ptr<blob_t[]>;
106
- #else
107
- using payload_t = py::array_t<blob_t>;
108
- #endif /* STANDALONE_REKORDER */
109
-
110
- struct frame_header_t {
111
- std::uint8_t category{ 0 };
112
- std::uint16_t counter{ 0U };
113
- std::uint64_t timestamp{ 0ULL };
114
- std::uint16_t length{ 0U };
115
- };
116
-
117
- #pragma pack(pop)
118
-
119
- using FrameTuple = std::tuple<std::uint8_t, std::uint16_t, std::uint64_t, std::uint16_t, payload_t>;
120
- using FrameVector = std::vector<FrameTuple>;
121
- using FrameTupleWriter = std::tuple<std::uint8_t, std::uint16_t, std::uint64_t, std::uint16_t, char*>;
122
-
123
- enum class FrameCategory : std::uint8_t {
124
- META,
125
- CMD,
126
- RES,
127
- ERR,
128
- EV,
129
- SERV,
130
- DAQ,
131
- STIM,
132
- };
133
-
134
- namespace detail {
135
- const std::string FILE_EXTENSION(".xmraw");
136
- const std::string MAGIC{ "ASAMINT::XCP_RAW" };
137
- constexpr auto MAGIC_SIZE = 16;
138
- constexpr auto VERSION = 0x0100;
139
- constexpr auto FILE_HEADER_SIZE = sizeof(FileHeaderType);
140
- constexpr auto CONTAINER_SIZE = sizeof(ContainerHeaderType);
141
- } // namespace detail
142
-
143
- constexpr auto file_header_size() -> std::uint64_t {
144
- return (detail::FILE_HEADER_SIZE + detail::MAGIC_SIZE);
145
- }
146
-
147
- using rounding_func_t = std::function<std::uint64_t(std::uint64_t)>;
148
-
149
- inline rounding_func_t create_rounding_func(std::uint64_t multiple) {
150
- return [multiple](std::uint64_t value) {
151
- return (value + (multiple - 1)) & ~(multiple - 1);
152
- };
153
- }
154
-
155
- const auto round_to_alignment = create_rounding_func(__ALIGNMENT_REQUIREMENT);
156
-
157
- inline void _fcopy(char* dest, char const * src, std::uint64_t n) noexcept {
158
- for (std::uint64_t i = 0; i < n; ++i) {
159
- dest[i] = src[i];
160
- }
161
- }
162
-
163
- #if STANDALONE_REKORDER == 1
164
- inline blob_t* get_payload_ptr(const payload_t& payload) noexcept {
165
- return payload.get();
166
- }
167
-
168
- inline payload_t create_payload(std::uint64_t size, blob_t const * data) noexcept {
169
- auto pl = std::make_shared<blob_t[]>(size);
170
- _fcopy(reinterpret_cast<char*>(pl.get()), reinterpret_cast<char const *>(data), size);
171
- return pl;
172
- }
173
- #else
174
- inline payload_t create_payload(std::uint64_t size, blob_t const * data) {
175
- return py::array_t<blob_t>(size, data);
176
- }
177
-
178
- inline blob_t* get_payload_ptr(const payload_t& payload) noexcept {
179
- py::buffer_info buf = payload.request();
180
-
181
- return static_cast<blob_t*>(buf.ptr);
182
- }
183
- #endif /* STANDALONE_REKORDER */
184
-
185
- #ifdef _WIN32
186
- inline std::string error_string(std::string_view func, std::error_code error_code) {
187
- LPSTR messageBuffer = nullptr;
188
- std::ostringstream ss;
189
-
190
- size_t size = FormatMessageA(
191
- FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
192
- static_cast<DWORD>(error_code.value()), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL
193
- );
194
-
195
- std::string message(messageBuffer, size);
196
- LocalFree(messageBuffer);
197
-
198
- ss << "[ERROR] ";
199
- ss << func << ": ";
200
- ss << message;
201
- return ss.str();
202
- }
203
-
204
- inline std::error_code get_last_error() {
205
- return std::error_code(GetLastError(), std::system_category());
206
- }
207
-
208
- #else
209
- inline std::string error_string(std::string_view func, std::error_code error_code) {
210
- std::ostringstream ss;
211
-
212
- auto message = strerror(static_cast<int>(error_code.value()));
213
-
214
- ss << "[ERROR] ";
215
- ss << func << ": ";
216
- ss << message;
217
- return ss.str();
218
- }
219
-
220
- inline std::error_code get_last_error() {
221
- return std::error_code(errno, std::system_category());
222
- }
223
-
224
- #endif // _WIN32
225
-
226
- inline std::string& ltrim(std::string& s) {
227
- auto it = std::find_if(s.begin(), s.end(), [](char c) { return !std::isspace<char>(c, std::locale::classic()); });
228
- s.erase(s.begin(), it);
229
- return s;
230
- }
231
-
232
- inline std::string& rtrim(std::string& s) {
233
- auto it = std::find_if(s.rbegin(), s.rend(), [](char c) { return !std::isspace<char>(c, std::locale::classic()); });
234
- s.erase(it.base(), s.end());
235
- return s;
236
- }
237
-
238
- inline std::string& trim(std::string& s) {
239
- return ltrim(rtrim(s));
240
- }
241
-
242
- inline std::string current_timestamp() {
243
- std::time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
244
-
245
- #if defined(_MSC_VER)
246
- errno_t err;
247
- char tbuf[128];
248
- std::string result{};
249
-
250
- err = ::ctime_s(tbuf, 128, &now);
251
- if (err == 0) {
252
- result = tbuf;
253
- }
254
-
255
- #else
256
- std::string result{ ::ctime(&now) };
257
- #endif
258
-
259
- // result.erase(std::remove_if(result.begin(), result.end(), ::isspace), result.end());
260
- return trim(result);
261
- }
262
-
263
- inline void hexdump(blob_t const * buf, std::uint16_t sz) {
264
- for (std::uint16_t idx = 0; idx < sz; ++idx) {
265
- printf("%02X ", buf[idx]);
266
- }
267
- printf("\n\r");
268
- }
269
-
270
- #include "reader.hpp"
271
- #include "unfolder.hpp"
272
- #include "writer.hpp"
273
-
274
- #endif // __REKORDER_HPP
1
+
2
+ #if !defined(__REKORDER_HPP)
3
+ #define __REKORDER_HPP
4
+
5
+ #if !defined(STANDALONE_REKORDER)
6
+ #define STANDALONE_REKORDER 0
7
+ #endif /* STANDALONE_REKORDER */
8
+
9
+ #include <array>
10
+ #include <atomic>
11
+ #include <bit>
12
+ #include <bitset>
13
+ #include <cctype>
14
+ #include <cerrno>
15
+ #include <chrono>
16
+ #include <cstdint>
17
+ #include <cstdio>
18
+ #include <cstdlib>
19
+ #include <cstring>
20
+ #include <ctime>
21
+ #include <exception>
22
+ #include <filesystem>
23
+ #include <functional>
24
+ #include <optional>
25
+ #include <sstream>
26
+ #include <stdexcept>
27
+ #include <string>
28
+ #include <thread>
29
+ #include <utility>
30
+ #include <variant>
31
+ #include <vector>
32
+
33
+ #include "blockmem.hpp"
34
+ #include "event.hpp"
35
+ #include "tsqueue.hpp"
36
+
37
+ #if defined(_WIN32)
38
+ #include <Windows.h>
39
+ #include <fcntl.h>
40
+ #include <io.h>
41
+ #endif /* _WIN32 */
42
+
43
+ #include "lz4hc.h"
44
+ #include "mio.hpp"
45
+
46
+ #if STANDALONE_REKORDER == 0
47
+ #include <pybind11/numpy.h>
48
+ #include <pybind11/pybind11.h>
49
+ #include <pybind11/stl.h>
50
+
51
+ namespace py = pybind11;
52
+ using namespace pybind11::literals;
53
+ #endif /* STANDALONE_REKORDER */
54
+
55
+ #if !defined(__BIGGEST_ALIGNMENT__)
56
+ #define __BIGGEST_ALIGNMENT__ (8)
57
+ #endif
58
+
59
+ #define __ALIGNMENT_REQUIREMENT __BIGGEST_ALIGNMENT__
60
+ #define __ALIGN alignas(__ALIGNMENT_REQUIREMENT)
61
+
62
+ constexpr auto kilobytes(std::uint32_t value) -> std::uint32_t {
63
+ return value * 1024;
64
+ }
65
+
66
+ constexpr auto megabytes(std::uint32_t value) -> std::uint32_t {
67
+ return kilobytes(value) * 1024;
68
+ }
69
+
70
+ constexpr std::uint16_t XCP_PAYLOAD_MAX = 0xFFFFUL;
71
+
72
+ constexpr std::uint16_t XMRAW_RELATIVE_TIMESTAMPS = 0x0002UL;
73
+ constexpr std::uint16_t XMRAW_HAS_METADATA = 0x0004UL;
74
+
75
+ /*
76
+ byte-order is, where applicable little ending (LSB first).
77
+ */
78
+ #pragma pack(push)
79
+ #pragma pack(1)
80
+
81
+ struct FileHeaderType {
82
+ std::uint16_t hdr_size;
83
+ std::uint16_t version;
84
+ std::uint16_t options;
85
+ std::uint64_t num_containers;
86
+ std::uint64_t record_count;
87
+ std::uint64_t size_compressed;
88
+ std::uint64_t size_uncompressed;
89
+ };
90
+
91
+ using HeaderTuple = std::tuple<std::uint16_t, std::uint16_t, std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t, double>;
92
+
93
+ static_assert(sizeof(FileHeaderType) == 38);
94
+
95
+ struct ContainerHeaderType {
96
+ std::uint32_t record_count;
97
+ std::uint32_t size_compressed;
98
+ std::uint32_t size_uncompressed;
99
+ };
100
+
101
+ using blob_t = unsigned char;
102
+ using blob_string = std::basic_string<blob_t>;
103
+
104
+ #if STANDALONE_REKORDER == 1
105
+ using payload_t = std::shared_ptr<blob_t[]>;
106
+ #else
107
+ using payload_t = py::array_t<blob_t>;
108
+ #endif /* STANDALONE_REKORDER */
109
+
110
+ struct frame_header_t {
111
+ std::uint8_t category{ 0 };
112
+ std::uint16_t counter{ 0U };
113
+ std::uint64_t timestamp{ 0ULL };
114
+ std::uint16_t length{ 0U };
115
+ };
116
+
117
+ #pragma pack(pop)
118
+
119
+ using FrameTuple = std::tuple<std::uint8_t, std::uint16_t, std::uint64_t, std::uint16_t, payload_t>;
120
+ using FrameVector = std::vector<FrameTuple>;
121
+ using FrameTupleWriter = std::tuple<std::uint8_t, std::uint16_t, std::uint64_t, std::uint16_t, char*>;
122
+
123
+ enum class FrameCategory : std::uint8_t {
124
+ META,
125
+ CMD,
126
+ RES,
127
+ ERR,
128
+ EV,
129
+ SERV,
130
+ DAQ,
131
+ STIM,
132
+ };
133
+
134
+ namespace detail {
135
+ const std::string FILE_EXTENSION(".xmraw");
136
+ const std::string MAGIC{ "ASAMINT::XCP_RAW" };
137
+ constexpr auto MAGIC_SIZE = 16;
138
+ constexpr auto VERSION = 0x0100;
139
+ constexpr auto FILE_HEADER_SIZE = sizeof(FileHeaderType);
140
+ constexpr auto CONTAINER_SIZE = sizeof(ContainerHeaderType);
141
+ } // namespace detail
142
+
143
+ constexpr auto file_header_size() -> std::uint64_t {
144
+ return (detail::FILE_HEADER_SIZE + detail::MAGIC_SIZE);
145
+ }
146
+
147
+ using rounding_func_t = std::function<std::uint64_t(std::uint64_t)>;
148
+
149
+ inline rounding_func_t create_rounding_func(std::uint64_t multiple) {
150
+ return [multiple](std::uint64_t value) {
151
+ return (value + (multiple - 1)) & ~(multiple - 1);
152
+ };
153
+ }
154
+
155
+ const auto round_to_alignment = create_rounding_func(__ALIGNMENT_REQUIREMENT);
156
+
157
+ inline void _fcopy(char* dest, char const * src, std::uint64_t n) noexcept {
158
+ for (std::uint64_t i = 0; i < n; ++i) {
159
+ dest[i] = src[i];
160
+ }
161
+ }
162
+
163
+ #if STANDALONE_REKORDER == 1
164
+ inline blob_t* get_payload_ptr(const payload_t& payload) noexcept {
165
+ return payload.get();
166
+ }
167
+
168
+ inline payload_t create_payload(std::uint64_t size, blob_t const * data) noexcept {
169
+ auto pl = std::make_shared<blob_t[]>(size);
170
+ _fcopy(reinterpret_cast<char*>(pl.get()), reinterpret_cast<char const *>(data), size);
171
+ return pl;
172
+ }
173
+ #else
174
+ inline payload_t create_payload(std::uint64_t size, blob_t const * data) {
175
+ return py::array_t<blob_t>(size, data);
176
+ }
177
+
178
+ inline blob_t* get_payload_ptr(const payload_t& payload) noexcept {
179
+ py::buffer_info buf = payload.request();
180
+
181
+ return static_cast<blob_t*>(buf.ptr);
182
+ }
183
+ #endif /* STANDALONE_REKORDER */
184
+
185
+ #ifdef _WIN32
186
+ inline std::string error_string(std::string_view func, std::error_code error_code) {
187
+ LPSTR messageBuffer = nullptr;
188
+ std::ostringstream ss;
189
+
190
+ size_t size = FormatMessageA(
191
+ FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
192
+ static_cast<DWORD>(error_code.value()), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL
193
+ );
194
+
195
+ std::string message(messageBuffer, size);
196
+ LocalFree(messageBuffer);
197
+
198
+ ss << "[ERROR] ";
199
+ ss << func << ": ";
200
+ ss << message;
201
+ return ss.str();
202
+ }
203
+
204
+ inline std::error_code get_last_error() {
205
+ return std::error_code(GetLastError(), std::system_category());
206
+ }
207
+
208
+ #else
209
+ inline std::string error_string(std::string_view func, std::error_code error_code) {
210
+ std::ostringstream ss;
211
+
212
+ auto message = strerror(static_cast<int>(error_code.value()));
213
+
214
+ ss << "[ERROR] ";
215
+ ss << func << ": ";
216
+ ss << message;
217
+ return ss.str();
218
+ }
219
+
220
+ inline std::error_code get_last_error() {
221
+ return std::error_code(errno, std::system_category());
222
+ }
223
+
224
+ #endif // _WIN32
225
+
226
+ inline std::string& ltrim(std::string& s) {
227
+ auto it = std::find_if(s.begin(), s.end(), [](char c) { return !std::isspace<char>(c, std::locale::classic()); });
228
+ s.erase(s.begin(), it);
229
+ return s;
230
+ }
231
+
232
+ inline std::string& rtrim(std::string& s) {
233
+ auto it = std::find_if(s.rbegin(), s.rend(), [](char c) { return !std::isspace<char>(c, std::locale::classic()); });
234
+ s.erase(it.base(), s.end());
235
+ return s;
236
+ }
237
+
238
+ inline std::string& trim(std::string& s) {
239
+ return ltrim(rtrim(s));
240
+ }
241
+
242
+ inline std::string current_timestamp() {
243
+ std::time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
244
+
245
+ #if defined(_MSC_VER)
246
+ errno_t err;
247
+ char tbuf[128];
248
+ std::string result{};
249
+
250
+ err = ::ctime_s(tbuf, 128, &now);
251
+ if (err == 0) {
252
+ result = tbuf;
253
+ }
254
+
255
+ #else
256
+ std::string result{ ::ctime(&now) };
257
+ #endif
258
+
259
+ // result.erase(std::remove_if(result.begin(), result.end(), ::isspace), result.end());
260
+ return trim(result);
261
+ }
262
+
263
+ inline void hexdump(blob_t const * buf, std::uint16_t sz) {
264
+ for (std::uint16_t idx = 0; idx < sz; ++idx) {
265
+ printf("%02X ", buf[idx]);
266
+ }
267
+ printf("\n\r");
268
+ }
269
+
270
+ #include "reader.hpp"
271
+ #include "unfolder.hpp"
272
+ #include "writer.hpp"
273
+
274
+ #endif // __REKORDER_HPP