A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at records-reader 52 lines 1.3 kB view raw
1#pragma once 2#include <HalStorage.h> 3 4#include <iostream> 5 6namespace serialization { 7template <typename T> 8static void writePod(std::ostream& os, const T& value) { 9 os.write(reinterpret_cast<const char*>(&value), sizeof(T)); 10} 11 12template <typename T> 13static void writePod(FsFile& file, const T& value) { 14 file.write(reinterpret_cast<const uint8_t*>(&value), sizeof(T)); 15} 16 17template <typename T> 18static void readPod(std::istream& is, T& value) { 19 is.read(reinterpret_cast<char*>(&value), sizeof(T)); 20} 21 22template <typename T> 23static void readPod(FsFile& file, T& value) { 24 file.read(reinterpret_cast<uint8_t*>(&value), sizeof(T)); 25} 26 27static void writeString(std::ostream& os, const std::string& s) { 28 const uint32_t len = s.size(); 29 writePod(os, len); 30 os.write(s.data(), len); 31} 32 33static void writeString(FsFile& file, const std::string& s) { 34 const uint32_t len = s.size(); 35 writePod(file, len); 36 file.write(reinterpret_cast<const uint8_t*>(s.data()), len); 37} 38 39static void readString(std::istream& is, std::string& s) { 40 uint32_t len; 41 readPod(is, len); 42 s.resize(len); 43 is.read(&s[0], len); 44} 45 46static void readString(FsFile& file, std::string& s) { 47 uint32_t len; 48 readPod(file, len); 49 s.resize(len); 50 file.read(&s[0], len); 51} 52} // namespace serialization