Commit 695072e1 authored by zhujiashun's avatar zhujiashun

replase const BUTIL_RAPIDJSON_NAMESPACE::Value with auto

parent 4ee40610
......@@ -135,20 +135,16 @@ int ConsulNamingService::GetServers(const char* service_name,
}
for (BUTIL_RAPIDJSON_NAMESPACE::SizeType i = 0; i < services.Size(); ++i) {
BUTIL_RAPIDJSON_NAMESPACE::Value::ConstMemberIterator itr =
services[i].FindMember("Service");
if (itr == services[i].MemberEnd()) {
auto itr_service = services[i].FindMember("Service");
if (itr_service == services[i].MemberEnd()) {
LOG(ERROR) << "No service info in node: "
<< RapidjsonValueToString(services[i]);
continue;
}
const BUTIL_RAPIDJSON_NAMESPACE::Value& service = itr->value;
BUTIL_RAPIDJSON_NAMESPACE::Value::ConstMemberIterator itr_address =
service.FindMember("Address");
BUTIL_RAPIDJSON_NAMESPACE::Value::ConstMemberIterator itr_port =
service.FindMember("Port");
const BUTIL_RAPIDJSON_NAMESPACE::Value& service = itr_service->value;
auto itr_address = service.FindMember("Address");
auto itr_port = service.FindMember("Port");
if (itr_address == service.MemberEnd() ||
!itr_address->value.IsString() ||
itr_port == service.MemberEnd() ||
......@@ -169,12 +165,12 @@ int ConsulNamingService::GetServers(const char* service_name,
ServerNode node;
node.addr = end_point;
itr = service.FindMember("Tags");
if (itr != service.MemberEnd()) {
if (itr->value.IsArray()) {
if (itr->value.Size() > 0) {
auto itr_tags = service.FindMember("Tags");
if (itr_tags != service.MemberEnd()) {
if (itr_tags->value.IsArray()) {
if (itr_tags->value.Size() > 0) {
// Tags in consul is an array, here we only use the first one.
const BUTIL_RAPIDJSON_NAMESPACE::Value& tag = itr->value[0];
const BUTIL_RAPIDJSON_NAMESPACE::Value& tag = itr_tags->value[0];
if (tag.IsString()) {
node.tag = tag.GetString();
} else {
......
......@@ -39,8 +39,7 @@ int DiscoveryNamingService::ParseNodesResult(
BUTIL_RAPIDJSON_NAMESPACE::Document nodes;
const std::string response = buf.to_string();
nodes.Parse(response.c_str());
BUTIL_RAPIDJSON_NAMESPACE::Value::ConstMemberIterator itr =
nodes.FindMember("data");
auto itr = nodes.FindMember("data");
if (itr == nodes.MemberEnd()) {
LOG(ERROR) << "No data field in discovery nodes response";
return -1;
......@@ -52,11 +51,8 @@ int DiscoveryNamingService::ParseNodesResult(
}
for (BUTIL_RAPIDJSON_NAMESPACE::SizeType i = 0; i < data.Size(); ++i) {
const BUTIL_RAPIDJSON_NAMESPACE::Value& addr_item = data[i];
BUTIL_RAPIDJSON_NAMESPACE::Value::ConstMemberIterator itr_addr =
addr_item.FindMember("addr");
BUTIL_RAPIDJSON_NAMESPACE::Value::ConstMemberIterator itr_status =
addr_item.FindMember("status");
auto itr_addr = addr_item.FindMember("addr");
auto itr_status = addr_item.FindMember("status");
if (itr_addr == addr_item.MemberEnd() ||
!itr_addr->value.IsString() ||
itr_status == addr_item.MemberEnd() ||
......@@ -79,32 +75,31 @@ int DiscoveryNamingService::ParseFetchsResult(
BUTIL_RAPIDJSON_NAMESPACE::Document d;
const std::string response = buf.to_string();
d.Parse(response.c_str());
BUTIL_RAPIDJSON_NAMESPACE::Value::ConstMemberIterator itr =
d.FindMember("data");
if (itr == d.MemberEnd()) {
auto itr_data = d.FindMember("data");
if (itr_data == d.MemberEnd()) {
LOG(ERROR) << "No data field in discovery fetchs response";
return -1;
}
const BUTIL_RAPIDJSON_NAMESPACE::Value& data = itr->value;
itr = data.FindMember(service_name);
if (itr == data.MemberEnd()) {
const BUTIL_RAPIDJSON_NAMESPACE::Value& data = itr_data->value;
auto itr_service = data.FindMember(service_name);
if (itr_service == data.MemberEnd()) {
LOG(ERROR) << "No " << service_name << " field in discovery response";
return -1;
}
const BUTIL_RAPIDJSON_NAMESPACE::Value& services = itr->value;
itr = services.FindMember("instances");
if (itr == services.MemberEnd()) {
const BUTIL_RAPIDJSON_NAMESPACE::Value& services = itr_service->value;
auto itr_instances = services.FindMember("instances");
if (itr_instances == services.MemberEnd()) {
LOG(ERROR) << "Fail to find instances";
return -1;
}
const BUTIL_RAPIDJSON_NAMESPACE::Value& instances = itr->value;
const BUTIL_RAPIDJSON_NAMESPACE::Value& instances = itr_instances->value;
if (!instances.IsArray()) {
LOG(ERROR) << "Fail to parse instances as an array";
return -1;
}
for (BUTIL_RAPIDJSON_NAMESPACE::SizeType i = 0; i < instances.Size(); ++i) {
itr = instances[i].FindMember("addrs");
auto itr = instances[i].FindMember("addrs");
if (itr == instances[i].MemberEnd() || !itr->value.IsArray()) {
LOG(ERROR) << "Fail to find addrs or addrs is not an array";
return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment