@@ -6,83 +6,4 @@ using namespace ZEngine::Core::Containers;
66
77namespace Tetragrama ::Helpers
88{
9- void SerializeStringData (std::ostream& os, ZEngine::Core::Containers::StringView str)
10- {
11- size_t f_count = str.size ();
12- os.write (reinterpret_cast <const char *>(&f_count), sizeof (size_t ));
13- os.write (str.data (), f_count + 1 );
14- }
15-
16- void DeserializeStringData (ZEngine::Core::Memory::ArenaAllocator* Arena, std::istream& in, ZEngine::Core::Containers::String& d)
17- {
18- size_t v_count;
19- char buf[DEFAULT_STR_BUFFER] = {0 };
20- in.read (reinterpret_cast <char *>(&v_count), sizeof (size_t ));
21- in.read (buf, v_count + 1 );
22-
23- d.init (Arena, buf);
24- }
25-
26- void SerializeStringArrayData (std::ostream& os, ZEngine::Core::Containers::ArrayView<ZEngine::Core::Containers::String> str_view)
27- {
28- size_t count = str_view.size ();
29- os.write (reinterpret_cast <const char *>(&count), sizeof (size_t ));
30- for (unsigned i = 0 ; i < count; ++i)
31- {
32- size_t f_count = str_view[i].size ();
33- os.write (reinterpret_cast <const char *>(&f_count), sizeof (size_t ));
34- os.write (str_view[i].data (), f_count + 1 );
35- }
36- }
37-
38- void SerializeMapData (std::ostream& os, ZEngine::Core::Containers::HashMap<uint32_t , uint32_t >& data)
39- {
40- std::vector<uint32_t > flat_data = {};
41- flat_data.reserve (data.size () * 2 );
42-
43- auto view = data.view ();
44- for (auto d : view)
45- {
46- flat_data.push_back (d.first );
47- flat_data.push_back (d.second );
48- }
49-
50- size_t data_count = flat_data.size ();
51- os.write (reinterpret_cast <const char *>(&data_count), sizeof (size_t ));
52- os.write (reinterpret_cast <const char *>(flat_data.data ()), sizeof (uint32_t ) * flat_data.size ());
53- }
54-
55- void DeserializeStringArrayData (ZEngine::Core::Memory::ArenaAllocator* Arena, std::istream& in, ZEngine::Core::Containers::Array<ZEngine::Core::Containers::String>& data)
56- {
57- size_t data_count;
58- in.read (reinterpret_cast <char *>(&data_count), sizeof (size_t ));
59- data.init (Arena, data_count);
60-
61- for (int i = 0 ; i < data_count; ++i)
62- {
63- size_t v_count;
64- char buf[DEFAULT_STR_BUFFER] = {0 };
65- in.read (reinterpret_cast <char *>(&v_count), sizeof (size_t ));
66- in.read (buf, v_count + 1 );
67-
68- String v;
69- v.init (Arena, buf);
70- data.push (v);
71- }
72- }
73-
74- void DeserializeMapData (ZEngine::Core::Memory::ArenaAllocator* Arena, std::istream& in, ZEngine::Core::Containers::HashMap<uint32_t , uint32_t >& data)
75- {
76- size_t data_count;
77- in.read (reinterpret_cast <char *>(&data_count), sizeof (size_t ));
78- data.init (Arena, data_count);
79-
80- uint32_t buf[DEFAULT_STR_BUFFER] = {0 };
81- in.read (reinterpret_cast <char *>(buf), sizeof (uint32_t ) * data_count);
82-
83- for (int i = 0 ; i < data_count; i += 2 )
84- {
85- data[buf[i]] = buf[i + 1 ];
86- }
87- }
889} // namespace Tetragrama::Helpers
0 commit comments