1 //
2 // Copyright 2018 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #include <grpc/support/port_platform.h>
18 
19 #include "src/core/ext/filters/client_channel/lb_policy/xds/xds_attributes.h"
20 
21 #include "absl/strings/str_cat.h"
22 
23 #include "src/core/lib/gpr/useful.h"
24 
25 namespace grpc_core {
26 
27 const char* kXdsLocalityNameAttributeKey = "xds_locality_name";
28 
Cmp(const AttributeInterface * other) const29 int XdsLocalityAttribute::Cmp(const AttributeInterface* other) const {
30   const auto* other_locality_attr =
31       static_cast<const XdsLocalityAttribute*>(other);
32   int r = locality_name_->Compare(*other_locality_attr->locality_name_);
33   if (r != 0) return r;
34   return QsortCompare(weight_, other_locality_attr->weight_);
35 }
36 
ToString() const37 std::string XdsLocalityAttribute::ToString() const {
38   return absl::StrCat("{name=", locality_name_->AsHumanReadableString(),
39                       ", weight=", weight_, "}");
40 }
41 
42 }  // namespace grpc_core
43