Serialization.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_HPP
12 #define CUBBYFLOW_SERIALIZATION_HPP
13 
14 #include <Core/Array/ArrayView.hpp>
15 
16 #include <vector>
17 
18 namespace CubbyFlow
19 {
22 {
23  public:
25  Serializable() = default;
26 
28  Serializable(const Serializable&) = default;
29 
31  Serializable(Serializable&&) noexcept = default;
32 
34  virtual ~Serializable() = default;
35 
37  Serializable& operator=(const Serializable&) = default;
38 
40  Serializable& operator=(Serializable&&) noexcept = default;
41 
43  virtual void Serialize(std::vector<uint8_t>* buffer) const = 0;
44 
46  virtual void Deserialize(const std::vector<uint8_t>& buffer) = 0;
47 };
48 
50 void Serialize(const Serializable* serializable, std::vector<uint8_t>* buffer);
51 
53 void Serialize(const uint8_t* data, size_t size, std::vector<uint8_t>* buffer);
54 
56 template <typename T>
57 void Serialize(const ConstArrayView1<T>& array, std::vector<uint8_t>* buffer);
58 
60 void Deserialize(const std::vector<uint8_t>& buffer,
61  Serializable* serializable);
62 
64 void Deserialize(const std::vector<uint8_t>& buffer,
65  std::vector<uint8_t>* data);
66 
68 template <typename T>
69 void Deserialize(const std::vector<uint8_t>& buffer, Array1<T>* array);
70 } // namespace CubbyFlow
71 
73 
74 #endif
Abstract base class for any serializable class.
Definition: Serialization.hpp:21
virtual ~Serializable()=default
Default virtual destructor.
virtual void Deserialize(const std::vector< uint8_t > &buffer)=0
Deserializes this instance from the flat buffer.
Definition: pybind11Utils.hpp:20
Definition: Array-Impl.hpp:19
virtual void Serialize(std::vector< uint8_t > *buffer) const =0
Serializes this instance into the flat buffer.
Generic N-dimensional array class interface.
Definition: Array.hpp:32
Serializable()=default
Default constructor.
Serializable & operator=(const Serializable &)=default
Default copy assignment operator.