Nets v3.0.0
OutStreamMessage Class Reference

Network output stream message container. (TCP). More...

#include <stream-message.hpp>

Public Member Functions

 OutStreamMessage (uint8_t *buffer, size_t bufferSize, size_t messageSize, uint8_t lengthSize) noexcept
 Creates a new output stream message. (TCP).
 OutStreamMessage (std::vector< uint8_t > &buffer, size_t messageSize, uint8_t lengthSize) noexcept
 Creates a new output stream message. (TCP).
 OutStreamMessage () noexcept=default
 Creates a new empty output stream message.
const uint8_tgetBuffer () const noexcept
 Returns stream message buffer.
size_t getSize () const noexcept
 Returns stream message size in bytes.
bool write (const void *data, size_t count) noexcept
 Writes data to the stream message and advances offset.
bool write (uint8_t value) noexcept
 Writes 8-bit unsigned integer value to the stream message and advances offset.
bool write (uint16_t value) noexcept
 Writes 16-bit unsigned integer value to the stream message and advances offset.
bool write (uint32_t value) noexcept
 Writes 32-bit unsigned integer value to the stream message and advances offset.
bool write (uint64_t value) noexcept
 Writes 64-bit unsigned integer value to the stream message and advances offset.
bool write (int8_t value) noexcept
 Writes 8-bit signed integer value to the stream message and advances offset.
bool write (int16_t value) noexcept
 Writes 16-bit signed integer value to the stream message and advances offset.
bool write (int32_t value) noexcept
 Writes 32-bit signed integer value to the stream message and advances offset.
bool write (int64_t value) noexcept
 Writes 64-bit signed integer value to the stream message and advances offset.
bool write (float value) noexcept
 Writes 32-bit signed integer value to the stream message and advances offset.
bool write (double value) noexcept
 Writes 64-bit signed integer value to the stream message and advances offset.
bool write (std::string_view value, uint8_t lengthSize) noexcept
 Writes string to the stream message and advances offset.
bool write (bool value) noexcept
 Writes boolean value to the stream message and advances offset.
bool write (const void *data, size_t dataSize, uint8_t lengthSize) noexcept
 Writes data to the stream message and advances offset.
template<class T>
bool write (const std::vector< T > &data, uint8_t lengthSize) noexcept
 Writes vector data to the stream message and advances offset.
template<class T, size_t N>
bool write (const std::array< T, N > &data, uint8_t lengthSize) noexcept
 Writes array data to the stream message and advances offset.
const uint8_tgetEnd () const noexcept
 Returns stream message end pointer.
bool isComplete () const noexcept
 Returns true if stream message is not empty and complete, otherwise false.
size_t getLeft () const noexcept
 Returns stream message byte count left to read or write.
bool read (const void *&data, size_t count) noexcept
 Reads data from the stream message and advances offset.
bool read (uint8_t &value) noexcept
 Reads 8-bit unsigned integer value from the stream message and advances offset.
bool read (uint16_t &value) noexcept
 Reads 16-bit unsigned integer value from the stream message and advances offset.
bool read (uint32_t &value) noexcept
 Reads 32-bit unsigned integer value from the stream message and advances offset.
bool read (uint64_t &value) noexcept
 Reads 64-bit unsigned integer value from the stream message and advances offset.
bool read (int8_t &value) noexcept
 Reads 8-bit signed integer value from the stream message and advances offset.
bool read (int16_t &value) noexcept
 Reads 16-bit signed integer value from the stream message and advances offset.
bool read (int32_t &value) noexcept
 Reads 32-bit signed integer value from the stream message and advances offset.
bool read (int64_t &value) noexcept
 Reads 64-bit signed integer value from the stream message and advances offset.
bool read (float &value) noexcept
 Reads 32-bit floating point value from the stream message and advances offset.
bool read (double &value) noexcept
 Reads 64-bit floating point value from the stream message and advances offset.
bool read (std::string_view &value, uint8_t lengthSize) noexcept
 Reads string from the stream message and advances offset.
