Generalize cereal message macro
Reviewers: florijan Reviewed By: florijan Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1053
This commit is contained in:
parent
9ad7d82a54
commit
19e96c98b6
@ -1,59 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "cereal/archives/binary.hpp"
|
||||
#include "cereal/types/base_class.hpp"
|
||||
#include "cereal/types/memory.hpp"
|
||||
#include "cereal/types/polymorphic.hpp"
|
||||
#include "cereal/types/string.hpp"
|
||||
#include "cereal/types/utility.hpp"
|
||||
#include "cereal/types/vector.hpp"
|
||||
#include "utils/rpc_pimp.hpp"
|
||||
|
||||
#include "communication/rpc/rpc.hpp"
|
||||
#include "transactions/commit_log.hpp"
|
||||
#include "transactions/snapshot.hpp"
|
||||
#include "transactions/type.hpp"
|
||||
|
||||
#define NO_MEMBER_MESSAGE(name) \
|
||||
namespace tx { \
|
||||
using communication::messaging::Message; \
|
||||
struct name : public Message { \
|
||||
name() {} \
|
||||
template <class Archive> \
|
||||
void serialize(Archive &ar) { \
|
||||
ar(cereal::virtual_base_class<Message>(this)); \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
CEREAL_REGISTER_TYPE(tx::name);
|
||||
|
||||
#define SINGLE_MEMBER_MESSAGE(name, type) \
|
||||
namespace tx { \
|
||||
using communication::messaging::Message; \
|
||||
struct name : public Message { \
|
||||
name() {} \
|
||||
name(const type &member) : member(member) {} \
|
||||
type member; \
|
||||
template <class Archive> \
|
||||
void serialize(Archive &ar) { \
|
||||
ar(cereal::virtual_base_class<Message>(this), member); \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
CEREAL_REGISTER_TYPE(tx::name);
|
||||
|
||||
SINGLE_MEMBER_MESSAGE(SnapshotReq, transaction_id_t)
|
||||
SINGLE_MEMBER_MESSAGE(SnapshotRes, Snapshot)
|
||||
NO_MEMBER_MESSAGE(GcSnapshotReq)
|
||||
SINGLE_MEMBER_MESSAGE(ClogInfoReq, transaction_id_t)
|
||||
SINGLE_MEMBER_MESSAGE(ClogInfoRes, CommitLog::Info)
|
||||
SINGLE_MEMBER_MESSAGE(ActiveTransactionsReq, transaction_id_t)
|
||||
SINGLE_MEMBER_MESSAGE(IsActiveReq, transaction_id_t)
|
||||
SINGLE_MEMBER_MESSAGE(IsActiveRes, bool)
|
||||
|
||||
#undef SINGLE_MEMBER_MESSAGE
|
||||
#undef NO_MEMBER_MESSAGE
|
||||
|
||||
namespace tx {
|
||||
|
||||
RPC_SINGLE_MEMBER_MESSAGE(SnapshotReq, transaction_id_t)
|
||||
RPC_SINGLE_MEMBER_MESSAGE(SnapshotRes, Snapshot)
|
||||
RPC_NO_MEMBER_MESSAGE(GcSnapshotReq)
|
||||
RPC_SINGLE_MEMBER_MESSAGE(ClogInfoReq, transaction_id_t)
|
||||
RPC_SINGLE_MEMBER_MESSAGE(ClogInfoRes, CommitLog::Info)
|
||||
RPC_SINGLE_MEMBER_MESSAGE(ActiveTransactionsReq, transaction_id_t)
|
||||
RPC_SINGLE_MEMBER_MESSAGE(IsActiveReq, transaction_id_t)
|
||||
RPC_SINGLE_MEMBER_MESSAGE(IsActiveRes, bool)
|
||||
|
||||
using SnapshotRpc =
|
||||
communication::rpc::RequestResponse<SnapshotReq, SnapshotRes>;
|
||||
using GcSnapshotRpc =
|
||||
@ -66,4 +30,13 @@ using ActiveTransactionsRpc =
|
||||
communication::rpc::RequestResponse<ActiveTransactionsReq, SnapshotRes>;
|
||||
using IsActiveRpc =
|
||||
communication::rpc::RequestResponse<IsActiveReq, IsActiveRes>;
|
||||
}
|
||||
} // namespace tx
|
||||
|
||||
CEREAL_REGISTER_TYPE(tx::SnapshotReq);
|
||||
CEREAL_REGISTER_TYPE(tx::SnapshotRes);
|
||||
CEREAL_REGISTER_TYPE(tx::GcSnapshotReq);
|
||||
CEREAL_REGISTER_TYPE(tx::ClogInfoReq);
|
||||
CEREAL_REGISTER_TYPE(tx::ClogInfoRes);
|
||||
CEREAL_REGISTER_TYPE(tx::ActiveTransactionsReq);
|
||||
CEREAL_REGISTER_TYPE(tx::IsActiveReq);
|
||||
CEREAL_REGISTER_TYPE(tx::IsActiveRes);
|
||||
|
32
src/utils/rpc_pimp.hpp
Normal file
32
src/utils/rpc_pimp.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "cereal/archives/binary.hpp"
|
||||
#include "cereal/types/base_class.hpp"
|
||||
#include "cereal/types/memory.hpp"
|
||||
#include "cereal/types/polymorphic.hpp"
|
||||
#include "cereal/types/string.hpp"
|
||||
#include "cereal/types/utility.hpp"
|
||||
#include "cereal/types/vector.hpp"
|
||||
|
||||
#define RPC_NO_MEMBER_MESSAGE(name) \
|
||||
using communication::messaging::Message; \
|
||||
struct name : public Message { \
|
||||
name() {} \
|
||||
template <class Archive> \
|
||||
void serialize(Archive &ar) { \
|
||||
ar(::cereal::virtual_base_class<Message>(this)); \
|
||||
} \
|
||||
};
|
||||
|
||||
#define RPC_SINGLE_MEMBER_MESSAGE(name, type) \
|
||||
using communication::messaging::Message; \
|
||||
struct name : public Message { \
|
||||
name() {} \
|
||||
name(const type &member) : member(member) {} \
|
||||
type member; \
|
||||
template <class Archive> \
|
||||
void serialize(Archive &ar) { \
|
||||
ar(::cereal::virtual_base_class<Message>(this), member); \
|
||||
} \
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user