hashimoto | c6bd512 | 2015-12-14 06:41:49 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
hashimoto | 32e9f8bb | 2015-12-18 08:06:12 | [diff] [blame^] | 5 | #ifndef CHROMEOS_BINDER_BUFFER_READER_H_ |
| 6 | #define CHROMEOS_BINDER_BUFFER_READER_H_ |
hashimoto | c6bd512 | 2015-12-14 06:41:49 | [diff] [blame] | 7 | |
| 8 | #include "base/macros.h" |
hashimoto | 32e9f8bb | 2015-12-18 08:06:12 | [diff] [blame^] | 9 | #include "chromeos/chromeos_export.h" |
hashimoto | c6bd512 | 2015-12-14 06:41:49 | [diff] [blame] | 10 | |
| 11 | namespace binder { |
| 12 | |
| 13 | // BufferReader reads data from the given buffer. |
hashimoto | 32e9f8bb | 2015-12-18 08:06:12 | [diff] [blame^] | 14 | class CHROMEOS_EXPORT BufferReader { |
hashimoto | c6bd512 | 2015-12-14 06:41:49 | [diff] [blame] | 15 | public: |
| 16 | BufferReader(const char* data, size_t size); |
| 17 | ~BufferReader(); |
| 18 | |
| 19 | const char* data() const { return data_; } |
| 20 | size_t size() const { return size_; } |
| 21 | size_t position() const { return position_; } |
| 22 | |
| 23 | // Returns true when there is some data to read. |
| 24 | bool HasMoreData() const; |
| 25 | |
| 26 | // Copies the specified number of bytes from the buffer to |out|. |
| 27 | // |out| shouldn't overlap with |data_|. |
| 28 | bool Read(void* out, size_t num_bytes); |
| 29 | |
| 30 | // Moves the position |num_bytes| forward. |
| 31 | bool Skip(size_t num_bytes); |
| 32 | |
| 33 | private: |
| 34 | const char* data_; |
| 35 | size_t size_; |
| 36 | size_t position_; |
| 37 | |
| 38 | DISALLOW_COPY_AND_ASSIGN(BufferReader); |
| 39 | }; |
| 40 | |
| 41 | } // namespace binder |
| 42 | |
hashimoto | 32e9f8bb | 2015-12-18 08:06:12 | [diff] [blame^] | 43 | #endif // CHROMEOS_BINDER_BUFFER_READER_H_ |