bool read (std::string &value, uint8_t lengthSize) noexcept
 Reads string from the stream message and advances offset.
bool read (bool &value) noexcept
 Reads boolean value from the stream message and advances offset.
bool read (const void *&data, size_t &dataSize, uint8_t lengthSize) noexcept
 Reads data from the stream message and advances offset.
template<class T>
bool read (std::vector< T > &data, uint8_t lengthSize) noexcept
 Reads vector data from the stream message and advances offset.

Data Fields

uint8_titer

Static Public Attributes

static constexpr uint8_t maxLengthSize = STREAM_MESSAGE_MAX_LENGTH_SIZE
 Maximum size of the stream message length in bytes.
static constexpr uint16_t maxDatagramSize = MAX_DATAGRAM_MESSAGE_SIZE
 Safe maximum UDP datagram size in bytes. (Includes IP and VPN overhead).

Protected Attributes

uint8_tbuffer = nullptr
size_t size = 0
uint8_tend

Detailed Description

Network output stream message container. (TCP).

See the stream-message.h

Constructor & Destructor Documentation

◆ OutStreamMessage() [1/2]

OutStreamMessage ( uint8_t * buffer,
size_t bufferSize,
size_t messageSize,
uint8_t lengthSize )
inlinenoexcept

Creates a new output stream message. (TCP).

See the createStreamMessage().

Parameters
[in,out]buffermessage data buffer
bufferSizemessage buffer size in bytes
messageSizemessage size in bytes
lengthSizemessage header length size in bytes

◆ OutStreamMessage() [2/2]

OutStreamMessage ( std::vector< uint8_t > & buffer,
size_t messageSize,
uint8_t lengthSize )
inlinenoexcept

Creates a new output stream message. (TCP).

See the createStreamMessage().

Parameters
[in,out]buffermessage data buffer
messageSizemessage size in bytes
lengthSizemessage header size in bytes

Member Function Documentation

◆ write() [1/16]

bool write ( const void * data,
size_t count )
inlinenoexcept

Writes data to the stream message and advances offset.

See the writeStreamMessage().

Returns
True if no more space to write data, otherwise false.
Parameters
[in]datamessage data to write
countmessage byte count to write

◆ write() [2/16]

bool write ( uint8_t value)
inlinenoexcept

Writes 8-bit unsigned integer value to the stream message and advances offset.

See the writeStreamMessageUint8().

Returns
True if no more space to write data, otherwise false.
Parameters
valueunsigned integer value to write

◆ write() [3/16]

bool write ( uint16_t value)
inlinenoexcept

Writes 16-bit unsigned integer value to the stream message and advances offset.

See the writeStreamMessageUint16().

Returns
True if no more space to write data, otherwise false.
Parameters
valueunsigned integer value to write

◆ write() [4/16]

bool write ( uint32_t value)
inlinenoexcept

Writes 32-bit unsigned integer value to the stream message and advances offset.

See the writeStreamMessageUint32().

Returns
True if no more space to write data, otherwise false.
Parameters
valueunsigned integer value to write

◆ write() [5/16]

bool write ( uint64_t value)
inlinenoexcept

Writes 64-bit unsigned integer value to the stream message and advances offset.

See the writeStreamMessageUint64().

Returns
True if no more space to write data, otherwise false.
Parameters
valueunsigned integer value to write

◆ write() [6/16]

bool write ( int8_t value)
inlinenoexcept

Writes 8-bit signed integer value to the stream message and advances offset.

See the writeStreamMessageInt8().

Returns
True if no more space to write data, otherwise false.
Parameters
valuesigned integer value to write

◆ write() [7/16]

bool write ( int16_t value)
inlinenoexcept

Writes 16-bit signed integer value to the stream message and advances offset.

See the writeStreamMessageInt16().

Returns
True if no more space to write data, otherwise false.
Parameters
valuesigned integer value to write

◆ write() [8/16]

bool write ( int32_t value)
inlinenoexcept

