# ChunkedAdapter

<a id="chunkedadapter"></a>

# ChunkedAdapter

```cpp
#include <icy/http/packetizers.h>

class ChunkedAdapter
```

[Defined in src/http/include/icy/http/packetizers.h:29](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/packetizers.h#L29)

> **Inherits:** [`PacketProcessor`](https://auscaster.com/icey/docs/api-reference/icy-PacketProcessor.md#packetprocessor)

HTTP chunked transfer encoding adapter for streaming responses.

## List of all members

| Name | Kind | Owner |
|------|------|-------|
| [`connection`](#connection) | `variable` | Declared here |
| [`contentType`](#contenttype) | `variable` | Declared here |
| [`frameSeparator`](#frameseparator) | `variable` | Declared here |
| [`initial`](#initial) | `variable` | Declared here |
| [`nocopy`](#nocopy) | `variable` | Declared here |
| [`emitter`](#emitter-10) | `variable` | Declared here |
| [`ChunkedAdapter`](#chunkedadapter-1) | `function` | Declared here |
| [`ChunkedAdapter`](#chunkedadapter-2) | `function` | Declared here |
| [`~ChunkedAdapter`](#chunkedadapter-3) | `function` | Declared here |
| [`emitHeader`](#emitheader) | `function` | Declared here |
| [`process`](#process-15) | `function` | Declared here |
| [`PacketProcessor`](https://auscaster.com/icey/docs/api-reference/icy-PacketProcessor.md#packetprocessor-1) | `function` | Inherited from [`PacketProcessor`](https://auscaster.com/icey/docs/api-reference/icy-PacketProcessor.md#packetprocessor) |
| [`process`](https://auscaster.com/icey/docs/api-reference/icy-PacketProcessor.md#process-1) | `function` | Inherited from [`PacketProcessor`](https://auscaster.com/icey/docs/api-reference/icy-PacketProcessor.md#packetprocessor) |
| [`accepts`](https://auscaster.com/icey/docs/api-reference/icy-PacketProcessor.md#accepts-1) | `function` | Inherited from [`PacketProcessor`](https://auscaster.com/icey/docs/api-reference/icy-PacketProcessor.md#packetprocessor) |
| [`operator<<`](https://auscaster.com/icey/docs/api-reference/icy-PacketProcessor.md#operator-69) | `function` | Inherited from [`PacketProcessor`](https://auscaster.com/icey/docs/api-reference/icy-PacketProcessor.md#packetprocessor) |
| [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter-1) | `function` | Inherited from [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter) |
| [`~PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter-2) | `function` | Inherited from [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter) |
| [`emit`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#emit-1) | `function` | Inherited from [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter) |
| [`emit`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#emit-2) | `function` | Inherited from [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter) |
| [`emit`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#emit-3) | `function` | Inherited from [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter) |
| [`emit`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#emit-4) | `function` | Inherited from [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter) |
| [`emit`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#emit-5) | `function` | Inherited from [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter) |
| [`getEmitter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#getemitter) | `function` | Inherited from [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter) |
| [`retention`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#retention-1) | `function` | Inherited from [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter) |
| [`onStreamStateChange`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#onstreamstatechange-1) | `function` | Inherited from [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter) |
| [`_emitter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#_emitter) | `variable` | Inherited from [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter) |
| [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter-3) | `function` | Inherited from [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter) |
| [`operator=`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#operator-72) | `function` | Inherited from [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter) |
| [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter-4) | `function` | Inherited from [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter) |
| [`operator=`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#operator-73) | `function` | Inherited from [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter) |

## Inherited from [`PacketProcessor`](https://auscaster.com/icey/docs/api-reference/icy-PacketProcessor.md#packetprocessor)

| Kind | Name | Description |
|------|------|-------------|
| `function` | [`PacketProcessor`](https://auscaster.com/icey/docs/api-reference/icy-PacketProcessor.md#packetprocessor-1) `inline` |  |
| `function` | [`process`](https://auscaster.com/icey/docs/api-reference/icy-PacketProcessor.md#process-1) `virtual` | This method performs processing on the given packet and emits the result. |
| `function` | [`accepts`](https://auscaster.com/icey/docs/api-reference/icy-PacketProcessor.md#accepts-1) `virtual` `inline` | This method ensures compatibility with the given packet type. Return false to reject the packet. |
| `function` | [`operator<<`](https://auscaster.com/icey/docs/api-reference/icy-PacketProcessor.md#operator-69) `virtual` `inline` | [Stream](https://auscaster.com/icey/docs/api-reference/icy-Stream.md#stream) operator alias for [process()](https://auscaster.com/icey/docs/api-reference/icy-PacketProcessor.md#process-1) |

## Inherited from [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter)

| Kind | Name | Description |
|------|------|-------------|
| `function` | [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter-1)  | Construct the adapter, binding it to the given packet signal. |
| `function` | [`~PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter-2) `virtual` `inline` |  |
| `function` | [`emit`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#emit-1) `virtual` | Emit a mutable raw buffer as a packet. |
| `function` | [`emit`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#emit-2) `virtual` | Emit a read-only raw buffer as a packet (data is copied internally). |
| `function` | [`emit`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#emit-3) `virtual` | Emit a string as a packet (data is copied internally). |
| `function` | [`emit`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#emit-4) `virtual` | Emit a flag-only packet carrying no payload data. |
| `function` | [`emit`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#emit-5) `virtual` | Emit an existing packet directly onto the outgoing signal. |
| `function` | [`getEmitter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#getemitter)  | Returns a reference to the outgoing packet signal. |
| `function` | [`retention`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#retention-1) `virtual` `const` | Returns how this adapter treats incoming packet lifetime. Most adapters are synchronous and therefore only borrow the packet for the current call chain. Queue-style adapters override this to advertise that they clone before deferred use. Callers may treat the first adapter reporting Cloned or Retained as the explicit ownership boundary in the stream graph. |
| `function` | [`onStreamStateChange`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#onstreamstatechange-1) `virtual` `inline` | Called by the [PacketStream](https://auscaster.com/icey/docs/api-reference/icy-PacketStream.md#packetstream) to notify when the internal [Stream](https://auscaster.com/icey/docs/api-reference/icy-Stream.md#stream) state changes. On receiving the Stopped state, it is the responsibility of the adapter to have ceased all outgoing packet transmission, especially in multi-thread scenarios. |
| `variable` | [`_emitter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#_emitter)  |  |
| `function` | [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter-3)  | NonCopyable and NonMovable. |
| `function` | [`operator=`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#operator-72)  | Deleted assignment operator. |
| `function` | [`PacketStreamAdapter`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#packetstreamadapter-4)  | Deleted constructor. |
| `function` | [`operator=`](https://auscaster.com/icey/docs/api-reference/icy-PacketStreamAdapter.md#operator-73)  | Deleted assignment operator. |

## Public Attributes

| Return | Name | Description |
|--------|------|-------------|
| [`Connection::Ptr`](https://auscaster.com/icey/docs/api-reference/icy-http-Connection.md#ptr-17) | [`connection`](#connection)  | HTTP connection to send the initial response header through. |
| `std::string` | [`contentType`](#contenttype)  | Content-Type value for the chunked response. |
| `std::string` | [`frameSeparator`](#frameseparator)  | Optional separator written before each chunk payload. |
| `bool` | [`initial`](#initial)  | True until the first chunk is processed and the header emitted. |
| `bool` | [`nocopy`](#nocopy)  | If true, header/data/footer are emitted as separate packets. |
| [`PacketSignal`](https://auscaster.com/icey/docs/api-reference/base.md#packetsignal) | [`emitter`](#emitter-10)  |  |

---

<a id="connection"></a>

### connection

```cpp
Connection::Ptr connection
```

Type: [`Connection::Ptr`](https://auscaster.com/icey/docs/api-reference/icy-http-Connection.md#ptr-17)

[Defined in src/http/include/icy/http/packetizers.h:32](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/packetizers.h#L32)

HTTP connection to send the initial response header through.

---

<a id="contenttype"></a>

### contentType

```cpp
std::string contentType
```

[Defined in src/http/include/icy/http/packetizers.h:33](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/packetizers.h#L33)

Content-Type value for the chunked response.

---

<a id="frameseparator"></a>

### frameSeparator

```cpp
std::string frameSeparator
```

[Defined in src/http/include/icy/http/packetizers.h:34](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/packetizers.h#L34)

Optional separator written before each chunk payload.

---

<a id="initial"></a>

### initial

```cpp
bool initial
```

[Defined in src/http/include/icy/http/packetizers.h:35](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/packetizers.h#L35)

True until the first chunk is processed and the header emitted.

---

<a id="nocopy"></a>

### nocopy

```cpp
bool nocopy
```

[Defined in src/http/include/icy/http/packetizers.h:36](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/packetizers.h#L36)

If true, header/data/footer are emitted as separate packets.

---

<a id="emitter-10"></a>

### emitter

```cpp
PacketSignal emitter
```

Type: [`PacketSignal`](https://auscaster.com/icey/docs/api-reference/base.md#packetsignal)

[Defined in src/http/include/icy/http/packetizers.h:146](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/packetizers.h#L146)

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`ChunkedAdapter`](#chunkedadapter-1) `inline` | Creates a [ChunkedAdapter](#chunkedadapter) that sends its initial response header through the given connection. The content type is read from the connection's outgoing header. |
|  | [`ChunkedAdapter`](#chunkedadapter-2) `inline` | Creates a [ChunkedAdapter](#chunkedadapter) that emits its own raw HTTP/1.1 200 response header. Use this when no [Connection](https://auscaster.com/icey/docs/api-reference/icy-http-Connection.md#connection-1) object is available. |
|  | [`~ChunkedAdapter`](#chunkedadapter-3) `virtual` `inline` |  |
| `void` | [`emitHeader`](#emitheader) `virtual` `inline` | Emits the initial HTTP/1.1 200 OK response headers with chunked transfer encoding. If a connection is set, headers are written through it; otherwise a raw response string is emitted via the packet signal. |
| `void` | [`process`](#process-15) `virtual` `inline` `override` | Encodes an incoming packet as a chunked transfer encoding chunk and emits it. Emits the HTTP response headers on the first call. |

---

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

### ChunkedAdapter

`inline`

```cpp
inline ChunkedAdapter(Connection::Ptr connection = nullptr, const std::string & frameSeparator = "", bool nocopy = true)
```

[Defined in src/http/include/icy/http/packetizers.h:43](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/packetizers.h#L43)

Creates a [ChunkedAdapter](#chunkedadapter) that sends its initial response header through the given connection. The content type is read from the connection's outgoing header.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `connection` | [`Connection::Ptr`](https://auscaster.com/icey/docs/api-reference/icy-http-Connection.md#ptr-17) | HTTP connection to use. May be nullptr to emit a raw response instead. |
| `frameSeparator` | `const std::string &` | Optional data prepended to each chunk payload. |
| `nocopy` | `bool` | If true, header and payload are emitted as separate packets (avoids copies). |

---

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

### ChunkedAdapter

`inline`

```cpp
inline ChunkedAdapter(const std::string & contentType, const std::string & frameSeparator = "", bool nocopy = true)
```

[Defined in src/http/include/icy/http/packetizers.h:56](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/packetizers.h#L56)

Creates a [ChunkedAdapter](#chunkedadapter) that emits its own raw HTTP/1.1 200 response header. Use this when no [Connection](https://auscaster.com/icey/docs/api-reference/icy-http-Connection.md#connection-1) object is available.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `contentType` | `const std::string &` | Content-Type value for the response. |
| `frameSeparator` | `const std::string &` | Optional data prepended to each chunk payload. |
| `nocopy` | `bool` | If true, header and payload are emitted as separate packets. |

---

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

### ~ChunkedAdapter

`virtual` `inline`

```cpp
virtual inline ~ChunkedAdapter()
```

[Defined in src/http/include/icy/http/packetizers.h:66](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/packetizers.h#L66)

---

<a id="emitheader"></a>

### emitHeader

`virtual` `inline`

```cpp
virtual inline void emitHeader()
```

[Defined in src/http/include/icy/http/packetizers.h:71](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/packetizers.h#L71)

Emits the initial HTTP/1.1 200 OK response headers with chunked transfer encoding. If a connection is set, headers are written through it; otherwise a raw response string is emitted via the packet signal.

---

<a id="process-15"></a>

### process

`virtual` `inline` `override`

```cpp
virtual inline void process(IPacket & packet) override
```

[Defined in src/http/include/icy/http/packetizers.h:108](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/packetizers.h#L108)

Encodes an incoming packet as a chunked transfer encoding chunk and emits it. Emits the HTTP response headers on the first call.

#### Reimplements

- [`PacketProcessor::process`](https://auscaster.com/icey/docs/api-reference/icy-PacketProcessor.md#process-1)

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `packet` | [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) & | Packet containing the raw payload data. |

#### Exceptions

| Exception | Description |
|-----------|-------------|
| `std::invalid_argument` | if the packet does not carry data. |
