10 #ifndef EIGEN_SERIALIZER_H
11 #define EIGEN_SERIALIZER_H
13 #include <type_traits>
26 template<
typename T,
typename EnableIf =
void>
32 std::is_trivial<T>::value
33 && std::is_standard_layout<T>::value>> {
57 memcpy(dest, &value,
sizeof(value));
58 return dest +
sizeof(value);
72 memcpy(&value, src,
sizeof(value));
73 return src +
sizeof(value);
79 template<
typename Derived>
82 typedef typename Derived::Scalar
Scalar;
90 return sizeof(Header) +
sizeof(
Scalar) * value.size();
96 const size_t header_bytes =
sizeof(Header);
97 const size_t data_bytes =
sizeof(
Scalar) * value.size();
98 Header header = {value.rows(), value.cols()};
100 memcpy(dest, &header, header_bytes);
101 dest += header_bytes;
102 memcpy(dest, value.data(), data_bytes);
103 return dest + data_bytes;
109 const size_t header_bytes =
sizeof(Header);
112 memcpy(&header, src, header_bytes);
114 const size_t data_bytes =
sizeof(
Scalar) * header.rows * header.cols;
116 value.resize(header.rows, header.cols);
117 memcpy(value.data(), src, data_bytes);
118 return src + data_bytes;
122 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
124 Serializer<DenseBase<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > > {};
126 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
128 Serializer<DenseBase<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > > {};
133 template<
size_t N,
typename... Types>
134 struct serialize_impl;
136 template<
size_t N,
typename T1,
typename... Ts>
137 struct serialize_impl<N, T1, Ts...> {
143 size_t size = serializer.size(value);
149 Serializer serializer;
150 dest = serializer.serialize(dest,
end, value);
156 Serializer serializer;
157 src = serializer.deserialize(src,
end, value);
164 struct serialize_impl<0> {
184 template<
typename... Args>
187 return internal::serialize_impl<
sizeof...(args), Args...>::
serialize_size(args...);
198 template<
typename... Args>
201 return internal::serialize_impl<
sizeof...(args), Args...>::
serialize(dest,
end, args...);
212 template<
typename... Args>
215 return internal::serialize_impl<
sizeof...(args), Args...>::
deserialize(src,
end, args...);
#define EIGEN_USING_STD(FUNC)
#define EIGEN_PREDICT_FALSE(x)
#define EIGEN_DEVICE_FUNC
General-purpose arrays with easy API for coefficient-wise operations.
Base class for all dense matrices, vectors, and arrays.
The matrix class, also used for vectors and row-vectors.
const uint8_t * deserialize(const uint8_t *src, const uint8_t *end, Derived &value) const
uint8_t * serialize(uint8_t *dest, uint8_t *end, const Derived &value)
size_t size(const Derived &value) const
uint8_t * serialize(uint8_t *dest, uint8_t *end, const T &value)
size_t size(const T &value) const
const uint8_t * deserialize(const uint8_t *src, const uint8_t *end, T &value) const
static const lastp1_t end
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
uint8_t * serialize(uint8_t *dest, uint8_t *end, const Args &... args)
size_t serialize_size(const Args &... args)
const uint8_t * deserialize(const uint8_t *src, const uint8_t *end, Args &... args)