Horizon Official Technical Documentation
MessageBuffer Class Reference

#include <MessageBuffer.hpp>

Public Member Functions

 MessageBuffer ()
 
 MessageBuffer (std::size_t initial_size)
 
 MessageBuffer (MessageBuffer const &right)
 
 MessageBuffer (MessageBuffer &&right)
 
void reset ()
 
void resize (size_type bytes)
 
std::string to_string ()
 
uint8_t * get_base_pointer ()
 
uint8_t * get_read_pointer ()
 
uint8_t * get_write_pointer ()
 
void read_completed (size_type bytes)
 
void write_completed (size_type bytes)
 
size_type get_active_size () const
 
size_type get_remaining_space () const
 
size_type get_buffer_size () const
 
void normalize ()
 
void ensure_free_space ()
 
void write (void const *data, std::size_t size)
 
std::vector< uint8_t > && move ()
 
const std::vector< uint8_t > & copy ()
 
MessageBufferoperator= (MessageBuffer const &right)
 
MessageBufferoperator= (MessageBuffer &&right)
 

Public Attributes

uint32_t MAX_BUFFER_LENGTH {1536}
 

Private Types

typedef std::vector< uint8_t >::size_type size_type
 

Private Attributes

size_type _wpos
 
size_type _rpos
 
std::vector< uint8_t > _storage
 

Member Typedef Documentation

◆ size_type

typedef std::vector<uint8_t>::size_type MessageBuffer::size_type
private

Constructor & Destructor Documentation

◆ MessageBuffer() [1/4]

MessageBuffer::MessageBuffer ( )
inline
44 : _wpos(0), _rpos(0), _storage()
45 {
47 }
size_type _rpos
Definition: MessageBuffer.hpp:153
size_type _wpos
Definition: MessageBuffer.hpp:152
std::vector< uint8_t > _storage
Definition: MessageBuffer.hpp:154
uint32_t MAX_BUFFER_LENGTH
Definition: MessageBuffer.hpp:42

References _storage, and MAX_BUFFER_LENGTH.

◆ MessageBuffer() [2/4]

MessageBuffer::MessageBuffer ( std::size_t  initial_size)
inlineexplicit
50 : _wpos(0), _rpos(0), _storage()
51 {
52 _storage.resize(initial_size);
53 }

References _storage.

◆ MessageBuffer() [3/4]

MessageBuffer::MessageBuffer ( MessageBuffer const &  right)
inline
56 : _wpos(right._wpos), _rpos(right._rpos), _storage(right._storage)
57 {
58 }

◆ MessageBuffer() [4/4]

MessageBuffer::MessageBuffer ( MessageBuffer &&  right)
inline
61 : _wpos(right._wpos), _rpos(right._rpos), _storage(right.move())
62 {
63 }
std::vector< uint8_t > && move()
Definition: MessageBuffer.hpp:119

Member Function Documentation

◆ copy()

const std::vector< uint8_t > & MessageBuffer::copy ( )
inline
127{ return _storage; }

References _storage.

◆ ensure_free_space()

void MessageBuffer::ensure_free_space ( )
inline
105 {
106 // resize buffer if it's already full
107 if (get_remaining_space() == 0)
108 _storage.resize(_storage.size() * 3 / 2);
109 }
size_type get_remaining_space() const
Definition: MessageBuffer.hpp:89

References _storage, and get_remaining_space().

+ Here is the call graph for this function:

◆ get_active_size()

size_type MessageBuffer::get_active_size ( ) const
inline
88{ return _wpos - _rpos; }

References _rpos, and _wpos.

Referenced by normalize().

+ Here is the caller graph for this function:

◆ get_base_pointer()

uint8_t * MessageBuffer::get_base_pointer ( )
inline
81{ return _storage.data(); }

References _storage.

Referenced by get_read_pointer(), get_write_pointer(), and normalize().

+ Here is the caller graph for this function:

◆ get_buffer_size()

