Loading...
Searching...
No Matches
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
16namespace CubbyFlow
17{
18template <typename T>
19void 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
25template <typename T>
26void 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
ValueType Length() const
Definition MatrixExpression-Impl.hpp:278
Definition Matrix.hpp:30
Pointer data()
Definition Matrix-Impl.hpp:298
Definition pybind11Utils.hpp:21
void Deserialize(const std::vector< uint8_t > &buffer, Array1< T > *array)
Deserializes buffer to data chunk using common schema.
Definition Serialization-Impl.hpp:26
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:738
void Serialize(const ConstArrayView1< T > &array, std::vector< uint8_t > *buffer)
Serializes data chunk using common schema.
Definition Serialization-Impl.hpp:19