mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2025-12-16 22:27:42 +03:00
28 lines
651 B
C++
28 lines
651 B
C++
#pragma once
|
|
#include <iostream>
|
|
|
|
namespace serialization {
|
|
template <typename T>
|
|
static void writePod(std::ostream& os, const T& value) {
|
|
os.write(reinterpret_cast<const char*>(&value), sizeof(T));
|
|
}
|
|
|
|
template <typename T>
|
|
static void readPod(std::istream& is, T& value) {
|
|
is.read(reinterpret_cast<char*>(&value), sizeof(T));
|
|
}
|
|
|
|
static void writeString(std::ostream& os, const std::string& s) {
|
|
const uint32_t len = s.size();
|
|
writePod(os, len);
|
|
os.write(s.data(), len);
|
|
}
|
|
|
|
static void readString(std::istream& is, std::string& s) {
|
|
uint32_t len;
|
|
readPod(is, len);
|
|
s.resize(len);
|
|
is.read(&s[0], len);
|
|
}
|
|
} // namespace serialization
|