1 //
2 // Copyright (C) 2017 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 #include "property_info_serializer/property_info_serializer.h"
18 
19 #include "property_info_parser/property_info_parser.h"
20 
21 #include <set>
22 
23 #include "trie_builder.h"
24 #include "trie_serializer.h"
25 
26 namespace android {
27 namespace properties {
28 
BuildTrie(const std::vector<PropertyInfoEntry> & property_info,const std::string & default_context,const std::string & default_type,std::string * serialized_trie,std::string * error)29 bool BuildTrie(const std::vector<PropertyInfoEntry>& property_info,
30                const std::string& default_context, const std::string& default_type,
31                std::string* serialized_trie, std::string* error) {
32   // Check that names are legal first
33   auto trie_builder = TrieBuilder(default_context, default_type);
34 
35   for (const auto& [name, context, type, is_exact] : property_info) {
36     if (!trie_builder.AddToTrie(name, context, type, is_exact, error)) {
37       return false;
38     }
39   }
40 
41   auto trie_serializer = TrieSerializer();
42   *serialized_trie = trie_serializer.SerializeTrie(trie_builder);
43   return true;
44 }
45 
46 }  // namespace properties
47 }  // namespace android
48