blob: 378dafdb4dc632c6d3081b2446f0d03f0f872124 [file] [log] [blame]
Adam Lesinski59e04c62016-02-04 15:59:23 -08001/*
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
29namespace aapt {
30
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070031class CompiledFileOutputStream {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070032 public:
33 explicit CompiledFileOutputStream(
34 google::protobuf::io::ZeroCopyOutputStream* out);
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070035
Adam Lesinskicacb28f2016-10-19 12:18:14 -070036 void WriteLittleEndian32(uint32_t value);
37 void WriteCompiledFile(const pb::CompiledFile* compiledFile);
38 void WriteData(const BigBuffer* buffer);
39 void WriteData(const void* data, size_t len);
40 bool HadError();
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070041
Adam Lesinskicacb28f2016-10-19 12:18:14 -070042 private:
43 DISALLOW_COPY_AND_ASSIGN(CompiledFileOutputStream);
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070044
Adam Lesinskicacb28f2016-10-19 12:18:14 -070045 void ensureAlignedWrite();
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070046
Adam Lesinskicacb28f2016-10-19 12:18:14 -070047 google::protobuf::io::CodedOutputStream mOut;
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070048};
49
50class CompiledFileInputStream {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070051 public:
52 explicit CompiledFileInputStream(const void* data, size_t size);
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070053
Adam Lesinskicacb28f2016-10-19 12:18:14 -070054 bool ReadLittleEndian32(uint32_t* outVal);
55 bool ReadCompiledFile(pb::CompiledFile* outVal);
56 bool ReadDataMetaData(uint64_t* outOffset, uint64_t* outLen);
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070057
Adam Lesinskicacb28f2016-10-19 12:18:14 -070058 private:
59 DISALLOW_COPY_AND_ASSIGN(CompiledFileInputStream);
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070060
Adam Lesinskicacb28f2016-10-19 12:18:14 -070061 void ensureAlignedRead();
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070062
Adam Lesinskicacb28f2016-10-19 12:18:14 -070063 google::protobuf::io::CodedInputStream mIn;
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070064};
65
Adam Lesinski59e04c62016-02-04 15:59:23 -080066std::unique_ptr<pb::ResourceTable> serializeTableToPb(ResourceTable* table);
Adam Lesinskicacb28f2016-10-19 12:18:14 -070067std::unique_ptr<ResourceTable> deserializeTableFromPb(
68 const pb::ResourceTable& pbTable, const Source& source, IDiagnostics* diag);
Adam Lesinski59e04c62016-02-04 15:59:23 -080069
Adam Lesinskicacb28f2016-10-19 12:18:14 -070070std::unique_ptr<pb::CompiledFile> serializeCompiledFileToPb(
71 const ResourceFile& file);
72std::unique_ptr<ResourceFile> deserializeCompiledFileFromPb(
73 const pb::CompiledFile& pbFile, const Source& source, IDiagnostics* diag);
Adam Lesinski59e04c62016-02-04 15:59:23 -080074
Adam Lesinskicacb28f2016-10-19 12:18:14 -070075} // namespace aapt
Adam Lesinski59e04c62016-02-04 15:59:23 -080076
77#endif /* AAPT_FLATTEN_TABLEPROTOSERIALIZER_H */