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 | |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
hashimoto | c6bd512 | 2015-12-14 06:41:49 | [diff] [blame] | 10 | #include "base/macros.h" |
hashimoto | 32e9f8bb | 2015-12-18 08:06:12 | [diff] [blame] | 11 | #include "chromeos/chromeos_export.h" |
hashimoto | c6bd512 | 2015-12-14 06:41:49 | [diff] [blame] | 12 | |
| 13 | namespace binder { |
| 14 | |
| 15 | // BufferReader reads data from the given buffer. |
hashimoto | 32e9f8bb | 2015-12-18 08:06:12 | [diff] [blame] | 16 | class CHROMEOS_EXPORT BufferReader { |
hashimoto | c6bd512 | 2015-12-14 06:41:49 | [diff] [blame] | 17 | public: |
| 18 | BufferReader(const char* data, size_t size); |
| 19 | ~BufferReader(); |
| 20 | |
| 21 | const char* data() const { return data_; } |
| 22 | size_t size() const { return size_; } |
hashimoto | 493d7d09 | 2016-01-08 06:45:31 | [diff] [blame^] | 23 | const char* current() const { return current_; } |
hashimoto | c6bd512 | 2015-12-14 06:41:49 | [diff] [blame] | 24 | |
| 25 | // Returns true when there is some data to read. |
| 26 | bool HasMoreData() const; |
| 27 | |
| 28 | // Copies the specified number of bytes from the buffer to |out|. |
| 29 | // |out| shouldn't overlap with |data_|. |
| 30 | bool Read(void* out, size_t num_bytes); |
| 31 | |
| 32 | // Moves the position |num_bytes| forward. |
| 33 | bool Skip(size_t num_bytes); |
| 34 | |
| 35 | private: |
| 36 | const char* data_; |
| 37 | size_t size_; |
hashimoto | 493d7d09 | 2016-01-08 06:45:31 | [diff] [blame^] | 38 | const char* current_; |
hashimoto | c6bd512 | 2015-12-14 06:41:49 | [diff] [blame] | 39 | |
| 40 | DISALLOW_COPY_AND_ASSIGN(BufferReader); |
| 41 | }; |
| 42 | |
| 43 | } // namespace binder |
| 44 | |
hashimoto | 32e9f8bb | 2015-12-18 08:06:12 | [diff] [blame] | 45 | #endif // CHROMEOS_BINDER_BUFFER_READER_H_ |