# DynamicBitWriter

<a id="dynamicbitwriter"></a>

# DynamicBitWriter

```cpp
#include <buffer.h>

class DynamicBitWriter
```

Defined in src/base/include/icy/buffer.h:596

> **Inherits:** [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter)

Class for reading/writing dynamically resizable binary streams.

Note that when using the constructor with the [Buffer](https://sourcey.com/examples/docs-showcase/reference/cpp/base.md#buffer) reference as an argument, the writer will dynamically expand the given buffer when writing passed the buffer capacity. All other cases will throw a std::out_of_range error when writing past the buffer capacity.

## List of all members

| Name | Kind | Owner |
|------|------|-------|
| [`DynamicBitWriter`](#dynamicbitwriter-1) | `function` | Declared here |
| [`DynamicBitWriter`](#dynamicbitwriter-2) | `function` | Declared here |
| [`~DynamicBitWriter`](#dynamicbitwriter-3) | `function` | Declared here |
| [`put`](#put-2) | `function` | Declared here |
| [`update`](#update-2) | `function` | Declared here |
| [`_buffer`](#_buffer) | `variable` | Declared here |
| [`_offset`](#_offset) | `variable` | Declared here |
| [`operator<<`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#operator-1) | `friend` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter-1) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter-2) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter-3) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`~BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter-4) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`put`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#put) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`put`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#put-1) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`putU8`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#putu8) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`putU16`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#putu16) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`putU24`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#putu24) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`putU32`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#putu32) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`putU64`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#putu64) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`update`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#update) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`update`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#update-1) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`updateU8`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#updateu8) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`updateU16`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#updateu16) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`updateU24`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#updateu24) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`updateU32`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#updateu32) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`updateU64`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#updateu64) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`seek`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#seek-1) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`skip`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#skip-1) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`limit`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#limit-1) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`position`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#position-1) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`available`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#available-1) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`begin`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#begin-1) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`current`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#current-1) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`begin`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#begin-2) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`current`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#current-2) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`order`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#order-1) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`toString`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#tostring-1) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`_position`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#_position-1) | `variable` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`_limit`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#_limit-1) | `variable` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`_order`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#_order-1) | `variable` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`_bytes`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#_bytes-1) | `variable` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |
| [`init`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#init-1) | `function` | Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter) |

## Inherited from [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter)

| Kind | Name | Description |
|------|------|-------------|
| `friend` | [`operator<<`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#operator-1) `inline` |  |
| `function` | [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter-1)  | Constructs a `[BitWriter](icy-BitWriter.html#bitwriter)` over a raw byte array with a fixed capacity. |
| `function` | [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter-2)  | Constructs a `[BitWriter](icy-BitWriter.html#bitwriter)` backed by a `[Buffer](base.html#buffer)`. Writes are bounded by the buffer's capacity; use `[DynamicBitWriter](#dynamicbitwriter)` for auto-resize. |
| `function` | [`BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter-3)  | Constructs a `[BitWriter](icy-BitWriter.html#bitwriter)` over a `[MutableBuffer](icy-MutableBuffer.html#mutablebuffer-6)` with a fixed capacity. |
| `function` | [`~BitWriter`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#bitwriter-4) `virtual` |  |
| `function` | [`put`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#put) `virtual` | Append bytes to the buffer. Throws a `std::out_of_range` exception if reading past the limit. |
| `function` | [`put`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#put-1)  | Appends the contents of a string. Throws `std::out_of_range` if capacity is exceeded. |
| `function` | [`putU8`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#putu8)  | Appends an unsigned 8-bit integer. Throws `std::out_of_range` if capacity is exceeded. |
| `function` | [`putU16`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#putu16)  | Appends an unsigned 16-bit integer with byte-order conversion. Throws `std::out_of_range` if capacity is exceeded. |
| `function` | [`putU24`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#putu24)  | Appends the low 24 bits of a 32-bit integer with byte-order conversion. Throws `std::out_of_range` if capacity is exceeded. |
| `function` | [`putU32`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#putu32)  | Appends an unsigned 32-bit integer with byte-order conversion. Throws `std::out_of_range` if capacity is exceeded. |
| `function` | [`putU64`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#putu64)  | Appends an unsigned 64-bit integer with byte-order conversion. Throws `std::out_of_range` if capacity is exceeded. |
| `function` | [`update`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#update) `virtual` | Update a byte range. Throws a `std::out_of_range` exception if reading past the limit. |
| `function` | [`update`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#update-1)  | Overwrites a previously written string at the given absolute position. |
| `function` | [`updateU8`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#updateu8)  | Overwrites a `uint8_t` at the given absolute position. |
| `function` | [`updateU16`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#updateu16)  | Overwrites a `uint16_t` at the given absolute position, with byte-order conversion. |
| `function` | [`updateU24`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#updateu24)  | Overwrites 3 bytes (low 24 bits of `val`) at the given absolute position, with byte-order conversion. |
| `function` | [`updateU32`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#updateu32)  | Overwrites a `uint32_t` at the given absolute position, with byte-order conversion. |
| `function` | [`updateU64`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#updateu64)  | Overwrites a `uint64_t` at the given absolute position, with byte-order conversion. |
| `function` | [`seek`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#seek-1)  | Set position pointer to absolute position. Throws a `std::out_of_range` exception if the value exceeds the limit. |
| `function` | [`skip`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#skip-1)  | Set position pointer to relative position. Throws a `std::out_of_range` exception if the value exceeds the limit. |
| `function` | [`limit`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#limit-1) `const` `nodiscard` | Returns the write limit. |
| `function` | [`position`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#position-1) `const` `inline` `nodiscard` | Returns the current write position. |
| `function` | [`available`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#available-1) `const` `nodiscard` | Returns the number of elements between the current write position and the limit. |
| `function` | [`begin`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#begin-1) `inline` `nodiscard` | Returns a pointer to the start of the write buffer. |
| `function` | [`current`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#current-1) `inline` `nodiscard` | Returns a pointer to the current write position. |
| `function` | [`begin`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#begin-2) `const` `inline` `nodiscard` | Returns a const pointer to the start of the write buffer. |
| `function` | [`current`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#current-2) `const` `inline` `nodiscard` | Returns a const pointer to the current write position. |
| `function` | [`order`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#order-1) `const` `inline` | Returns the byte order used for multi-byte integer writes. |
| `function` | [`toString`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#tostring-1)  | Returns all bytes written so far as a `std::string`. |
| `variable` | [`_position`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#_position-1)  |  |
| `variable` | [`_limit`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#_limit-1)  |  |
| `variable` | [`_order`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#_order-1)  |  |
| `variable` | [`_bytes`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#_bytes-1)  |  |
| `function` | [`init`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#init-1) `virtual` |  |

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`DynamicBitWriter`](#dynamicbitwriter-1)  | Constructs a `[DynamicBitWriter](#dynamicbitwriter)` backed by a dynamically resizable `[Buffer](base.html#buffer)`. The buffer is expanded automatically as data is written. |
|  | [`DynamicBitWriter`](#dynamicbitwriter-2)  | Constructs a `[DynamicBitWriter](#dynamicbitwriter)` that inserts data starting at a specific iterator position. |
|  | [`~DynamicBitWriter`](#dynamicbitwriter-3) `virtual` |  |
| `void` | [`put`](#put-2) `virtual` `override` | Append bytes to the buffer. Throws a `std::out_of_range` exception if reading past the limit. |
| `bool` | [`update`](#update-2) `virtual` `override` | Update a byte range. Throws a `std::out_of_range` exception if reading past the limit. |

---

<a id="dynamicbitwriter-1"></a>

### DynamicBitWriter

```cpp
DynamicBitWriter(Buffer & buf, ByteOrder order = ByteOrder::Network)
```

Defined in src/base/include/icy/buffer.h:603

Constructs a `[DynamicBitWriter](#dynamicbitwriter)` backed by a dynamically resizable `[Buffer](base.html#buffer)`. The buffer is expanded automatically as data is written.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `buf` | [`Buffer`](https://sourcey.com/examples/docs-showcase/reference/cpp/base.md#buffer) & | [Buffer](https://sourcey.com/examples/docs-showcase/reference/cpp/base.md#buffer) to write into; expanded as needed. |
| `order` | `ByteOrder` | Byte order used for multi-byte integer writes. |

---

<a id="dynamicbitwriter-2"></a>

### DynamicBitWriter

```cpp
DynamicBitWriter(Buffer & buf, Buffer::iterator offset, ByteOrder order = ByteOrder::Network)
```

Defined in src/base/include/icy/buffer.h:609

Constructs a `[DynamicBitWriter](#dynamicbitwriter)` that inserts data starting at a specific iterator position.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `buf` | [`Buffer`](https://sourcey.com/examples/docs-showcase/reference/cpp/base.md#buffer) & | [Buffer](https://sourcey.com/examples/docs-showcase/reference/cpp/base.md#buffer) to write into; expanded as needed. |
| `offset` | `Buffer::iterator` | Iterator into `buf` indicating the insertion start point. |
| `order` | `ByteOrder` | Byte order used for multi-byte integer writes. |

---

<a id="dynamicbitwriter-3"></a>

### ~DynamicBitWriter

`virtual`

```cpp
virtual ~DynamicBitWriter()
```

Defined in src/base/include/icy/buffer.h:610

---

<a id="put-2"></a>

### put

`virtual` `override`

```cpp
virtual void put(const char * val, size_t len) override
```

Defined in src/base/include/icy/buffer.h:614

Append bytes to the buffer. Throws a `std::out_of_range` exception if reading past the limit.

#### Reimplements

- [`BitWriter::put`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#put)

---

<a id="update-2"></a>

### update

`virtual` `override`

```cpp
virtual bool update(const char * val, size_t len, size_t pos) override
```

Defined in src/base/include/icy/buffer.h:618

Update a byte range. Throws a `std::out_of_range` exception if reading past the limit.

#### Reimplements

- [`BitWriter::update`](https://sourcey.com/examples/docs-showcase/reference/cpp/icy-BitWriter.md#update)

## Protected Attributes

| Return | Name | Description |
|--------|------|-------------|
| [`Buffer`](https://sourcey.com/examples/docs-showcase/reference/cpp/base.md#buffer) & | [`_buffer`](#_buffer)  |  |
| `size_t` | [`_offset`](#_offset)  |  |

---

<a id="_buffer"></a>

### _buffer

```cpp
Buffer & _buffer
```

Type: [`Buffer`](https://sourcey.com/examples/docs-showcase/reference/cpp/base.md#buffer) &

Defined in src/base/include/icy/buffer.h:621

---

<a id="_offset"></a>

### _offset

```cpp
size_t _offset
```

Defined in src/base/include/icy/buffer.h:622
