From c51a61c0f0de65a3e64f589816a56f21ed4e8528 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Sun, 15 Aug 2021 17:14:06 -0700 Subject: Initial work on data streams --- core/src/Utils/IO/StringIntegration.hpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 core/src/Utils/IO/StringIntegration.hpp (limited to 'core/src/Utils/IO/StringIntegration.hpp') diff --git a/core/src/Utils/IO/StringIntegration.hpp b/core/src/Utils/IO/StringIntegration.hpp new file mode 100644 index 0000000..d4be23a --- /dev/null +++ b/core/src/Utils/IO/StringIntegration.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include "Utils/IO/DataStream.hpp" + +#include +#include +#include + +void ReadFromDataStream(DataStream& s, std::string& str) +{ + uint64_t size; + s.Read(size); + + str = {}; + str.reserve(size); + s.ReadBytes(size, std::back_inserter(str)); +} + +void WriteToDataStream(DataStream& s, const std::string& str) +{ + s.Write((uint64_t)str.size()); + s.WriteBytes(str.size(), str.data()); +} + +void WriteToDataStream(DataStream& s, const std::string_view& str) +{ + s.Write((uint64_t)str.size()); + s.WriteBytes(str.size(), str.data()); +} \ No newline at end of file -- cgit v1.2.3-70-g09d2