# IPacketCreationStrategy

<a id="ipacketcreationstrategy"></a>

# IPacketCreationStrategy

```cpp
#include <icy/packetfactory.h>

class IPacketCreationStrategy
```

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

> **Subclassed by:** [`PacketCreationStrategy< PacketT >`](https://auscaster.com/icey/docs/api-reference/icy-PacketCreationStrategy.md#packetcreationstrategy)

Abstract strategy for creating typed packets from raw buffer data.

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`IPacketCreationStrategy`](#ipacketcreationstrategy-1)  | Defaulted constructor. |
|  | [`~IPacketCreationStrategy`](#ipacketcreationstrategy-2) `virtual` | Defaulted destructor. |
| [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) * | [`create`](#create) `virtual` `const` | Attempts to create a typed packet from the given buffer. |
| `int` | [`priority`](#priority) `virtual` `const` | Returns the dispatch priority of this strategy (0–100; higher runs first). |

---

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

### IPacketCreationStrategy

```cpp
IPacketCreationStrategy() = default
```

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

Defaulted constructor.

---

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

### ~IPacketCreationStrategy

`virtual`

```cpp
virtual ~IPacketCreationStrategy() = default
```

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

Defaulted destructor.

---

<a id="create"></a>

### create

`virtual` `const`

```cpp
virtual IPacket * create(const ConstBuffer & buffer, size_t & nread) const
```

[Defined in src/base/include/icy/packetfactory.h:38](https://github.com/auscaster/icey/blob/main/src/base/include/icy/packetfactory.h#L38)

Attempts to create a typed packet from the given buffer. 
#### Returns
Newly allocated packet on success, nullptr if the buffer does not match.

#### Reimplemented by

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

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `buffer` | const [`ConstBuffer`](https://auscaster.com/icey/docs/api-reference/icy-ConstBuffer.md#constbuffer-6) & | Raw input data. |
| `nread` | `size_t &` | Set to the number of bytes consumed on success, 0 otherwise. |

---

<a id="priority"></a>

### priority

`virtual` `const`

```cpp
virtual int priority() const
```

[Defined in src/base/include/icy/packetfactory.h:41](https://github.com/auscaster/icey/blob/main/src/base/include/icy/packetfactory.h#L41)

Returns the dispatch priority of this strategy (0–100; higher runs first).

#### Reimplemented by

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