Add support for std::pair in SLK
Reviewers: teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1717
This commit is contained in:
parent
878b5c9f2b
commit
0493470f98
@ -12,6 +12,7 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "communication/rpc/streams.hpp"
|
#include "communication/rpc/streams.hpp"
|
||||||
@ -262,6 +263,21 @@ inline void Load(std::experimental::optional<T> *obj, Reader *reader) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename A, typename B>
|
||||||
|
inline void Save(const std::pair<A, B> &obj, Builder *builder) {
|
||||||
|
Save(obj.first, builder);
|
||||||
|
Save(obj.second, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename A, typename B>
|
||||||
|
inline void Load(std::pair<A, B> *obj, Reader *reader) {
|
||||||
|
A first;
|
||||||
|
B second;
|
||||||
|
Load(&first, reader);
|
||||||
|
Load(&second, reader);
|
||||||
|
*obj = std::pair<A, B>(std::move(first), std::move(second));
|
||||||
|
}
|
||||||
|
|
||||||
// Implementation of three argument serialization for complex types.
|
// Implementation of three argument serialization for complex types.
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -227,6 +227,18 @@ TEST(CustomSerialization, OptionalStringFull) {
|
|||||||
ASSERT_EQ(*original, *decoded);
|
ASSERT_EQ(*original, *decoded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(CustomSerialization, Pair) {
|
||||||
|
std::pair<std::string, int> original{"nandare!", 5};
|
||||||
|
slk::Builder builder;
|
||||||
|
slk::Save(original, &builder);
|
||||||
|
ASSERT_EQ(builder.size(),
|
||||||
|
sizeof(uint64_t) + original.first.size() + sizeof(int));
|
||||||
|
std::pair<std::string, int> decoded;
|
||||||
|
slk::Reader reader(builder.data(), builder.size());
|
||||||
|
slk::Load(&decoded, &reader);
|
||||||
|
ASSERT_EQ(original, decoded);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(CustomSerialization, SharedPtrEmpty) {
|
TEST(CustomSerialization, SharedPtrEmpty) {
|
||||||
std::shared_ptr<std::string> original;
|
std::shared_ptr<std::string> original;
|
||||||
std::vector<std::string *> saved;
|
std::vector<std::string *> saved;
|
||||||
@ -434,7 +446,8 @@ TEST(CustomSerialization, VectorSharedPtr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(CustomSerialization, OptionalSharedPtr) {
|
TEST(CustomSerialization, OptionalSharedPtr) {
|
||||||
std::experimental::optional<std::shared_ptr<std::string>> original = std::make_shared<std::string>("nandare!");
|
std::experimental::optional<std::shared_ptr<std::string>> original =
|
||||||
|
std::make_shared<std::string>("nandare!");
|
||||||
std::vector<std::string *> saved;
|
std::vector<std::string *> saved;
|
||||||
|
|
||||||
slk::Builder builder;
|
slk::Builder builder;
|
||||||
|
Loading…
Reference in New Issue
Block a user