Message
Message
#include <icy/stun/message.h>class MessageDefined in src/stun/include/icy/stun/message.h:31
STUN/TURN protocol message with method, class, transaction ID, and attributes.
List of all members
| Name | Kind | Owner |
|---|---|---|
Message | function | Declared here |
Message | function | Declared here |
Message | function | Declared here |
Message | function | Declared here |
operator= | function | Declared here |
operator= | function | Declared here |
~Message | function | Declared here |
clone | function | Declared here |
setClass | function | Declared here |
setMethod | function | Declared here |
setTransactionID | function | Declared here |
classType | function | Declared here |
methodType | function | Declared here |
transactionID | function | Declared here |
size | function | Declared here |
methodString | function | Declared here |
classString | function | Declared here |
errorString | function | Declared here |
add | function | Declared here |
add | function | Declared here |
get | function | Declared here |
get | function | Declared here |
read | function | Declared here |
write | function | Declared here |
toString | function | Declared here |
print | function | Declared here |
className | function | Declared here |
_class | variable | Declared here |
_method | variable | Declared here |
_size | variable | Declared here |
_transactionID | variable | Declared here |
_attrs | variable | Declared here |
MethodType | enum | Declared here |
ClassType | enum | Declared here |
ErrorCodes | enum | Declared here |
computeBodySize | function | Declared here |
operator<< | friend | Inherited from IPacket |
opaque | variable | Inherited from IPacket |
info | variable | Inherited from IPacket |
flags | variable | Inherited from IPacket |
IPacket | function | Inherited from IPacket |
IPacket | function | Inherited from IPacket |
operator= | function | Inherited from IPacket |
clone | function | Inherited from IPacket |
~IPacket | function | Inherited from IPacket |
read | function | Inherited from IPacket |
write | function | Inherited from IPacket |
size | function | Inherited from IPacket |
hasData | function | Inherited from IPacket |
data | function | Inherited from IPacket |
constData | function | Inherited from IPacket |
className | function | Inherited from IPacket |
print | function | Inherited from IPacket |
Inherited from IPacket
| Kind | Name | Description |
|---|---|---|
friend | operator<< inline | Stream insertion operator; delegates to print(). |
variable | opaque | Optional type-safe context data. Use std::any_cast to retrieve. Lifetime of the stored value is tied to the packet's lifetime. |
variable | info | Optional extra information about the packet. |
variable | flags | Provides basic information about the packet. |
function | IPacket inline | |
function | IPacket inline | Copy constructor; clones the info object if present. |
function | operator= inline | Copy assignment; clones the info object if present. |
function | clone virtual const | Returns a heap-allocated deep copy of this packet. |
function | ~IPacket virtual | Defaulted destructor. |
function | read virtual | Read/parse to the packet from the given input buffer. The number of bytes read is returned. |
function | write virtual const | Copy/generate to the packet given output buffer. The number of bytes written can be obtained from the buffer. |
function | size virtual const inline | The size of the packet in bytes. |
function | hasData virtual const inline | Returns true if the packet has a non-null data pointer. |
function | data virtual const inline | The packet data pointer for buffered packets. |
function | constData virtual const inline | The const packet data pointer for buffered packets. |
function | className virtual const | Returns the class name of this packet type for logging and diagnostics. |
function | print virtual const inline | Prints a human-readable representation to the given stream. |
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 noexcept | Move constructor. | |
Message & | operator= | Deep-copy assignment; clones all attributes from that. |
Message & | operator= noexcept | Move assignment. |
std::unique_ptr< IPacket > | clone virtual const override | |
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 | |
MethodType | methodType const | |
const TransactionID & | transactionID const inline | |
size_t | size virtual const inline override | |
std::string | methodString const | |
std::string | classString const | |
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 override | Parses a STUN/TURN packet from the given buffer. |
void | write virtual const override | Serialises this message into a STUN/TURN wire-format packet. |
std::string | toString const | |
void | print virtual const override | Writes the same representation as toString() to the given stream. |
const char * | className virtual const inline override | Returns the class name of this packet type for logging and diagnostics. |
Message
Message()Defined in src/stun/include/icy/stun/message.h:92
Constructs a default message (Request class, Undefined method) with a randomly generated 12-byte transaction ID.
Message
Message(ClassType clss, MethodType meth)Defined in src/stun/include/icy/stun/message.h:97
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)Defined in src/stun/include/icy/stun/message.h:100
Deep-copy constructor; clones all attributes.
Message
noexcept
Message(Message && that) noexceptDefined in src/stun/include/icy/stun/message.h:103
Move constructor.
operator=
Message & operator=(const Message & that)Defined in src/stun/include/icy/stun/message.h:106
Deep-copy assignment; clones all attributes from that.
operator=
noexcept
Message & operator=(Message && that) noexceptDefined in src/stun/include/icy/stun/message.h:109
Move assignment.
clone
virtual const override
virtual std::unique_ptr< IPacket > clone() const overrideDefined in src/stun/include/icy/stun/message.h:114
Returns
A heap-allocated deep copy of this message.
Reimplements
setClass
void setClass(ClassType type)Defined in src/stun/include/icy/stun/message.h:118
Sets the message class field.
Parameters
typeOne of Request, Indication, SuccessResponse, ErrorResponse.
setMethod
void setMethod(MethodType type)Defined in src/stun/include/icy/stun/message.h:122
Sets the message method field.
Parameters
typeOne of the MethodType enumerators.
setTransactionID
void setTransactionID(const std::string & id)Defined in src/stun/include/icy/stun/message.h:126
Sets the 12-byte transaction ID.
Parameters
idMust be exactly kTransactionIdLength (12) bytes.
classType
const
ClassType classType() constDefined in src/stun/include/icy/stun/message.h:129
Returns
The message class.
methodType
const
MethodType methodType() constDefined in src/stun/include/icy/stun/message.h:132
Returns
The message method.
transactionID
const inline
inline const TransactionID & transactionID() constDefined in src/stun/include/icy/stun/message.h:135
Returns
Reference to the 12-byte transaction ID string.
size
virtual const inline override
virtual inline size_t size() const overrideDefined in src/stun/include/icy/stun/message.h:138
Returns
Total body size in bytes (sum of padded attribute headers and bodies).
Reimplements
methodString
const
std::string methodString() constDefined in src/stun/include/icy/stun/message.h:141
Returns
Human-readable method name (e.g. "BINDING", "ALLOCATE").
classString
const
std::string classString() constDefined in src/stun/include/icy/stun/message.h:144
Returns
Human-readable class name (e.g. "Request", "SuccessResponse").
errorString
const
std::string errorString(uint16_t errorCode) constDefined in src/stun/include/icy/stun/message.h:149
Maps 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()Defined in src/stun/include/icy/stun/message.h:156
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)Defined in src/stun/include/icy/stun/message.h:166
Appends an attribute to the message, taking ownership via unique_ptr.
Parameters
attrAttribute to add.
get
const
Attribute * get(Attribute::Type type, int index = 0) constDefined in src/stun/include/icy/stun/message.h:172
Returns 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 = 0) constDefined in src/stun/include/icy/stun/message.h:179
Type-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 override
virtual ssize_t read(const ConstBuffer & buf) overrideDefined in src/stun/include/icy/stun/message.h:188
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.
Reimplements
write
virtual const override
virtual void write(Buffer & buf) const overrideDefined in src/stun/include/icy/stun/message.h:192
Serialises this message into a STUN/TURN wire-format packet.
Parameters
bufDestination buffer; data is appended.
Reimplements
toString
const
std::string toString() constDefined in src/stun/include/icy/stun/message.h:195
Returns
A concise string representation for logging (method, transaction ID, attribute types).
virtual const override
virtual void print(std::ostream & os) const overrideDefined in src/stun/include/icy/stun/message.h:199
Writes the same representation as toString() to the given stream.
Parameters
osOutput stream.
Reimplements
className
virtual const inline override
virtual inline const char * className() const overrideDefined in src/stun/include/icy/stun/message.h:201
Returns the class name of this packet type for logging and diagnostics.
Reimplements
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 _classDefined in src/stun/include/icy/stun/message.h:204
_method
uint16_t _methodDefined in src/stun/include/icy/stun/message.h:205
_size
uint16_t _sizeDefined in src/stun/include/icy/stun/message.h:206
Set by read(); write() uses computeBodySize() instead.
_transactionID
TransactionID _transactionIDDefined in src/stun/include/icy/stun/message.h:207
_attrs
std::vector< std::unique_ptr< Attribute > > _attrsDefined in src/stun/include/icy/stun/message.h:208
Public Types
| Name | Description |
|---|---|
MethodType | |
ClassType | |
ErrorCodes |
MethodType
enum MethodTypeDefined in src/stun/include/icy/stun/message.h:34
| 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 ClassTypeDefined in src/stun/include/icy/stun/message.h:55
| Value | Description |
|---|---|
Request | |
Indication | |
SuccessResponse | |
ErrorResponse |
ErrorCodes
enum ErrorCodesDefined in src/stun/include/icy/stun/message.h:63
| 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() constDefined in src/stun/include/icy/stun/message.h:212
Computes the wire body size from the current attribute list.
