8 #ifndef ZSERIO_SERIALIZE_UTIL_H_INC
9 #define ZSERIO_SERIALIZE_UTIL_H_INC
11 #include <string_view>
12 #include <type_traits>
52 template <
typename T,
typename ALLOC,
typename... ARGS, std::enable_if_t<is_allocator_v<ALLOC>,
int> = 0>
55 const View<T> view(data, std::forward<ARGS>(arguments)...);
86 template <
typename T,
typename ALLOC,
typename... ARGS, std::enable_if_t<is_allocator_v<ALLOC>,
int> = 0>
89 const View<T> view(data, std::forward<ARGS>(arguments)...);
117 template <
typename T,
typename... ARGS,
122 return serialize(data,
typename T::allocator_type(), std::forward<ARGS>(arguments)...);
150 template <
typename T,
typename... ARGS,
155 return serializeToBytes(data,
typename T::allocator_type(), std::forward<ARGS>(arguments)...);
180 template <
typename T,
typename ALLOC,
typename... ARGS>
186 return detail::read(reader, data, std::forward<ARGS>(arguments)...);
209 template <
typename T,
typename ALLOC,
typename... ARGS>
212 return deserialize<T>(buffer,
ArrayPreallocation(), data, std::forward<ARGS>(arguments)...);
237 template <
typename T,
typename... ARGS>
243 return detail::read(reader, data, std::forward<ARGS>(arguments)...);
266 template <
typename T,
typename... ARGS>
297 template <
typename T,
typename ALLOC>
300 detail::validate(view,
"");
301 const BitSize bitSize = detail::initializeOffsets(view, 0);
304 detail::write(writer, view);
334 template <
typename T,
typename ALLOC>
337 detail::validate(view,
"");
338 const BitSize bitSize = detail::initializeOffsets(view, 0);
341 detail::write(writer, view);
369 template <
typename T>
372 return serialize(view,
typename T::allocator_type());
396 template <
typename T>
426 template <
typename T,
typename ALLOC>
430 size_t bitSize = detail::bitSizeOf(dataView, 0);
434 detail::write(writer, dataView);
462 template <
typename T,
typename ALLOC>
466 size_t bitSize = detail::bitSizeOf(dataView, 0);
470 detail::write(writer, dataView);
496 template <
typename T>
499 return serialize(dataView,
typename T::allocator_type());
523 template <
typename T>
552 template <
typename T,
typename ALLOC,
typename... ARGS>
554 const typename T::allocator_type& allocator, ARGS&&... arguments)
559 return DataView<T>(reader, std::move(data), std::forward<ARGS>(arguments)...);
583 template <
typename T,
typename ALLOC,
typename... ARGS>
585 const BasicBitBuffer<ALLOC>& buffer,
const typename T::allocator_type& allocator, ARGS&&... arguments)
587 return deserialize<T>(buffer,
ArrayPreallocation(), allocator, std::forward<ARGS>(arguments)...);
612 template <
typename T,
typename... ARGS>
614 const typename T::allocator_type& allocator, ARGS&&... arguments)
619 return DataView<T>(reader, std::move(data), std::forward<ARGS>(arguments)...);
643 template <
typename T,
typename... ARGS>
645 Span<const uint8_t> buffer,
const typename T::allocator_type& allocator, ARGS&&... arguments)
647 return deserializeFromBytes<T>(buffer,
ArrayPreallocation(), allocator, std::forward<ARGS>(arguments)...);
671 template <
typename T,
typename ALLOC,
typename... ARGS,
676 return deserialize<T>(
677 buffer, maxArrayAlloc,
typename T::allocator_type(), std::forward<ARGS>(arguments)...);
700 template <
typename T,
typename ALLOC,
typename... ARGS,
704 return deserialize<T>(buffer,
ArrayPreallocation(), std::forward<ARGS>(arguments)...);
726 template <
typename T,
typename... ARGS, std::enable_if_t<!
is_first_allocator_v<ARGS...>,
int> = 0>
730 return deserializeFromBytes<T>(
731 buffer, maxArrayPrealloc,
typename T::allocator_type(), std::forward<ARGS>(arguments)...);
752 template <
typename T,
typename... ARGS,
756 return deserializeFromBytes<T>(buffer,
ArrayPreallocation(), std::forward<ARGS>(arguments)...);
776 template <
typename T>
800 template <
typename T>
803 const auto bitBuffer =
serialize(dataView);
824 template <
typename T,
typename... ARGS>
827 const View<T> view(data, std::forward<ARGS>(arguments)...);
855 template <
typename T,
typename... ARGS>
857 std::string_view fileName,
ArrayPreallocation maxArrayPrealloc, T& data, ARGS&&... arguments)
860 return deserialize(bitBuffer, maxArrayPrealloc, data, std::forward<ARGS>(arguments)...);
885 template <
typename T,
typename... ARGS>
915 template <
typename T,
typename... ARGS>
920 return deserialize<T>(bitBuffer, maxArrayPrealloc, std::forward<ARGS>(arguments)...);
945 template <
typename T,
typename... ARGS>
948 return deserializeFromFile<T>(fileName,
ArrayPreallocation(), std::forward<ARGS>(arguments)...);
std::vector< T, ALLOC > Vector
void serializeToFile(const View< T > &view, std::string_view fileName)
BasicBitBuffer< ALLOC > serialize(const T &data, const ALLOC &allocator, ARGS &&... arguments)
void writeBufferToFile(const uint8_t *buffer, size_t bitSize, BitsTag, std::string_view fileName)
View< T > deserializeFromBytes(Span< const uint8_t > buffer, ArrayPreallocation maxArrayPrealloc, T &data, ARGS &&... arguments)
View< T > deserializeFromFile(std::string_view fileName, ArrayPreallocation maxArrayPrealloc, T &data, ARGS &&... arguments)
Vector< uint8_t, ALLOC > serializeToBytes(const T &data, const ALLOC &allocator, ARGS &&... arguments)
BitBuffer readBufferFromFile(std::string_view fileName)
constexpr bool is_first_allocator_v
View< T > deserialize(const BasicBitBuffer< ALLOC > &buffer, ArrayPreallocation maxArrayPrealloc, T &data, ARGS &&... arguments)
constexpr bool is_first_array_preallocation_v