blob: d8ee6323bbc6b1d4a23af4ab2deec90ea7c90d98 [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
hashimoto32e9f8bb2015-12-18 08:06:125#ifndef CHROMEOS_BINDER_BUFFER_READER_H_
6#define CHROMEOS_BINDER_BUFFER_READER_H_
hashimotoc6bd5122015-12-14 06:41:497
avi6e1a22d2015-12-21 03:43:208#include <stddef.h>
9
hashimotoc6bd5122015-12-14 06:41:4910#include "base/macros.h"
hashimoto32e9f8bb2015-12-18 08:06:1211#include "chromeos/chromeos_export.h"
hashimotoc6bd5122015-12-14 06:41:4912
13namespace binder {
14
15// BufferReader reads data from the given buffer.
hashimoto32e9f8bb2015-12-18 08:06:1216class CHROMEOS_EXPORT BufferReader {
hashimotoc6bd5122015-12-14 06:41:4917 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_; }
hashimoto493d7d092016-01-08 06:45:3123 const char* current() const { return current_; }
hashimotoc6bd5122015-12-14 06:41:4924
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_;
hashimoto493d7d092016-01-08 06:45:3138 const char* current_;
hashimotoc6bd5122015-12-14 06:41:4939
40 DISALLOW_COPY_AND_ASSIGN(BufferReader);
41};
42
43} // namespace binder
44
hashimoto32e9f8bb2015-12-18 08:06:1245#endif // CHROMEOS_BINDER_BUFFER_READER_H_