IPPL (Independent Parallel Particle Layer)
IPPL
Loading...
Searching...
No Matches
LogEntry.cpp
Go to the documentation of this file.
2
3namespace ippl {
4
5 void serializeString(std::vector<char>& buffer, const std::string& str) {
6 size_t length = str.size();
7 serializeBasicType(buffer, length); // First, serialize the length of the string
8 buffer.insert(buffer.end(), str.begin(), str.end()); // Then, serialize the string itself
9 }
10
11 std::string deserializeString(const std::vector<char>& buffer, size_t& offset) {
12 size_t length =
13 deserializeBasicType<size_t>(buffer, offset); // Get the length of the string
14 std::string str(buffer.begin() + offset,
15 buffer.begin() + offset + length); // Extract the string
16 offset += length;
17 return str;
18 }
19
20 std::vector<char> LogEntry::serialize() const {
21 std::vector<char> buffer;
22
27 serializeBasicType(buffer, rank);
28
29 // Serialize the timestamp (as duration since epoch)
30 auto duration = timestamp.time_since_epoch().count();
31 serializeBasicType(buffer, duration);
32
33 size_t mapSize = parameters.size();
34 serializeBasicType(buffer, mapSize);
35 for (const auto& pair : parameters) {
36 serializeString(buffer, pair.first);
37 serializeString(buffer, pair.second);
38 }
39
40 return buffer;
41 }
42
43 LogEntry LogEntry::deserialize(const std::vector<char>& buffer, size_t offset) {
44 LogEntry entry;
45 size_t current_pos = offset;
46
47 entry.methodName = deserializeString(buffer, current_pos);
48 entry.usedSize = deserializeBasicType<size_t>(buffer, current_pos);
49 entry.freeSize = deserializeBasicType<size_t>(buffer, current_pos);
50 entry.memorySpace = deserializeString(buffer, current_pos);
51 entry.rank = deserializeBasicType<int>(buffer, current_pos);
52
53 auto duration = deserializeBasicType<long long>(buffer, current_pos);
54 entry.timestamp = std::chrono::time_point<std::chrono::high_resolution_clock>(
55 std::chrono::high_resolution_clock::duration(duration));
56
57 size_t mapSize = deserializeBasicType<size_t>(buffer, current_pos);
58 for (size_t i = 0; i < mapSize; ++i) {
59 std::string key = deserializeString(buffer, current_pos);
60 std::string value = deserializeString(buffer, current_pos);
61 entry.parameters[key] = value;
62 }
63
64 return entry;
65 }
66
67} // namespace ippl
Definition Archive.h:20
void serializeString(std::vector< char > &buffer, const std::string &str)
Definition LogEntry.cpp:5
std::string deserializeString(const std::vector< char > &buffer, size_t &offset)
Definition LogEntry.cpp:11
T deserializeBasicType(const std::vector< char > &buffer, size_t &offset)
Definition LogEntry.h:33
void serializeBasicType(std::vector< char > &buffer, const T &value)
Definition LogEntry.h:26
std::string methodName
Definition LogEntry.h:13
std::map< std::string, std::string > parameters
Definition LogEntry.h:14
std::string memorySpace
Definition LogEntry.h:17
size_t freeSize
Definition LogEntry.h:16
std::chrono::time_point< std::chrono::high_resolution_clock > timestamp
Definition LogEntry.h:19
size_t usedSize
Definition LogEntry.h:15
static LogEntry deserialize(const std::vector< char > &buffer, size_t offset=0)
Definition LogEntry.cpp:43
std::vector< char > serialize() const
Definition LogEntry.cpp:20