10 #ifndef ZSERIO_SERIALIZE_UTIL_H_INC 11 #define ZSERIO_SERIALIZE_UTIL_H_INC 26 void initializeChildrenImpl(std::true_type, T&
object)
28 object.initializeChildren();
32 void initializeChildrenImpl(std::false_type, T&)
36 void initializeChildren(T&
object)
38 initializeChildrenImpl(has_initialize_children<T>(),
object);
41 template <
typename T,
typename ...ARGS>
42 void initializeImpl(std::true_type, T&
object, ARGS&&... arguments)
44 object.initialize(std::forward<ARGS>(arguments)...);
48 void initializeImpl(std::false_type, T&
object)
50 initializeChildren(
object);
53 template <
typename T,
typename ...ARGS>
54 void initialize(T&
object, ARGS&&... arguments)
56 initializeImpl(has_initialize<T>(),
object, std::forward<ARGS>(arguments)...);
59 template <
typename T,
typename =
void>
60 struct allocator_chooser
62 using type = std::allocator<uint8_t>;
66 struct allocator_chooser<T, detail::void_t<typename T::allocator_type>>
68 using type =
typename T::allocator_type;
72 template <
typename T,
typename ALLOC,
typename ...ARGS>
73 BasicBitBuffer<ALLOC>
serialize(T&
object,
const ALLOC& allocator, ARGS&&... arguments)
75 detail::initialize(
object, std::forward<ARGS>(arguments)...);
77 BitStreamWriter writer(bitBuffer);
109 template <
typename T,
typename ALLOC,
typename ...ARGS,
110 typename std::enable_if<!std::is_enum<T>::value && is_allocator<ALLOC>::value,
int>::type = 0>
137 template <typename T, typename ALLOC = typename detail::allocator_chooser<T>::type,
typename ...ARGS,
138 typename std::enable_if<!std::is_enum<T>::value &&
163 template <
typename T,
typename ALLOC = std::allocator<u
int8_t>,
164 typename std::enable_if<std::is_enum<T>::value,
int>::type = 0>
192 template <
typename T,
typename ALLOC,
typename ...ARGS>
193 typename std::enable_if<!std::is_enum<T>::value, T>::type
deserialize(
197 return T(reader, std::forward<ARGS>(arguments)...);
218 template <
typename T,
typename ALLOC>
222 return zserio::read<T>(reader);
250 template <
typename T,
typename ALLOC,
typename ...ARGS,
251 typename std::enable_if<!std::is_enum<T>::value && is_allocator<ALLOC>::value,
int>::type = 0>
255 std::forward<ARGS>(arguments)...);
284 template <typename T, typename ALLOC = typename detail::allocator_chooser<T>::type,
typename ...ARGS,
285 typename std::enable_if<!std::is_enum<T>::value &&
290 std::forward<ARGS>(arguments)...);
313 template <
typename T,
typename ALLOC = std::allocator<u
int8_t>,
314 typename std::enable_if<std::is_enum<T>::value,
int>::type = 0>
345 template <
typename T,
typename ...ARGS>
350 return T(reader, std::forward<ARGS>(arguments)...);
371 template <
typename T>
375 return zserio::read<T>(reader);
394 template <
typename T,
typename ...ARGS>
397 const auto bitBuffer =
serialize(
object, std::forward<ARGS>(arguments)...);
423 template <
typename T,
typename ...ARGS>
427 return deserialize<T>(bitBuffer, std::forward<ARGS>(arguments)...);
432 #endif // ZSERIO_SERIALIZE_UTIL_H_INC
const vector< uint8_t, ALLOC > & getBytes() const
BasicBitBuffer< ALLOC > serialize(T &object, const ALLOC &allocator, ARGS &&...arguments)
void writeBufferToFile(const uint8_t *buffer, size_t bitSize, BitsTag, const std::string &fileName)
BasicBitBuffer< ALLOC > serialize(T enumValue, const ALLOC &allocator=ALLOC())
zserio::string< PropagatingPolymorphicAllocator< char >> string
void write(BitStreamWriter &out, T value)
void serializeToFile(T &object, const std::string &fileName, ARGS &&...arguments)
std::vector< T, RebindAlloc< ALLOC, T >> vector
vector< uint8_t, ALLOC > serializeToBytes(T &object, const ALLOC &allocator, ARGS &&...arguments)
BitBuffer readBufferFromFile(const std::string &fileName)
size_t initializeOffsets(size_t bitPosition, T value)
T deserializeFromFile(const std::string &fileName, ARGS &&...arguments)
std::enable_if<!std::is_enum< T >::value, T >::type deserialize(const BasicBitBuffer< ALLOC > &bitBuffer, ARGS &&...arguments)
size_t bitSizeOf(T value)
std::enable_if<!std::is_enum< T >::value, T >::type deserializeFromBytes(Span< const uint8_t > buffer, ARGS &&...arguments)