Extract io serialization to a library
Summary: Serialization is only needed in distributed Memgraph Reviewers: mferencevic, msantl Reviewed By: msantl Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1846
This commit is contained in:
parent
e3cf4d0df8
commit
71360cba2a
@ -233,7 +233,8 @@ add_custom_target(generate_capnp DEPENDS generate_lcp_distributed ${generated_ca
|
|||||||
|
|
||||||
set(MG_DISTRIBUTED_LIBS stdc++fs Threads::Threads fmt cppitertools
|
set(MG_DISTRIBUTED_LIBS stdc++fs Threads::Threads fmt cppitertools
|
||||||
antlr_opencypher_parser_lib dl glog gflags capnp kj
|
antlr_opencypher_parser_lib dl glog gflags capnp kj
|
||||||
mg-utils mg-io mg-integrations-kafka mg-requests mg-communication mg-auth mg-stats)
|
mg-utils mg-io mg-io-serialization mg-integrations-kafka mg-requests
|
||||||
|
mg-communication mg-auth mg-stats)
|
||||||
|
|
||||||
# STATIC library used by memgraph executables
|
# STATIC library used by memgraph executables
|
||||||
add_library(mg-distributed STATIC ${mg_distributed_sources})
|
add_library(mg-distributed STATIC ${mg_distributed_sources})
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "durability/distributed/recovery.hpp"
|
#include "durability/distributed/recovery.hpp"
|
||||||
#include "durability/distributed/serialization.hpp"
|
#include "durability/distributed/serialization.hpp"
|
||||||
#include "io/network/endpoint.hpp"
|
#include "io/network/endpoint.hpp"
|
||||||
|
#include "io/network/serialization.hpp"
|
||||||
cpp<#
|
cpp<#
|
||||||
|
|
||||||
(lcp:namespace distributed)
|
(lcp:namespace distributed)
|
||||||
|
@ -4,13 +4,15 @@ set(io_src_files
|
|||||||
network/socket.cpp
|
network/socket.cpp
|
||||||
network/utils.cpp)
|
network/utils.cpp)
|
||||||
|
|
||||||
define_add_capnp(add_capnp io_src_files io_capnp_files)
|
|
||||||
|
|
||||||
add_capnp(network/endpoint.capnp)
|
|
||||||
|
|
||||||
add_custom_target(generate_io_capnp DEPENDS ${io_capnp_files})
|
|
||||||
|
|
||||||
add_library(mg-io STATIC ${io_src_files})
|
add_library(mg-io STATIC ${io_src_files})
|
||||||
target_link_libraries(mg-io stdc++fs Threads::Threads fmt glog mg-utils)
|
target_link_libraries(mg-io stdc++fs Threads::Threads fmt glog mg-utils)
|
||||||
target_link_libraries(mg-io capnp kj)
|
|
||||||
add_dependencies(mg-io generate_io_capnp)
|
set(io_serialization_src_files)
|
||||||
|
|
||||||
|
define_add_capnp(add_capnp io_serialization_src_files io_capnp_files)
|
||||||
|
add_capnp(network/endpoint.capnp)
|
||||||
|
add_custom_target(generate_io_capnp DEPENDS ${io_capnp_files})
|
||||||
|
|
||||||
|
add_library(mg-io-serialization STATIC ${io_serialization_src_files})
|
||||||
|
target_link_libraries(mg-io-serialization mg-io capnp kj)
|
||||||
|
add_dependencies(mg-io-serialization generate_io_capnp)
|
||||||
|
@ -24,18 +24,6 @@ Endpoint::Endpoint(const std::string &address, uint16_t port)
|
|||||||
CHECK(family_ != 0) << "Not a valid IPv4 or IPv6 address: " << address;
|
CHECK(family_ != 0) << "Not a valid IPv4 or IPv6 address: " << address;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Save(const Endpoint &endpoint, capnp::Endpoint::Builder *builder) {
|
|
||||||
builder->setAddress(endpoint.address());
|
|
||||||
builder->setPort(endpoint.port());
|
|
||||||
builder->setFamily(endpoint.family());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Load(Endpoint *endpoint, const capnp::Endpoint::Reader &reader) {
|
|
||||||
endpoint->address_ = reader.getAddress();
|
|
||||||
endpoint->port_ = reader.getPort();
|
|
||||||
endpoint->family_ = reader.getFamily();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Endpoint::operator==(const Endpoint &other) const {
|
bool Endpoint::operator==(const Endpoint &other) const {
|
||||||
return address_ == other.address_ && port_ == other.port_ &&
|
return address_ == other.address_ && port_ == other.port_ &&
|
||||||
family_ == other.family_;
|
family_ == other.family_;
|
||||||
|
@ -5,11 +5,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
// TODO: SLK serialization should be its own thing
|
|
||||||
#include "communication/rpc/serialization.hpp"
|
|
||||||
#include "io/network/endpoint.capnp.h"
|
|
||||||
#include "utils/exceptions.hpp"
|
|
||||||
|
|
||||||
namespace io::network {
|
namespace io::network {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,24 +30,4 @@ class Endpoint {
|
|||||||
unsigned char family_{0};
|
unsigned char family_{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
void Save(const Endpoint &endpoint, capnp::Endpoint::Builder *builder);
|
|
||||||
|
|
||||||
void Load(Endpoint *endpoint, const capnp::Endpoint::Reader &reader);
|
|
||||||
|
|
||||||
} // namespace io::network
|
} // namespace io::network
|
||||||
|
|
||||||
namespace slk {
|
|
||||||
|
|
||||||
inline void Save(const io::network::Endpoint &endpoint, slk::Builder *builder) {
|
|
||||||
slk::Save(endpoint.address_, builder);
|
|
||||||
slk::Save(endpoint.port_, builder);
|
|
||||||
slk::Save(endpoint.family_, builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Load(io::network::Endpoint *endpoint, slk::Reader *reader) {
|
|
||||||
slk::Load(&endpoint->address_, reader);
|
|
||||||
slk::Load(&endpoint->port_, reader);
|
|
||||||
slk::Load(&endpoint->family_, reader);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace slk
|
|
||||||
|
38
src/io/network/serialization.hpp
Normal file
38
src/io/network/serialization.hpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// TODO: SLK serialization should be its own thing
|
||||||
|
#include "communication/rpc/serialization.hpp"
|
||||||
|
#include "io/network/endpoint.capnp.h"
|
||||||
|
#include "io/network/endpoint.hpp"
|
||||||
|
|
||||||
|
namespace io::network {
|
||||||
|
|
||||||
|
inline void Save(const Endpoint &endpoint, capnp::Endpoint::Builder *builder) {
|
||||||
|
builder->setAddress(endpoint.address());
|
||||||
|
builder->setPort(endpoint.port());
|
||||||
|
builder->setFamily(endpoint.family());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Load(Endpoint *endpoint, const capnp::Endpoint::Reader &reader) {
|
||||||
|
endpoint->address_ = reader.getAddress();
|
||||||
|
endpoint->port_ = reader.getPort();
|
||||||
|
endpoint->family_ = reader.getFamily();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace io::network
|
||||||
|
|
||||||
|
namespace slk {
|
||||||
|
|
||||||
|
inline void Save(const io::network::Endpoint &endpoint, slk::Builder *builder) {
|
||||||
|
slk::Save(endpoint.address_, builder);
|
||||||
|
slk::Save(endpoint.port_, builder);
|
||||||
|
slk::Save(endpoint.family_, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Load(io::network::Endpoint *endpoint, slk::Reader *reader) {
|
||||||
|
slk::Load(&endpoint->address_, reader);
|
||||||
|
slk::Load(&endpoint->port_, reader);
|
||||||
|
slk::Load(&endpoint->family_, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace slk
|
Loading…
Reference in New Issue
Block a user