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