20#include "cereal/archives/binary.hpp"
34template <
typename OutArchive,
typename InArchive,
typename Allocator,
typename DataBufferType>
37 std::basic_string<char, std::char_traits<char>,
Allocator> _data;
38 DataBufferType _object;
42 typename DataBufferType::value_type;
50 std::basic_stringstream<char, std::char_traits<char>,
Allocator>
buffer;
60 return std::move(_object);
65 std::istringstream
buffer(std::string(_data.begin(), _data.end()));
104template <
typename...
Args>
115template <
bool serialization_used,
typename BufferType>
133template <
typename Archive = cereal::BinaryOutputArchive,
typename Allocator = std::allocator<
char>,
typename T>
134auto as_serialized(T
const& data) {
135 internal::GenericDataBuffer<
139 internal::BufferModifiability::constant,
140 internal::BufferOwnership::referencing,
141 internal::BufferType::in_buffer>
144 return internal::SerializationBuffer<Archive, void, Allocator,
decltype(buffer)>{std::move(buffer)};
158 typename OutArchive = cereal::BinaryOutputArchive,
159 typename InArchive = cereal::BinaryInputArchive,
160 typename Allocator = std::allocator<char>,
162auto as_serialized(T&& data) {
163 if constexpr (std::is_rvalue_reference_v<T&&>) {
164 internal::GenericDataBuffer<
165 std::remove_reference_t<T>,
168 internal::BufferModifiability::modifiable,
169 internal::BufferOwnership::owning,
170 internal::BufferType::in_out_buffer>
172 return internal::SerializationBuffer<OutArchive, InArchive, Allocator,
decltype(buffer)>{std::move(buffer)};
174 internal::GenericDataBuffer<
175 std::remove_reference_t<T>,
178 internal::BufferModifiability::modifiable,
179 internal::BufferOwnership::referencing,
180 internal::BufferType::in_out_buffer>
182 return internal::SerializationBuffer<OutArchive, InArchive, Allocator,
decltype(buffer)>{std::move(buffer)};
193template <
typename T,
typename Archive = cereal::BinaryInputArchive,
typename Allocator = std::allocator<
char>>
194auto as_deserializable() {
195 internal::GenericDataBuffer<
199 internal::BufferModifiability::modifiable,
200 internal::BufferOwnership::owning,
201 internal::BufferType::out_buffer>
203 return internal::SerializationBuffer<void, Archive, Allocator,
decltype(buffer)>{std::move(buffer)};
214template <
typename Archive = cereal::BinaryInputArchive,
typename Allocator = std::allocator<
char>,
typename T>
215auto as_deserializable(T&&
object) {
216 if constexpr (std::is_rvalue_reference_v<T&&>) {
217 internal::GenericDataBuffer<
218 std::remove_reference_t<T>,
221 internal::BufferModifiability::modifiable,
222 internal::BufferOwnership::owning,
223 internal::BufferType::out_buffer>
224 buffer(std::move(
object));
225 return internal::SerializationBuffer<void, Archive, Allocator, decltype(buffer)>(std::move(buffer));
227 internal::GenericDataBuffer<
228 std::remove_reference_t<T>,
231 internal::BufferModifiability::modifiable,
232 internal::BufferOwnership::referencing,
233 internal::BufferType::out_buffer>
235 return internal::SerializationBuffer<void, Archive, Allocator, decltype(buffer)>(std::move(buffer));
STL-compatible allocator for requesting memory using the builtin MPI allocator.
Definition allocator.hpp:32
Buffer holding serialized data.
Definition serialization.hpp:35
SerializationBuffer(DataBufferType &&object)
Construct a serialization buffer from a GenericDataBuffer containing the object to serialize/deserial...
Definition serialization.hpp:46
void resize(size_t size)
Resize the underlying buffer.
Definition serialization.hpp:86
void deserialize()
Deserialize from the character buffer stored internally into the encapsulated object.
Definition serialization.hpp:64
char * data() noexcept
Access the underlying buffer.
Definition serialization.hpp:75
DataBufferType extract() &&
Extract the GenericDataBuffer containing the encapsulated object.
Definition serialization.hpp:59
typename DataBufferType::value_type data_type
Type of the encapsulated object to serialize/deserialize.
Definition serialization.hpp:41
char const * data() const noexcept
Access the underlying buffer.
Definition serialization.hpp:80
size_t size() const
Access the size of the underlying buffer.
Definition serialization.hpp:91
void serialize()
Serialize the object into the character buffer stored internally.
Definition serialization.hpp:49
ParameterType
Each input parameter to one of the MPI calls wrapped by KaMPIng needs to has one of the following tag...
Definition named_parameter_types.hpp:33
constexpr bool is_serialization_buffer_v
Type trait to check if a type is a serialization buffer.
Definition serialization.hpp:109
constexpr bool is_serialization_buffer_v_impl
Type trait to check if a type is a serialization buffer.
Definition serialization.hpp:101
auto deserialization_repack(BufferType buffer)
If serialization_used is true, this takes a received serialization buffer, deserializes the data and ...
Definition serialization.hpp:116
BufferType
Enum to specify whether a buffer is an in buffer of an out buffer. Out buffer will be used to directl...
Definition data_buffer.hpp:258
Tag type to identify serialization support.
Definition serialization.hpp:97