blob: 33cdc7bbe4988bec13787ef2d043806abc9c541b [file] [log] [blame]
Adam Lesinski21efb682016-09-14 17:35:43 -07001/*
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 Lesinski21efb682016-09-14 17:35:43 -070020#include <string>
21
Adam Lesinskice5e56e2016-10-21 17:56:45 -070022#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
23
Adam Lesinski21efb682016-09-14 17:35:43 -070024namespace aapt {
25namespace 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 Lesinskice5e56e2016-10-21 17:56:45 -070033class InputStream : public ::google::protobuf::io::ZeroCopyInputStream {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070034 public:
35 virtual std::string GetError() const { return {}; }
Adam Lesinski21efb682016-09-14 17:35:43 -070036
Adam Lesinskicacb28f2016-10-19 12:18:14 -070037 virtual bool HadError() const = 0;
Adam Lesinski21efb682016-09-14 17:35:43 -070038};
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 Lesinskice5e56e2016-10-21 17:56:45 -070046class OutputStream : public ::google::protobuf::io::ZeroCopyOutputStream {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070047 public:
48 virtual std::string GetError() const { return {}; }
Adam Lesinski21efb682016-09-14 17:35:43 -070049
Adam Lesinskicacb28f2016-10-19 12:18:14 -070050 virtual bool HadError() const = 0;
Adam Lesinski21efb682016-09-14 17:35:43 -070051};
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 Lesinskice5e56e2016-10-21 17:56:45 -070058bool Copy(OutputStream* out, InputStream* in);
Adam Lesinski21efb682016-09-14 17:35:43 -070059
Adam Lesinskicacb28f2016-10-19 12:18:14 -070060} // namespace io
61} // namespace aapt
Adam Lesinski21efb682016-09-14 17:35:43 -070062
63#endif /* AAPT_IO_IO_H */