# Message

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

# Message

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

class Message
```

[Defined in src/symple/include/icy/symple/message.h:27](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L27)

> **Inherits:** `Value`, [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket)
> **Subclassed by:** [`Command`](https://auscaster.com/icey/docs/api-reference/icy-smpl-Command.md#command), [`Event`](https://auscaster.com/icey/docs/api-reference/icy-smpl-Event.md#event-2), [`Presence`](https://auscaster.com/icey/docs/api-reference/icy-smpl-Presence.md#presence)

Base Symple protocol message with addressing, status, data, and notes.

## List of all members

| Name | Kind | Owner |
|------|------|-------|
| [`Message`](#message-13) | `function` | Declared here |
| [`Message`](#message-14) | `function` | Declared here |
| [`Message`](#message-15) | `function` | Declared here |
| [`operator=`](#operator-247) | `function` | Declared here |
| [`~Message`](#message-16) | `function` | Declared here |
| [`clone`](#clone-22) | `function` | Declared here |
| [`valid`](#valid-15) | `function` | Declared here |
| [`clear`](#clear-11) | `function` | Declared here |
| [`clearData`](#cleardata) | `function` | Declared here |
| [`clearNotes`](#clearnotes) | `function` | Declared here |
| [`type`](#type-25) | `function` | Declared here |
| [`id`](#id-12) | `function` | Declared here |
| [`to`](#to) | `function` | Declared here |
| [`from`](#from) | `function` | Declared here |
| [`toUser`](#touser) | `function` | Declared here |
| [`toId`](#toid) | `function` | Declared here |
| [`fromUser`](#fromuser) | `function` | Declared here |
| [`fromId`](#fromid) | `function` | Declared here |
| [`status`](#status-3) | `function` | Declared here |
| [`setType`](#settype-2) | `function` | Declared here |
| [`setTo`](#setto) | `function` | Declared here |
| [`setTo`](#setto-1) | `function` | Declared here |
| [`setTo`](#setto-2) | `function` | Declared here |
| [`setFrom`](#setfrom) | `function` | Declared here |
| [`setFrom`](#setfrom-1) | `function` | Declared here |
| [`setFrom`](#setfrom-2) | `function` | Declared here |
| [`setStatus`](#setstatus-1) | `function` | Declared here |
| [`notes`](#notes) | `function` | Declared here |
| [`setNote`](#setnote) | `function` | Declared here |
| [`addNote`](#addnote) | `function` | Declared here |
| [`data`](#data-9) | `function` | Declared here |
| [`data`](#data-10) | `function` | Declared here |
| [`setData`](#setdata) | `function` | Declared here |
| [`setData`](#setdata-1) | `function` | Declared here |
| [`setData`](#setdata-2) | `function` | Declared here |
| [`setData`](#setdata-3) | `function` | Declared here |
| [`setData`](#setdata-4) | `function` | Declared here |
| [`removeData`](#removedata) | `function` | Declared here |
| [`hasData`](#hasdata-1) | `function` | Declared here |
| [`read`](#read-17) | `function` | Declared here |
| [`read`](#read-18) | `function` | Declared here |
| [`write`](#write-46) | `function` | Declared here |
| [`isRequest`](#isrequest) | `function` | Declared here |
| [`size`](#size-20) | `function` | Declared here |
| [`print`](#print-18) | `function` | Declared here |
| [`className`](#classname-13) | `function` | Declared here |
| [`data`](#data-11) | `function` | Declared here |
| [`hasData`](#hasdata-2) | `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-13)  | Constructs a new message with a random ID and type set to "message". |
|  | [`Message`](#message-14)  | Constructs a message from a JSON value; sets missing id/type fields. |
|  | [`Message`](#message-15)  | Copy constructor; preserves or generates id/type fields. |
| [`Message`](#message-12) & | [`operator=`](#operator-247)  | Defaulted assignment operator. |
|  | [`~Message`](#message-16) `virtual` |  |
| std::unique_ptr< [`IPacket`](https://auscaster.com/icey/docs/api-reference/icy-IPacket.md#ipacket) > | [`clone`](#clone-22) `virtual` `const` `override` | Returns a heap-allocated copy of this message. |
| `bool` | [`valid`](#valid-15) `virtual` `const` | Returns true if the message has both `type` and `id` fields. |
| `void` | [`clear`](#clear-11) `virtual` | Clears all JSON fields from this message. |
| `void` | [`clearData`](#cleardata) `virtual` | Clears the `data` sub-object. |
| `void` | [`clearNotes`](#clearnotes) `virtual` | Clears the `notes` array. |
| `std::string` | [`type`](#type-25) `const` | Returns the message type string (defaults to "message"). |
| `std::string` | [`id`](#id-12) `const` | Returns the message ID string. |
| [`Address`](https://auscaster.com/icey/docs/api-reference/icy-smpl-Address.md#address-13) | [`to`](#to) `const` | Returns the recipient address parsed from the `to` field. |
| [`Address`](https://auscaster.com/icey/docs/api-reference/icy-smpl-Address.md#address-13) | [`from`](#from) `const` | Returns the sender address parsed from the `from` field. |
| `std::string` | [`toUser`](#touser) `const` | Returns the user component of the `to` address without constructing an [Address](https://auscaster.com/icey/docs/api-reference/icy-smpl-Address.md#address-13). |
| `std::string` | [`toId`](#toid) `const` | Returns the id component of the `to` address without constructing an [Address](https://auscaster.com/icey/docs/api-reference/icy-smpl-Address.md#address-13). |
| `std::string` | [`fromUser`](#fromuser) `const` | Returns the user component of the `from` address without constructing an [Address](https://auscaster.com/icey/docs/api-reference/icy-smpl-Address.md#address-13). |
| `std::string` | [`fromId`](#fromid) `const` | Returns the id component of the `from` address without constructing an [Address](https://auscaster.com/icey/docs/api-reference/icy-smpl-Address.md#address-13). |
| `int` | [`status`](#status-3) `const` | Returns the HTTP status code, or -1 if not set. |
| `void` | [`setType`](#settype-2)  | Sets the message type field. |
| `void` | [`setTo`](#setto)  | Sets the `to` field from a peer's address. |
| `void` | [`setTo`](#setto-1)  | Sets the `to` field from an address object. |
| `void` | [`setTo`](#setto-2)  | Sets the `to` field from an address string. |
| `void` | [`setFrom`](#setfrom)  | Sets the `from` field from a peer's address. |
| `void` | [`setFrom`](#setfrom-1)  | Sets the `from` field from an address object. |
| `void` | [`setFrom`](#setfrom-2)  | Sets the `from` field from an address string. |
| `void` | [`setStatus`](#setstatus-1)  | HTTP status codes are used to describe the message response. Throws std::invalid_argument if code is outside [101, 504]. **See also**: [http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) |
| [`json::Value`](https://auscaster.com/icey/docs/api-reference/icy-json.md#value) & | [`notes`](#notes)  | Returns a reference to the `notes` JSON array. |
| `void` | [`setNote`](#setnote)  | Replaces all notes with a single note. |
| `void` | [`addNote`](#addnote)  | Appends a note to the `notes` array. |
| [`json::Value`](https://auscaster.com/icey/docs/api-reference/icy-json.md#value) | [`data`](#data-9) `const` | Returns a copy of the named data field. |
| [`json::Value`](https://auscaster.com/icey/docs/api-reference/icy-json.md#value) & | [`data`](#data-10)  | Returns a reference to the named data field (creates it if absent). |
| [`json::Value`](https://auscaster.com/icey/docs/api-reference/icy-json.md#value) & | [`setData`](#setdata)  | Creates or replaces a named data field; returns a reference to it. |
| `void` | [`setData`](#setdata-1)  | Sets a named data field to a C-string value. |
| `void` | [`setData`](#setdata-2)  | Sets a named data field to a string value. |
| `void` | [`setData`](#setdata-3)  | Sets a named data field to a JSON value. |
| `void` | [`setData`](#setdata-4)  | Sets a named data field to an integer value. |
| `void` | [`removeData`](#removedata)  | Removes a named field from the `data` sub-object. |
| `bool` | [`hasData`](#hasdata-1)  | Returns true if the named field exists in the `data` sub-object. |
| `ssize_t` | [`read`](#read-17) `virtual` `override` | Deserialises the message from a raw buffer. |
| `ssize_t` | [`read`](#read-18) `virtual` | Deserialises the message from a JSON string. |
| `void` | [`write`](#write-46) `virtual` `const` `override` | Serialises the message as JSON into a buffer. |
| `bool` | [`isRequest`](#isrequest) `const` | Returns true if no status code has been set (i.e. [status()](#status-3) == -1). |
| `size_t` | [`size`](#size-20) `virtual` `const` `override` | Returns the serialised JSON size in bytes. |
| `void` | [`print`](#print-18) `virtual` `const` `override` | Pretty-prints the message JSON to the given stream. |
| `const char *` | [`className`](#classname-13) `virtual` `const` `inline` `override` | Returns the class name of this packet type for logging and diagnostics. |
| `char *` | [`data`](#data-11) `virtual` `const` `inline` | The packet data pointer for buffered packets. |
| `bool` | [`hasData`](#hasdata-2) `virtual` `const` `inline` | Returns true if the packet has a non-null data pointer. |

---

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

### Message

```cpp
Message()
```

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

Constructs a new message with a random ID and type set to "message".

---

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

### Message

```cpp
Message(const json::Value & root)
```

[Defined in src/symple/include/icy/symple/message.h:39](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L39)

Constructs a message from a JSON value; sets missing id/type fields.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `root` | const [`json::Value`](https://auscaster.com/icey/docs/api-reference/icy-json.md#value) & | JSON object to initialise from. |

---

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

### Message

```cpp
Message(const Message & root)
```

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

Copy constructor; preserves or generates id/type fields.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `root` | const [`Message`](#message-12) & | Source message. |

---

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

### operator=

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

[Defined in src/symple/include/icy/symple/message.h:45](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L45)

Defaulted assignment operator.

---

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

### ~Message

`virtual`

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

[Defined in src/symple/include/icy/symple/message.h:46](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L46)

---

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

### clone

`virtual` `const` `override`

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

[Defined in src/symple/include/icy/symple/message.h:49](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L49)

Returns a heap-allocated copy of this message.

#### Reimplements

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

---

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

### valid

`virtual` `const`

```cpp
virtual bool valid() const
```

[Defined in src/symple/include/icy/symple/message.h:52](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L52)

Returns true if the message has both `type` and `id` fields.

#### Reimplemented by

- [`Command::valid`](https://auscaster.com/icey/docs/api-reference/icy-smpl-Command.md#valid-11)
- [`Event::valid`](https://auscaster.com/icey/docs/api-reference/icy-smpl-Event.md#valid-12)

---

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

### clear

`virtual`

```cpp
virtual void clear()
```

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

Clears all JSON fields from this message.

---

<a id="cleardata"></a>

### clearData

`virtual`

```cpp
virtual void clearData()
```

[Defined in src/symple/include/icy/symple/message.h:58](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L58)

Clears the `data` sub-object.

---

<a id="clearnotes"></a>

### clearNotes

`virtual`

```cpp
virtual void clearNotes()
```

[Defined in src/symple/include/icy/symple/message.h:61](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L61)

Clears the `notes` array.

---

<a id="type-25"></a>

### type

`const`

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

[Defined in src/symple/include/icy/symple/message.h:64](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L64)

Returns the message type string (defaults to "message").

---

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

### id

`const`

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

[Defined in src/symple/include/icy/symple/message.h:67](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L67)

Returns the message ID string.

---

<a id="to"></a>

### to

`const`

```cpp
Address to() const
```

[Defined in src/symple/include/icy/symple/message.h:70](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L70)

Returns the recipient address parsed from the `to` field.

---

<a id="from"></a>

### from

`const`

```cpp
Address from() const
```

[Defined in src/symple/include/icy/symple/message.h:73](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L73)

Returns the sender address parsed from the `from` field.

---

<a id="touser"></a>

### toUser

`const`

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

[Defined in src/symple/include/icy/symple/message.h:76](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L76)

Returns the user component of the `to` address without constructing an [Address](https://auscaster.com/icey/docs/api-reference/icy-smpl-Address.md#address-13).

---

<a id="toid"></a>

### toId

`const`

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

[Defined in src/symple/include/icy/symple/message.h:79](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L79)

Returns the id component of the `to` address without constructing an [Address](https://auscaster.com/icey/docs/api-reference/icy-smpl-Address.md#address-13).

---

<a id="fromuser"></a>

### fromUser

`const`

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

[Defined in src/symple/include/icy/symple/message.h:82](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L82)

Returns the user component of the `from` address without constructing an [Address](https://auscaster.com/icey/docs/api-reference/icy-smpl-Address.md#address-13).

---

<a id="fromid"></a>

### fromId

`const`

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

[Defined in src/symple/include/icy/symple/message.h:85](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L85)

Returns the id component of the `from` address without constructing an [Address](https://auscaster.com/icey/docs/api-reference/icy-smpl-Address.md#address-13).

---

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

### status

`const`

```cpp
int status() const
```

[Defined in src/symple/include/icy/symple/message.h:88](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L88)

Returns the HTTP status code, or -1 if not set.

---

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

### setType

```cpp
void setType(std::string_view type)
```

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

Sets the message type field.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `type` | `std::string_view` | Type string (e.g. "message", "command"). |

---

<a id="setto"></a>

### setTo

```cpp
void setTo(const Peer & to)
```

[Defined in src/symple/include/icy/symple/message.h:96](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L96)

Sets the `to` field from a peer's address.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `to` | const [`Peer`](https://auscaster.com/icey/docs/api-reference/icy-smpl-Peer.md#peer-1) & | Destination peer. |

---

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

### setTo

```cpp
void setTo(const Address & to)
```

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

Sets the `to` field from an address object.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `to` | const [`Address`](https://auscaster.com/icey/docs/api-reference/icy-smpl-Address.md#address-13) & | Destination address. |

---

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

### setTo

```cpp
void setTo(std::string_view to)
```

[Defined in src/symple/include/icy/symple/message.h:104](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L104)

Sets the `to` field from an address string.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `to` | `std::string_view` | Destination address string. |

---

<a id="setfrom"></a>

### setFrom

```cpp
void setFrom(const Peer & from)
```

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

Sets the `from` field from a peer's address.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `from` | const [`Peer`](https://auscaster.com/icey/docs/api-reference/icy-smpl-Peer.md#peer-1) & | Sender peer. |

---

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

### setFrom

```cpp
void setFrom(const Address & from)
```

[Defined in src/symple/include/icy/symple/message.h:112](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L112)

Sets the `from` field from an address object.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `from` | const [`Address`](https://auscaster.com/icey/docs/api-reference/icy-smpl-Address.md#address-13) & | Sender address. |

---

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

### setFrom

```cpp
void setFrom(std::string_view from)
```

[Defined in src/symple/include/icy/symple/message.h:116](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L116)

Sets the `from` field from an address string.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `from` | `std::string_view` | Sender address string. |

---

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

### setStatus

```cpp
void setStatus(int code)
```

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

HTTP status codes are used to describe the message response. Throws std::invalid_argument if code is outside [101, 504]. **See also**: [http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `code` | `int` | HTTP status code. |

---

<a id="notes"></a>

### notes

```cpp
json::Value & notes()
```

[Defined in src/symple/include/icy/symple/message.h:125](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L125)

Returns a reference to the `notes` JSON array.

---

<a id="setnote"></a>

### setNote

```cpp
void setNote(std::string_view type, std::string_view text)
```

[Defined in src/symple/include/icy/symple/message.h:130](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L130)

Replaces all notes with a single note.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `type` | `std::string_view` | Note severity: `info`, `warn`, or `error`. |
| `text` | `std::string_view` | Note message text. |

---

<a id="addnote"></a>

### addNote

```cpp
void addNote(std::string_view type, std::string_view text)
```

[Defined in src/symple/include/icy/symple/message.h:135](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L135)

Appends a note to the `notes` array.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `type` | `std::string_view` | Note severity: `info`, `warn`, or `error`. |
| `text` | `std::string_view` | Note message text. |

---

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

### data

`const`

```cpp
json::Value data(std::string_view name) const
```

[Defined in src/symple/include/icy/symple/message.h:139](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L139)

Returns a copy of the named data field.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `std::string_view` | Field name within `data`. |

---

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

### data

```cpp
json::Value & data(std::string_view name)
```

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

Returns a reference to the named data field (creates it if absent).

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `std::string_view` | Field name within `data`. |

---

<a id="setdata"></a>

### setData

```cpp
json::Value & setData(std::string_view name)
```

[Defined in src/symple/include/icy/symple/message.h:147](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L147)

Creates or replaces a named data field; returns a reference to it.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `std::string_view` | Field name within `data`. |

---

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

### setData

```cpp
void setData(std::string_view name, const char * data)
```

[Defined in src/symple/include/icy/symple/message.h:152](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L152)

Sets a named data field to a C-string value.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `std::string_view` | Field name within `data`. |
| `data` | `const char *` | String value to assign. |

---

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

### setData

```cpp
void setData(std::string_view name, std::string_view data)
```

[Defined in src/symple/include/icy/symple/message.h:157](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L157)

Sets a named data field to a string value.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `std::string_view` | Field name within `data`. |
| `data` | `std::string_view` | String value to assign. |

---

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

### setData

```cpp
void setData(std::string_view name, const json::Value & data)
```

[Defined in src/symple/include/icy/symple/message.h:162](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L162)

Sets a named data field to a JSON value.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `std::string_view` | Field name within `data`. |
| `data` | const [`json::Value`](https://auscaster.com/icey/docs/api-reference/icy-json.md#value) & | JSON value to assign. |

---

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

### setData

```cpp
void setData(std::string_view name, int data)
```

[Defined in src/symple/include/icy/symple/message.h:167](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L167)

Sets a named data field to an integer value.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `std::string_view` | Field name within `data`. |
| `data` | `int` | Integer value to assign. |

---

<a id="removedata"></a>

### removeData

```cpp
void removeData(std::string_view name)
```

[Defined in src/symple/include/icy/symple/message.h:171](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L171)

Removes a named field from the `data` sub-object.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `std::string_view` | Field name to remove. |

---

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

### hasData

```cpp
bool hasData(std::string_view name)
```

[Defined in src/symple/include/icy/symple/message.h:175](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L175)

Returns true if the named field exists in the `data` sub-object.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `std::string_view` | Field name to look up. |

---

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

### read

`virtual` `override`

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

[Defined in src/symple/include/icy/symple/message.h:180](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L180)

Deserialises the message from a raw buffer. 
#### Returns
Number of bytes consumed.

#### 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 the JSON payload. |

---

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

### read

`virtual`

```cpp
virtual ssize_t read(const std::string & root)
```

[Defined in src/symple/include/icy/symple/message.h:185](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L185)

Deserialises the message from a JSON string. 
#### Returns
Number of characters consumed.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `root` | `const std::string &` | JSON string to parse. |

---

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

### write

`virtual` `const` `override`

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

[Defined in src/symple/include/icy/symple/message.h:189](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L189)

Serialises the message as JSON into a buffer.

#### 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) & | Buffer to append to. |

---

<a id="isrequest"></a>

### isRequest

`const`

```cpp
bool isRequest() const
```

[Defined in src/symple/include/icy/symple/message.h:192](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L192)

Returns true if no status code has been set (i.e. [status()](#status-3) == -1).

---

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

### size

`virtual` `const` `override`

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

[Defined in src/symple/include/icy/symple/message.h:195](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L195)

Returns the serialised JSON size in bytes.

#### Reimplements

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

---

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

### print

`virtual` `const` `override`

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

[Defined in src/symple/include/icy/symple/message.h:199](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/message.h#L199)

Pretty-prints the message JSON 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-13"></a>

### className

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

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

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

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)

---

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

### data

`virtual` `const` `inline`

```cpp
virtual inline char * data() const
```

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

The packet data pointer for buffered packets.

#### Reimplements

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

---

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

### hasData

`virtual` `const` `inline`

```cpp
virtual inline bool hasData() const
```

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

Returns true if the packet has a non-null data pointer.

#### Reimplements

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