---
url: https://docs.moqtail.dev/ts/api/model/classes/ReasonPhrase.md
---
# Class: ReasonPhrase

Represents a protocol ReasonPhrase, a short UTF-8 string used for error or status reporting.
Enforces a maximum byte length and validates encoding.

## Constructors

### Constructor

> **new ReasonPhrase**(`phrase`): `ReasonPhrase`

Constructs a ReasonPhrase, validating UTF-8 encoding and length.

#### Parameters

##### phrase

`string`

The string to use as the reason phrase.

#### Returns

`ReasonPhrase`

#### Throws

[InvalidUTF8Error](InvalidUTF8Error.md) if encoding fails.

#### Throws

[LengthExceedsMaxError](LengthExceedsMaxError.md) if the encoded phrase exceeds [MAX_REASON_PHRASE_LEN](../variables/MAX_REASON_PHRASE_LEN.md) bytes.

## Accessors

### phrase

#### Get Signature

> **get** **phrase**(): `string`

Returns the phrase string.

##### Returns

`string`

## Methods

### serialize()

> **serialize**(): [`FrozenByteBuffer`](FrozenByteBuffer.md)

Serializes the ReasonPhrase into a [FrozenByteBuffer](FrozenByteBuffer.md) containing:
varint(length_of_phrase_bytes) || phrase_bytes

#### Returns

[`FrozenByteBuffer`](FrozenByteBuffer.md)

The serialized buffer.

***

### deserialize()

> `static` **deserialize**(`buf`): `ReasonPhrase`

Deserializes a ReasonPhrase from the given buffer.
Reads varint(length) || utf8‑bytes.

#### Parameters

##### buf

[`BaseByteBuffer`](BaseByteBuffer.md)

The buffer to read from.

#### Returns

`ReasonPhrase`

The deserialized ReasonPhrase.

#### Throws

:[CastingError](CastingError.md) if the length cannot be safely cast to a number.

#### Throws

:[LengthExceedsMaxError](LengthExceedsMaxError.md) if the length exceeds [MAX_REASON_PHRASE_LEN](../variables/MAX_REASON_PHRASE_LEN.md).

#### Throws

:[NotEnoughBytesError](NotEnoughBytesError.md) if the buffer does not contain enough bytes.

#### Throws

:[InvalidUTF8Error](InvalidUTF8Error.md) if decoding fails.
