STUN module (rfc5389)

ErrorCode

Implements the STUN ERROR-CODE attribute (RFC 5389 section 15.6).

ErrorCode

#include <icy/stun/attributes.h>

Inherits: Attribute

Implements the STUN ERROR-CODE attribute (RFC 5389 section 15.6). Encodes a 3-digit error code as a class (hundreds digit) and number (tens + units digits), plus an optional UTF-8 reason phrase.

Public Methods

ReturnNameDescription
ErrorCode#### Parameters
ErrorCodeCopy constructor.
std::unique_ptr< Attribute >clone virtualReturns a deep copy of this attribute.
voidsetErrorCodeSets the error code, splitting it into class and number fields.
voidsetReasonSets the UTF-8 reason phrase and updates the attribute size.
interrorCode const#### Returns
uint8_terrorClass const inline#### Returns
uint8_terrorNumber const inline#### Returns
const std::string &reason const inline#### Returns
voidread virtualReads the body (not the type or size) for this type of attribute from the given buffer.
voidwrite virtual constWrites the body (not the type or size) to the given buffer.

ErrorCode

ErrorCode(uint16_t size)

Parameters

  • size Initial body length in bytes (must be >= MinSize).

ErrorCode

ErrorCode(const ErrorCode & r)

Copy constructor.


clone

virtual

virtual std::unique_ptr< Attribute > clone()

Returns a deep copy of this attribute.


setErrorCode

void setErrorCode(int code)

Sets the error code, splitting it into class and number fields.

Parameters

  • code 3-digit error code (e.g. 401, 438).

setReason

void setReason(const std::string & reason)

Sets the UTF-8 reason phrase and updates the attribute size.

Parameters

  • reason Human-readable error description.

errorCode

const

int errorCode() const

Returns

The full 3-digit error code (class * 100 + number).


errorClass

const inline

inline uint8_t errorClass() const

Returns

The hundreds digit of the error code (e.g. 4 for a 4xx error).


errorNumber

const inline

inline uint8_t errorNumber() const

Returns

The tens+units portion of the error code (0-99).


reason

const inline

inline const std::string & reason() const

Returns

The reason phrase string (may be empty).


read

virtual

virtual void read(BitReader & reader)

Reads the body (not the type or size) for this type of attribute from the given buffer.

Parameters

  • reader Source bit reader positioned at the attribute body.

write

virtual const

virtual void write(BitWriter & writer) const

Writes the body (not the type or size) to the given buffer.

Parameters

  • writer Destination bit writer.

Public Static Attributes

ReturnNameDescription
constexpr uint16_tTypeID static
constexpr uint16_tMinSize static4 bytes before the reason phrase.

TypeID

static

constexpr uint16_t TypeID = 0x0009

MinSize

static

constexpr uint16_t MinSize = 4

4 bytes before the reason phrase.

Private Attributes

ReturnNameDescription
uint8_t_class
uint8_t_number
std::string_reason

_class

uint8_t _class

_number

uint8_t _number

_reason

std::string _reason