-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservicenode.cpp
41 lines (32 loc) · 1.28 KB
/
servicenode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "servicenode.h"
#include <folly/dynamic.h>
#include <folly/json.h>
using std::make_shared;
ServiceNode::ServiceNode() {}
ServiceNode::ServiceNode(const std::string &serviceName, const std::string &url)
: _serviceName(serviceName), _url(url) {}
string ServiceNode::getUrl() const { return _url; }
string ServiceNode::getServiceName() const { return _serviceName; }
bool ServiceNode::operator==(const ServiceNode &other) const {
return _serviceName == other.getServiceName() && _url == other.getUrl();
}
bool ServiceNode::operator!=(const ServiceNode &other) const {
return (*this == other) == false;
}
shared_ptr<ServiceNode> ServiceNode::parseJson(const std::string &str) {
folly::dynamic json_obj = folly::parseJson(str);
if (json_obj.count("service-name") && json_obj.count("url")) {
return make_shared<ServiceNode>(json_obj["service-name"].asString(),
json_obj["url"].asString());
} else
return nullptr;
}
folly::dynamic ServiceNode::to_dynamic() const {
return folly::dynamic::object("service-name", _serviceName)("url", _url);
}
std::ostream &operator<<(std::ostream &os, const ServiceNode &c) {
folly::dynamic d = folly::dynamic::object("service-name", c.getServiceName())(
"url", c.getUrl());
os << d;
return os;
}