summaryrefslogtreecommitdiffstats
path: root/chromeos/binder/buffer_reader.h
blob: d8ee6323bbc6b1d4a23af4ab2deec90ea7c90d98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_BINDER_BUFFER_READER_H_
#define CHROMEOS_BINDER_BUFFER_READER_H_

#include <stddef.h>

#include "base/macros.h"
#include "chromeos/chromeos_export.h"

namespace binder {

// BufferReader reads data from the given buffer.
class CHROMEOS_EXPORT BufferReader {
 public:
  BufferReader(const char* data, size_t size);
  ~BufferReader();

  const char* data() const { return data_; }
  size_t size() const { return size_; }
  const char* current() const { return current_; }

  // Returns true when there is some data to read.
  bool HasMoreData() const;

  // Copies the specified number of bytes from the buffer to |out|.
  // |out| shouldn't overlap with |data_|.
  bool Read(void* out, size_t num_bytes);

  // Moves the position |num_bytes| forward.
  bool Skip(size_t num_bytes);

 private:
  const char* data_;
  size_t size_;
  const char* current_;

  DISALLOW_COPY_AND_ASSIGN(BufferReader);
};

}  // namespace binder

#endif  // CHROMEOS_BINDER_BUFFER_READER_H_