StringAttribute
StringAttribute
#include <icy/stun/attributes.h>Inherits:
Attribute
Implements a STUN/TURN attribute that holds an arbitrary byte string. Used for Username, Password, Realm, Nonce, Software, Data, and similar attributes.
Public Methods
| Return | Name | Description |
|---|---|---|
StringAttribute | #### Parameters | |
StringAttribute | Copy constructor; duplicates stored bytes. | |
std::unique_ptr< Attribute > | clone virtual | Returns a deep copy of this attribute. |
const char * | bytes const inline | #### Returns |
void | setBytes | Replaces the stored bytes with a copy of the given buffer and updates the attribute's reported size. |
std::string | asString const | #### Returns |
void | copyBytes | Copies a null-terminated string into the attribute, using strlen to determine the length. |
void | copyBytes | Copies an arbitrary block of memory into the attribute. |
uint8_t | getByte const | Returns a single byte from the stored buffer. |
void | setByte | Overwrites a single byte in the stored buffer. |
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. |
StringAttribute
StringAttribute(uint16_t type, uint16_t size)Parameters
typeWire type code for the concrete attribute.sizeInitial body length in bytes (0 for variable-length attributes).
StringAttribute
StringAttribute(const StringAttribute & r)Copy constructor; duplicates stored bytes.
clone
virtual
virtual std::unique_ptr< Attribute > clone()Returns a deep copy of this attribute.
bytes
const inline
inline const char * bytes() constReturns
Pointer to the raw byte buffer.
setBytes
void setBytes(const char * bytes, size_t size)Replaces the stored bytes with a copy of the given buffer and updates the attribute's reported size.
Parameters
bytesSource data pointer.sizeNumber of bytes to copy.
asString
const
std::string asString() constReturns
The stored bytes as a std::string.
copyBytes
void copyBytes(const char * bytes)Copies a null-terminated string into the attribute, using strlen to determine the length.
Parameters
bytesNull-terminated source string.
copyBytes
void copyBytes(const void * bytes, size_t size)Copies an arbitrary block of memory into the attribute.
Parameters
bytesSource data pointer.sizeNumber of bytes to copy.
getByte
const
uint8_t getByte(int index) constReturns a single byte from the stored buffer.
Parameters
indexZero-based byte offset.
Returns
The byte value at index.
setByte
void setByte(int index, uint8_t value)Overwrites a single byte in the stored buffer.
Parameters
indexZero-based byte offset.valueNew value to write.
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.
Private Attributes
| Return | Name | Description |
|---|---|---|
std::vector< char > | _bytes |
_bytes
std::vector< char > _bytes