Adam Lesinski | 21efb68 | 2016-09-14 17:35:43 -0700 | [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_IO_IO_H |
| 18 | #define AAPT_IO_IO_H |
| 19 | |
Adam Lesinski | 21efb68 | 2016-09-14 17:35:43 -0700 | [diff] [blame] | 20 | #include <string> |
| 21 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame^] | 22 | #include "google/protobuf/io/zero_copy_stream_impl_lite.h" |
| 23 | |
Adam Lesinski | 21efb68 | 2016-09-14 17:35:43 -0700 | [diff] [blame] | 24 | namespace aapt { |
| 25 | namespace io { |
| 26 | |
| 27 | /** |
| 28 | * InputStream interface that inherits from protobuf's ZeroCopyInputStream, |
| 29 | * but adds error handling methods to better report issues. |
| 30 | * |
| 31 | * The code style here matches the protobuf style. |
| 32 | */ |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame^] | 33 | class InputStream : public ::google::protobuf::io::ZeroCopyInputStream { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 34 | public: |
| 35 | virtual std::string GetError() const { return {}; } |
Adam Lesinski | 21efb68 | 2016-09-14 17:35:43 -0700 | [diff] [blame] | 36 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 37 | virtual bool HadError() const = 0; |
Adam Lesinski | 21efb68 | 2016-09-14 17:35:43 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | /** |
| 41 | * OutputStream interface that inherits from protobuf's ZeroCopyOutputStream, |
| 42 | * but adds error handling methods to better report issues. |
| 43 | * |
| 44 | * The code style here matches the protobuf style. |
| 45 | */ |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame^] | 46 | class OutputStream : public ::google::protobuf::io::ZeroCopyOutputStream { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 47 | public: |
| 48 | virtual std::string GetError() const { return {}; } |
Adam Lesinski | 21efb68 | 2016-09-14 17:35:43 -0700 | [diff] [blame] | 49 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 50 | virtual bool HadError() const = 0; |
Adam Lesinski | 21efb68 | 2016-09-14 17:35:43 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | /** |
| 54 | * Copies the data from in to out. Returns true if there was no error. |
| 55 | * If there was an error, check the individual streams' HadError/GetError |
| 56 | * methods. |
| 57 | */ |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame^] | 58 | bool Copy(OutputStream* out, InputStream* in); |
Adam Lesinski | 21efb68 | 2016-09-14 17:35:43 -0700 | [diff] [blame] | 59 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 60 | } // namespace io |
| 61 | } // namespace aapt |
Adam Lesinski | 21efb68 | 2016-09-14 17:35:43 -0700 | [diff] [blame] | 62 | |
| 63 | #endif /* AAPT_IO_IO_H */ |