Writes 32-bit signed integer value to the stream message and advances offset.

See the writeStreamMessageInt32().

Returns
True if no more space to write data, otherwise false.
Parameters
valuesigned integer value to write

◆ write() [9/16]

bool write ( int64_t value)
inlinenoexcept

Writes 64-bit signed integer value to the stream message and advances offset.

See the writeStreamMessageInt64().

Returns
True if no more space to write data, otherwise false.
Parameters
valuesigned integer value to write

◆ write() [10/16]

bool write ( float value)
inlinenoexcept

Writes 32-bit signed integer value to the stream message and advances offset.

See the writeStreamMessageFloat32().

Returns
True if no more space to write data, otherwise false.
Parameters
valuefloating point value to write

◆ write() [11/16]

bool write ( double value)
inlinenoexcept

Writes 64-bit signed integer value to the stream message and advances offset.

See the writeStreamMessageFloat64().

Returns
True if no more space to write data, otherwise false.
Parameters
valuefloating point value to write

◆ write() [12/16]

bool write ( std::string_view value,
uint8_t lengthSize )
inlinenoexcept

Writes string to the stream message and advances offset.

See the writeStreamMessageData().

Returns
True if no more space to write data, otherwise false.
Parameters
valuemessage string to write
lengthSizelength of the string size in bytes

◆ write() [13/16]

bool write ( bool value)
inlinenoexcept

Writes boolean value to the stream message and advances offset.

See the writeStreamMessageBool().

Returns
True if no more space to write data, otherwise false.
Parameters
valueboolean value to write

◆ write() [14/16]

bool write ( const void * data,
size_t dataSize,
uint8_t lengthSize )
inlinenoexcept

Writes data to the stream message and advances offset.

See the writeStreamMessageData().

Returns
True if no more space to write data, otherwise false.
Parameters
[in]datamessage data to write
dataSizesize of the data in bytes
lengthSizelength of the data size in bytes

◆ write() [15/16]

template<class T>
bool write ( const std::vector< T > & data,
uint8_t lengthSize )
inlinenoexcept

Writes vector data to the stream message and advances offset.

See the writeStreamMessageData().

Returns
True if no more space to write data, otherwise false.
Template Parameters
Ttype of the vector data
Parameters
[in]datamessage data vector to write
lengthSizelength of the data size in bytes

◆ write() [16/16]

template<class T, size_t N>
bool write ( const std::array< T, N > & data,
uint8_t lengthSize )
inlinenoexcept

Writes array data to the stream message and advances offset.

See the writeStreamMessageData().

Returns
True if no more space to write data, otherwise false.
Template Parameters
Ttype of the array data
Ssize of the array
Parameters
[in]datamessage data array to write
lengthSizelength of the data size in bytes

◆ isComplete()

bool isComplete ( ) const
inlinenoexceptinherited

Returns true if stream message is not empty and complete, otherwise false.

See the isStreamMessageComplete().

◆ getLeft()

size_t getLeft ( ) const
inlinenoexceptinherited

Returns stream message byte count left to read or write.

See the getStreamMessageLeft().

◆ read() [1/16]

bool read ( const void *& data,
size_t count )
inlinenoexceptinherited

Reads data from the stream message and advances offset.

See the readStreamMessage().

Returns
True if no more data to read, otherwise false.
Parameters
[out]datareference to the message data
countmessage byte count to read

◆ read() [2/16]

bool read ( uint8_t & value)
inlinenoexceptinherited

Reads 8-bit unsigned integer value from the stream message and advances offset.

See the readStreamMessageUint8().

Returns
True if no more data to read, otherwise false.
Parameters
[out]valuereference to the unsigned integer value

◆ read() [3/16]

bool read ( uint16_t & value)
inlinenoexceptinherited

Reads 16-bit unsigned integer value from the stream message and advances offset.

See the readStreamMessageUint16().

Returns
True if no more data to read, otherwise false.
Parameters
[out]valuereference to the unsigned integer value

◆ read() [4/16]

