xref: /aosp_15_r20/external/perfetto/src/tools/proto_merger/allowlist.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
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 #ifndef SRC_TOOLS_PROTO_MERGER_ALLOWLIST_H_
18 #define SRC_TOOLS_PROTO_MERGER_ALLOWLIST_H_
19 
20 #include <map>
21 #include <set>
22 #include <string>
23 #include <vector>
24 
25 #include "perfetto/base/status.h"
26 
27 // We include this intentionally instead of forward declaring to allow
28 // for an easy find/replace transformation when moving to Google3.
29 #include <google/protobuf/descriptor.h>
30 
31 namespace perfetto {
32 namespace proto_merger {
33 
34 // Represents an allow-list for proto messages, fields and enums.
35 struct Allowlist {
36   using Oneof = std::set<int>;
37   struct Message {
38     std::set<std::string> enums;
39     std::map<std::string, Oneof> oneofs;
40     std::set<int> fields;
41 
42     // Needs to be a std::map as std::unordered_map causes complaints about
43     // self-referentiality from GCC.
44     std::map<std::string, Message> nested_messages;
45   };
46   std::map<std::string, Message> messages;
47   std::set<std::string> enums;
48 };
49 
50 // Creates a Allowlist struct from a list of allowed fields rooted at the given
51 // descriptor.
52 base::Status AllowlistFromFieldList(
53     const google::protobuf::Descriptor&,
54     const std::vector<std::string>& allowed_fields,
55     Allowlist& allowlist);
56 
57 }  // namespace proto_merger
58 }  // namespace perfetto
59 
60 #endif  // SRC_TOOLS_PROTO_MERGER_ALLOWLIST_H_
61