forked from derat/xsettingsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_writer.h
39 lines (26 loc) · 815 Bytes
/
data_writer.h
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
// Copyright 2009 Daniel Erat <[email protected]>
// All rights reserved.
#ifndef __XSETTINGSD_DATA_WRITER_H__
#define __XSETTINGSD_DATA_WRITER_H__
#include <cstdlib> // for size_t
#include <stdint.h>
#include "common.h"
namespace xsettingsd {
// Provides an interface for writing different types of data to a buffer.
class DataWriter {
public:
DataWriter(char* buffer, size_t buf_len);
size_t bytes_written() const { return bytes_written_; }
bool WriteBytes(const char* data, size_t bytes_to_write);
bool WriteInt8(int8_t num);
bool WriteInt16(int16_t num);
bool WriteInt32(int32_t num);
bool WriteZeros(size_t bytes_to_write);
private:
char* buffer_; // not owned
size_t buf_len_;
size_t bytes_written_;
DISALLOW_COPY_AND_ASSIGN(DataWriter);
};
} // namespace xsettingsd
#endif