Something went wrong. Try again.
A fork of https://github.com/crosspoint-reader/crosspoint-reader
Something went wrong. Try again.
1.3 kB · 52 lines
C
at master
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253#pragma once#include <HalStorage.h>
#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 writePod(FsFile& file, const T& value) { file.write(reinterpret_cast<const uint8_t*>(&value), sizeof(T));}
template <typename T>static void readPod(std::istream& is, T& value) { is.read(reinterpret_cast<char*>(&value), sizeof(T));}
template <typename T>static void readPod(FsFile& file, T& value) { file.read(reinterpret_cast<uint8_t*>(&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 writeString(FsFile& file, const std::string& s) { const uint32_t len = s.size(); writePod(file, len); file.write(reinterpret_cast<const uint8_t*>(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);}
static void readString(FsFile& file, std::string& s) { uint32_t len; readPod(file, len); s.resize(len); file.read(&s[0], len);}} // namespace serialization