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