Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
695072e1
Commit
695072e1
authored
Oct 12, 2018
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replase const BUTIL_RAPIDJSON_NAMESPACE::Value with auto
parent
4ee40610
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
32 deletions
+23
-32
consul_naming_service.cpp
src/brpc/policy/consul_naming_service.cpp
+10
-14
discovery_naming_service.cpp
src/brpc/policy/discovery_naming_service.cpp
+13
-18
No files found.
src/brpc/policy/consul_naming_service.cpp
View file @
695072e1
...
...
@@ -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
{
...
...
src/brpc/policy/discovery_naming_service.cpp
View file @
695072e1
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment