Line data Source code
1 : #ifndef IPPL_LOGENTRY_H
2 : #define IPPL_LOGENTRY_H
3 :
4 : #include <chrono>
5 : #include <cstring>
6 : #include <map>
7 : #include <string>
8 : #include <vector>
9 :
10 : namespace ippl {
11 :
12 : struct LogEntry {
13 : std::string methodName;
14 : std::map<std::string, std::string> parameters;
15 : size_t usedSize;
16 : size_t freeSize;
17 : std::string memorySpace;
18 : int rank;
19 : std::chrono::time_point<std::chrono::high_resolution_clock> timestamp;
20 :
21 : std::vector<char> serialize() const;
22 : static LogEntry deserialize(const std::vector<char>& buffer, size_t offset = 0);
23 : };
24 :
25 : template <typename T>
26 22 : void serializeBasicType(std::vector<char>& buffer, const T& value) {
27 22 : size_t size = sizeof(T);
28 22 : buffer.resize(buffer.size() + size);
29 22 : std::memcpy(buffer.data() + buffer.size() - size, &value, size);
30 22 : }
31 :
32 : template <typename T>
33 11 : T deserializeBasicType(const std::vector<char>& buffer, size_t& offset) {
34 : T value;
35 11 : std::memcpy(&value, buffer.data() + offset, sizeof(T));
36 11 : offset += sizeof(T);
37 11 : return value;
38 : }
39 :
40 : } // namespace ippl
41 :
42 : #endif
|