qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::protocol::base::byte_terminated< _IO_, _EndByte > Class Template Reference

Protocol for messages delimited by a specific single byte character. More...

#include <base.h>

Inheritance diagram for qb::protocol::base::byte_terminated< _IO_, _EndByte >:
Collaboration diagram for qb::protocol::base::byte_terminated< _IO_, _EndByte >:

Public Member Functions

 byte_terminated ()=delete
 Default constructor (deleted)
virtual ~byte_terminated ()=default
 Virtual destructor.
 byte_terminated (_IO_ &io) noexcept
 Constructor with I/O reference.
std::size_t shiftSize (std::size_t const size) const noexcept
 Calculates the message size without the delimiter.
std::size_t getMessageSize () noexcept final
 Determines the size of the next complete message.
void reset () noexcept final
 Resets the protocol state.
Public Member Functions inherited from qb::io::async::IProtocol
virtual ~IProtocol ()=default
 Virtual destructor.
bool ok () const noexcept
 Checks if the protocol is in a valid operational state.
void not_ok () noexcept
 Marks the protocol as being in an invalid or non-operational state.
void set_should_flush (bool should_flush) noexcept
 Sets the flag indicating whether the protocol should flush the input buffer after processing a message.
bool should_flush () const noexcept
 Gets the flag indicating whether the protocol should flush the input buffer after processing a message.

Static Public Attributes

static constexpr const std::size_t delimiter_size
 Delimiter size (1 byte)
static constexpr const char end = _EndByte
 End character.

Additional Inherited Members

Protected Member Functions inherited from qb::io::async::AProtocol< _IO_ >
 AProtocol ()=delete
 Default constructor is deleted to ensure an I/O component is always associated.
 AProtocol (_IO_ &io) noexcept
 Constructor that associates the protocol with an I/O component.
virtual ~AProtocol ()=default
 Virtual destructor.
virtual void onMessage (std::size_t size) noexcept=0
 Processes a complete message from the input buffer of the associated I/O component.
Protected Attributes inherited from qb::io::async::AProtocol< _IO_ >
_IO_ & _io
 Reference to the I/O component instance that this protocol is associated with.

Detailed Description

template<typename _IO_, char _EndByte = '\0'>
class qb::protocol::base::byte_terminated< _IO_, _EndByte >

Protocol for messages delimited by a specific single byte character.

This class implements a protocol where messages are framed by a specific termination byte (e.g., '\0' for null-terminated strings, '
' for line-based messages). It inherits from qb::io::async::AProtocol.

Template Parameters
_IO_The I/O component type (e.g., a TCP session class) that will use this protocol. It needs to provide an in() method returning a reference to its input buffer (e.g., qb::allocator::pipe<char>).
_EndByteThe single byte character that marks the end of a message. Defaults to '\0'.

Constructor & Destructor Documentation

◆ byte_terminated()

template<typename _IO_, char _EndByte = '\0'>
qb::protocol::base::byte_terminated< _IO_, _EndByte >::byte_terminated ( _IO_ & io)
inlinenoexcept

Constructor with I/O reference.

Parameters
ioReference to the I/O object that uses this protocol

Member Function Documentation

◆ shiftSize()

template<typename _IO_, char _EndByte = '\0'>
std::size_t qb::protocol::base::byte_terminated< _IO_, _EndByte >::shiftSize ( std::size_t const size) const
inlinenoexcept

Calculates the message size without the delimiter.

Parameters
sizeTotal size including the delimiter
Returns
Message size without the delimiter

◆ getMessageSize()

template<typename _IO_, char _EndByte = '\0'>
std::size_t qb::protocol::base::byte_terminated< _IO_, _EndByte >::getMessageSize ( )
inlinefinalvirtualnoexcept

Determines the size of the next complete message.

Searches for the termination byte in the input buffer.

Returns
Message size if found, 0 otherwise

Implements qb::io::async::AProtocol< _IO_ >.

◆ reset()

template<typename _IO_, char _EndByte = '\0'>
void qb::protocol::base::byte_terminated< _IO_, _EndByte >::reset ( )
inlinefinalvirtualnoexcept

Resets the protocol state.

Implements qb::io::async::AProtocol< _IO_ >.

Member Data Documentation

◆ delimiter_size

template<typename _IO_, char _EndByte = '\0'>
const std::size_t qb::protocol::base::byte_terminated< _IO_, _EndByte >::delimiter_size
staticconstexpr
Initial value:
=
1

Delimiter size (1 byte)