bool read ( uint32_t & value)
inlinenoexceptinherited

Reads 32-bit unsigned integer value from the stream message and advances offset.

See the readStreamMessageUint32().

Returns
True if no more data to read, otherwise false.
Parameters
[out]valuereference to the unsigned integer value

◆ read() [5/16]

bool read ( uint64_t & value)
inlinenoexceptinherited

Reads 64-bit unsigned integer value from the stream message and advances offset.

See the readStreamMessageUint64().

Returns
True if no more data to read, otherwise false.
Parameters
[out]valuereference to the unsigned integer value

◆ read() [6/16]

bool read ( int8_t & value)
inlinenoexceptinherited

Reads 8-bit signed integer value from the stream message and advances offset.

See the readStreamMessageInt8().

Returns
True if no more data to read, otherwise false.
Parameters
[out]valuereference to the signed integer value

◆ read() [7/16]

bool read ( int16_t & value)
inlinenoexceptinherited

Reads 16-bit signed integer value from the stream message and advances offset.

See the readStreamMessageInt16().

Returns
True if no more data to read, otherwise false.
Parameters
[out]valuereference to the signed integer value

◆ read() [8/16]

bool read ( int32_t & value)
inlinenoexceptinherited

Reads 32-bit signed integer value from the stream message and advances offset.

See the readStreamMessageInt32().

Returns
True if no more data to read, otherwise false.
Parameters
[out]valuereference to the signed integer value

◆ read() [9/16]

bool read ( int64_t & value)
inlinenoexceptinherited

Reads 64-bit signed integer value from the stream message and advances offset.

See the readStreamMessageInt64().

Returns
True if no more data to read, otherwise false.
Parameters
[out]valuereference to the signed integer value

◆ read() [10/16]

bool read ( float & value)
inlinenoexceptinherited

Reads 32-bit floating point value from the stream message and advances offset.

See the readStreamMessageFloat32().

Returns
True if no more data to read, otherwise false.
Parameters
[out]valuereference to the floating point value

◆ read() [11/16]

bool read ( double & value)
inlinenoexceptinherited

Reads 64-bit floating point value from the stream message and advances offset.

See the readStreamMessageFloat64().

Returns
True if no more data to read, otherwise false.
Parameters
[out]valuereference to the floating point value

◆ read() [12/16]

bool read ( std::string_view & value,
uint8_t lengthSize )
inlinenoexceptinherited

Reads string from the stream message and advances offset.

See the readStreamMessageData().

Returns
True if no more data to read, otherwise false.
Parameters
[out]valuereference to the message string
lengthSizelength of the string size in bytes

◆ read() [13/16]

bool read ( std::string & value,
uint8_t lengthSize )
inlinenoexceptinherited

Reads string from the stream message and advances offset.

See the readStreamMessageData().

Returns
True if no more data to read, otherwise false.
Parameters
[out]valuereference to the message string
lengthSizelength of the string size in bytes

◆ read() [14/16]

bool read ( bool & value)
inlinenoexceptinherited

Reads boolean value from the stream message and advances offset.

See the readStreamMessageBool().

Returns
True if no more data to read, otherwise false.
Parameters
[out]valuereference to the boolean value

◆ read() [15/16]

bool read ( const void *& data,
size_t & dataSize,
uint8_t lengthSize )
inlinenoexceptinherited

Reads data from the stream message and advances offset.

See the readStreamMessageData().

Returns
True if no more data to read, otherwise false.
Parameters
[out]datareference to the message data
[out]dataSizereference to the data size in bytes
lengthSizelength of the data size in bytes

◆ read() [16/16]

template<class T>
bool read ( std::vector< T > & data,
uint8_t lengthSize )
inlinenoexceptinherited

Reads vector data from the stream message and advances offset.

See the readStreamMessageData().

Returns
True if no more data to read, otherwise false.
Template Parameters
Ttype of the vector data
Parameters
[out]datareference to the message data vector
lengthSizelength of the data size in bytes