Serialization-Impl.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_SERIALIZATION_IMPL_HPP
12 #define CUBBYFLOW_SERIALIZATION_IMPL_HPP
13 
14 #include <cstring>
15 
16 namespace CubbyFlow
17 {
18 template <typename T>
19 void Serialize(const ConstArrayView1<T>& array, std::vector<uint8_t>* buffer)
20 {
21  const size_t size = sizeof(T) * array.Length();
22  Serialize(reinterpret_cast<const uint8_t*>(array.data()), size, buffer);
23 }
24 
25 template <typename T>
26 void Deserialize(const std::vector<uint8_t>& buffer, Array1<T>* array)
27 {
28  std::vector<uint8_t> data;
29  Deserialize(buffer, &data);
30  array->Resize(data.size() / sizeof(T));
31  std::memcpy(array->data(), data.data(), data.size());
32 }
33 } // namespace CubbyFlow
34 
35 #endif
void Serialize(const ConstArrayView1< T > &array, std::vector< uint8_t > *buffer)
Serializes data chunk using common schema.
Definition: Serialization-Impl.hpp:19
Definition: pybind11Utils.hpp:20
void Deserialize(const std::vector< uint8_t > &buffer, Array1< T > *array)
Deserializes buffer to data chunk using common schema.
Definition: Serialization-Impl.hpp:26
Definition: Array-Impl.hpp:19
size_t Length() const
Definition: ArrayBase-Impl.hpp:84
Generic N-dimensional array class interface.
Definition: Array.hpp:32
Pointer data()
Definition: ArrayBase-Impl.hpp:39
void Resize(Vector< size_t, N > size_, const T &initVal=T{})
Definition: Array-Impl.hpp:286