• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 AAPT_FORMAT_PROTO_PROTOSERIALIZE_H
18 #define AAPT_FORMAT_PROTO_PROTOSERIALIZE_H
19 
20 #include "android-base/macros.h"
21 #include "androidfw/ConfigDescription.h"
22 
23 #include "Configuration.pb.h"
24 #include "ResourceTable.h"
25 #include "ResourceValues.h"
26 #include "Resources.pb.h"
27 #include "ResourcesInternal.pb.h"
28 #include "StringPool.h"
29 #include "xml/XmlDom.h"
30 
31 namespace aapt {
32 
33 struct SerializeXmlOptions {
34   /** Remove text nodes that only contain whitespace. */
35   bool remove_empty_text_nodes = false;
36 };
37 
38 struct SerializeTableOptions {
39     /** Prevent serializing the source pool and source protos.  */
40     bool exclude_sources = false;
41 
42     // When true, all the entry names in pb:ResourceTable are collapsed to a
43     // single entry name. When the proto table is converted to binary
44     // resources.arsc, the key string pool is collapsed to a single entry. All
45     // resource entries have name indices that point to this single value.
46     bool collapse_key_stringpool = false;
47 
48     // Set of resources to avoid collapsing to a single entry in key stringpool.
49     std::set<ResourceName> name_collapse_exemptions;
50 };
51 
52 // Serializes a Value to its protobuf representation. An optional StringPool will hold the
53 // source path string.
54 void SerializeValueToPb(const Value& value, pb::Value* out_value, StringPool* src_pool = nullptr);
55 
56 // Serialize an Item into its protobuf representation. pb::Item does not store the source path nor
57 // comments of an Item.
58 void SerializeItemToPb(const Item& item, pb::Item* out_item);
59 
60 // Serializes an XML element into its protobuf representation.
61 void SerializeXmlToPb(const xml::Element& el, pb::XmlNode* out_node,
62                       const SerializeXmlOptions options = {});
63 
64 // Serializes an XmlResource into its protobuf representation. The ResourceFile is NOT serialized.
65 void SerializeXmlResourceToPb(const xml::XmlResource& resource, pb::XmlNode* out_node,
66                               const SerializeXmlOptions options = {});
67 
68 // Serializes a StringPool into its protobuf representation, which is really just the binary
69 // ResStringPool representation stuffed into a bytes field.
70 void SerializeStringPoolToPb(const StringPool& pool, pb::StringPool* out_pb_pool, IDiagnostics* diag);
71 
72 // Serializes a ConfigDescription into its protobuf representation.
73 void SerializeConfig(const android::ConfigDescription& config, pb::Configuration* out_pb_config);
74 
75 // Serializes a ResourceTable into its protobuf representation.
76 void SerializeTableToPb(const ResourceTable& table, pb::ResourceTable* out_table,
77                         IDiagnostics* diag, SerializeTableOptions options = {});
78 
79 // Serializes a ResourceFile into its protobuf representation.
80 void SerializeCompiledFileToPb(const ResourceFile& file, pb::internal::CompiledFile* out_file);
81 
82 }  // namespace aapt
83 
84 #endif /* AAPT_FORMAT_PROTO_PROTOSERIALIZE_H */
85