blob: c42738e4199eda6f55f43ad25139f5c42319e1cd [file] [log] [blame]
hashimotoc6bd5122015-12-14 06:41:491// 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
5#ifndef BINDER_BUFFER_READER_H_
6#define BINDER_BUFFER_READER_H_
7
8#include "base/macros.h"
9
10namespace binder {
11
12// BufferReader reads data from the given buffer.
13class BufferReader {
14 public:
15 BufferReader(const char* data, size_t size);
16 ~BufferReader();
17
18 const char* data() const { return data_; }
19 size_t size() const { return size_; }
20 size_t position() const { return position_; }
21
22 // Returns true when there is some data to read.
23 bool HasMoreData() const;
24
25 // Copies the specified number of bytes from the buffer to |out|.
26 // |out| shouldn't overlap with |data_|.
27 bool Read(void* out, size_t num_bytes);
28
29 // Moves the position |num_bytes| forward.
30 bool Skip(size_t num_bytes);
31
32 private:
33 const char* data_;
34 size_t size_;
35 size_t position_;
36
37 DISALLOW_COPY_AND_ASSIGN(BufferReader);
38};
39
40} // namespace binder
41
42#endif // BINDER_BUFFER_READER_H_