# Stream

## Public member functions

<pre class="language-cpp"><code class="lang-cpp">Stream();
Stream(const Stream &#x26;stream);
Stream(const std::vector&#x3C;unsigned char> &#x26;buffer);
Stream(const std::string &#x26;str);
Stream(const char str[], size_t size);
~Stream();
void operator += (const Stream &#x26;stream);
void operator += (const unsigned char &#x26;data);
void operator += (const std::string &#x26;str);
Stream operator = (const Stream &#x26;stream);
unsigned char operator[](size_t n);
const std::vector&#x3C;unsigned char> &#x26;getBuffer() const;
size_t size() const;
void clear();
<strong>Stream subStream(size_t pos) const;
</strong>Stream subStream(size_t pos, size_t len) const;
<strong>std::string toString() const;
</strong>void setDataCharArray(const char *data, size_t size);
void setDataUInt(unsigned int data);
void setDataUShort(unsigned short data);
void setDataUChar(unsigned char data);
void setDataInt(int data);
void setDataShort(short data);
void setDataChar(char data);
unsigned int getDataUInt();
unsigned short getDataUShort();
unsigned char getDataUChar();
int getDataInt();
short getDataShort();
char getDataChar();
</code></pre>

## Private attributes

```cpp
std::vector<unsigned char> _buffer;
```

## Member functions documentation

### Constructor

```cpp
Stream();
Stream(const Stream &stream);
Stream(const std::vector<unsigned char> &buffer);
Stream(const std::string &str);
Stream(const char str[], size_t size);
```

#### Parameters

* `stream:` The Stream to copy
* `buffer:` The buffer to copy
* `str:` The string to put as buffer
* `size:` The size of the string if needed

### operator+=

This operator concat another binary data to the current object

```cpp
void operator += (const Stream &stream);
void operator += (const unsigned char &data);
void operator += (const std::string &str);
```

#### Parameters

* `stream:` The stream to concat
* `data:` The single byte to concat
* `str:` The string that contain binary data to concat

### operator=

This operator change the buffer of the current object

```cpp
Stream operator = (const Stream &stream);
```

#### Parameters

* `stream:` The source stream

### operator\[]

This operator return the value at the position `n` of the buffer

```cpp
unsigned char operator[](size_t n);
```

### getBuffer

This method return the buffer that contain the binary data

```cpp
const std::vector<unsigned char> &getBuffer() const;
```

### size

This method return the size of the binary data in bytes

```cpp
size_t size() const;
```

### clear

This method clear the binary data

```cpp
void clear();
```

### subStream

This method return newly constructed Stream object with its value initialized to a copy of a substream of this object.

<pre class="language-cpp"><code class="lang-cpp"><strong>Stream subStream(size_t pos) const;
</strong>Stream subStream(size_t pos, size_t len) const;
</code></pre>

#### Parameters

* `pos:` Position of the first byte to put in the substream
* `len:` The number of byte to includes in the substream

### toString

This method return the stream in form of a std::string.

<pre class="language-cpp"><code class="lang-cpp"><strong>std::string toString() const;
</strong></code></pre>

### setData

This bunch of methods concat binary data to the Stream object.

```cpp
void setDataCharArray(const char *data, size_t size);
void setDataUInt(unsigned int data);
void setDataUShort(unsigned short data);
void setDataUChar(unsigned char data);
void setDataInt(int data);
void setDataShort(short data);
void setDataChar(char data);
```

#### Parameters

* `data:` The varable you want to append in the Stream
* `size:` The number of byte you want to append if needed

### getData

This bunch of methods extract a binary data from the Stream object and return it

```cpp
unsigned int getDataUInt();
unsigned short getDataUShort();
unsigned char getDataUChar();
int getDataInt();
short getDataShort();
char getDataChar();
```
