Message
Message
#include <icy/stun/message.h>STUN/TURN protocol message with method, class, transaction ID, and attributes.
Public Methods
| Return | Name | Description |
|---|---|---|
Message | Constructs a default message (Request class, Undefined method) with a randomly generated 12-byte transaction ID. | |
Message | Constructs a message with explicit class and method. | |
Message | Deep-copy constructor; clones all attributes. | |
Message | Move constructor. | |
Message & | operator= | Deep-copy assignment; clones all attributes from that. |
Message & | operator= | Move assignment. |
std::unique_ptr< IPacket > | clone virtual const | #### Returns |
void | setClass | Sets the message class field. |
void | setMethod | Sets the message method field. |
void | setTransactionID | Sets the 12-byte transaction ID. |
ClassType | classType const | #### Returns |
MethodType | methodType const | #### Returns |
const TransactionID & | transactionID const inline | #### Returns |
size_t | size virtual const inline | #### Returns |
std::string | methodString const | #### Returns |
std::string | classString const | #### Returns |
std::string | errorString const | Maps a numeric error code to its canonical string description. |
T & | add inline | Constructs an attribute of type T in-place and appends it to the message. Returns a reference to the new attribute for further configuration. |
void | add | Appends an attribute to the message, taking ownership via unique_ptr. |
Attribute * | get const | Returns the Nth attribute of the given type, or nullptr if not found. |
T * | get const inline | Type-safe attribute accessor using the concrete attribute's TypeID. |
ssize_t | read virtual | Parses a STUN/TURN packet from the given buffer. |
void | write virtual const | Serialises this message into a STUN/TURN wire-format packet. |
std::string | toString const | #### Returns |
void | print virtual const | Writes the same representation as toString() to the given stream. |
const char * | className virtual const inline | Returns the class name of this packet type for logging and diagnostics. |
Message
Message()Constructs a default message (Request class, Undefined method) with a randomly generated 12-byte transaction ID.
Message
Message(ClassType clss, MethodType meth)Constructs a message with explicit class and method.
Parameters
clssMessage class (Request, Indication, SuccessResponse, or ErrorResponse).methMessage method (Binding, Allocate, Refresh, etc.).
Message
Message(const Message & that)Deep-copy constructor; clones all attributes.
Message
Message(Message && that) noexceptMove constructor.
operator=
Message & operator=(const Message & that)Deep-copy assignment; clones all attributes from that.
operator=
Message & operator=(Message && that) noexceptMove assignment.
clone
virtual const
virtual std::unique_ptr< IPacket > clone() constReturns
A heap-allocated deep copy of this message.
setClass
void setClass(ClassType type)Sets the message class field.
Parameters
typeOne of Request, Indication, SuccessResponse, ErrorResponse.
setMethod
void setMethod(MethodType type)Sets the message method field.
Parameters
typeOne of the MethodType enumerators.
setTransactionID
void setTransactionID(const std::string & id)Sets the 12-byte transaction ID.
Parameters
idMust be exactly kTransactionIdLength (12) bytes.
classType
const
ClassType classType() constReturns
The message class.
methodType
const
MethodType methodType() constReturns
The message method.
transactionID
const inline
inline const TransactionID & transactionID() constReturns
Reference to the 12-byte transaction ID string.
size
virtual const inline
virtual inline size_t size() constReturns
Total body size in bytes (sum of padded attribute headers and bodies).
methodString
const
std::string methodString() constReturns
Human-readable method name (e.g. "BINDING", "ALLOCATE").
classString
const
std::string classString() constReturns
Human-readable class name (e.g. "Request", "SuccessResponse").
errorString
const
std::string errorString(uint16_t errorCode) constMaps a numeric error code to its canonical string description.
Parameters
errorCodeOne of the ErrorCodes enumerators.
Returns
Human-readable error string, or "UnknownError" if not recognised.
add
inline
template<typename T> inline T & add()Constructs an attribute of type T in-place and appends it to the message. Returns a reference to the new attribute for further configuration.
Parameters
TConcrete attribute type (e.g. stun::Lifetime, stun::XorMappedAddress).
Returns
Reference to the newly added attribute.
add
void add(std::unique_ptr< Attribute > attr)Appends an attribute to the message, taking ownership via unique_ptr.
Parameters
attrAttribute to add.
get
const
Attribute * get(Attribute::Type type, int index) constReturns the Nth attribute of the given type, or nullptr if not found.
Parameters
typeAttribute type code to search for.indexZero-based occurrence index (0 = first match).
Returns
Raw pointer to the attribute (owned by this message), or nullptr.
get
const inline
template<typename T> inline T * get(int index) constType-safe attribute accessor using the concrete attribute's TypeID.
Parameters
TConcrete attribute type (must define TypeID).
Parameters
indexZero-based occurrence index.
Returns
Pointer to T, or nullptr if the attribute is absent.
read
virtual
virtual ssize_t read(const ConstBuffer & buf)Parses a STUN/TURN packet from the given buffer.
Parameters
bufBuffer containing at least one complete STUN message.
Returns
Number of bytes consumed, or 0 on parse failure.
write
virtual const
virtual void write(Buffer & buf) constSerialises this message into a STUN/TURN wire-format packet.
Parameters
bufDestination buffer; data is appended.
toString
const
std::string toString() constReturns
A concise string representation for logging (method, transaction ID, attribute types).
virtual const
virtual void print(std::ostream & os) constWrites the same representation as toString() to the given stream.
Parameters
osOutput stream.
className
virtual const inline
virtual inline const char * className() constReturns the class name of this packet type for logging and diagnostics.
Protected Attributes
| Return | Name | Description |
|---|---|---|
uint16_t | _class | |
uint16_t | _method | |
uint16_t | _size | Set by read(); write() uses computeBodySize() instead. |
TransactionID | _transactionID | |
std::vector< std::unique_ptr< Attribute > > | _attrs |
_class
uint16_t _class_method
uint16_t _method_size
uint16_t _sizeSet by read(); write() uses computeBodySize() instead.
_transactionID
TransactionID _transactionID_attrs
std::vector< std::unique_ptr< Attribute > > _attrsPublic Types
| Name | Description |
|---|---|
MethodType | |
ClassType | |
ErrorCodes |
MethodType
enum MethodType| Value | Description |
|---|---|
Undefined | default error type |
Binding | STUN. |
Allocate | TURN. |
Refresh | |
SendIndication | (only indication semantics defined) |
DataIndication | (only indication semantics defined) |
CreatePermission | (only request/response semantics defined) |
ChannelBind | (only request/response semantics defined) |
Connect | TURN TCP RFC 6062. |
ConnectionBind | |
ConnectionAttempt |
ClassType
enum ClassType| Value | Description |
|---|---|
Request | |
Indication | |
SuccessResponse | |
ErrorResponse |
ErrorCodes
enum ErrorCodes| Value | Description |
|---|---|
TryAlternate | |
BadRequest | |
NotAuthorized | |
Forbidden | |
UnknownAttribute | |
StaleCredentials | |
IntegrityCheckFailure | |
MissingUsername | |
UseTLS | |
AllocationMismatch | |
StaleNonce | |
WrongCredentials | |
UnsupportedTransport | |
AllocationQuotaReached | |
RoleConflict | |
ServerError | |
InsufficientCapacity | |
GlobalFailure | |
ConnectionAlreadyExists | TURN TCP. |
ConnectionTimeoutOrFailure |
Private Methods
| Return | Name | Description |
|---|---|---|
uint16_t | computeBodySize const | Computes the wire body size from the current attribute list. |
computeBodySize
const
uint16_t computeBodySize() constComputes the wire body size from the current attribute list.
