ErrorCode
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
| Return | Name | Description |
|---|---|---|
ErrorCode | #### Parameters | |
ErrorCode | Copy constructor. | |
std::unique_ptr< Attribute > | clone virtual | Returns a deep copy of this attribute. |
void | setErrorCode | Sets the error code, splitting it into class and number fields. |
void | setReason | Sets the UTF-8 reason phrase and updates the attribute size. |
int | errorCode const | #### Returns |
uint8_t | errorClass const inline | #### Returns |
uint8_t | errorNumber const inline | #### Returns |
const std::string & | reason const inline | #### Returns |
void | read virtual | Reads the body (not the type or size) for this type of attribute from the given buffer. |
void | write virtual const | Writes the body (not the type or size) to the given buffer. |
ErrorCode
ErrorCode(uint16_t size)Parameters
sizeInitial 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
code3-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
reasonHuman-readable error description.
errorCode
const
int errorCode() constReturns
The full 3-digit error code (class * 100 + number).
errorClass
const inline
inline uint8_t errorClass() constReturns
The hundreds digit of the error code (e.g. 4 for a 4xx error).
errorNumber
const inline
inline uint8_t errorNumber() constReturns
The tens+units portion of the error code (0-99).
reason
const inline
inline const std::string & reason() constReturns
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
readerSource bit reader positioned at the attribute body.
write
virtual const
virtual void write(BitWriter & writer) constWrites the body (not the type or size) to the given buffer.
Parameters
writerDestination bit writer.
Public Static Attributes
| Return | Name | Description |
|---|---|---|
constexpr uint16_t | TypeID static | |
constexpr uint16_t | MinSize static | 4 bytes before the reason phrase. |
TypeID
static
constexpr uint16_t TypeID = 0x0009MinSize
static
constexpr uint16_t MinSize = 44 bytes before the reason phrase.
Private Attributes
_class
uint8_t _class_number
uint8_t _number_reason
std::string _reason