Adam Lesinski | 59e04c6 | 2016-02-04 15:59:23 -0800 | [diff] [blame] | 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_FLATTEN_TABLEPROTOSERIALIZER_H |
| 18 | #define AAPT_FLATTEN_TABLEPROTOSERIALIZER_H |
| 19 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 20 | #include "android-base/macros.h" |
| 21 | #include "google/protobuf/io/coded_stream.h" |
| 22 | #include "google/protobuf/io/zero_copy_stream_impl_lite.h" |
| 23 | |
Adam Lesinski | 59e04c6 | 2016-02-04 15:59:23 -0800 | [diff] [blame] | 24 | #include "Diagnostics.h" |
| 25 | #include "ResourceTable.h" |
| 26 | #include "Source.h" |
| 27 | #include "proto/ProtoHelpers.h" |
| 28 | |
Adam Lesinski | 59e04c6 | 2016-02-04 15:59:23 -0800 | [diff] [blame] | 29 | namespace aapt { |
| 30 | |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 31 | class CompiledFileOutputStream { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 32 | public: |
Adam Lesinski | b791721 | 2017-08-10 15:37:28 -0700 | [diff] [blame] | 33 | explicit CompiledFileOutputStream(google::protobuf::io::ZeroCopyOutputStream* out); |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 34 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 35 | void WriteLittleEndian32(uint32_t value); |
Adam Lesinski | b791721 | 2017-08-10 15:37:28 -0700 | [diff] [blame] | 36 | void WriteCompiledFile(const pb::internal::CompiledFile* compiledFile); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 37 | void WriteData(const BigBuffer* buffer); |
| 38 | void WriteData(const void* data, size_t len); |
| 39 | bool HadError(); |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 40 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 41 | private: |
| 42 | DISALLOW_COPY_AND_ASSIGN(CompiledFileOutputStream); |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 43 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 44 | void EnsureAlignedWrite(); |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 45 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 46 | google::protobuf::io::CodedOutputStream out_; |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | class CompiledFileInputStream { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 50 | public: |
| 51 | explicit CompiledFileInputStream(const void* data, size_t size); |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 52 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 53 | bool ReadLittleEndian32(uint32_t* outVal); |
Adam Lesinski | b791721 | 2017-08-10 15:37:28 -0700 | [diff] [blame] | 54 | bool ReadCompiledFile(pb::internal::CompiledFile* outVal); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 55 | bool ReadDataMetaData(uint64_t* outOffset, uint64_t* outLen); |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 56 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 57 | private: |
| 58 | DISALLOW_COPY_AND_ASSIGN(CompiledFileInputStream); |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 59 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 60 | void EnsureAlignedRead(); |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 61 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 62 | google::protobuf::io::CodedInputStream in_; |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 65 | std::unique_ptr<pb::ResourceTable> SerializeTableToPb(ResourceTable* table); |
Adam Lesinski | b791721 | 2017-08-10 15:37:28 -0700 | [diff] [blame] | 66 | std::unique_ptr<ResourceTable> DeserializeTableFromPb(const pb::ResourceTable& pbTable, |
| 67 | const Source& source, IDiagnostics* diag); |
Adam Lesinski | 59e04c6 | 2016-02-04 15:59:23 -0800 | [diff] [blame] | 68 | |
Adam Lesinski | b791721 | 2017-08-10 15:37:28 -0700 | [diff] [blame] | 69 | std::unique_ptr<pb::internal::CompiledFile> SerializeCompiledFileToPb(const ResourceFile& file); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 70 | std::unique_ptr<ResourceFile> DeserializeCompiledFileFromPb( |
Adam Lesinski | b791721 | 2017-08-10 15:37:28 -0700 | [diff] [blame] | 71 | const pb::internal::CompiledFile& pbFile, const Source& source, IDiagnostics* diag); |
Adam Lesinski | 59e04c6 | 2016-02-04 15:59:23 -0800 | [diff] [blame] | 72 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 73 | } // namespace aapt |
Adam Lesinski | 59e04c6 | 2016-02-04 15:59:23 -0800 | [diff] [blame] | 74 | |
| 75 | #endif /* AAPT_FLATTEN_TABLEPROTOSERIALIZER_H */ |