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:
Teon Banek 2019-02-06 14:06:18 +01:00
parent e3cf4d0df8
commit 71360cba2a
6 changed files with 51 additions and 46 deletions

View File

@ -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
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
add_library(mg-distributed STATIC ${mg_distributed_sources})

View File

@ -9,6 +9,7 @@
#include "durability/distributed/recovery.hpp"
#include "durability/distributed/serialization.hpp"
#include "io/network/endpoint.hpp"
#include "io/network/serialization.hpp"
cpp<#
(lcp:namespace distributed)

View File

@ -4,13 +4,15 @@ set(io_src_files
network/socket.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})
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)

View File

@ -24,18 +24,6 @@ Endpoint::Endpoint(const std::string &address, uint16_t port)
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 {
return address_ == other.address_ && port_ == other.port_ &&
family_ == other.family_;

View File

@ -5,11 +5,6 @@
#include <iostream>
#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 {
/**
@ -35,24 +30,4 @@ class Endpoint {
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 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

View 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