Skip to content

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 if encoding fails.

Throws ​

LengthExceedsMaxError if the encoded phrase exceeds MAX_REASON_PHRASE_LEN bytes.

Accessors ​

phrase ​

Get Signature ​

get phrase(): string

Returns the phrase string.

Returns ​

string

Methods ​

serialize() ​

serialize(): FrozenByteBuffer

Serializes the ReasonPhrase into a FrozenByteBuffer containing: varint(length_of_phrase_bytes) || phrase_bytes

Returns ​

FrozenByteBuffer

The serialized buffer.


deserialize() ​

static deserialize(buf): ReasonPhrase

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

Parameters ​

buf ​

BaseByteBuffer

The buffer to read from.

Returns ​

ReasonPhrase

The deserialized ReasonPhrase.

Throws ​

:CastingError if the length cannot be safely cast to a number.

Throws ​

:LengthExceedsMaxError if the length exceeds MAX_REASON_PHRASE_LEN.

Throws ​

:NotEnoughBytesError if the buffer does not contain enough bytes.

Throws ​

:InvalidUTF8Error if decoding fails.