R-Type 0.1
Loading...
Searching...
No Matches
PacketWriter Class Reference

Growable buffer of big-endian values, capped at MAX_PAYLOAD_SIZE. More...

#include <protocol/PacketWriter.hpp>

Public Member Functions

 PacketWriter ()
 Creates an empty writer with the full capacity reserved.
 
bool writeUInt8 (std::uint8_t value)
 Appends one byte.
 
bool writeUInt16 (std::uint16_t value)
 Appends a 16-bit unsigned integer in big-endian order.
 
bool writeUInt32 (std::uint32_t value)
 Appends a 32-bit unsigned integer in big-endian order.
 
bool writeBytes (const std::uint8_t *data, std::size_t size)
 Appends raw bytes.
 
bool empty () const
 Tells whether nothing has been written yet.
 
void clear ()
 Discards every written byte.
 
const std::vector< std::uint8_t > & getData () const
 Returns the written bytes.
 
std::size_t getSize () const
 Returns the number of written bytes.
 

Detailed Description

Growable buffer of big-endian values, capped at MAX_PAYLOAD_SIZE.

Member Function Documentation

◆ writeUInt8()

bool PacketWriter::writeUInt8 ( std::uint8_t value)

Appends one byte.

Parameters
valueByte to append.
Returns
True on success, false if the buffer is full.

◆ writeUInt16()

bool PacketWriter::writeUInt16 ( std::uint16_t value)

Appends a 16-bit unsigned integer in big-endian order.

Parameters
valueValue to append.
Returns
True on success, false if the buffer is full.

◆ writeUInt32()

bool PacketWriter::writeUInt32 ( std::uint32_t value)

Appends a 32-bit unsigned integer in big-endian order.

Parameters
valueValue to append.
Returns
True on success, false if the buffer is full.

◆ writeBytes()

bool PacketWriter::writeBytes ( const std::uint8_t * data,
std::size_t size )

Appends raw bytes.

Parameters
dataBytes to append.
sizeNumber of bytes to append.
Returns
True on success, false if the buffer would overflow.

◆ empty()

bool PacketWriter::empty ( ) const

Tells whether nothing has been written yet.

Returns
True if the buffer is empty.

◆ getData()

const std::vector< std::uint8_t > & PacketWriter::getData ( ) const

Returns the written bytes.

Returns
The underlying buffer.

◆ getSize()

std::size_t PacketWriter::getSize ( ) const

Returns the number of written bytes.

Returns
The buffer size.