Home
STUN module (rfc5389)

StringAttribute

Implements a STUN/TURN attribute that holds an arbitrary byte string.

StringAttribute

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

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

Inherits: Attribute

Implements a STUN/TURN attribute that holds an arbitrary byte string. Used for Username, Password, Realm, Nonce, Software, Data, and similar attributes.

List of all members

NameKindOwner
StringAttributefunctionDeclared here
StringAttributefunctionDeclared here
~StringAttributefunctionDeclared here
clonefunctionDeclared here
bytesfunctionDeclared here
setBytesfunctionDeclared here
asStringfunctionDeclared here
copyBytesfunctionDeclared here
copyBytesfunctionDeclared here
getBytefunctionDeclared here
setBytefunctionDeclared here
readfunctionDeclared here
writefunctionDeclared here
_bytesvariableDeclared 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
StringAttribute
StringAttributeCopy constructor; duplicates stored bytes.
std::unique_ptr< Attribute >clone virtual overrideReturns a deep copy of this attribute.
const char *bytes const inline
voidsetBytesReplaces the stored bytes with a copy of the given buffer and updates the attribute's reported size.
std::stringasString const
voidcopyBytesCopies a null-terminated string into the attribute, using strlen to determine the length.
voidcopyBytesCopies an arbitrary block of memory into the attribute.
uint8_tgetByte constReturns a single byte from the stored buffer.
voidsetByteOverwrites a single byte in the stored buffer.
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.

StringAttribute

StringAttribute(uint16_t type, uint16_t size = 0)

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

Parameters

  • type Wire type code for the concrete attribute.

  • size Initial body length in bytes (0 for variable-length attributes).


StringAttribute

StringAttribute(const StringAttribute & r)

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

Copy constructor; duplicates stored bytes.


clone

virtual override

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

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

Returns a deep copy of this attribute.

Reimplements

bytes

const inline

inline const char * bytes() const

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

Returns

Pointer to the raw byte buffer.


setBytes

void setBytes(const char * bytes, size_t size)

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

Replaces the stored bytes with a copy of the given buffer and updates the attribute's reported size.

Parameters

  • bytes Source data pointer.

  • size Number of bytes to copy.


asString

const

std::string asString() const

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

Returns

The stored bytes as a std::string.


copyBytes

void copyBytes(const char * bytes)

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

Copies a null-terminated string into the attribute, using strlen to determine the length.

Parameters

  • bytes Null-terminated source string.

copyBytes

void copyBytes(const void * bytes, size_t size)

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

Copies an arbitrary block of memory into the attribute.

Parameters

  • bytes Source data pointer.

  • size Number of bytes to copy.


getByte

const

uint8_t getByte(int index) const

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

Returns a single byte from the stored buffer.

Parameters

  • index Zero-based byte offset.

Returns

The byte value at index.


setByte

void setByte(int index, uint8_t value)

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

Overwrites a single byte in the stored buffer.

Parameters

  • index Zero-based byte offset.

  • value New value to write.


read

virtual override

virtual void read(BitReader & reader) override

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

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:416

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

Parameters

  • writer Destination bit writer.
Reimplements

Private Attributes

ReturnNameDescription
std::vector< char >_bytes

_bytes

std::vector< char > _bytes

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