summaryrefslogtreecommitdiff
path: root/protocols/WhatsApp/src/WhatsAPI++/ByteArray.h
blob: 5a3f90d22144138291b778ce10d6e70fbfa1aa4d (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
46
47
48
49
50
51
52
53
/*
 * ByteArray.h
 *
 *  Created on: 26/06/2012
 *      Author: Antonio
 */



#ifndef BYTEARRAY_H_
#define BYTEARRAY_H_

#include <vector>
#include <string>

class ByteArrayOutputStream {
protected:
	std::vector<unsigned char> buf;
	size_t position;

public:
	ByteArrayOutputStream(int size = 32);
	virtual ~ByteArrayOutputStream();

	std::vector<unsigned char>& getBuffer();
	void setPosition(size_t count);
	void write(int i);
	void write(unsigned char* c, size_t length);
	void write(const std::string& s);
	void setLength(size_t length);

	__forceinline size_t getCapacity() const { return buf.capacity(); }
	__forceinline size_t getLength() const { return buf.size(); }
	__forceinline size_t getPosition() const { return position; }
};

class ByteArrayInputStream {
protected:
	std::vector<unsigned char>* buf;
	size_t pos;
	size_t mark;
	size_t count;

public:
	ByteArrayInputStream(std::vector<unsigned char>* buf,  size_t off, size_t length );
	ByteArrayInputStream(std::vector<unsigned char>* buf);
	int read();
	int read(std::vector<unsigned char>& b, size_t off, size_t length);

	virtual ~ByteArrayInputStream();
};

#endif /* BYTEARRAY_H_ */