Apache Mesos
type_utils_differencers.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #include <memory>
18 
19 #include <google/protobuf/descriptor.h>
20 #include <google/protobuf/util/message_differencer.h>
21 
22 namespace mesos {
23 namespace typeutils {
24 namespace internal {
25 
26 // Creates a protobuf `MessageDifferencer` specifically configured for
27 // comparing `FrameworkInfo`s (either V0 or V1 ones).
28 //
29 // TODO(asekretenko): Remove the `unique_ptr` wrapper if `MessageDifferencer`
30 // becomes move-constructible in future versions of protobuf.
31 template <class TFrameworkInfo>
32 std::unique_ptr<::google::protobuf::util::MessageDifferencer>
34 {
35  static const ::google::protobuf::Descriptor* descriptor =
36  TFrameworkInfo::descriptor();
37 
38  CHECK_EQ(13, descriptor->field_count())
39  << "After adding a field to FrameworkInfo, please make sure "
40  << "that FrameworkInfoDifferencer handles this field properly;"
41  << "after that, adjust the expected fields count in this check.";
42 
43  std::unique_ptr<::google::protobuf::util::MessageDifferencer> differencer{
44  new ::google::protobuf::util::MessageDifferencer()};
45 
46  differencer->TreatAsSet(descriptor->FindFieldByName("capabilities"));
47  differencer->TreatAsSet(descriptor->FindFieldByName("roles"));
48  return differencer;
49 }
50 
51 } // namespace internal {
52 } // namespace typeutils {
53 } // namespace mesos {
Definition: agent.hpp:25
Definition: attributes.hpp:24
std::unique_ptr<::google::protobuf::util::MessageDifferencer > createFrameworkInfoDifferencer()
Definition: type_utils_differencers.hpp:33