RAVENNAKIT
Loading...
Searching...
No Matches
rav::ByteBuffer Class Reference

A wrapper around std::vector with some facilities for writing different types to it in different byte orders. More...

#include <byte_buffer.hpp>

Public Member Functions

 ByteBuffer ()=default
 ByteBuffer (const size_t size)
 ByteBuffer (const ByteBuffer &)=default
ByteBuffer & operator= (const ByteBuffer &)=default
 ByteBuffer (ByteBuffer &&) noexcept=default
ByteBuffer & operator= (ByteBuffer &&) noexcept=default
const uint8_t * data () const
size_t size () const
void clear ()
 Clears the data.
void write (const uint8_t *data, const size_t size)
 Appends given data to the buffer.
template<typename Type, std::enable_if_t< std::is_trivially_copyable_v< Type >, bool > = true>
void write_ne (const Type value)
 Writes a value to the stream in native byte order (not to be confused with network-endian).
template<typename Type, std::enable_if_t< std::is_trivially_copyable_v< Type >, bool > = true>
void write_be (const Type value)
 Writes a big-endian value to the stream.
template<typename Type, std::enable_if_t< std::is_trivially_copyable_v< Type >, bool > = true>
void write_le (const Type value)
 Writes a little-endian value to the stream.

Detailed Description

A wrapper around std::vector with some facilities for writing different types to it in different byte orders.

Definition at line 36 of file byte_buffer.hpp.

Constructor & Destructor Documentation

◆ ByteBuffer() [1/4]

rav::ByteBuffer::ByteBuffer ( )
default

◆ ByteBuffer() [2/4]

rav::ByteBuffer::ByteBuffer ( const size_t size)
inlineexplicit

Definition at line 40 of file byte_buffer.hpp.

◆ ByteBuffer() [3/4]

rav::ByteBuffer::ByteBuffer ( const ByteBuffer & )
default

◆ ByteBuffer() [4/4]

rav::ByteBuffer::ByteBuffer ( ByteBuffer && )
defaultnoexcept

Member Function Documentation

◆ clear()

void rav::ByteBuffer::clear ( )
inline

Clears the data.

Definition at line 65 of file byte_buffer.hpp.

◆ data()

const uint8_t * rav::ByteBuffer::data ( ) const
inlinenodiscard
Returns
A pointer to the data in the buffer.

Definition at line 51 of file byte_buffer.hpp.

◆ operator=() [1/2]

ByteBuffer & rav::ByteBuffer::operator= ( ByteBuffer && )
defaultnoexcept

◆ operator=() [2/2]

ByteBuffer & rav::ByteBuffer::operator= ( const ByteBuffer & )
default

◆ size()

size_t rav::ByteBuffer::size ( ) const
inlinenodiscard
Returns
The current size of the buffer.

Definition at line 58 of file byte_buffer.hpp.

◆ write()

void rav::ByteBuffer::write ( const uint8_t * data,
const size_t size )
inline

Appends given data to the buffer.

Parameters
dataThe data to append.
sizeThe size of the data.

Definition at line 74 of file byte_buffer.hpp.

◆ write_be()

template<typename Type, std::enable_if_t< std::is_trivially_copyable_v< Type >, bool > = true>
void rav::ByteBuffer::write_be ( const Type value)
inline

Writes a big-endian value to the stream.

Template Parameters
TypeThe type of the value to write.
Parameters
valueThe value to write.
Returns
An expected indicating success or failure.

Definition at line 96 of file byte_buffer.hpp.

◆ write_le()

template<typename Type, std::enable_if_t< std::is_trivially_copyable_v< Type >, bool > = true>
void rav::ByteBuffer::write_le ( const Type value)
inline

Writes a little-endian value to the stream.

Template Parameters
TypeThe type of the value to write.
Parameters
valueThe value to write.
Returns
An expected indicating success or failure.

Definition at line 107 of file byte_buffer.hpp.

◆ write_ne()

template<typename Type, std::enable_if_t< std::is_trivially_copyable_v< Type >, bool > = true>
void rav::ByteBuffer::write_ne ( const Type value)
inline

Writes a value to the stream in native byte order (not to be confused with network-endian).

Template Parameters
TypeThe type of the value to write.
Parameters
valueThe value to write.
Returns
An expected indicating success or failure.

Definition at line 85 of file byte_buffer.hpp.


The documentation for this class was generated from the following file: