# Peer

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

# Peer

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

class Peer
```

[Defined in src/symple/include/icy/symple/peer.h:30](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/peer.h#L30)

> **Inherits:** `Value`

Symple peer record containing identity, presence, and custom fields.

A [Peer](#peer-1) object may also contain arbitrary application data set by the client to share with other peers on the network. **See also**: [Address](https://auscaster.com/icey/docs/api-reference/icy-smpl-Address.md#address-13) for further methods and [basic](https://auscaster.com/icey/docs/api-reference/icy-basic.md#basic) accessors.

## Friends

| Name | Description |
|------|-------------|
| [`operator<<`](#operator-248) `inline` |  |

---

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

### operator<<

`inline`

```cpp
friend inline std::ostream & operator<<(std::ostream & os, const Peer & peer)
```

[Defined in src/symple/include/icy/symple/peer.h:101](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/peer.h#L101)

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`Peer`](#peer-2)  | Constructs an empty peer with type set to "Peer". |
|  | [`Peer`](#peer-3)  | Copy constructor; preserves type field. |
| [`Peer`](#peer-1) & | [`operator=`](#operator-249)  | Copy-assigns peer data from another peer. |
|  | [`Peer`](#peer-4)  | Constructs a peer from a raw JSON value. |
|  | [`~Peer`](#peer-5) `virtual` |  |
| [`Address`](https://auscaster.com/icey/docs/api-reference/icy-smpl-Address.md#address-13) | [`address`](#address-18) `const` | Returns the peer's address (user + session ID). |
| `std::string` | [`id`](#id-13) `const` | Returns the session ID assigned by the server. |
| `std::string` | [`user`](#user-2) `const` | Returns the user identifier. |
| `std::string` | [`name`](#name-18) `const` | Returns the display name. |
| `std::string` | [`type`](#type-26) `const` | Returns the peer type string (e.g. "Peer", "bot"). |
| `std::string` | [`host`](#host-3) `const` | Returns the host address associated with this peer. |
| `void` | [`setID`](#setid-1)  | Sets the session ID field. |
| `void` | [`setUser`](#setuser)  | Sets the user identifier field. |
| `void` | [`setName`](#setname-3)  | Sets the display name field. |
| `void` | [`setType`](#settype-3)  | Sets the peer type field. |
| `void` | [`setHost`](#sethost-2)  | Sets the host address field. |
| `bool` | [`valid`](#valid-16) `virtual` | Updates the peer from the given data object. |
| `void` | [`print`](#print-19) `const` | Writes the peer's JSON representation to the given stream. |
| `const char *` | [`className`](#classname-14) `virtual` `const` `inline` |  |

---

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

### Peer

```cpp
Peer()
```

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

Constructs an empty peer with type set to "Peer".

---

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

### Peer

```cpp
Peer(const Peer & r)
```

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

Copy constructor; preserves type field.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `r` | const [`Peer`](#peer-1) & | Source peer. |

---

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

### operator=

```cpp
Peer & operator=(const Peer & r)
```

[Defined in src/symple/include/icy/symple/peer.h:42](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/peer.h#L42)

Copy-assigns peer data from another peer.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `r` | const [`Peer`](#peer-1) & | Source peer. |

---

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

### Peer

```cpp
Peer(const json::Value & r)
```

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

Constructs a peer from a raw JSON value.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `r` | const [`json::Value`](https://auscaster.com/icey/docs/api-reference/icy-json.md#value) & | JSON object containing peer fields. |

---

<a id="peer-5"></a>

### ~Peer

`virtual`

```cpp
virtual ~Peer()
```

[Defined in src/symple/include/icy/symple/peer.h:48](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/peer.h#L48)

---

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

### address

`const`

```cpp
Address address() const
```

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

Returns the peer's address (user + session ID). 
#### Returns
[Address](https://auscaster.com/icey/docs/api-reference/icy-smpl-Address.md#address-13) constructed from the `user` and `id` fields.

---

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

### id

`const`

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

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

Returns the session ID assigned by the server.

---

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

### user

`const`

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

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

Returns the user identifier.

---

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

### name

`const`

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

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

Returns the display name.

---

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

### type

`const`

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

[Defined in src/symple/include/icy/symple/peer.h:65](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/peer.h#L65)

Returns the peer type string (e.g. "Peer", "bot").

---

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

### host

`const`

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

[Defined in src/symple/include/icy/symple/peer.h:68](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/peer.h#L68)

Returns the host address associated with this peer.

---

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

### setID

```cpp
void setID(std::string_view id)
```

[Defined in src/symple/include/icy/symple/peer.h:72](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/peer.h#L72)

Sets the session ID field.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `id` | `std::string_view` | Session ID string. |

---

<a id="setuser"></a>

### setUser

```cpp
void setUser(std::string_view user)
```

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

Sets the user identifier field.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `user` | `std::string_view` | User identifier string. |

---

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

### setName

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

[Defined in src/symple/include/icy/symple/peer.h:80](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/peer.h#L80)

Sets the display name field.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `std::string_view` | Display name string. |

---

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

### setType

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

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

Sets the peer type field.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `type` | `std::string_view` | Type string. |

---

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

### setHost

```cpp
void setHost(std::string_view host)
```

[Defined in src/symple/include/icy/symple/peer.h:89](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/peer.h#L89)

Sets the host address field.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `host` | `std::string_view` | Host address string. |

---

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

### valid

`virtual`

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

[Defined in src/symple/include/icy/symple/peer.h:95](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/peer.h#L95)

Updates the peer from the given data object.

Returns true if the peer has `id`, `user`, and `type` fields.

---

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

### print

`const`

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

[Defined in src/symple/include/icy/symple/peer.h:99](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/peer.h#L99)

Writes the peer's JSON representation to the given stream.

#### Parameters

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

---

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

### className

`virtual` `const` `inline`

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

[Defined in src/symple/include/icy/symple/peer.h:107](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/peer.h#L107)
