Adam Lesinski | 8cdca1b | 2017-09-28 15:50:03 -0700 | [diff] [blame] | 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 AAPT_PROTO_PROTODESERIALIZE_H |
| 18 | #define AAPT_PROTO_PROTODESERIALIZE_H |
| 19 | |
| 20 | #include "android-base/macros.h" |
| 21 | #include "androidfw/ResourceTypes.h" |
| 22 | #include "google/protobuf/io/coded_stream.h" |
| 23 | |
| 24 | #include "ConfigDescription.h" |
| 25 | #include "Configuration.pb.h" |
| 26 | #include "ResourceTable.h" |
| 27 | #include "ResourceValues.h" |
| 28 | #include "Resources.pb.h" |
| 29 | #include "ResourcesInternal.pb.h" |
| 30 | #include "StringPool.h" |
| 31 | #include "xml/XmlDom.h" |
| 32 | |
| 33 | namespace aapt { |
| 34 | |
| 35 | std::unique_ptr<Value> DeserializeValueFromPb(const pb::Value& pb_value, |
| 36 | const android::ResStringPool& src_pool, |
| 37 | const ConfigDescription& config, |
| 38 | StringPool* value_pool, std::string* out_error); |
| 39 | |
| 40 | std::unique_ptr<Item> DeserializeItemFromPb(const pb::Item& pb_item, |
| 41 | const android::ResStringPool& src_pool, |
| 42 | const ConfigDescription& config, StringPool* value_pool, |
| 43 | std::string* out_error); |
| 44 | |
| 45 | std::unique_ptr<xml::XmlResource> DeserializeXmlResourceFromPb(const pb::XmlNode& pb_node, |
| 46 | std::string* out_error); |
| 47 | |
| 48 | bool DeserializeXmlFromPb(const pb::XmlNode& pb_node, xml::Element* out_el, StringPool* value_pool, |
| 49 | std::string* out_error); |
| 50 | |
| 51 | bool DeserializeConfigFromPb(const pb::Configuration& pb_config, ConfigDescription* out_config, |
| 52 | std::string* out_error); |
| 53 | |
| 54 | bool DeserializeTableFromPb(const pb::ResourceTable& pb_table, ResourceTable* out_table, |
| 55 | std::string* out_error); |
| 56 | |
| 57 | bool DeserializeCompiledFileFromPb(const pb::internal::CompiledFile& pb_file, |
| 58 | ResourceFile* out_file, std::string* out_error); |
| 59 | |
| 60 | class CompiledFileInputStream { |
| 61 | public: |
| 62 | explicit CompiledFileInputStream(const void* data, size_t size); |
| 63 | |
| 64 | bool ReadLittleEndian32(uint32_t* outVal); |
| 65 | bool ReadCompiledFile(pb::internal::CompiledFile* outVal); |
| 66 | bool ReadDataMetaData(uint64_t* outOffset, uint64_t* outLen); |
| 67 | |
| 68 | private: |
| 69 | DISALLOW_COPY_AND_ASSIGN(CompiledFileInputStream); |
| 70 | |
| 71 | void EnsureAlignedRead(); |
| 72 | |
| 73 | ::google::protobuf::io::CodedInputStream in_; |
| 74 | }; |
| 75 | |
| 76 | } // namespace aapt |
| 77 | |
| 78 | #endif /* AAPT_PROTO_PROTODESERIALIZE_H */ |