File: data_reader.h

package info (click to toggle)
xsettingsd 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 204 kB
  • sloc: cpp: 2,135; makefile: 19; sh: 6
file content (43 lines) | stat: -rw-r--r-- 832 bytes parent folder | download | duplicates (5)
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
// Copyright 2009 Daniel Erat <dan@erat.org>
// All rights reserved.

#ifndef __XSETTINGSD_DATA_READER_H__
#define __XSETTINGSD_DATA_READER_H__

#include <cstdlib>  // for size_t
#include <stdint.h>
#include <string>

#include "common.h"

namespace xsettingsd {

// Like DataWriter, but not.
class DataReader {
 public:
  DataReader(const char* buffer, size_t buf_len);

  void set_reverse_bytes(bool reverse) { reverse_bytes_ = reverse; }

  size_t bytes_read() const { return bytes_read_; }

  bool ReadBytes(std::string* out, size_t size);
  bool ReadInt8(int8_t* out);
  bool ReadInt16(int16_t* out);
  bool ReadInt32(int32_t* out);

 private:
  const char* buffer_;  // not owned

  size_t buf_len_;

  size_t bytes_read_;

  bool reverse_bytes_;

  DISALLOW_COPY_AND_ASSIGN(DataReader);
};

}  // namespace xsettingsd

#endif