size_type MessageBuffer::get_buffer_size ( ) const
inline
90{ return _storage.size(); }

References _storage.

◆ get_read_pointer()

uint8_t * MessageBuffer::get_read_pointer ( )
inline
82{ return get_base_pointer() + _rpos; }
uint8_t * get_base_pointer()
Definition: MessageBuffer.hpp:81

References _rpos, and get_base_pointer().

Referenced by normalize(), and to_string().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_remaining_space()

size_type MessageBuffer::get_remaining_space ( ) const
inline
89{ return _storage.size() - _wpos; }

References _storage, and _wpos.

Referenced by ensure_free_space().

+ Here is the caller graph for this function:

◆ get_write_pointer()

uint8_t * MessageBuffer::get_write_pointer ( )
inline
83{ return get_base_pointer() + _wpos; }

References _wpos, and get_base_pointer().

Referenced by to_string(), and write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ move()

std::vector< uint8_t > && MessageBuffer::move ( )
inline
120 {
121 _wpos = 0;
122 _rpos = 0;
123
124 return std::move(_storage);
125 }

References _rpos, _storage, and _wpos.

◆ normalize()

void MessageBuffer::normalize ( )
inline
94 {
95 if (_rpos) {
96 if (_rpos != _wpos)
98 _wpos -= _rpos;
99 _rpos = 0;
100 }
101 }
size_type get_active_size() const
Definition: MessageBuffer.hpp:88
uint8_t * get_read_pointer()
Definition: MessageBuffer.hpp:82

References _rpos, _wpos, get_active_size(), get_base_pointer(), and get_read_pointer().

+ Here is the call graph for this function:

◆ operator=() [1/2]

MessageBuffer & MessageBuffer::operator= ( MessageBuffer &&  right)
inline
141 {
142 if (this != &right) {
143 _wpos = right._wpos;
144 _rpos = right._rpos;
145 _storage = right.move();
146 }
147
148 return *this;
149 }

References _rpos, _storage, and _wpos.

◆ operator=() [2/2]

MessageBuffer & MessageBuffer::operator= ( MessageBuffer const &  right)
inline
130 {
131 if (this != &right) {
132 _wpos = right._wpos;
133 _rpos = right._rpos;
134 _storage = right._storage;
135 }
136
137 return *this;
138 }

References _rpos, _storage, and _wpos.

◆ read_completed()

void MessageBuffer::read_completed ( size_type  bytes)
inline
85{ _rpos += bytes; }

References _rpos.

◆ reset()

void MessageBuffer::reset ( )
inline
66 {
67 _wpos = 0;
68 _rpos = 0;
69 }

References _rpos, and _wpos.

◆ resize()

void MessageBuffer::resize ( size_type  bytes)
inline
72 {
73 _storage.resize(bytes);
74 }

References _storage.

◆ to_string()

std::string MessageBuffer::to_string ( )
inline
77 {
78 return std::string(get_read_pointer(), get_write_pointer());
79 }
uint8_t * get_write_pointer()
Definition: MessageBuffer.hpp:83

References get_read_pointer(), and get_write_pointer().

+ Here is the call graph for this function:

◆ write()

void MessageBuffer::write ( void const *  data,
std::size_t  size 
)
inline
112 {
113 if (size) {
114 memcpy(get_write_pointer(), data, size);
115 write_completed(size);
116 }
117 }
void write_completed(size_type bytes)
Definition: MessageBuffer.hpp:86

References get_write_pointer(), and write_completed().

+ Here is the call graph for this function:

◆ write_completed()

void MessageBuffer::write_completed ( size_type  bytes)
inline
86{ _wpos += bytes; }

References _wpos.

Referenced by write().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _rpos

◆ _storage

std::vector<uint8_t> MessageBuffer::_storage
private

◆ _wpos

◆ MAX_BUFFER_LENGTH

uint32_t MessageBuffer::MAX_BUFFER_LENGTH {1536}

Referenced by MessageBuffer().


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