diff options
author | rtk0c <[email protected]> | 2021-08-15 17:14:06 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2021-08-15 17:14:06 -0700 |
commit | c51a61c0f0de65a3e64f589816a56f21ed4e8528 (patch) | |
tree | ba1737b64d5307f9dedc934d9398297d3fb8ee82 /core/src/Utils/IO/StringIntegration.hpp | |
parent | 64a6dbcfdb89a5f57d93d47a2be0c741dda4662d (diff) |
Initial work on data streams
Diffstat (limited to 'core/src/Utils/IO/StringIntegration.hpp')
-rw-r--r-- | core/src/Utils/IO/StringIntegration.hpp | 29 |
1 files changed, 29 insertions, 0 deletions
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 <iterator> +#include <string> +#include <string_view> + +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 |