-
Notifications
You must be signed in to change notification settings - Fork 2
/
Buffer.hpp
105 lines (71 loc) · 3.02 KB
/
Buffer.hpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* This file is part of PHPinnacle/Buffer.
*
* (c) PHPinnacle Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
#pragma once
#include <vector>
#include <sstream>
#include <exception>
struct BufferOverflow : public std::exception {};
class Buffer {
public:
Buffer() noexcept;
Buffer(const std::vector<unsigned char>&) noexcept;
void clear() noexcept;
void write(char * str, long length) noexcept;
void merge(const Buffer&) noexcept;
void discard(unsigned long long n);
unsigned long long size() const noexcept;
bool empty() const noexcept;
std::string bytes() const noexcept;
std::string flush() noexcept;
/************************** Writing ***************************/
template <class T> inline void append(const T &val) noexcept;
void appendString(const std::string&) noexcept;
void appendBoolean(bool) noexcept;
void appendInt8(char) noexcept;
void appendUint8(unsigned char) noexcept;
void appendInt16(short) noexcept;
void appendUint16(unsigned short) noexcept;
void appendInt32(int) noexcept;
void appendUint32(unsigned int) noexcept;
void appendInt64(long long) noexcept;
void appendUint64(unsigned long long) noexcept;
void appendFloat(float) noexcept;
void appendDouble(double) noexcept;
/************************** Reading ***************************/
template <class T> inline T read(unsigned long long offset) const;
std::string readString(unsigned long long size, unsigned long long offset) const;
bool readBoolean(unsigned long long offset) const;
char readInt8(unsigned long long offset) const;
unsigned char readUint8(unsigned long long offset) const;
short readInt16(unsigned long long offset) const;
unsigned short readUint16(unsigned long long offset) const;
int readInt32(unsigned long long offset) const;
unsigned int readUint32(unsigned long long offset) const;
long long readInt64(unsigned long long offset) const;
unsigned long long readUint64(unsigned long long offset) const;
float readFloat(unsigned long long offset) const;
double readDouble(unsigned long long offset) const;
/************************** Consuming ***************************/
template <class T> inline T consume();
std::string consumeString(unsigned long long size);
bool consumeBool();
char consumeInt8();
unsigned char consumeUint8();
short consumeInt16();
unsigned short consumeUint16();
int consumeInt32();
unsigned int consumeUint32();
long long consumeInt64();
unsigned long long consumeUint64();
float consumeFloat();
double consumeDouble();
~Buffer();
private:
std::vector<unsigned char> buffer;
};