DelegateMQ
Loading...
Searching...
No Matches
cereal/Serializer.h
Go to the documentation of this file.
1#ifndef SERIALIZER_H
2#define SERIALIZER_H
3
10
11#include <cereal/archives/binary.hpp>
12#include <cereal/types/string.hpp>
13#include <cereal/types/vector.hpp>
15#include <iostream>
16#include <type_traits>
17#include <sstream>
18
19// Type trait to check if a type is const
20template <typename T>
21using is_const_type = std::is_const<std::remove_reference_t<T>>;
22
23template <class R>
24struct Serializer; // Not defined
25
26// Serialize all target function argument data using Cereal
27template<class RetType, class... Args>
28class Serializer<RetType(Args...)> : public dmq::ISerializer<RetType(Args...)>
29{
30public:
31 // Write arguments to a stream
32 virtual std::ostream& Write(std::ostream& os, Args... args) override {
33 try {
34 os.seekp(0);
35 cereal::BinaryOutputArchive archive(os);
36 (archive(args), ...); // C++17 fold expression to serialize each argument
37 }
38 catch (const std::exception& e) {
39 std::cerr << "Cereal serialize error: " << e.what() << std::endl;
40 throw;
41 }
42 return os;
43 }
44
45 // Read arguments from a stream
46 virtual std::istream& Read(std::istream& is, Args&... args) override {
47 try {
48 cereal::BinaryInputArchive archive(is);
49 (archive(args), ...); // C++17 fold expression to deserialize
50 }
51 catch (const std::exception& e) {
52 std::cerr << "Cereal deserialize error: " << e.what() << std::endl;
53 throw;
54 }
55 return is;
56 }
57};
58
59#endif
Delegate serializer interface class.
std::is_const< std::remove_reference_t< T > > is_const_type
Definition bitsery/Serializer.h:21
virtual std::istream & Read(std::istream &is, Args &... args) override
Definition cereal/Serializer.h:46
virtual std::ostream & Write(std::ostream &os, Args... args) override
Definition cereal/Serializer.h:32
Definition bitsery/Serializer.h:24
Definition ISerializer.h:12