aboutsummaryrefslogtreecommitdiff
path: root/core/src/Utils/IO/StringIntegration.hpp
blob: a90ea98395cb47dee3ab0d7fde6811464daf8da9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma once

#include <iterator>
#include <string>
#include <string_view>

namespace DataStreamAdapters {
struct String
{
	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());
	}
};

struct StringView
{
	void WriteToDataStream(DataStream& s, const std::string_view& str)
	{
		s.Write((uint64_t)str.size());
		s.WriteBytes(str.size(), str.data());
	}
};
} // namespace DataStreamAdapters