DelegateMQ
Loading...
Searching...
No Matches
serialize/Serializer.h
Go to the documentation of this file.
1#ifndef SERIALIZER_H
2#define SERIALIZER_H
3
10
12#include "msg_serialize.h"
13#include <iostream>
14
15template <class R>
16struct Serializer; // Not defined
17
18// Serialize all target function argument data using serialize class
19template<class RetType, class... Args>
20class Serializer<RetType(Args...)> : public dmq::ISerializer<RetType(Args...)>
21{
22public:
23 // Write arguments to a stream
24 virtual std::ostream& Write(std::ostream& os, Args... args) override {
25 try {
26 os.seekp(0, std::ios::beg);
27 serialize ser;
28 (ser.write(os, args), ...); // C++17 fold expression to serialize each argument
29 }
30 catch (const std::exception& e) {
31 std::cerr << "Serialize error: " << e.what() << std::endl;
32 throw;
33 }
34 return os;
35 }
36
37 // Read arguments from a stream
38 virtual std::istream& Read(std::istream& is, Args&... args) override {
39 try {
40 serialize ser;
41 (ser.read(is, args), ...); // C++17 fold expression to unserialize each argument
42 }
43 catch (const std::exception& e) {
44 std::cerr << "Deserialize error: " << e.what() << std::endl;
45 throw;
46 }
47 return is;
48 }
49};
50
51#endif
Delegate serializer interface class.
virtual std::istream & Read(std::istream &is, Args &... args) override
Definition serialize/Serializer.h:38
virtual std::ostream & Write(std::ostream &os, Args... args) override
Definition serialize/Serializer.h:24
The serialize class binary serializes and deserializes C++ objects.
Definition msg_serialize.h:105
std::istream & read(std::istream &is, I *t_)
Definition msg_serialize.h:195
std::ostream & write(std::ostream &os, I *t_)
Definition msg_serialize.h:349
Definition bitsery/Serializer.h:24
Definition ISerializer.h:12