Home
STUN module (rfc5389)

ErrorCode

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

ErrorCode

#include <icy/stun/attributes.h>
class ErrorCode

Defined in src/stun/include/icy/stun/attributes.h:520

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.

List of all members

NameKindOwner
ErrorCodefunctionDeclared here
ErrorCodefunctionDeclared here
~ErrorCodefunctionDeclared here
clonefunctionDeclared here
setErrorCodefunctionDeclared here
setReasonfunctionDeclared here
errorCodefunctionDeclared here
errorClassfunctionDeclared here
errorNumberfunctionDeclared here
reasonfunctionDeclared here
readfunctionDeclared here
writefunctionDeclared here
TypeIDvariableDeclared here
MinSizevariableDeclared here
_classvariableDeclared here
_numbervariableDeclared here
_reasonvariableDeclared here
~AttributefunctionInherited from Attribute
clonefunctionInherited from Attribute
readfunctionInherited from Attribute
writefunctionInherited from Attribute
typefunctionInherited from Attribute
sizefunctionInherited from Attribute
paddingBytesfunctionInherited from Attribute
paddedBytesfunctionInherited from Attribute
consumePaddingfunctionInherited from Attribute
writePaddingfunctionInherited from Attribute
typeStringfunctionInherited from Attribute
TypeIDvariableInherited from Attribute
createfunctionInherited from Attribute
paddingBytesfunctionInherited from Attribute
paddedBytesfunctionInherited from Attribute
typeStringfunctionInherited from Attribute
_typevariableInherited from Attribute
_sizevariableInherited from Attribute
AttributefunctionInherited from Attribute
setLengthfunctionInherited from Attribute
TypeenumInherited from Attribute

Inherited from Attribute

KindNameDescription
function~Attribute virtual inline
functionclone virtualReturns a deep copy of this attribute.
functionread virtualReads the body (not the type or size) for this type of attribute from the given buffer.
functionwrite virtual constWrites the body (not the type or size) to the given buffer.
functiontype const
functionsize const
functionpaddingBytes const inline
functionpaddedBytes const inline
functionconsumePadding constAdvances the reader past any 4-byte alignment padding that follows this attribute's body.
functionwritePadding constWrites zero-fill padding bytes to align this attribute to a 4-byte boundary.
functiontypeString
variableTypeID static constexpr
functioncreate staticCreates an attribute of the given wire type and body size. Returns nullptr if the type is unknown or the size is invalid.
functionpaddingBytes static inline constexprReturns the 4-byte alignment padding required for a body of size bytes.
functionpaddedBytes static inline constexprReturns the body length including 4-byte alignment padding.
functiontypeString static
variable_type
variable_size
functionAttribute
functionsetLengthUpdates the stored body length.
enumType

Public Methods

ReturnNameDescription
ErrorCode
ErrorCodeCopy constructor.
std::unique_ptr< Attribute >clone virtual overrideReturns 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
uint8_terrorClass const inline
uint8_terrorNumber const inline
const std::string &reason const inline
voidread virtual overrideReads the body (not the type or size) for this type of attribute from the given buffer.
voidwrite virtual const overrideWrites the body (not the type or size) to the given buffer.

ErrorCode

ErrorCode(uint16_t size = MinSize)

Defined in src/stun/include/icy/stun/attributes.h:524

Parameters

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

ErrorCode

ErrorCode(const ErrorCode & r)

Defined in src/stun/include/icy/stun/attributes.h:527

Copy constructor.


clone

virtual override

virtual std::unique_ptr< Attribute > clone() override

Defined in src/stun/include/icy/stun/attributes.h:531

Returns a deep copy of this attribute.

Reimplements

setErrorCode

void setErrorCode(int code)

Defined in src/stun/include/icy/stun/attributes.h:538

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)

Defined in src/stun/include/icy/stun/attributes.h:542

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

Parameters

  • reason Human-readable error description.

errorCode

const

int errorCode() const

Defined in src/stun/include/icy/stun/attributes.h:545

Returns

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


errorClass

const inline

inline uint8_t errorClass() const

Defined in src/stun/include/icy/stun/attributes.h:548

Returns

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


errorNumber

const inline

inline uint8_t errorNumber() const

Defined in src/stun/include/icy/stun/attributes.h:551

Returns

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


reason

const inline

inline const std::string & reason() const

Defined in src/stun/include/icy/stun/attributes.h:554

Returns

The reason phrase string (may be empty).


read

virtual override

virtual void read(BitReader & reader) override

Defined in src/stun/include/icy/stun/attributes.h:556

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.
Reimplements

write

virtual const override

virtual void write(BitWriter & writer) const override

Defined in src/stun/include/icy/stun/attributes.h:557

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

Parameters

  • writer Destination bit writer.
Reimplements

Public Static Attributes

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

TypeID

static constexpr

constexpr uint16_t TypeID = 0x0009

Defined in src/stun/include/icy/stun/attributes.h:533


MinSize

static constexpr

constexpr uint16_t MinSize = 4

Defined in src/stun/include/icy/stun/attributes.h:534

4 bytes before the reason phrase.

Private Attributes

ReturnNameDescription
uint8_t_class
uint8_t_number
std::string_reason

_class

uint8_t _class

Defined in src/stun/include/icy/stun/attributes.h:560


_number

uint8_t _number

Defined in src/stun/include/icy/stun/attributes.h:561


_reason

std::string _reason

Defined in src/stun/include/icy/stun/attributes.h:562