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 #ifndef PROPERTY_INFO_SERIALIZER_TRIE_SERIALIZER_H 18 #define PROPERTY_INFO_SERIALIZER_TRIE_SERIALIZER_H 19 20 #include <string> 21 #include <vector> 22 23 #include "property_info_parser/property_info_parser.h" 24 25 #include "trie_builder.h" 26 #include "trie_node_arena.h" 27 28 namespace android { 29 namespace properties { 30 31 class TrieSerializer { 32 public: 33 TrieSerializer(); 34 35 std::string SerializeTrie(const TrieBuilder& trie_builder); 36 37 private: 38 void SerializeStrings(const std::set<std::string>& strings); 39 uint32_t WritePropertyEntry(const PropertyEntryBuilder& property_entry); 40 41 // Writes a new TrieNode to arena, and recursively writes its children. 42 // Returns the offset within arena. 43 uint32_t WriteTrieNode(const TrieBuilderNode& builder_node); 44 serialized_info()45 const PropertyInfoArea* serialized_info() const { 46 return reinterpret_cast<const PropertyInfoArea*>(arena_->data().data()); 47 } 48 49 std::unique_ptr<TrieNodeArena> arena_; 50 }; 51 52 } // namespace properties 53 } // namespace android 54 55 #endif 56