# Message

<a id="message-6"></a>

# Message

```cpp
#include <icy/stun/message.h>

class Message
```

[Defined in src/stun/include/icy/stun/message.h:31](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L31)

> **Inherits:** [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket)
> **Subclassed by:** [`Request`](https://auscaster.com/icey/docs/api-reference/icy-turn-Request.md#request-14)

STUN/TURN protocol message with method, class, transaction ID, and attributes.

## List of all members

| Name | Kind | Owner |
|------|------|-------|
| [`Message`](#message-7) | `function` | Declared here |
| [`Message`](#message-8) | `function` | Declared here |
| [`Message`](#message-9) | `function` | Declared here |
| [`Message`](#message-10) | `function` | Declared here |
| [`operator=`](#operator-232) | `function` | Declared here |
| [`operator=`](#operator-233) | `function` | Declared here |
| [`~Message`](#message-11) | `function` | Declared here |
| [`clone`](#clone-15) | `function` | Declared here |
| [`setClass`](#setclass) | `function` | Declared here |
| [`setMethod`](#setmethod-1) | `function` | Declared here |
| [`setTransactionID`](#settransactionid) | `function` | Declared here |
| [`classType`](#classtype) | `function` | Declared here |
| [`methodType`](#methodtype) | `function` | Declared here |
| [`transactionID`](#transactionid-2) | `function` | Declared here |
| [`size`](#size-14) | `function` | Declared here |
| [`methodString`](#methodstring) | `function` | Declared here |
| [`classString`](#classstring) | `function` | Declared here |
| [`errorString`](#errorstring) | `function` | Declared here |
| [`add`](#add-9) | `function` | Declared here |
| [`add`](#add-10) | `function` | Declared here |
| [`get`](#get-18) | `function` | Declared here |
| [`get`](#get-19) | `function` | Declared here |
| [`read`](#read-10) | `function` | Declared here |
| [`write`](#write-39) | `function` | Declared here |
| [`toString`](#tostring-11) | `function` | Declared here |
| [`print`](#print-15) | `function` | Declared here |
| [`className`](#classname-12) | `function` | Declared here |
| [`_class`](#_class-1) | `variable` | Declared here |
| [`_method`](#_method-1) | `variable` | Declared here |
| [`_size`](#_size-4) | `variable` | Declared here |
| [`_transactionID`](#_transactionid) | `variable` | Declared here |
| [`_attrs`](#_attrs) | `variable` | Declared here |
| [`MethodType`](#methodtype-1) | `enum` | Declared here |
| [`ClassType`](#classtype-1) | `enum` | Declared here |
| [`ErrorCodes`](#errorcodes) | `enum` | Declared here |
| [`computeBodySize`](#computebodysize) | `function` | Declared here |
| [`operator<<`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#operator-41) | `friend` | Inherited from [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) |
| [`opaque`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#opaque) | `variable` | Inherited from [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) |
| [`info`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#info) | `variable` | Inherited from [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) |
| [`flags`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#flags) | `variable` | Inherited from [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) |
| [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket-1) | `function` | Inherited from [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) |
| [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket-2) | `function` | Inherited from [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) |
| [`operator=`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#operator-42) | `function` | Inherited from [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) |
| [`clone`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#clone-1) | `function` | Inherited from [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) |
| [`~IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket-3) | `function` | Inherited from [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) |
| [`read`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#read-1) | `function` | Inherited from [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) |
| [`write`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#write-4) | `function` | Inherited from [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) |
| [`size`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#size-1) | `function` | Inherited from [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) |
| [`hasData`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#hasdata) | `function` | Inherited from [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) |
| [`data`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#data-2) | `function` | Inherited from [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) |
| [`constData`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#constdata) | `function` | Inherited from [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) |
| [`className`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#classname-1) | `function` | Inherited from [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) |
| [`print`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#print) | `function` | Inherited from [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) |

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

| Kind | Name | Description |
|------|------|-------------|
| `friend` | [`operator<<`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#operator-41) `inline` | [Stream](https://auscaster.com/icey/docs/api-reference/icy-Stream.md#stream) insertion operator; delegates to [print()](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#print). |
| `variable` | [`opaque`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#opaque)  | Optional type-safe context data. Use std::any_cast to retrieve. Lifetime of the stored value is tied to the packet's lifetime. |
| `variable` | [`info`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#info)  | Optional extra information about the packet. |
| `variable` | [`flags`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#flags)  | Provides basic information about the packet. |
| `function` | [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket-1) `inline` |  |
| `function` | [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket-2) `inline` | Copy constructor; clones the info object if present. |
| `function` | [`operator=`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#operator-42) `inline` | Copy assignment; clones the info object if present. |
| `function` | [`clone`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#clone-1) `virtual` `const` | Returns a heap-allocated deep copy of this packet. |
| `function` | [`~IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket-3) `virtual` | Defaulted destructor. |
| `function` | [`read`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#read-1) `virtual` | Read/parse to the packet from the given input buffer. The number of bytes read is returned. |
| `function` | [`write`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#write-4) `virtual` `const` | Copy/generate to the packet given output buffer. The number of bytes written can be obtained from the buffer. |
| `function` | [`size`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#size-1) `virtual` `const` `inline` | The size of the packet in bytes. |
| `function` | [`hasData`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#hasdata) `virtual` `const` `inline` | Returns true if the packet has a non-null data pointer. |
| `function` | [`data`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#data-2) `virtual` `const` `inline` | The packet data pointer for buffered packets. |
| `function` | [`constData`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#constdata) `virtual` `const` `inline` | The const packet data pointer for buffered packets. |
| `function` | [`className`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#classname-1) `virtual` `const` | Returns the class name of this packet type for logging and diagnostics. |
| `function` | [`print`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#print) `virtual` `const` `inline` | Prints a human-readable representation to the given stream. |

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`Message`](#message-7)  | Constructs a default message (Request class, Undefined method) with a randomly generated 12-byte transaction ID. |
|  | [`Message`](#message-8)  | Constructs a message with explicit class and method. |
|  | [`Message`](#message-9)  | Deep-copy constructor; clones all attributes. |
|  | [`Message`](#message-10) `noexcept` | Move constructor. |
| [`Message`](#message-6) & | [`operator=`](#operator-232)  | Deep-copy assignment; clones all attributes from `that`. |
| [`Message`](#message-6) & | [`operator=`](#operator-233) `noexcept` | Move assignment. |
|  | [`~Message`](#message-11) `virtual` |  |
| std::unique_ptr< [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) > | [`clone`](#clone-15) `virtual` `const` `override` |  |
| `void` | [`setClass`](#setclass)  | Sets the message class field. |
| `void` | [`setMethod`](#setmethod-1)  | Sets the message method field. |
| `void` | [`setTransactionID`](#settransactionid)  | Sets the 12-byte transaction ID. |
| [`ClassType`](#classtype-1) | [`classType`](#classtype) `const` |  |
| [`MethodType`](#methodtype-1) | [`methodType`](#methodtype) `const` |  |
| const [`TransactionID`](https://auscaster.com/icey/docs/api-reference/icy-stun.md#transactionid-1) & | [`transactionID`](#transactionid-2) `const` |  |
| `size_t` | [`size`](#size-14) `virtual` `const` `inline` `override` |  |
| `std::string` | [`methodString`](#methodstring) `const` |  |
| `std::string` | [`classString`](#classstring) `const` |  |
| `std::string` | [`errorString`](#errorstring) `const` | Maps a numeric error code to its canonical string description. |
| `T &` | [`add`](#add-9) `inline` | Constructs an attribute of type T in-place and appends it to the message. Returns a reference to the new attribute for further configuration. |
| `void` | [`add`](#add-10)  | Appends an attribute to the message, taking ownership via unique_ptr. |
| [`Attribute`](https://auscaster.com/icey/docs/api-reference/icy-stun-Attribute.md#attribute) * | [`get`](#get-18) `const` | Returns the Nth attribute of the given type, or nullptr if not found. |
| `T *` | [`get`](#get-19) `const` `inline` | Type-safe attribute accessor using the concrete attribute's TypeID. |
| `ssize_t` | [`read`](#read-10) `virtual` `override` | Parses a STUN/TURN packet from the given buffer. |
| `void` | [`write`](#write-39) `virtual` `const` `override` | Serialises this message into a STUN/TURN wire-format packet. |
| `std::string` | [`toString`](#tostring-11) `const` |  |
| `void` | [`print`](#print-15) `virtual` `const` `override` | Writes the same representation as [toString()](#tostring-11) to the given stream. |
| `const char *` | [`className`](#classname-12) `virtual` `const` `inline` `override` | Returns the class name of this packet type for logging and diagnostics. |

---

<a id="message-7"></a>

### Message

```cpp
Message()
```

[Defined in src/stun/include/icy/stun/message.h:92](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L92)

Constructs a default message (Request class, Undefined method) with a randomly generated 12-byte transaction ID.

---

<a id="message-8"></a>

### Message

```cpp
Message(ClassType clss, MethodType meth)
```

[Defined in src/stun/include/icy/stun/message.h:97](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L97)

Constructs a message with explicit class and method.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `clss` | [`ClassType`](#classtype-1) | [Message](#message-6) class (Request, Indication, SuccessResponse, or ErrorResponse). |
| `meth` | [`MethodType`](#methodtype-1) | [Message](#message-6) method (Binding, Allocate, Refresh, etc.). |

---

<a id="message-9"></a>

### Message

```cpp
Message(const Message & that)
```

[Defined in src/stun/include/icy/stun/message.h:100](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L100)

Deep-copy constructor; clones all attributes.

---

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

### Message

`noexcept`

```cpp
Message(Message && that) noexcept
```

[Defined in src/stun/include/icy/stun/message.h:103](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L103)

Move constructor.

---

<a id="operator-232"></a>

### operator=

```cpp
Message & operator=(const Message & that)
```

[Defined in src/stun/include/icy/stun/message.h:106](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L106)

Deep-copy assignment; clones all attributes from `that`.

---

<a id="operator-233"></a>

### operator=

`noexcept`

```cpp
Message & operator=(Message && that) noexcept
```

[Defined in src/stun/include/icy/stun/message.h:109](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L109)

Move assignment.

---

<a id="message-11"></a>

### ~Message

`virtual`

```cpp
virtual ~Message()
```

[Defined in src/stun/include/icy/stun/message.h:111](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L111)

---

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

### clone

`virtual` `const` `override`

```cpp
virtual std::unique_ptr< IPacket > clone() const override
```

[Defined in src/stun/include/icy/stun/message.h:114](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L114)

#### Returns
A heap-allocated deep copy of this message.

#### Reimplements

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

---

<a id="setclass"></a>

### setClass

```cpp
void setClass(ClassType type)
```

[Defined in src/stun/include/icy/stun/message.h:118](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L118)

Sets the message class field.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `type` | [`ClassType`](#classtype-1) | One of Request, Indication, SuccessResponse, ErrorResponse. |

---

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

### setMethod

```cpp
void setMethod(MethodType type)
```

[Defined in src/stun/include/icy/stun/message.h:122](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L122)

Sets the message method field.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `type` | [`MethodType`](#methodtype-1) | One of the MethodType enumerators. |

---

<a id="settransactionid"></a>

### setTransactionID

```cpp
void setTransactionID(const std::string & id)
```

[Defined in src/stun/include/icy/stun/message.h:126](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L126)

Sets the 12-byte transaction ID.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `id` | `const std::string &` | Must be exactly kTransactionIdLength (12) bytes. |

---

<a id="classtype"></a>

### classType

`const`

```cpp
ClassType classType() const
```

[Defined in src/stun/include/icy/stun/message.h:129](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L129)

#### Returns
The message class.

---

<a id="methodtype"></a>

### methodType

`const`

```cpp
MethodType methodType() const
```

[Defined in src/stun/include/icy/stun/message.h:132](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L132)

#### Returns
The message method.

---

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

### transactionID

`const`

```cpp
const TransactionID & transactionID() const
```

[Defined in src/stun/include/icy/stun/message.h:137](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L137)

#### Returns
Reference to the 12-byte transaction ID string. Generated lazily on first access for outgoing messages; parse paths overwrite it from the wire without paying for generation.

---

<a id="size-14"></a>

### size

`virtual` `const` `inline` `override`

```cpp
virtual inline size_t size() const override
```

[Defined in src/stun/include/icy/stun/message.h:140](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L140)

#### Returns
Total body size in bytes (sum of padded attribute headers and bodies).

#### Reimplements

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

---

<a id="methodstring"></a>

### methodString

`const`

```cpp
std::string methodString() const
```

[Defined in src/stun/include/icy/stun/message.h:143](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L143)

#### Returns
Human-readable method name (e.g. "BINDING", "ALLOCATE").

---

<a id="classstring"></a>

### classString

`const`

```cpp
std::string classString() const
```

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

#### Returns
Human-readable class name (e.g. "Request", "SuccessResponse").

---

<a id="errorstring"></a>

### errorString

`const`

```cpp
std::string errorString(uint16_t errorCode) const
```

[Defined in src/stun/include/icy/stun/message.h:151](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L151)

Maps a numeric error code to its canonical string description. 
#### Returns
Human-readable error string, or "UnknownError" if not recognised.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `errorCode` | `uint16_t` | One of the ErrorCodes enumerators. |

---

<a id="add-9"></a>

### add

`inline`

```cpp
template<typename T> inline T & add()
```

[Defined in src/stun/include/icy/stun/message.h:158](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L158)

Constructs an attribute of type T in-place and appends it to the message. Returns a reference to the new attribute for further configuration. 
#### Returns
Reference to the newly added attribute.

---

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

### add

```cpp
void add(std::unique_ptr< Attribute > attr)
```

[Defined in src/stun/include/icy/stun/message.h:168](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L168)

Appends an attribute to the message, taking ownership via unique_ptr.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `attr` | std::unique_ptr< [`Attribute`](https://auscaster.com/icey/docs/api-reference/icy-stun-Attribute.md#attribute) > | [Attribute](https://auscaster.com/icey/docs/api-reference/icy-stun-Attribute.md#attribute) to add. |

---

<a id="get-18"></a>

### get

`const`

```cpp
Attribute * get(Attribute::Type type, int index = 0) const
```

[Defined in src/stun/include/icy/stun/message.h:174](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L174)

Returns the Nth attribute of the given type, or nullptr if not found. 
#### Returns
Raw pointer to the attribute (owned by this message), or nullptr.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `type` | [`Attribute::Type`](https://auscaster.com/icey/docs/api-reference/icy-stun-Attribute.md#type-18) | [Attribute](https://auscaster.com/icey/docs/api-reference/icy-stun-Attribute.md#attribute) type code to search for. |
| `index` | `int` | Zero-based occurrence index (0 = first match). |

---

<a id="get-19"></a>

### get

`const` `inline`

```cpp
template<typename T> inline T * get(int index = 0) const
```

[Defined in src/stun/include/icy/stun/message.h:181](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L181)

Type-safe attribute accessor using the concrete attribute's TypeID. 
#### Returns
Pointer to T, or nullptr if the attribute is absent.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `index` | `int` | Zero-based occurrence index. |

---

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

### read

`virtual` `override`

```cpp
virtual ssize_t read(const ConstBuffer & buf) override
```

[Defined in src/stun/include/icy/stun/message.h:190](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L190)

Parses a STUN/TURN packet from the given buffer. 
#### Returns
Number of bytes consumed, or 0 on parse failure.

#### Reimplements

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

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `buf` | const [`ConstBuffer`](https://auscaster.com/icey/docs/api-reference/icy-ConstBuffer.md#constbuffer-6) & | Buffer containing at least one complete STUN message. |

---

<a id="write-39"></a>

### write

`virtual` `const` `override`

```cpp
virtual void write(Buffer & buf) const override
```

[Defined in src/stun/include/icy/stun/message.h:194](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L194)

Serialises this message into a STUN/TURN wire-format packet.

#### Reimplements

- [`IPacket::write`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#write-4)

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `buf` | [`Buffer`](https://auscaster.com/icey/docs/api-reference/base.md#buffer) & | Destination buffer; data is appended. |

---

<a id="tostring-11"></a>

### toString

`const`

```cpp
std::string toString() const
```

[Defined in src/stun/include/icy/stun/message.h:197](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L197)

#### Returns
A concise string representation for logging (method, transaction ID, attribute types).

---

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

### print

`virtual` `const` `override`

```cpp
virtual void print(std::ostream & os) const override
```

[Defined in src/stun/include/icy/stun/message.h:201](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L201)

Writes the same representation as [toString()](#tostring-11) to the given stream.

#### Reimplements

- [`IPacket::print`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#print)

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `os` | `std::ostream &` | Output stream. |

---

<a id="classname-12"></a>

### className

`virtual` `const` `inline` `override`

```cpp
virtual inline const char * className() const override
```

[Defined in src/stun/include/icy/stun/message.h:203](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L203)

Returns the class name of this packet type for logging and diagnostics.

#### Reimplements

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

## Protected Attributes

| Return | Name | Description |
|--------|------|-------------|
| `uint16_t` | [`_class`](#_class-1)  |  |
| `uint16_t` | [`_method`](#_method-1)  |  |
| `uint16_t` | [`_size`](#_size-4)  | Set by [read()](#read-10); [write()](#write-39) uses computeBodySize() instead |
| [`TransactionID`](https://auscaster.com/icey/docs/api-reference/icy-stun.md#transactionid-1) | [`_transactionID`](#_transactionid)  | Empty until first use; see [transactionID()](#transactionid-2). Mutable for lazy generation from the const accessor. |
| std::vector< std::unique_ptr< [`Attribute`](https://auscaster.com/icey/docs/api-reference/icy-stun-Attribute.md#attribute) > > | [`_attrs`](#_attrs)  |  |

---

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

### _class

```cpp
uint16_t _class
```

[Defined in src/stun/include/icy/stun/message.h:206](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L206)

---

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

### _method

```cpp
uint16_t _method
```

[Defined in src/stun/include/icy/stun/message.h:207](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L207)

---

<a id="_size-4"></a>

### _size

```cpp
uint16_t _size
```

[Defined in src/stun/include/icy/stun/message.h:208](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L208)

Set by [read()](#read-10); [write()](#write-39) uses computeBodySize() instead

---

<a id="_transactionid"></a>

### _transactionID

```cpp
TransactionID _transactionID
```

Type: [`TransactionID`](https://auscaster.com/icey/docs/api-reference/icy-stun.md#transactionid-1)

[Defined in src/stun/include/icy/stun/message.h:211](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L211)

Empty until first use; see [transactionID()](#transactionid-2). Mutable for lazy generation from the const accessor.

---

<a id="_attrs"></a>

### _attrs

```cpp
std::vector< std::unique_ptr< Attribute > > _attrs
```

Type: std::vector< std::unique_ptr< [`Attribute`](https://auscaster.com/icey/docs/api-reference/icy-stun-Attribute.md#attribute) > >

[Defined in src/stun/include/icy/stun/message.h:212](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L212)

## Public Types

| Name | Description |
|------|-------------|
| [`MethodType`](#methodtype-1)  |  |
| [`ClassType`](#classtype-1)  |  |
| [`ErrorCodes`](#errorcodes)  |  |

---

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

### MethodType

```cpp
enum MethodType
```

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

| Value | Description |
|-------|-------------|
| `Undefined` | default error type |
| `Binding` | STUN. |
| `Allocate` | TURN. |
| `Refresh` |  |
| `SendIndication` | (only indication semantics defined) |
| `DataIndication` | (only indication semantics defined) |
| `CreatePermission` | (only request/response semantics defined) |
| `ChannelBind` | (only request/response semantics defined) |
| `Connect` | TURN TCP RFC 6062. |
| `ConnectionBind` |  |
| `ConnectionAttempt` |  |

---

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

### ClassType

```cpp
enum ClassType
```

[Defined in src/stun/include/icy/stun/message.h:55](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L55)

| Value | Description |
|-------|-------------|
| `Request` |  |
| `Indication` |  |
| `SuccessResponse` |  |
| `ErrorResponse` |  |

---

<a id="errorcodes"></a>

### ErrorCodes

```cpp
enum ErrorCodes
```

[Defined in src/stun/include/icy/stun/message.h:63](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L63)

| Value | Description |
|-------|-------------|
| `TryAlternate` |  |
| `BadRequest` |  |
| `NotAuthorized` |  |
| `Forbidden` |  |
| `UnknownAttribute` |  |
| `StaleCredentials` |  |
| `IntegrityCheckFailure` |  |
| `MissingUsername` |  |
| `UseTLS` |  |
| `AllocationMismatch` |  |
| `StaleNonce` |  |
| `WrongCredentials` |  |
| `UnsupportedTransport` |  |
| `AllocationQuotaReached` |  |
| `RoleConflict` |  |
| `ServerError` |  |
| `InsufficientCapacity` |  |
| `GlobalFailure` |  |
| `ConnectionAlreadyExists` | TURN TCP. |
| `ConnectionTimeoutOrFailure` |  |
## Private Methods

| Return | Name | Description |
|--------|------|-------------|
| `uint16_t` | [`computeBodySize`](#computebodysize) `const` | Computes the wire body size from the current attribute list. |

---

<a id="computebodysize"></a>

### computeBodySize

`const`

```cpp
uint16_t computeBodySize() const
```

[Defined in src/stun/include/icy/stun/message.h:216](https://github.com/auscaster/icey/blob/main/src/stun/include/icy/stun/message.h#L216)

Computes the wire body size from the current attribute list.
