13 virtual bool IsStreamGood()
const = 0;
14 virtual uint64_t GetStreamPosition() = 0;
15 virtual void SetStreamPosition(uint64_t position) = 0;
16 virtual bool WriteData(
const char* data,
const size_t size) = 0;
18 operator bool()
const {
return IsStreamGood(); }
20 void WriteBuffer(
FBuffer buffer,
bool bWriteSize =
true);
21 void WriteZero(uint64_t size);
22 void WriteString(
const std::string&
string);
25 void WriteRaw(
const T& type)
27 const bool success = WriteData((
char*)&type,
sizeof(T));
31 void WriteObject(
const T& obj)
33 T::Serialize(
this, obj);
36 template<
typename Key,
typename Value>
37 void WriteMap(
const std::map<Key, Value>& map,
const bool bWriteSize =
true)
41 WriteRaw<uint32_t>((uint32_t)map.size());
44 for (
const auto& [key, value] : map)
46 if constexpr (std::is_trivial<Key>())
52 WriteObject<Key>(key);
55 if constexpr (std::is_trivial<Value>())
57 WriteRaw<Value>(value);
61 WriteObject<Value>(value);
66 template<
typename Key,
typename Value>
67 void WriteMap(
const std::unordered_map<Key, Value>& map,
const bool bWriteSize =
true)
71 WriteRaw<uint32_t>((uint32_t)map.size());
74 for (
const auto& [key, value] : map)
76 if constexpr (std::is_trivial<Key>())
82 WriteObject<Key>(key);
85 if constexpr (std::is_trivial<Value>())
87 WriteRaw<Value>(value);
91 WriteObject<Value>(value);
96 template<
typename Value>
97 void WriteMap(
const std::unordered_map<std::string, Value>& map,
bool bWriteSize =
true)
100 WriteRaw<uint32_t>((uint32_t)map.size());
102 for (
const auto& [key, value] : map)
106 if constexpr (std::is_trivial<Value>())
107 WriteRaw<Value>(value);
109 WriteObject<Value>(value);
114 void WriteArray(
const std::vector<T>& array,
bool bWriteSize =
true)
117 WriteRaw<uint32_t>((uint32_t)array.size());
119 for (
const auto& element : array)
121 if constexpr (std::is_trivial<T>())
122 WriteRaw<T>(element);
124 WriteObject<T>(element);
131 inline void StreamWriter::WriteArray(
const std::vector<std::string>& array,
bool bWriteSize)