#ifndef GERMANAIRLINESVA_FILE_HELPERS_H #define GERMANAIRLINESVA_FILE_HELPERS_H #include #include #include #include namespace germanairlinesva { namespace file { static inline const std::string readString(std::ifstream &in, std::uint8_t length) { std::vector value(length + 1); in.read(value.data(), length); return std::string(std::move(value.data())); } static inline const std::string readString(std::ifstream &in) { std::uint8_t length; in.read(reinterpret_cast(&length), 1); std::vector value(length + 1); in.read(value.data(), length); return std::string(std::move(value.data())); } template static inline const T read(std::ifstream &in) { T value; in.read(reinterpret_cast(&value), sizeof(value)); return value; } static inline void writeString(std::ofstream &out, std::string value) { std::uint8_t length = value.length(); out.write(reinterpret_cast(&length), sizeof(length)); out.write(value.data(), length); } static inline void writeString(std::ofstream &out, std::string value, std::uint8_t length) { out.write(value.data(), length); } template static inline void write(std::ofstream &out, T value) { out.write(reinterpret_cast(&value), sizeof(value)); } } // namespace file } // namespace germanairlinesva #endif