20#ifdef KAMPING_ENABLE_SERIALIZATION
21 #include "cereal/archives/binary.hpp"
27#ifdef KAMPING_ENABLE_SERIALIZATION
37template <
typename OutArchive,
typename InArchive,
typename Allocator,
typename DataBufferType>
38class SerializationBuffer {
40 std::basic_string<char, std::char_traits<char>, Allocator> _data;
41 DataBufferType _object;
45 typename DataBufferType::value_type;
49 SerializationBuffer(DataBufferType&&
object) : _data(), _object(
std::move(object)) {}
53 std::basic_stringstream<char, std::char_traits<char>, Allocator> buffer;
55 OutArchive archive(buffer);
56 archive(_object.underlying());
62 DataBufferType extract() && {
63 return std::move(_object);
68 std::istringstream buffer(std::string(_data.begin(), _data.end()));
70 InArchive archive(buffer);
71 archive(_object.underlying());
75 using value_type = char;
78 char* data() noexcept {
83 char const* data() const noexcept {
89 void resize(
size_t size) {
106#ifdef KAMPING_ENABLE_SERIALIZATION
108template <
typename...
Args>
120template <
bool serialization_used,
typename BufferType>
131#ifdef KAMPING_ENABLE_SERIALIZATION
138template <
typename Archive = cereal::BinaryOutputArchive,
typename Allocator = std::allocator<
char>,
typename T>
139auto as_serialized(T
const& data) {
140 internal::GenericDataBuffer<
144 internal::BufferModifiability::constant,
145 internal::BufferOwnership::referencing,
146 internal::BufferType::in_buffer>
149 return internal::SerializationBuffer<Archive, void, Allocator,
decltype(buffer)>{std::move(buffer)};
163 typename OutArchive = cereal::BinaryOutputArchive,
164 typename InArchive = cereal::BinaryInputArchive,
165 typename Allocator = std::allocator<char>,
167auto as_serialized(T&& data) {
168 if constexpr (std::is_rvalue_reference_v<T&&>) {
169 internal::GenericDataBuffer<
170 std::remove_reference_t<T>,
173 internal::BufferModifiability::modifiable,
174 internal::BufferOwnership::owning,
175 internal::BufferType::in_out_buffer>
177 return internal::SerializationBuffer<OutArchive, InArchive, Allocator,
decltype(buffer)>{std::move(buffer)};
179 internal::GenericDataBuffer<
180 std::remove_reference_t<T>,
183 internal::BufferModifiability::modifiable,
184 internal::BufferOwnership::referencing,
185 internal::BufferType::in_out_buffer>
187 return internal::SerializationBuffer<OutArchive, InArchive, Allocator,
decltype(buffer)>{std::move(buffer)};
198template <
typename T,
typename Archive = cereal::BinaryInputArchive,
typename Allocator = std::allocator<
char>>
199auto as_deserializable() {
200 internal::GenericDataBuffer<
204 internal::BufferModifiability::modifiable,
205 internal::BufferOwnership::owning,
206 internal::BufferType::out_buffer>
208 return internal::SerializationBuffer<void, Archive, Allocator,
decltype(buffer)>{std::move(buffer)};
219template <
typename Archive = cereal::BinaryInputArchive,
typename Allocator = std::allocator<
char>,
typename T>
220auto as_deserializable(T&&
object) {
221 if constexpr (std::is_rvalue_reference_v<T&&>) {
222 internal::GenericDataBuffer<
223 std::remove_reference_t<T>,
226 internal::BufferModifiability::modifiable,
227 internal::BufferOwnership::owning,
228 internal::BufferType::out_buffer>
229 buffer(std::move(
object));
230 return internal::SerializationBuffer<void, Archive, Allocator, decltype(buffer)>(std::move(buffer));
232 internal::GenericDataBuffer<
233 std::remove_reference_t<T>,
236 internal::BufferModifiability::modifiable,
237 internal::BufferOwnership::referencing,
238 internal::BufferType::out_buffer>
240 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
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:114
constexpr bool is_serialization_buffer_v_impl
Type trait to check if a type is a serialization buffer.
Definition serialization.hpp:105
auto deserialization_repack(BufferType buffer)
If serialization_used is true, this takes a received serialization buffer, deserializes the data and ...
Definition serialization.hpp:121
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:287
Tag type to identify serialization support.
Definition serialization.hpp:101