-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBuffer.h
85 lines (63 loc) · 2.3 KB
/
Buffer.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
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
//-------------- notice that : we use utf-8 string ------------//
//notice that : we permit using correct cpu (big little endian)//
#pragma once
#include "Common.h"
EASY_NS_BEGIN
//we need reference
class Buffer : public Ref
{
private:
char* m_buffer;
int m_len;
bool m_weakptr;
public:
~Buffer();
Buffer(int len);
//length() do not include "\0"
Buffer(const char* str);
//when you have str , and know its length
Buffer(char* str, int len);
bool isBigEndian();
void write(const char* str,int offset,int len,bool same = false);
const char* toString();
int length();
//note that : end mean the last element
//copy from soff to pt at poff
void copy(Buffer* pt, int poff, int soff, int send);
Buffer* slice(int offset, int end);
//read method
unsigned char readUInt8(int offset);
unsigned short readUInt16LE(int offset);
unsigned short readUInt16BE(int offset);
unsigned int readUInt32LE(int offset);
unsigned int readUInt32BE(int offset);
signed char readInt8(int offset); //in android,char is unsigned as default
signed short readInt16LE(int offset);
signed short readInt16BE(int offset);
signed int readInt32LE(int offset);
signed int readInt32BE(int offset);
long long readInt64LE(int offset);
long long readInt64BE(int offset);
float readFloatLE(int offset);
float readFloatBE(int offset);
double readDoubleLE(int offset);
double readDoubleBE(int offset);
//write method
void writeUInt8(unsigned char value, int offset);
void writeUInt16LE(unsigned short value, int offset);
void writeUInt16BE(unsigned short value, int offset);
void writeUInt32LE(unsigned int value, int offset);
void writeUInt32BE(unsigned int value, int offset);
void writeInt8(char value, int offset);
void writeInt16LE(short value, int offset);
void writeInt16BE(short value, int offset);
void writeInt32LE(int value, int offset);
void writeInt32BE(int value, int offset);
void writeInt64LE(long long value, int offset);
void writeInt64BE(long long value, int offset);
void writeFloatLE(float value, int offset);
void writeFloatBE(float value, int offset);
void writeDoubleLE(double value, int offset);
void writeDoubleBE(double value, int offset);
};
EASY_NS_END