AlteriomPainlessMesh v2.1.1
Easy ESP32/ESP8266 mesh networking with Alteriom IoT extensions
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
painlessmesh::buffer::SentBuffer< T > Class Template Reference

SentBuffer stores messages (strings) and allows them to be read in any length with priority-based scheduling. More...

#include <buffer.hpp>

Classes

struct  SendStats
 

Public Member Functions

 SentBuffer ()
 
bool push (const T &message, bool priority=false)
 
bool pushWithPriority (const T &message, uint8_t priorityLevel)
 
size_t requestLength (size_t buffer_length)
 
void read (size_t length, temp_buffer_t &buf)
 
const char * readPtr (size_t length)
 
void freeRead ()
 
bool empty ()
 
void clear ()
 
size_t size ()
 
uint8_t getLastReadPriority () const
 
SendStats getStats () const
 

Detailed Description

template<class T>
class painlessmesh::buffer::SentBuffer< T >

SentBuffer stores messages (strings) and allows them to be read in any length with priority-based scheduling.

Constructor & Destructor Documentation

◆ SentBuffer()

template<class T >
painlessmesh::buffer::SentBuffer< T >::SentBuffer ( )
inline

Member Function Documentation

◆ clear()

template<class T >
void painlessmesh::buffer::SentBuffer< T >::clear ( )
inline

◆ empty()

template<class T >
bool painlessmesh::buffer::SentBuffer< T >::empty ( )
inline

◆ freeRead()

template<class T >
void painlessmesh::buffer::SentBuffer< T >::freeRead ( )
inline

Clear the previously read messages from the buffer.

Should be called after a call of read() to clear the buffer.

◆ getLastReadPriority()

template<class T >
uint8_t painlessmesh::buffer::SentBuffer< T >::getLastReadPriority ( ) const
inline

Get priority of the last read message

◆ getStats()

template<class T >
SendStats painlessmesh::buffer::SentBuffer< T >::getStats ( ) const
inline

◆ push()

template<class T >
bool painlessmesh::buffer::SentBuffer< T >::push ( const T &  message,
bool  priority = false 
)
inline

push a message into the buffer with multi-level priority support.

Parameters
messageThe message to queue
priorityWhether this is a high priority message (legacy bool API)
Returns
true if the message was queued, false if the buffer is full and nothing lower-priority could be evicted (issue #388)

Legacy API: High priority messages (true) will be sent to the front of the buffer This maintains backward compatibility with existing code.

◆ pushWithPriority()

template<class T >
bool painlessmesh::buffer::SentBuffer< T >::pushWithPriority ( const T &  message,
uint8_t  priorityLevel 
)
inline

push a message with explicit priority level (0-3)

Parameters
messageThe message to queue
priorityLevelPriority level: 0=CRITICAL, 1=HIGH, 2=NORMAL, 3=LOW
Returns
true if the message was queued, false if the buffer is full and nothing lower-priority could be evicted (issue #388)

Messages are scheduled in priority order. Within same priority, FIFO order is maintained.

The buffer holds at most PAINLESSMESH_MAX_SENT_BUFFER_MESSAGES entries. At the cap, the newest message of a strictly lower priority class is evicted to make room (mirroring MessageQueue::makeSpace(): CRITICAL evicts HIGH/NORMAL/LOW, HIGH evicts NORMAL/LOW, NORMAL evicts LOW, LOW evicts nothing); when no lower-priority message exists the incoming message is rejected. Either way the drop is counted in getStats().dropped.

◆ read()

template<class T >
void painlessmesh::buffer::SentBuffer< T >::read ( size_t  length,
temp_buffer_t &  buf 
)
inline

Read the given length into the passed buffer (copy mode)

Note the user should first make sure the requested length is available using SentBuffer.requestLength(), otherwise this function might fail. Note that if multiple messages are read then they are separated using '\0'.

Performance note: Consider using readPtr() for zero-copy access when possible.

◆ readPtr()

template<class T >
const char * painlessmesh::buffer::SentBuffer< T >::readPtr ( size_t  length)
inline

Returns a pointer directly to the highest priority message

Note the user should first make sure the requested length is available using SentBuffer.requestLength(), otherwise this function might fail. Note that if multiple messages are read then they are separated using '\0'.

◆ requestLength()

template<class T >
size_t painlessmesh::buffer::SentBuffer< T >::requestLength ( size_t  buffer_length)
inline

Request whether the passed length is readable

Returns the actual length available (<= the requested length

◆ size()

template<class T >
size_t painlessmesh::buffer::SentBuffer< T >::size ( )
inline

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