| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef AAPT_FORMAT_CONTAINER_H |
| 18 |
#define AAPT_FORMAT_CONTAINER_H |
| 19 |
|
| 20 |
#include <inttypes.h> |
| 21 |
|
| 22 |
#include "google/protobuf/io/coded_stream.h" |
| 23 |
#include "google/protobuf/io/zero_copy_stream.h" |
| 24 |
|
| 25 |
#include "Resources.pb.h" |
| 26 |
#include "ResourcesInternal.pb.h" |
| 27 |
#include "io/Io.h" |
| 28 |
#include "io/Util.h" |
| 29 |
#include "util/BigBuffer.h" |
| 30 |
|
| 31 |
namespace aapt { |
| 32 |
|
| 33 |
enum ContainerEntryType : uint8_t { |
| 34 |
kResTable = 0x00u, |
| 35 |
kResFile = 0x01u, |
| 36 |
}; |
| 37 |
|
| 38 |
class ContainerWriter { |
| 39 |
public: |
| 40 |
explicit ContainerWriter(::google::protobuf::io::ZeroCopyOutputStream* out, size_t entry_count); |
| 41 |
|
| 42 |
bool AddResTableEntry(const pb::ResourceTable& table); |
| 43 |
bool AddResFileEntry(const pb::internal::CompiledFile& file, io::KnownSizeInputStream* in); |
| 44 |
bool HadError() const; |
| 45 |
std::string GetError() const; |
| 46 |
|
| 47 |
private: |
| 48 |
DISALLOW_COPY_AND_ASSIGN(ContainerWriter); |
| 49 |
|
| 50 |
::google::protobuf::io::ZeroCopyOutputStream* out_; |
| 51 |
size_t total_entry_count_; |
| 52 |
size_t current_entry_count_; |
| 53 |
std::string error_; |
| 54 |
}; |
| 55 |
|
| 56 |
class ContainerReader; |
| 57 |
|
| 58 |
class ContainerReaderEntry { |
| 59 |
public: |
| 60 |
ContainerEntryType Type() const; |
| 61 |
|
| 62 |
bool GetResTable(pb::ResourceTable* out_table); |
| 63 |
bool GetResFileOffsets(pb::internal::CompiledFile* out_file, off64_t* out_offset, |
| 64 |
size_t* out_len); |
| 65 |
|
| 66 |
bool HadError() const; |
| 67 |
std::string GetError() const; |
| 68 |
|
| 69 |
private: |
| 70 |
DISALLOW_COPY_AND_ASSIGN(ContainerReaderEntry); |
| 71 |
|
| 72 |
friend class ContainerReader; |
| 73 |
|
| 74 |
explicit ContainerReaderEntry(ContainerReader* reader); |
| 75 |
|
| 76 |
ContainerReader* reader_; |
| 77 |
ContainerEntryType type_ = ContainerEntryType::kResTable; |
| 78 |
size_t length_ = 0u; |
| 79 |
}; |
| 80 |
|
| 81 |
class ContainerReader { |
| 82 |
public: |
| 83 |
explicit ContainerReader(io::InputStream* in); |
| 84 |
|
| 85 |
ContainerReaderEntry* Next(); |
| 86 |
|
| 87 |
bool HadError() const; |
| 88 |
std::string GetError() const; |
| 89 |
|
| 90 |
private: |
| 91 |
DISALLOW_COPY_AND_ASSIGN(ContainerReader); |
| 92 |
|
| 93 |
friend class ContainerReaderEntry; |
| 94 |
|
| 95 |
io::InputStream* in_; |
| 96 |
io::ZeroCopyInputAdaptor adaptor_; |
| 97 |
::google::protobuf::io::CodedInputStream coded_in_; |
| 98 |
size_t total_entry_count_; |
| 99 |
size_t current_entry_count_; |
| 100 |
ContainerReaderEntry entry_; |
| 101 |
std::string error_; |
| 102 |
}; |
| 103 |
|
| 104 |
} |
| 105 |
|
| 106 |
#endif |