Serialization-Impl.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: Serialization-Impl.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Abstract base class for any serializable class.
6 > Created Time: 2017/04/28
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_SERIALIZATION_IMPL_H
10 #define CUBBYFLOW_SERIALIZATION_IMPL_H
11 
12 namespace CubbyFlow
13 {
14  template <typename T>
15  void Serialize(const ConstArrayAccessor1<T>& array, std::vector<uint8_t>* buffer)
16  {
17  const size_t size = sizeof(T) * array.size();
18  Serialize(reinterpret_cast<const uint8_t*>(array.data()), size, buffer);
19  }
20 
21  template <typename T>
22  void Deserialize(const std::vector<uint8_t>& buffer, Array1<T>* array)
23  {
24  std::vector<uint8_t> data;
25  Deserialize(buffer, &data);
26  array->Resize(data.size() / sizeof(T));
27  memcpy(array->data(), data.data(), data.size());
28  }
29 }
30 
31 #endif
void Resize(size_t size, const T &initVal=T())
Resizes the array with size and fill the new element with initVal.
Definition: Array1-Impl.h:83
const T *const data() const
Returns the raw pointer to the array data.
Definition: ArrayAccessor1-Impl.h:225
1-D read-only array accessor class.
Definition: ArrayAccessor1.h:185
1-D array class.
Definition: Array1.h:29
Definition: pybind11Utils.h:24
void Deserialize(const std::vector< uint8_t > &buffer, Array1< T > *array)
Deserializes buffer to data chunk using common schema.
Definition: Serialization-Impl.h:22
size_t size() const
Returns size of the array.
Definition: ArrayAccessor1-Impl.h:219
void Serialize(const ConstArrayAccessor1< T > &array, std::vector< uint8_t > *buffer)
Serializes data chunk using common schema.
Definition: Serialization-Impl.h:15
T * data()
Returns the raw pointer to the array data.
Definition: Array1-Impl.h:109